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 27 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< std::pair< std::size_t, double > > 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
 
void resetCurrentTimeStep (const double dt, TimeStep &, TimeStep &) override
 reset the current step size from the previous time
 
- Public Member Functions inherited from NumLib::TimeStepAlgorithm
 TimeStepAlgorithm (const double t0, const double t_end)
 
virtual ~TimeStepAlgorithm ()=default
 
double begin () const
 return the beginning of time steps
 
double 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.
 

Private Attributes

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

Additional Inherited Members

- Protected Attributes inherited from NumLib::TimeStepAlgorithm
const double _t_initial
 initial time
 
const double _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 181 of file FixedTimeStepping.cpp.

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

147 : TimeStepAlgorithm(t0, tn)
148{
149 double t_curr = _t_initial;
150
151 for (auto const& [repeat, delta_t] : repeat_dt_pairs)
152 {
153 if (repeat == 0)
154 {
155 OGS_FATAL("<repeat> is zero.");
156 }
157 if (delta_t <= 0.0)
158 {
159 OGS_FATAL("timestep <delta_t> is <= 0.0.");
160 }
161
162 if (t_curr <= _t_end)
163 {
164 t_curr = addTimeIncrement(_dt_vector, repeat, delta_t, t_curr);
165 }
166 }
167
168 // append last delta_t until t_end is reached
169 if (t_curr <= _t_end)
170 {
171 auto const delta_t = repeat_dt_pairs.back().second;
172 auto const repeat =
173 static_cast<std::size_t>(std::ceil((_t_end - t_curr) / delta_t));
174 addTimeIncrement(_dt_vector, repeat, delta_t, t_curr);
175 }
176
178 fixed_times_for_output);
179}
const double _t_initial
initial time
const double _t_end
end time
void incorporateFixedTimesForOutput(double const t_initial, double const t_end, std::vector< double > &delta_ts, std::vector< double > const &fixed_times_for_output)
double addTimeIncrement(std::vector< double > &delta_ts, std::size_t const repeat, double const delta_t, double const t_curr)
Returns sum of the newly added time increments.

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

Member Function Documentation

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

216{
217 // check if last time step
218 if (ts_current.timeStepNumber() == _dt_vector.size() ||
219 std::abs(ts_current.current() - end()) <
220 std::numeric_limits<double>::epsilon())
221 {
222 return std::make_tuple(false, 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}
double end() const
return the end of time steps
double current() const
return current time step
Definition TimeStep.h:90
std::size_t timeStepNumber() const
the time step number
Definition TimeStep.h:94

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

◆ resetCurrentTimeStep()

void NumLib::FixedTimeStepping::resetCurrentTimeStep ( const double dt,
TimeStep & ,
TimeStep &  )
inlineoverridevirtual

reset the current step size from the previous time

Reimplemented from NumLib::TimeStepAlgorithm.

Definition at line 59 of file FixedTimeStepping.h.

61 {
62 _dt_vector.push_back(dt);
63 }

References _dt_vector.

Member Data Documentation

◆ _dt_vector

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

a vector of time step sizes

Definition at line 67 of file FixedTimeStepping.h.

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


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