Chi-Tech
TimeStepper.h
Go to the documentation of this file.
1#ifndef CHITECH_TIMESTEPPER_H
2#define CHITECH_TIMESTEPPER_H
3
4#include "ChiObject.h"
5
6namespace chi_physics
7{
8
9enum class TimeStepStatus
10{
11 SUCCESS = 0,
12 FAILURE = 1,
13 NEUTRAL = 2
14};
15
16/**Base class for all timestep controllers.*/
17class TimeStepper : public ChiObject
18{
19public:
20 /**Overridable method to get the timestep size.*/
21 double TimeStepSize() const;
22
23 /**Returns the current controller time.*/
24 double Time() const;
25
26 /**Returns the current time index.*/
27 size_t TimeStepIndex() const;
28
29 /**Returns the current controller start_time.*/
30 double StartTime() const;
31
32 /**Returns the current controller end_time.*/
33 double EndTime() const;
34
35 /**Returns the current controller max time steps.*/
36 double MaxTimeSteps() const;
37
38 /**If start_time <= time <= end_time, this will return true.*/
39 bool IsActive() const;
40
41
42 /**Manually set the time step size.*/
43 void SetTimeStepSize(double dt);
44
45 /**Manually set the current time.*/
46 void SetTime(double time);
47
48 /**Manually set the start_time.*/
49 void SetStartTime(double time);
50
51 /**Manually set the end_time.*/
52 void SetEndTime(double time);
53
54 /**Manually set the maximum number of time steps. A negative number disables
55* this check.*/
56 void SetMaxTimeSteps(int n);
57
58 /**Manually sets the minimum time step size.*/
59 void SetMinimumTimeStepSize(double dt_min);
60
61 /**Advances the controller's state. The most basic action here is to
62 * advance time and the time index.*/
63 virtual void Advance();
64
65 /**Adapts according to the timestep status. If it could provide a change
66 * it returns true, otherwise false.*/
67 virtual bool Adapt(TimeStepStatus time_step_status) {return false;}
68
69 /**Builds a formatted string of the time information.*/
70 std::string StringTimeInfo(bool old_time=false) const;
71
72protected:
74 explicit TimeStepper(const chi::InputParameters& params);
75
76 double dt_;
77 double time_;
78 size_t t_index_;
79
81 double end_time_;
83 double dt_min_;
84
85 const double general_tolerance_;
86 /**Last dt before finishing.*/
87 double last_dt_;
88};
89
90}
91
92#endif // CHITECH_TIMESTEPPER_H
double MaxTimeSteps() const
Definition: TimeStepper.cc:64
static chi::InputParameters GetInputParameters()
Definition: TimeStepper.cc:8
void SetEndTime(double time)
Definition: TimeStepper.cc:94
virtual void Advance()
Definition: TimeStepper.cc:110
void SetTime(double time)
Definition: TimeStepper.cc:88
void SetTimeStepSize(double dt)
Definition: TimeStepper.cc:80
const double general_tolerance_
Definition: TimeStepper.h:85
double TimeStepSize() const
Definition: TimeStepper.cc:49
virtual bool Adapt(TimeStepStatus time_step_status)
Definition: TimeStepper.h:67
double EndTime() const
Definition: TimeStepper.cc:61
void SetMinimumTimeStepSize(double dt_min)
Definition: TimeStepper.cc:105
TimeStepper(const chi::InputParameters &params)
Definition: TimeStepper.cc:32
void SetStartTime(double time)
Definition: TimeStepper.cc:91
size_t TimeStepIndex() const
Definition: TimeStepper.cc:55
std::string StringTimeInfo(bool old_time=false) const
Definition: TimeStepper.cc:122
double StartTime() const
Definition: TimeStepper.cc:58