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: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_TimeStepControl_decl_hpp
10 #define Tempus_TimeStepControl_decl_hpp
11 
12 #include <iostream>
13 #include <iterator>
14 #include <sstream>
15 
16 #include "Teuchos_VerboseObject.hpp"
17 #include "Teuchos_Describable.hpp"
18 
19 #include "Tempus_config.hpp"
20 #include "Tempus_SolutionHistory.hpp"
22 
23 
24 namespace Tempus {
25 
48 template<class Scalar>
49 class TimeStepControl
50  : virtual public Teuchos::Describable,
51  virtual public Teuchos::VerboseObject<Tempus::TimeStepControl<Scalar> >
52 {
53 public:
54 
57 
60  Scalar initTime,
61  Scalar finalTime,
62  Scalar minTimeStep,
63  Scalar initTimeStep,
64  Scalar maxTimeStep,
65  int initIndex,
66  int finalIndex,
67  Scalar maxAbsError,
68  Scalar maxRelError,
69  int maxFailures,
70  int maxConsecFailures,
71  int numTimeSteps,
72  bool printDtChanges,
73  bool outputExactly,
74  std::vector<int> outputIndices,
75  std::vector<Scalar> outputTimes,
76  int outputIndexInterval,
77  Scalar outputTimeInterval,
78  Teuchos::RCP<TimeStepControlStrategy<Scalar>> stepControlStrategy);
79 
81  virtual ~TimeStepControl() {}
82 
83 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
84  virtual void getNextTimeStep(
87  Status & integratorStatus)
88  {
89  this->setNextTimeStep(sh, integratorStatus);
90  };
91 #endif
92 
94  virtual void setNextTimeStep(
95  const Teuchos::RCP<SolutionHistory<Scalar> > & solutionHistory,
96  Status & integratorStatus);
97 
99  virtual bool timeInRange(const Scalar time) const;
100 
102  virtual bool indexInRange(const int iStep) const;
103 
106 
108 
109  std::string description() const;
111  const Teuchos::EVerbosityLevel verbLevel) const;
113 
115 
116  virtual std::string getStepType() const { return stepControlStrategy_->getStepType(); }
117  virtual Scalar getInitTime() const { return initTime_; }
118  virtual Scalar getFinalTime() const { return finalTime_; }
119  virtual Scalar getMinTimeStep() const { return minTimeStep_; }
120  virtual Scalar getInitTimeStep() const { return initTimeStep_; }
121  virtual Scalar getMaxTimeStep() const { return maxTimeStep_; }
122  virtual int getInitIndex() const { return initIndex_; }
123  virtual int getFinalIndex() const { return finalIndex_; }
124  virtual Scalar getMaxAbsError() const { return maxAbsError_; }
125  virtual Scalar getMaxRelError() const { return maxRelError_; }
126  virtual bool getOutputExactly() const { return outputExactly_; }
127  virtual std::vector<int> getOutputIndices() const { return outputIndices_; }
128  virtual std::vector<Scalar> getOutputTimes() const { return outputTimes_; }
129  virtual int getMaxFailures() const { return maxFailures_; }
130  virtual int getMaxConsecFailures() const { return maxConsecFailures_; }
131  virtual bool getPrintDtChanges() const { return printDtChanges_; }
132  virtual int getNumTimeSteps() const { return numTimeSteps_; }
133 
136  virtual int getOutputIndexInterval() const { return outputIndexInterval_;}
137  virtual Scalar getOutputTimeInterval() const { return outputTimeInterval_;}
139 
141 
142  virtual void setInitTime(Scalar t) { initTime_ = t; isInitialized_ = false; }
143  virtual void setFinalTime(Scalar t) { finalTime_ = t; isInitialized_ = false; }
144  virtual void setMinTimeStep(Scalar t) { minTimeStep_ = t; isInitialized_ = false; }
145  virtual void setInitTimeStep(Scalar t) { initTimeStep_ = t; isInitialized_ = false; }
146  virtual void setMaxTimeStep(Scalar t) { maxTimeStep_ = t; isInitialized_ = false; }
147  virtual void setInitIndex(int i) { initIndex_ = i; isInitialized_ = false; }
148  virtual void setFinalIndex(int i) { finalIndex_ = i; isInitialized_ = false; }
149  virtual void setMaxAbsError(Scalar e) { maxAbsError_ = e; isInitialized_ = false; }
150  virtual void setMaxRelError(Scalar e) { maxRelError_ = e; isInitialized_ = false; }
151  virtual void setMaxFailures(int i) { maxFailures_ = i; isInitialized_ = false; }
152  virtual void setMaxConsecFailures(int i) { maxConsecFailures_ = i; isInitialized_ = false; }
153  virtual void setPrintDtChanges(bool b) { printDtChanges_ = b; isInitialized_ = false; }
154  virtual void setNumTimeSteps(int numTimeSteps);
155 
156  virtual void setOutputExactly(bool b) { outputExactly_ = b; isInitialized_ = false; }
157  virtual void setOutputIndices(std::vector<int> v) { outputIndices_ = v; isInitialized_ = false; }
158  virtual void setOutputTimes(std::vector<Scalar> v) { outputTimes_ = v; isInitialized_ = false; }
159  virtual void setOutputIndexInterval(int i) { outputIndexInterval_ = i; isInitialized_ = false; }
160  virtual void setOutputTimeInterval(Scalar t) { outputTimeInterval_ = t; isInitialized_ = false; }
161 
162  virtual void setTimeStepControlStrategy(
163  Teuchos::RCP<TimeStepControlStrategy<Scalar> > tscs = Teuchos::null);
165 
166  virtual void printDtChanges(int istep, Scalar dt_old, Scalar dt_new,
167  std::string reason) const;
168 
169  virtual void initialize() const;
170  virtual bool isInitialized() { return isInitialized_; }
171  virtual void checkInitialized();
172 
173 protected:
174 
175  mutable bool isInitialized_;
176  Scalar initTime_;
177  Scalar finalTime_;
178  Scalar minTimeStep_;
179  Scalar initTimeStep_;
180  Scalar maxTimeStep_;
183  Scalar maxAbsError_;
184  Scalar maxRelError_;
189 
191  std::vector<int> outputIndices_;
192  std::vector<Scalar> outputTimes_;
195 
197  Scalar dtAfterOutput_;
198 
200 
201 };
202 
203 
205 // ------------------------------------------------------------------------
206 template<class Scalar>
209  bool runInitialize = true);
210 
212 template<class Scalar>
214 {
215  auto tsc = rcp(new Tempus::TimeStepControl<Scalar>());
216  return Teuchos::rcp_const_cast<Teuchos::ParameterList> (tsc->getValidParameters());
217 }
218 
219 
220 } // namespace Tempus
221 
222 #endif // Tempus_TimeStepControl_decl_hpp
Teuchos::RCP< TimeStepControl< Scalar > > createTimeStepControl(Teuchos::RCP< Teuchos::ParameterList > const &pList, bool runInitialize=true)
Nonmember constructor from ParameterList.
virtual int getOutputIndexInterval() const
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
virtual void setOutputIndices(std::vector< int > v)
Scalar maxAbsError_
Maximum Absolute Error.
virtual Teuchos::RCP< TimeStepControlStrategy< Scalar > > getTimeStepControlStrategy() const
bool outputExactly_
Output Exactly On Output Times.
virtual Scalar getInitTimeStep() const
virtual void printDtChanges(int istep, Scalar dt_old, Scalar dt_new, std::string reason) const
virtual Scalar getOutputTimeInterval() const
Scalar maxRelError_
Maximum Relative Error.
virtual void setOutputTimes(std::vector< Scalar > v)
Teuchos::RCP< Teuchos::ParameterList > getTimeStepControlPL()
Nonmember function to return ParameterList with default values.
virtual std::vector< Scalar > getOutputTimes() const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< TimeStepControlStrategy< Scalar > > stepControlStrategy_
virtual void setTimeStepControlStrategy(Teuchos::RCP< TimeStepControlStrategy< Scalar > > tscs=Teuchos::null)
Status
Status for the Integrator, the Stepper and the SolutionState.
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.
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 setOutputTimeInterval(Scalar t)
virtual void setNextTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory, Status &integratorStatus)
Determine the time step size.
int maxFailures_
Maximum Number of Stepper Failures.
virtual void getNextTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &sh, Status &integratorStatus)
Deprecated get the time step size.
Scalar dtAfterOutput_
dt to reinstate after output step.
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
std::vector< Scalar > outputTimes_
Vector of output times.
virtual std::vector< int > getOutputIndices() const
virtual void setInitTimeStep(Scalar t)
int maxConsecFailures_
Maximum Number of Consecutive Stepper Failures.
std::vector< int > outputIndices_
Vector of output indices.
TimeStepControlStrategy class for TimeStepControl.
virtual Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return ParameterList with current values.
bool outputAdjustedDt_
Flag indicating that dt was adjusted for output.
virtual std::string getStepType() const