Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros 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 // Teuchos
13 #include "Teuchos_VerboseObject.hpp"
14 #include "Teuchos_Describable.hpp"
15 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
16 // Tempus
17 #include "Tempus_config.hpp"
18 #include "Tempus_SolutionHistory.hpp"
20 
21 #include <iostream>
22 #include <iterator>
23 #include <sstream>
24 
25 
26 namespace Tempus {
27 
28 /** \brief TimeStepControl manages the time step size.
29  * There several mechanicisms that effect the time step size and
30  * handled with this class:
31  * - Maximum and minimum time
32  * - Maximum and minimum time index
33  * - Maximum and minimum time step size
34  * - Maximum and minimum error
35  * - Maximum and minimum order
36  * - Startup considerations (e.g., ramping)
37  * - Solution and/or diagnostic output
38  * Additional step control can be added through the step control observer,
39  * or inheriting from this class.
40  * - Stability limits (e.g., CFL number)
41  */
42 template<class Scalar>
43 class TimeStepControl
44  : virtual public Teuchos::Describable,
45  virtual public Teuchos::ParameterListAcceptor,
46  virtual public Teuchos::VerboseObject<Tempus::TimeStepControl<Scalar> >
47 {
48 public:
49 
50  /// Constructor
51  TimeStepControl(Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null);
52 
53  /// Destructor
54  virtual ~TimeStepControl() {}
55 
56  virtual void initialize(Teuchos::RCP<Teuchos::ParameterList> pList =
57  Teuchos::null) { this->setParameterList(pList); }
58 
59  /** \brief Determine the time step size.*/
60  virtual void getNextTimeStep(
61  const Teuchos::RCP<SolutionHistory<Scalar> > & solutionHistory,
62  Status & integratorStatus);
63 
64  /** \brief Check if time is within minimum and maximum time. */
65  virtual bool timeInRange(const Scalar time) const;
66 
67  /** \brief Check if time step index is within minimum and maximum index. */
68  virtual bool indexInRange(const int iStep) const;
69 
70  /** \brief Set the TimeStepControlStrategy. */
71  virtual void setTimeStepControlStrategy(
72  Teuchos::RCP<TimeStepControlStrategy<Scalar> > tscs = Teuchos::null);
73 
74  /// \name Overridden from Teuchos::ParameterListAccepto{}
75  //@{
76  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl);
77  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
78  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
79  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
80  //@}
81 
82  /// \name Overridden from Teuchos::Describable
83  //@{
84  std::string description() const;
85  void describe(Teuchos::FancyOStream &out,
86  const Teuchos::EVerbosityLevel verbLevel) const;
87  //@}
88 
89  /// \name Get ParameterList values
90  //@{
91  virtual Scalar getInitTime() const
92  { return tscPL_->get<double>("Initial Time"); }
93  virtual Scalar getFinalTime() const
94  { return tscPL_->get<double>("Final Time"); }
95  virtual Scalar getMinTimeStep() const
96  { return tscPL_->get<double>("Minimum Time Step"); }
97  virtual Scalar getInitTimeStep() const
98  { return tscPL_->get<double>("Initial Time Step"); }
99  virtual Scalar getMaxTimeStep() const
100  { return tscPL_->get<double>("Maximum Time Step"); }
101  virtual int getInitIndex() const
102  { return tscPL_->get<int> ("Initial Time Index"); }
103  virtual int getFinalIndex() const
104  { return tscPL_->get<int> ("Final Time Index"); }
105  virtual Scalar getMaxAbsError() const
106  { return tscPL_->get<double>("Maximum Absolute Error"); }
107  virtual Scalar getMaxRelError() const
108  { return tscPL_->get<double>("Maximum Relative Error"); }
109  virtual int getMinOrder() const
110  { return tscPL_->get<int> ("Minimum Order"); }
111  virtual int getInitOrder() const
112  { return tscPL_->get<int> ("Initial Order"); }
113  virtual int getMaxOrder() const
114  { return tscPL_->get<int> ("Maximum Order"); }
115  virtual std::string getStepType() const
116  { return tscPL_->get<std::string>("Integrator Step Type"); }
117  virtual bool getOutputExactly() const
118  { return tscPL_->get<bool>("Output Exactly On Output Times"); }
119  virtual std::vector<int> getOutputIndices() const
120  { return outputIndices_; }
121  virtual std::vector<Scalar> getOutputTimes() const
122  { return outputTimes_; }
123  virtual int getMaxFailures() const
124  { return tscPL_->get<int>("Maximum Number of Stepper Failures"); }
125  virtual int getMaxConsecFailures() const
126  { return tscPL_->
127  get<int>("Maximum Number of Consecutive Stepper Failures"); }
128  virtual int getNumTimeSteps() const
129  { return tscPL_->get<int>("Number of Time Steps"); }
130  virtual Teuchos::RCP<TimeStepControlStrategyComposite<Scalar>>
133  { return outputIndexInterval_;}
134  virtual double getOutputTimeInterval()
135  { return outputTimeInterval_;}
136  //@}
137 
138  /// \name Set ParameterList values
139  //@{
140  virtual void setInitTime(Scalar InitTime)
141  { tscPL_->set<double>("Initial Time" , InitTime ); }
142  virtual void setFinalTime(Scalar FinalTime)
143  { tscPL_->set<double>("Final Time" , FinalTime ); }
144  virtual void setMinTimeStep(Scalar MinTimeStep)
145  { tscPL_->set<double>("Minimum Time Step" , MinTimeStep ); }
146  virtual void setInitTimeStep(Scalar InitTimeStep)
147  { tscPL_->set<double>("Initial Time Step" , InitTimeStep); }
148  virtual void setMaxTimeStep(Scalar MaxTimeStep)
149  { tscPL_->set<double>("Maximum Time Step" , MaxTimeStep ); }
150  virtual void setInitIndex(int InitIndex)
151  { tscPL_->set<int> ("Initial Time Index" , InitIndex ); }
152  virtual void setFinalIndex(int FinalIndex)
153  { tscPL_->set<int> ("Final Time Index" , FinalIndex ); }
154  virtual void setMaxAbsError(Scalar MaxAbsError)
155  { tscPL_->set<double>("Maximum Absolute Error" , MaxAbsError ); }
156  virtual void setMaxRelError(Scalar MaxRelError)
157  { tscPL_->set<double>("Maximum Relative Error" , MaxRelError ); }
158  virtual void setMinOrder(int MinOrder)
159  { tscPL_->set<int> ("Minimum Order" , MinOrder ); }
160  virtual void setInitOrder(int InitOrder)
161  { tscPL_->set<int> ("Initial Order" , InitOrder ); }
162  virtual void setMaxOrder(int MaxOrder)
163  { tscPL_->set<int> ("Maximum Order" , MaxOrder ); }
164  virtual void setStepType(std::string StepType)
165  { tscPL_->set<std::string>("Integrator Step Type", StepType ); }
166  virtual void setOutputExactly(bool OutputExactly)
167  { tscPL_->get<bool>("Output Exactly On Output Times", OutputExactly); }
168  virtual void setOutputIndices(std::vector<int> OutputIndices)
169  { outputIndices_ = OutputIndices;
170  std::ostringstream ss;
171  std::copy(OutputIndices.begin(), OutputIndices.end()-1,
172  std::ostream_iterator<int>(ss, ","));
173  ss << OutputIndices.back();
174  tscPL_->set<std::string>("Output Index List", ss.str());
175  }
176  virtual void setOutputTimes(std::vector<Scalar> OutputTimes)
177  {
178  outputTimes_ = OutputTimes;
179  std::ostringstream ss;
180  ss << std::setprecision(16);
181  if (!outputTimes_.empty()) {
182  for (size_t i=0; i < outputTimes_.size()-1; ++i)
183  ss << outputTimes_[i] << ",";
184  ss << outputTimes_[outputTimes_.size()-1];
185  }
186  tscPL_->set<std::string>("Output Time List", ss.str());
187  }
188  virtual void setMaxFailures(int MaxFailures)
189  { tscPL_->set<int>("Maximum Number of Stepper Failures", MaxFailures); }
190  virtual void setMaxConsecFailures(int MaxConsecFailures)
191  { tscPL_->set<int>
192  ("Maximum Number of Consecutive Stepper Failures", MaxConsecFailures); }
193  virtual void setNumTimeSteps(int numTimeSteps);
194  virtual void setOutputIndexInterval(int OutputIndexInterval)
195  { tscPL_->set<int>("Output Index Interval",OutputIndexInterval);
196  outputIndexInterval_ = OutputIndexInterval; }
197  virtual void setOutputTimeInterval(double OutputTimeInterval)
198  { tscPL_->set<double>("Output Time Interval",OutputTimeInterval);
199  outputTimeInterval_ = OutputTimeInterval; }
200  virtual void setPrintDtChanges(bool printDtChanges)
201  { printDtChanges_ = printDtChanges; }
202  virtual bool getPrintDtChanges() const { return printDtChanges_; }
203  //@}
204 
205 protected:
206 
207  Teuchos::RCP<Teuchos::ParameterList> tscPL_;
208 
209  std::vector<int> outputIndices_; ///< Vector of output indices.
210  std::vector<Scalar> outputTimes_; ///< Vector of output times.
213 
214  bool outputAdjustedDt_; ///< Flag indicating that dt was adjusted for output.
215  Scalar dtAfterOutput_; ///< dt to reinstate after output step.
216 
217  Teuchos::RCP<TimeStepControlStrategyComposite<Scalar>> stepControlStrategy_;
218 
220 
221 };
222 } // namespace Tempus
223 
224 #endif // Tempus_TimeStepControl_decl_hpp
virtual Teuchos::RCP< TimeStepControlStrategyComposite< Scalar > > getTimeStepControlStrategy() const
virtual void setOutputTimes(std::vector< Scalar > OutputTimes)
virtual void setPrintDtChanges(bool printDtChanges)
virtual void setInitTimeStep(Scalar InitTimeStep)
virtual void setFinalTime(Scalar FinalTime)
virtual void setOutputExactly(bool OutputExactly)
virtual void setNumTimeSteps(int numTimeSteps)
virtual Scalar getMaxRelError() const
Teuchos::RCP< TimeStepControlStrategyComposite< Scalar > > stepControlStrategy_
virtual ~TimeStepControl()
Destructor.
virtual void getNextTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory, Status &integratorStatus)
Determine the time step size.
virtual void setFinalIndex(int FinalIndex)
virtual Scalar getFinalTime() const
virtual void setInitIndex(int InitIndex)
virtual void setMaxFailures(int MaxFailures)
virtual void setMinTimeStep(Scalar MinTimeStep)
virtual Scalar getInitTimeStep() const
virtual void setOutputTimeInterval(double OutputTimeInterval)
virtual void setMaxOrder(int MaxOrder)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
virtual void setStepType(std::string StepType)
virtual std::vector< Scalar > getOutputTimes() const
virtual void initialize(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
virtual void setMaxTimeStep(Scalar MaxTimeStep)
virtual void setTimeStepControlStrategy(Teuchos::RCP< TimeStepControlStrategy< Scalar > > tscs=Teuchos::null)
Set the TimeStepControlStrategy.
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
virtual void setMaxConsecFailures(int MaxConsecFailures)
Teuchos::RCP< Teuchos::ParameterList > tscPL_
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual Scalar getMaxTimeStep() const
virtual Scalar getMinTimeStep() const
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
virtual void setOutputIndexInterval(int OutputIndexInterval)
Scalar dtAfterOutput_
dt to reinstate after output step.
virtual void setMinOrder(int MinOrder)
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 void setMaxAbsError(Scalar MaxAbsError)
virtual std::vector< int > getOutputIndices() const
virtual void setOutputIndices(std::vector< int > OutputIndices)
virtual void setMaxRelError(Scalar MaxRelError)
virtual void setInitTime(Scalar InitTime)
std::vector< int > outputIndices_
Vector of output indices.
StepControlStrategy class for TimeStepControl.
virtual Scalar getInitTime() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
bool outputAdjustedDt_
Flag indicating that dt was adjusted for output.
virtual void setInitOrder(int InitOrder)
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
TimeStepControl(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Constructor.
virtual std::string getStepType() const