OGS
NumLib::TimeStepAlgorithm Class Referenceabstract

Detailed Description

Interface of time stepping algorithms.

Definition at line 27 of file TimeStepAlgorithm.h.

#include <TimeStepAlgorithm.h>

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

Public Member Functions

 TimeStepAlgorithm (const double t0, const double t_end)
 
 TimeStepAlgorithm (const double t0, const double t_end, const double dt)
 
 TimeStepAlgorithm (const double t0, const double t_end, const std::vector< double > &all_step_sizes)
 
virtual ~TimeStepAlgorithm ()=default
 
double begin () const
 return the beginning of time steps More...
 
double end () const
 return the end of time steps More...
 
const TimeStep getTimeStep () const
 return current time step More...
 
void resetCurrentTimeStep (const double dt)
 reset the current step size from the previous time More...
 
virtual std::tuple< bool, double > next (const double solution_error, int number_iterations)=0
 
virtual bool accepted () const =0
 return if current time step is accepted or not More...
 
virtual void setAcceptedOrNot (const bool accepted)
 
const std::vector< double > & getTimeStepSizeHistory () const
 return a history of time step sizes More...
 
virtual bool isSolutionErrorComputationNeeded () const
 
virtual bool canReduceTimestepSize () const
 Query the timestepper if further time step size reduction is possible. More...
 

Protected Attributes

const double _t_initial
 initial time More...
 
const double _t_end
 end time More...
 
TimeStep _ts_prev
 previous time step information More...
 
TimeStep _ts_current
 current time step information More...
 
std::vector< double > _dt_vector
 a vector of time step sizes More...
 

Constructor & Destructor Documentation

◆ TimeStepAlgorithm() [1/3]

NumLib::TimeStepAlgorithm::TimeStepAlgorithm ( const double  t0,
const double  t_end 
)
inline

Definition at line 30 of file TimeStepAlgorithm.h.

31  : _t_initial(t0), _t_end(t_end), _ts_prev(t0), _ts_current(t0)
32  {
33  }
const double _t_initial
initial time
TimeStep _ts_current
current time step information
TimeStep _ts_prev
previous time step information
const double _t_end
end time

◆ TimeStepAlgorithm() [2/3]

NumLib::TimeStepAlgorithm::TimeStepAlgorithm ( const double  t0,
const double  t_end,
const double  dt 
)
inline

Definition at line 35 of file TimeStepAlgorithm.h.

36  : _t_initial(t0), _t_end(t_end), _ts_prev(t0), _ts_current(t0)
37  {
38  auto const new_size =
39  static_cast<std::size_t>(std::ceil((t_end - t0) / dt));
40  try
41  {
42  _dt_vector = std::vector<double>(new_size, dt);
43  }
44  catch (std::length_error const& e)
45  {
46  OGS_FATAL(
47  "Resize of the time steps vector failed for the requested new "
48  "size {:d}. Probably there is not enough memory ({:g} GiB "
49  "requested).\n"
50  "Thrown exception: {:s}",
51  new_size, new_size * sizeof(double) / 1024. / 1024. / 1024.,
52  e.what());
53  }
54  catch (std::bad_alloc const& e)
55  {
56  OGS_FATAL(
57  "Allocation of the time steps vector failed for the requested "
58  "size {:d}. Probably there is not enough memory ({:d} GiB "
59  "requested).\n"
60  "Thrown exception: {:s}",
61  new_size,
62  new_size * sizeof(double) / 1024. / 1024. / 1024.,
63  e.what());
64  }
65  }
#define OGS_FATAL(...)
Definition: Error.h:26
std::vector< double > _dt_vector
a vector of time step sizes

References _dt_vector, and OGS_FATAL.

◆ TimeStepAlgorithm() [3/3]

NumLib::TimeStepAlgorithm::TimeStepAlgorithm ( const double  t0,
const double  t_end,
const std::vector< double > &  all_step_sizes 
)
inline

Definition at line 67 of file TimeStepAlgorithm.h.

69  : _t_initial(t0),
70  _t_end(t_end),
71  _ts_prev(t0),
72  _ts_current(t0),
73  _dt_vector(all_step_sizes)
74  {
75  }

◆ ~TimeStepAlgorithm()

virtual NumLib::TimeStepAlgorithm::~TimeStepAlgorithm ( )
virtualdefault

Member Function Documentation

◆ accepted()

virtual bool NumLib::TimeStepAlgorithm::accepted ( ) const
pure virtual

return if current time step is accepted or not

Implemented in NumLib::IterationNumberBasedTimeStepping, NumLib::FixedTimeStepping, and NumLib::EvolutionaryPIDcontroller.

Referenced by setAcceptedOrNot().

◆ begin()

double NumLib::TimeStepAlgorithm::begin ( ) const
inline

return the beginning of time steps

Definition at line 80 of file TimeStepAlgorithm.h.

80 { return _t_initial; }

References _t_initial.

◆ canReduceTimestepSize()

virtual bool NumLib::TimeStepAlgorithm::canReduceTimestepSize ( ) const
inlinevirtual

Query the timestepper if further time step size reduction is possible.

Reimplemented in NumLib::IterationNumberBasedTimeStepping, and NumLib::EvolutionaryPIDcontroller.

Definition at line 120 of file TimeStepAlgorithm.h.

120 { return false; }

◆ end()

double NumLib::TimeStepAlgorithm::end ( ) const
inline

return the end of time steps

Definition at line 82 of file TimeStepAlgorithm.h.

82 { return _t_end; }

References _t_end.

◆ getTimeStep()

const TimeStep NumLib::TimeStepAlgorithm::getTimeStep ( ) const
inline

return current time step

Definition at line 84 of file TimeStepAlgorithm.h.

84 { return _ts_current; }

References _ts_current.

◆ getTimeStepSizeHistory()

const std::vector<double>& NumLib::TimeStepAlgorithm::getTimeStepSizeHistory ( ) const
inline

return a history of time step sizes

Definition at line 110 of file TimeStepAlgorithm.h.

111  {
112  return _dt_vector;
113  }

References _dt_vector.

◆ isSolutionErrorComputationNeeded()

virtual bool NumLib::TimeStepAlgorithm::isSolutionErrorComputationNeeded ( ) const
inlinevirtual

Get a flag to indicate whether this algorithm needs to compute solution error. The default return value is false.

Reimplemented in NumLib::IterationNumberBasedTimeStepping, and NumLib::EvolutionaryPIDcontroller.

Definition at line 117 of file TimeStepAlgorithm.h.

117 { return false; }

◆ next()

virtual std::tuple<bool, double> NumLib::TimeStepAlgorithm::next ( const double  solution_error,
int  number_iterations 
)
pure virtual

Move to the next time step

Parameters
solution_errorSolution error \(e_n\) between two successive time steps.
number_iterationsNumber of non-linear iterations used.
Returns
A step acceptance flag and the computed step size.

Implemented in NumLib::IterationNumberBasedTimeStepping, NumLib::FixedTimeStepping, and NumLib::EvolutionaryPIDcontroller.

◆ resetCurrentTimeStep()

void NumLib::TimeStepAlgorithm::resetCurrentTimeStep ( const double  dt)
inline

reset the current step size from the previous time

Definition at line 86 of file TimeStepAlgorithm.h.

87  {
89  _ts_current += dt;
90  _dt_vector.push_back(dt);
91  }

References _dt_vector, _ts_current, and _ts_prev.

◆ setAcceptedOrNot()

virtual void NumLib::TimeStepAlgorithm::setAcceptedOrNot ( const bool  accepted)
inlinevirtual

Set the status of the step.

Parameters
acceptedA boolean parameter is needed to indicated whether the step is accepted or not.

Reimplemented in NumLib::EvolutionaryPIDcontroller, and NumLib::IterationNumberBasedTimeStepping.

Definition at line 107 of file TimeStepAlgorithm.h.

107 { (void)accepted; };
virtual bool accepted() const =0
return if current time step is accepted or not

References accepted().

Member Data Documentation

◆ _dt_vector

std::vector<double> NumLib::TimeStepAlgorithm::_dt_vector
protected

a vector of time step sizes

Definition at line 134 of file TimeStepAlgorithm.h.

Referenced by TimeStepAlgorithm(), getTimeStepSizeHistory(), NumLib::FixedTimeStepping::next(), and resetCurrentTimeStep().

◆ _t_end

const double NumLib::TimeStepAlgorithm::_t_end
protected

end time

Definition at line 126 of file TimeStepAlgorithm.h.

Referenced by end(), and NumLib::FixedTimeStepping::next().

◆ _t_initial

const double NumLib::TimeStepAlgorithm::_t_initial
protected

initial time

Definition at line 124 of file TimeStepAlgorithm.h.

Referenced by begin().

◆ _ts_current

◆ _ts_prev


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