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  /// This is a copy constructor
54  TimeStepControl(const TimeStepControl<Scalar>& tsc);
55 
56  /// Destructor
57  virtual ~TimeStepControl() {}
58 
59  virtual void initialize(Teuchos::RCP<Teuchos::ParameterList> pList =
60  Teuchos::null) { this->setParameterList(pList); }
61 
62  /** \brief Determine the time step size.*/
63  virtual void getNextTimeStep(
64  const Teuchos::RCP<SolutionHistory<Scalar> > & solutionHistory,
65  Status & integratorStatus);
66 
67  /** \brief Check if time is within minimum and maximum time. */
68  virtual bool timeInRange(const Scalar time) const;
69 
70  /** \brief Check if time step index is within minimum and maximum index. */
71  virtual bool indexInRange(const int iStep) const;
72 
73  /** \brief Set the TimeStepControlStrategy. */
74  virtual void setTimeStepControlStrategy(
75  Teuchos::RCP<TimeStepControlStrategy<Scalar> > tscs = Teuchos::null);
76 
77  /// \name Overridden from Teuchos::ParameterListAccepto{}
78  //@{
79  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl);
80  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
81  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
82  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
83  //@}
84 
85  /// \name Overridden from Teuchos::Describable
86  //@{
87  std::string description() const;
88  void describe(Teuchos::FancyOStream &out,
89  const Teuchos::EVerbosityLevel verbLevel) const;
90  //@}
91 
92  /// \name Get ParameterList values
93  //@{
94  virtual Scalar getInitTime() const
95  { return tscPL_->get<double>("Initial Time"); }
96  virtual Scalar getFinalTime() const
97  { return tscPL_->get<double>("Final Time"); }
98  virtual Scalar getMinTimeStep() const
99  { return tscPL_->get<double>("Minimum Time Step"); }
100  virtual Scalar getInitTimeStep() const
101  { return tscPL_->get<double>("Initial Time Step"); }
102  virtual Scalar getMaxTimeStep() const
103  { return tscPL_->get<double>("Maximum Time Step"); }
104  virtual int getInitIndex() const
105  { return tscPL_->get<int> ("Initial Time Index"); }
106  virtual int getFinalIndex() const
107  { return tscPL_->get<int> ("Final Time Index"); }
108  virtual Scalar getMaxAbsError() const
109  { return tscPL_->get<double>("Maximum Absolute Error"); }
110  virtual Scalar getMaxRelError() const
111  { return tscPL_->get<double>("Maximum Relative Error"); }
112  virtual int getMinOrder() const
113  { return tscPL_->get<int> ("Minimum Order"); }
114  virtual int getInitOrder() const
115  { return tscPL_->get<int> ("Initial Order"); }
116  virtual int getMaxOrder() const
117  { return tscPL_->get<int> ("Maximum Order"); }
118  virtual std::string getStepType() const
119  { return tscPL_->get<std::string>("Integrator Step Type"); }
120  virtual bool getOutputExactly() const
121  { return tscPL_->get<bool>("Output Exactly On Output Times"); }
122  virtual std::vector<int> getOutputIndices() const
123  { return outputIndices_; }
124  virtual std::vector<Scalar> getOutputTimes() const
125  { return outputTimes_; }
126  virtual int getMaxFailures() const
127  { return tscPL_->get<int>("Maximum Number of Stepper Failures"); }
128  virtual int getMaxConsecFailures() const
129  { return tscPL_->
130  get<int>("Maximum Number of Consecutive Stepper Failures"); }
131  virtual int getNumTimeSteps() const
132  { return tscPL_->get<int>("Number of Time Steps"); }
133  virtual Teuchos::RCP<TimeStepControlStrategyComposite<Scalar>>
135  //@}
136 
137  /// \name Set ParameterList values
138  //@{
139  virtual void setInitTime(Scalar InitTime)
140  { tscPL_->set<double>("Initial Time" , InitTime ); }
141  virtual void setFinalTime(Scalar FinalTime)
142  { tscPL_->set<double>("Final Time" , FinalTime ); }
143  virtual void setMinTimeStep(Scalar MinTimeStep)
144  { tscPL_->set<double>("Minimum Time Step" , MinTimeStep ); }
145  virtual void setInitTimeStep(Scalar InitTimeStep)
146  { tscPL_->set<double>("Initial Time Step" , InitTimeStep); }
147  virtual void setMaxTimeStep(Scalar MaxTimeStep)
148  { tscPL_->set<double>("Maximum Time Step" , MaxTimeStep ); }
149  virtual void setInitIndex(int InitIndex)
150  { tscPL_->set<int> ("Initial Time Index" , InitIndex ); }
151  virtual void setFinalIndex(int FinalIndex)
152  { tscPL_->set<int> ("Final Time Index" , FinalIndex ); }
153  virtual void setMaxAbsError(Scalar MaxAbsError)
154  { tscPL_->set<double>("Maximum Absolute Error" , MaxAbsError ); }
155  virtual void setMaxRelError(Scalar MaxRelError)
156  { tscPL_->set<double>("Maximum Relative Error" , MaxRelError ); }
157  virtual void setMinOrder(int MinOrder)
158  { tscPL_->set<int> ("Minimum Order" , MinOrder ); }
159  virtual void setInitOrder(int InitOrder)
160  { tscPL_->set<int> ("Initial Order" , InitOrder ); }
161  virtual void setMaxOrder(int MaxOrder)
162  { tscPL_->set<int> ("Maximum Order" , MaxOrder ); }
163  virtual void setStepType(std::string StepType)
164  { tscPL_->set<std::string>("Integrator Step Type", StepType ); }
165  virtual void setOutputExactly(bool OutputExactly)
166  { tscPL_->get<bool>("Output Exactly On Output Times", OutputExactly); }
167  virtual void setOutputIndices(std::vector<int> OutputIndices)
168  { outputIndices_ = OutputIndices;
169  std::ostringstream ss;
170  std::copy(OutputIndices.begin(), OutputIndices.end()-1,
171  std::ostream_iterator<int>(ss, ","));
172  ss << OutputIndices.back();
173  tscPL_->set<std::string>("Output Index List", ss.str());
174  }
175  virtual void setOutputTimes(std::vector<Scalar> OutputTimes)
176  { outputTimes_ = OutputTimes;
177  std::ostringstream ss;
178  if (!outputTimes_.empty())
179  { std::copy(OutputTimes.begin(), OutputTimes.end()-1,
180  std::ostream_iterator<Scalar>(ss, ","));
181  ss << OutputTimes.back();
182  }
183  tscPL_->set<std::string>("Output Time List", ss.str());
184  }
185  virtual void setMaxFailures(int MaxFailures)
186  { tscPL_->set<int>("Maximum Number of Stepper Failures", MaxFailures); }
187  virtual void setMaxConsecFailures(int MaxConsecFailures)
188  { tscPL_->set<int>
189  ("Maximum Number of Consecutive Stepper Failures", MaxConsecFailures); }
190  virtual void setNumTimeSteps(int numTimeSteps);
191  virtual void setOutputIndexInterval(int OutputIndexInterval)
192  { tscPL_->set<int>("Output Index Interval",OutputIndexInterval); }
193  virtual void setOutputTimeInterval(double OutputTimeInterval)
194  { tscPL_->set<double>("Output Time Interval",OutputTimeInterval); }
195  //@}
196 
197 protected:
198 
199  Teuchos::RCP<Teuchos::ParameterList> tscPL_;
200 
201  std::vector<int> outputIndices_; ///< Vector of output indices.
202  std::vector<Scalar> outputTimes_; ///< Vector of output times.
203 
204  bool outputAdjustedDt_; ///< Flag indicating that dt was adjusted for output.
205  Scalar dtAfterOutput_; ///< dt to reinstate after output step.
206 
207  Teuchos::RCP<TimeStepControlStrategyComposite<Scalar>> stepControlStrategy_;
208 
209 };
210 } // namespace Tempus
211 
212 #endif // Tempus_TimeStepControl_decl_hpp
virtual Teuchos::RCP< TimeStepControlStrategyComposite< Scalar > > getTimeStepControlStrategy() const
virtual void setOutputTimes(std::vector< Scalar > OutputTimes)
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_
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
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