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 182 of file FixedTimeStepping.cpp.

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

153 : TimeStepAlgorithm(t0, tn)
154{
155 Time t_curr = _t_initial;
156
157 if (!areRepeatDtPairsValid(repeat_dt_pairs))
158 {
159 OGS_FATAL("FixedTimeStepping: Couldn't construct object from data");
160 }
161 for (auto const& [repeat, delta_t] : repeat_dt_pairs)
162 {
163 if (t_curr <= _t_end)
164 {
165 t_curr = addTimeIncrement(_dt_vector, repeat, delta_t, t_curr);
166 }
167 }
168
169 // append last delta_t until t_end is reached
170 if (t_curr <= _t_end)
171 {
172 auto const delta_t = std::get<1>(repeat_dt_pairs.back());
173 auto const repeat = static_cast<std::size_t>(
174 std::ceil((_t_end() - t_curr()) / delta_t));
175 addTimeIncrement(_dt_vector, repeat, delta_t, t_curr);
176 }
177
179 fixed_times_for_output);
180}
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 234 of file FixedTimeStepping.cpp.

236{
237 if (repeat_dt_pairs.empty())
238 {
239 return false;
240 }
241
242 for (auto const& [repeat, delta_t] : repeat_dt_pairs)
243 {
244 if (repeat == 0)
245 {
246 ERR("FixedTimeStepping: <repeat> is zero.");
247 return false;
248 }
249 if (delta_t <= 0.0)
250 {
251 ERR("FixedTimeStepping: timestep <delta_t> is <= 0.0.");
252 return false;
253 }
254 }
255 return true;
256}
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 214 of file FixedTimeStepping.cpp.

217{
218 // check if last time step
219 if (ts_current.timeStepNumber() == _dt_vector.size() ||
220 ts_current.current() >= end())
221 {
222 return std::make_tuple(true, 0.0);
223 }
224
225 double dt = _dt_vector[ts_current.timeStepNumber()];
226 if (ts_current.current() + dt > end())
227 { // upper bound by t_end
228 dt = end()() - ts_current.current()();
229 }
230
231 return std::make_tuple(true, dt);
232}
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: