Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_TimeStepControl_decl.hpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
10 #ifndef Tempus_TimeStepControl_decl_hpp
11 #define Tempus_TimeStepControl_decl_hpp
12 
13 #include <iostream>
14 #include <iterator>
15 #include <sstream>
16 
17 #include "Teuchos_VerboseObject.hpp"
18 #include "Teuchos_Describable.hpp"
19 
20 #include "Tempus_config.hpp"
21 #include "Tempus_SolutionHistory.hpp"
24 
25 namespace Tempus {
26 
49 template <class Scalar>
50 class TimeStepControl
51  : virtual public Teuchos::Describable,
52  virtual public Teuchos::VerboseObject<Tempus::TimeStepControl<Scalar>> {
53  public:
56 
59  Scalar initTime, Scalar finalTime, Scalar minTimeStep,
60  Scalar initTimeStep, Scalar maxTimeStep, int initIndex, int finalIndex,
61  Scalar maxAbsError, Scalar maxRelError, int maxFailures,
62  int maxConsecFailures, int numTimeSteps, bool printDtChanges,
63  bool outputExactly, std::vector<int> outputIndices,
64  std::vector<Scalar> outputTimes, int outputIndexInterval,
65  Scalar outputTimeInterval,
66  Teuchos::RCP<TimeEventComposite<Scalar>> timeEvent,
67  Teuchos::RCP<TimeStepControlStrategy<Scalar>> stepControlStrategy);
68 
70  virtual ~TimeStepControl() {}
71 
73  virtual void setNextTimeStep(
74  const Teuchos::RCP<SolutionHistory<Scalar>>& solutionHistory,
75  Status& integratorStatus);
76 
78  virtual bool timeInRange(const Scalar time) const;
79 
81  virtual bool indexInRange(const int iStep) const;
82 
85 
87 
88  std::string description() const;
90  const Teuchos::EVerbosityLevel verbLevel) const;
92 
94 
95  virtual std::string getStepType() const;
96  virtual Scalar getInitTime() const { return initTime_; }
97  virtual Scalar getFinalTime() const { return finalTime_; }
98  virtual Scalar getMinTimeStep() const { return minTimeStep_; }
99  virtual Scalar getInitTimeStep() const { return initTimeStep_; }
100  virtual Scalar getMaxTimeStep() const { return maxTimeStep_; }
101  virtual int getInitIndex() const { return initIndex_; }
102  virtual int getFinalIndex() const { return finalIndex_; }
103  virtual Scalar getMaxAbsError() const { return maxAbsError_; }
104  virtual Scalar getMaxRelError() const { return maxRelError_; }
105 
114  virtual bool getOutputExactly() const;
115 
116  virtual std::vector<int> getOutputIndices() const;
117  virtual std::vector<Scalar> getOutputTimes() const;
118  virtual int getOutputIndexInterval() const;
119  virtual Scalar getOutputTimeInterval() const;
120  virtual int getMaxFailures() const { return maxFailures_; }
121  virtual int getMaxConsecFailures() const { return maxConsecFailures_; }
122  virtual bool getPrintDtChanges() const { return printDtChanges_; }
123  virtual int getNumTimeSteps() const { return numTimeSteps_; }
125  {
126  return timeEvent_;
127  }
130  {
131  return stepControlStrategy_;
132  }
134 
136 
137  virtual void setInitTime(Scalar t)
138  {
139  initTime_ = t;
140  isInitialized_ = false;
141  }
142  virtual void setFinalTime(Scalar t)
143  {
144  finalTime_ = t;
145  isInitialized_ = false;
146  }
147  virtual void setMinTimeStep(Scalar t)
148  {
149  minTimeStep_ = t;
150  isInitialized_ = false;
151  }
152  virtual void setInitTimeStep(Scalar t)
153  {
154  initTimeStep_ = t;
155  isInitialized_ = false;
156  }
157  virtual void setMaxTimeStep(Scalar t)
158  {
159  maxTimeStep_ = t;
160  isInitialized_ = false;
161  }
162  virtual void setInitIndex(int i)
163  {
164  initIndex_ = i;
165  isInitialized_ = false;
166  }
167  virtual void setFinalIndex(int i)
168  {
169  finalIndex_ = i;
170  isInitialized_ = false;
171  }
172  virtual void setMaxAbsError(Scalar e)
173  {
174  maxAbsError_ = e;
175  isInitialized_ = false;
176  }
177  virtual void setMaxRelError(Scalar e)
178  {
179  maxRelError_ = e;
180  isInitialized_ = false;
181  }
182  virtual void setMaxFailures(int i)
183  {
184  maxFailures_ = i;
185  isInitialized_ = false;
186  }
187  virtual void setMaxConsecFailures(int i)
188  {
189  maxConsecFailures_ = i;
190  isInitialized_ = false;
191  }
192  virtual void setPrintDtChanges(bool b)
193  {
194  printDtChanges_ = b;
195  isInitialized_ = false;
196  }
197  virtual void setNumTimeSteps(int numTimeSteps);
198  virtual void setOutputExactly(bool b);
199  virtual void setOutputIndices(std::vector<int> v);
200  virtual void setOutputTimes(std::vector<Scalar> outputTimes);
201  virtual void setOutputIndexInterval(int i);
202  virtual void setOutputTimeInterval(Scalar t);
203  virtual void setTimeEvents(
204  Teuchos::RCP<TimeEventComposite<Scalar>> teb = Teuchos::null);
205  virtual void setTimeStepControlStrategy(
206  Teuchos::RCP<TimeStepControlStrategy<Scalar>> tscs = Teuchos::null);
208 
209  virtual void printDtChanges(int istep, Scalar dt_old, Scalar dt_new,
210  std::string reason) const;
211 
212  virtual void initialize() const;
213  virtual bool isInitialized() { return isInitialized_; }
214  virtual void checkInitialized();
215 
216  protected:
217  mutable bool isInitialized_;
218  Scalar initTime_;
219  Scalar finalTime_;
220  Scalar minTimeStep_;
221  Scalar initTimeStep_;
222  Scalar maxTimeStep_;
225  Scalar maxAbsError_;
226  Scalar maxRelError_;
231 
233 
236 
238 };
239 
241 // ------------------------------------------------------------------------
242 template <class Scalar>
245  bool runInitialize = true);
246 
248 template <class Scalar>
250 {
251  auto tsc = rcp(new Tempus::TimeStepControl<Scalar>());
252  return Teuchos::rcp_const_cast<Teuchos::ParameterList>(
253  tsc->getValidParameters());
254 }
255 
256 } // namespace Tempus
257 
258 #endif // Tempus_TimeStepControl_decl_hpp
virtual void setTimeEvents(Teuchos::RCP< TimeEventComposite< Scalar >> teb=Teuchos::null)
Teuchos::RCP< TimeStepControl< Scalar > > createTimeStepControl(Teuchos::RCP< Teuchos::ParameterList > const &pList, bool runInitialize=true)
Nonmember constructor from ParameterList.
int numTimeSteps_
Number of time steps for Constant time step.
Scalar maxTimeStep_
Maximum Time Step.
bool isInitialized_
Bool if TimeStepControl is initialized.
virtual void setNumTimeSteps(int numTimeSteps)
virtual Scalar getMaxRelError() const
virtual ~TimeStepControl()
Destructor.
virtual Scalar getFinalTime() const
Scalar maxAbsError_
Maximum Absolute Error.
virtual Teuchos::RCP< TimeStepControlStrategy< Scalar > > getTimeStepControlStrategy() const
Scalar dtAfterTimeEvent_
dt to reinstate after TimeEvent step.
virtual Scalar getInitTimeStep() const
virtual void printDtChanges(int istep, Scalar dt_old, Scalar dt_new, std::string reason) const
Teuchos::RCP< TimeEventComposite< Scalar > > timeEvent_
Scalar maxRelError_
Maximum Relative Error.
Teuchos::RCP< Teuchos::ParameterList > getTimeStepControlPL()
Nonmember function to return ParameterList with default values.
virtual void setOutputTimes(std::vector< Scalar > outputTimes)
virtual void setTimeStepControlStrategy(Teuchos::RCP< TimeStepControlStrategy< Scalar >> tscs=Teuchos::null)
virtual std::string getStepType() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< TimeStepControlStrategy< Scalar > > stepControlStrategy_
Status
Status for the Integrator, the Stepper and the SolutionState.
bool teAdjustedDt_
Flag indicating that dt was adjusted for time event.
This composite TimeEvent loops over added TimeEvents.
virtual bool indexInRange(const int iStep) const
Check if time step index is within minimum and maximum index.
virtual Scalar getMaxAbsError() const
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
Scalar initTimeStep_
Initial Time Step.
TimeStepControl()
Default Constructor.
Scalar minTimeStep_
Minimum Time Step.
virtual void setOutputTimeInterval(Scalar t)
bool printDtChanges_
Print timestep size when it changes.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual Scalar getMaxTimeStep() const
virtual Scalar getMinTimeStep() const
virtual void setNextTimeStep(const Teuchos::RCP< SolutionHistory< Scalar >> &solutionHistory, Status &integratorStatus)
Determine the time step size.
int maxFailures_
Maximum Number of Stepper Failures.
virtual bool timeInRange(const Scalar time) const
Check if time is within minimum and maximum time.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual int getOutputIndexInterval() const
virtual Scalar getOutputTimeInterval() const
virtual bool getOutputExactly() const
Return if the output needs to exactly happen on output time.
virtual void setInitTimeStep(Scalar t)
int maxConsecFailures_
Maximum Number of Consecutive Stepper Failures.
TimeStepControlStrategy class for TimeStepControl.
virtual Scalar getInitTime() const
virtual void setOutputIndices(std::vector< int > v)
virtual std::vector< Scalar > getOutputTimes() const
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return ParameterList with current values.
virtual std::vector< int > getOutputIndices() const
virtual Teuchos::RCP< TimeEventComposite< Scalar > > getTimeEvents() const