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 20 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)
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 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 175 of file FixedTimeStepping.cpp.

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

References NumLib::TimeStepAlgorithm::TimeStepAlgorithm(), _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 143 of file FixedTimeStepping.cpp.

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

230{
231 if (repeat_dt_pairs.empty())
232 {
233 return false;
234 }
235
236 for (auto const& [repeat, delta_t] : repeat_dt_pairs)
237 {
238 if (repeat == 0)
239 {
240 ERR("FixedTimeStepping: <repeat> is zero.");
241 return false;
242 }
243 if (delta_t <= 0.0)
244 {
245 ERR("FixedTimeStepping: timestep <delta_t> is <= 0.0.");
246 return false;
247 }
248 }
249 return true;
250}
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40

References ERR().

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

◆ next()

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
the computed step size.

Implements NumLib::TimeStepAlgorithm.

Definition at line 207 of file FixedTimeStepping.cpp.

211{
212 // check if last time step
213 if (ts_current.timeStepNumber() == _dt_vector.size() ||
214 ts_current.current() >= end())
215 {
216 return 0.0;
217 }
218
219 double dt = _dt_vector[ts_current.timeStepNumber()];
220 if (ts_current.current() + dt > end())
221 { // upper bound by t_end
222 dt = end()() - ts_current.current()();
223 }
224
225 return dt;
226}
Time end() const
return the end of time steps
Time current() const
return current time step
Definition TimeStep.h:71
std::size_t timeStepNumber() const
the time step number
Definition TimeStep.h:75

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 55 of file FixedTimeStepping.h.

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


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