Loading web-font TeX/Main/Regular
OGS
NumLib::FixedTimeStepping Class Referencefinal

Detailed Description

Fixed time stepping algorithm.

This algorithm returns time step size defined by a user priori.

Definition at line 29 of file FixedTimeStepping.h.

#include <FixedTimeStepping.h>

Inheritance diagram for NumLib::FixedTimeStepping:
[legend]
Collaboration diagram for NumLib::FixedTimeStepping:
[legend]

Public Member Functions

 FixedTimeStepping (double t0, double t_end, double dt)
 
 FixedTimeStepping (double t0, double tn, std::vector< RepeatDtPair > const &repeat_dt_pairs, std::vector< double > const &fixed_times_for_output)
 
std::tuple< bool, double > next (double solution_error, int number_iterations, NumLib::TimeStep &ts_previous, NumLib::TimeStep &ts_current) override
 
- Public Member Functions inherited from NumLib::TimeStepAlgorithm
 TimeStepAlgorithm (const double t0, const double t_end)
 
virtual ~TimeStepAlgorithm ()=default
 
Time begin () const
 return the beginning of time steps
 
Time end () const
 return the end of time steps
 
virtual void resetCurrentTimeStep (const double, TimeStep &, TimeStep &)
 reset the current step size from the previous time
 
virtual bool isSolutionErrorComputationNeeded () const
 
virtual bool canReduceTimestepSize (NumLib::TimeStep const &, NumLib::TimeStep const &) const
 Query the timestepper if further time step size reduction is possible.
 

Static Public Member Functions

static bool areRepeatDtPairsValid (std::vector< RepeatDtPair > const &repeat_dt_pairs)
 

Private Attributes

std::vector< double > _dt_vector
 a vector of time step sizes
 

Additional Inherited Members

- Protected Attributes inherited from NumLib::TimeStepAlgorithm
const Time _t_initial
 initial time
 
const Time _t_end
 end time
 

Constructor & Destructor Documentation

◆ FixedTimeStepping() [1/2]

NumLib::FixedTimeStepping::FixedTimeStepping ( double t0,
double t_end,
double dt )

Constructor with homogeneous time step size

A user provides a single time step size \Delta t. Total number of time steps is calculated by

n=\frac{t_{\rm n} - t_0}{\Delta t}

.

Parameters
t0start time
t_endend time
dtuniform time step size

Definition at line 184 of file FixedTimeStepping.cpp.

185 : TimeStepAlgorithm(t0, t_end)
186{
187 auto const new_size =
188 static_cast<std::size_t>(std::ceil((t_end - t0) / dt));
189 try
190 {
191 _dt_vector = std::vector<double>(new_size, dt);
192 }
193 catch (std::length_error const& e)
194 {
195 OGS_FATAL(
196 "Resize of the time steps vector failed for the requested new "
197 "size {}. Probably there is not enough memory ({:g} GiB "
198 "requested).\n"
199 "Thrown exception: {}",
200 new_size, new_size * sizeof(double) / 1024. / 1024. / 1024.,
201 e.what());
202 }
203 catch (std::bad_alloc const& e)
204 {
205 OGS_FATAL(
206 "Allocation of the time steps vector failed for the requested "
207 "size {}. Probably there is not enough memory ({:g} GiB "
208 "requested).\n"
209 "Thrown exception: {}",
210 new_size,
211 new_size * sizeof(double) / 1024. / 1024. / 1024.,
212 e.what());
213 }
214}
#define OGS_FATAL(...)
Definition Error.h:26
std::vector< double > _dt_vector
a vector of time step sizes
TimeStepAlgorithm(const double t0, const double t_end)

References _dt_vector, and OGS_FATAL.

◆ FixedTimeStepping() [2/2]

NumLib::FixedTimeStepping::FixedTimeStepping ( double t0,
double tn,
std::vector< RepeatDtPair > const & repeat_dt_pairs,
std::vector< double > const & fixed_times_for_output )

Constructor with user-specified time step sizes including additional time steps for output.

Definition at line 152 of file FixedTimeStepping.cpp.

155 : TimeStepAlgorithm(t0, tn)
156{
157 Time t_curr = _t_initial;
158
159 if (!areRepeatDtPairsValid(repeat_dt_pairs))
160 {
161 OGS_FATAL("FixedTimeStepping: Couldn't construct object from data");
162 }
163 for (auto const& [repeat, delta_t] : repeat_dt_pairs)
164 {
165 if (t_curr <= _t_end)
166 {
167 t_curr = addTimeIncrement(_dt_vector, repeat, delta_t, t_curr);
168 }
169 }
170
171 // append last delta_t until t_end is reached
172 if (t_curr <= _t_end)
173 {
174 auto const delta_t = std::get<1>(repeat_dt_pairs.back());
175 auto const repeat = static_cast<std::size_t>(
176 std::ceil((_t_end() - t_curr()) / delta_t));
177 addTimeIncrement(_dt_vector, repeat, delta_t, t_curr);
178 }
179
181 fixed_times_for_output);
182}
static bool areRepeatDtPairsValid(std::vector< RepeatDtPair > const &repeat_dt_pairs)
const Time _t_initial
initial time
void incorporateFixedTimesForOutput(NumLib::Time const t_initial, NumLib::Time const t_end, std::vector< double > &delta_ts, std::vector< double > const &fixed_times_for_output)
NumLib::Time addTimeIncrement(std::vector< double > &delta_ts, std::size_t const repeat, double const delta_t, NumLib::Time const t_curr)
Returns sum of the newly added time increments.

References _dt_vector, NumLib::TimeStepAlgorithm::_t_end, NumLib::TimeStepAlgorithm::_t_initial, areRepeatDtPairsValid(), NumLib::incorporateFixedTimesForOutput(), and OGS_FATAL.

Member Function Documentation

◆ areRepeatDtPairsValid()

bool NumLib::FixedTimeStepping::areRepeatDtPairsValid ( std::vector< RepeatDtPair > const & repeat_dt_pairs)
static

Definition at line 236 of file FixedTimeStepping.cpp.

238{
239 if (repeat_dt_pairs.empty())
240 {
241 return false;
242 }
243
244 for (auto const& [repeat, delta_t] : repeat_dt_pairs)
245 {
246 if (repeat == 0)
247 {
248 ERR("FixedTimeStepping: <repeat> is zero.");
249 return false;
250 }
251 if (delta_t <= 0.0)
252 {
253 ERR("FixedTimeStepping: timestep <delta_t> is <= 0.0.");
254 return false;
255 }
256 }
257 return true;
258}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45

References ERR().

Referenced by FixedTimeStepping(), and NumLib::createFixedTimeStepping().

◆ next()

std::tuple< bool, double > NumLib::FixedTimeStepping::next ( double solution_error,
int number_iterations,
NumLib::TimeStep & ts_previous,
NumLib::TimeStep & ts_current )
overridevirtual

Move to the next time step

Parameters
solution_errorSolution error e_n between two successive time steps.
number_iterationsNumber of non-linear iterations used.
ts_previousthe previous time step used to compute the size of the next step
ts_currentthe current time step used to compute the size of the next step
Returns
A step acceptance flag and the computed step size.

Implements NumLib::TimeStepAlgorithm.

Definition at line 216 of file FixedTimeStepping.cpp.

219{
220 // check if last time step
221 if (ts_current.timeStepNumber() == _dt_vector.size() ||
222 ts_current.current() >= end())
223 {
224 return std::make_tuple(true, 0.0);
225 }
226
227 double dt = _dt_vector[ts_current.timeStepNumber()];
228 if (ts_current.current() + dt > end())
229 { // upper bound by t_end
230 dt = end()() - ts_current.current()();
231 }
232
233 return std::make_tuple(true, dt);
234}
Time end() const
return the end of time steps
Time current() const
return current time step
Definition TimeStep.h:78
std::size_t timeStepNumber() const
the time step number
Definition TimeStep.h:82

References _dt_vector, NumLib::TimeStep::current(), NumLib::TimeStepAlgorithm::end(), and NumLib::TimeStep::timeStepNumber().

Member Data Documentation

◆ _dt_vector

std::vector<double> NumLib::FixedTimeStepping::_dt_vector
private

a vector of time step sizes

Definition at line 64 of file FixedTimeStepping.h.

Referenced by FixedTimeStepping(), FixedTimeStepping(), and next().


The documentation for this class was generated from the following files: