Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_IntegratorBasic_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_IntegratorBasic_decl_hpp
10 #define Tempus_IntegratorBasic_decl_hpp
11 
12 // Teuchos
13 #include "Teuchos_VerboseObject.hpp"
14 #include "Teuchos_Describable.hpp"
15 #include "Teuchos_ParameterList.hpp"
16 #include "Teuchos_Time.hpp"
17 // Thyra
18 #include "Thyra_ModelEvaluator.hpp"
19 #include "Thyra_NonlinearSolverBase.hpp"
20 // Tempus
21 #include "Tempus_Stepper.hpp"
22 #include "Tempus_Integrator.hpp"
23 #include "Tempus_TimeStepControl.hpp"
24 #include "Tempus_IntegratorObserverBasic.hpp"
25 #include "Tempus_IntegratorObserverComposite.hpp"
26 
27 #include <string>
28 
29 namespace Tempus {
30 
31 
32 /** \brief Basic time integrator
33  */
34 template<class Scalar>
35 class IntegratorBasic : virtual public Tempus::Integrator<Scalar>
36 {
37 public:
38 
39  /// Constructor with ParameterList and model, and will be fully initialized.
41  Teuchos::RCP<Teuchos::ParameterList> pList,
42  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
43 
44  /// Constructor with model and "Stepper Type" and is fully initialized with default settings.
46  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
47  std::string stepperType);
48 
49  /// Constructor that requires a subsequent setParameterList, setStepper, and initialize calls.
51 
52  /// Constructor with ParameterList and models, and will be fully initialized.
54  Teuchos::RCP<Teuchos::ParameterList> pList,
55  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models);
56 
57  /// Destructor
58  virtual ~IntegratorBasic() {}
59 
60  /// \name Basic integrator methods
61  //@{
62  /// Advance the solution to timeMax, and return true if successful.
63  virtual bool advanceTime();
64  /// Advance the solution to timeFinal, and return true if successful.
65  virtual bool advanceTime(const Scalar timeFinal) override;
66  /// Perform tasks before start of integrator.
67  virtual void startIntegrator();
68  /// Start time step.
69  virtual void startTimeStep();
70  /// Check if time step has passed or failed.
71  virtual void checkTimeStep();
72  /// Perform tasks after end of integrator.
73  virtual void endIntegrator();
74  /// Return a copy of the Tempus ParameterList
75  virtual Teuchos::RCP<Teuchos::ParameterList> getTempusParameterList()
76  override { return tempusPL_; }
77  virtual void setTempusParameterList(
78  Teuchos::RCP<Teuchos::ParameterList> pl) override
79  {
80  if (tempusPL_==Teuchos::null) tempusPL_=Teuchos::parameterList("Tempus");
81  if (pl != Teuchos::null) *tempusPL_ = *pl;
82  this->setParameterList(Teuchos::null);
83  }
84  //@}
85 
86  /// \name Accessor methods
87  //@{
88  /// Get current time
89  virtual Scalar getTime() const override
90  {return solutionHistory_->getCurrentTime();}
91  /// Get current index
92  virtual int getIndex() const override
93  {return solutionHistory_->getCurrentIndex();}
94  /// Get Status
95  virtual Status getStatus() const override
96  {return integratorStatus_;}
97  /// Get the Stepper
98  virtual Teuchos::RCP<Stepper<Scalar> > getStepper() const override
99  {return stepper_;}
100  /// Set the Stepper
101  virtual void setStepper(Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model);
102  /// Set the Stepper
103  virtual void setStepper(
104  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models);
105  /// Set the Stepper
106  virtual void setStepperWStepper(Teuchos::RCP<Stepper<Scalar> > stepper);
107  /// Set the initial state which has the initial conditions
108  virtual void initializeSolutionHistory(
109  Teuchos::RCP<SolutionState<Scalar> > state = Teuchos::null);
110  /// Set the initial state from Thyra::VectorBase(s)
111  virtual void initializeSolutionHistory(Scalar t0,
112  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x0,
113  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot0 = Teuchos::null,
114  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot0 = Teuchos::null);
115  /// Get the SolutionHistory
116  virtual Teuchos::RCP<const SolutionHistory<Scalar> > getSolutionHistory() const override
117  {return solutionHistory_;}
118  /// Set the SolutionHistory
119  virtual void setSolutionHistory(
120  Teuchos::RCP<SolutionHistory<Scalar> > sh = Teuchos::null);
121  /// Get the TimeStepControl
122  virtual Teuchos::RCP<const TimeStepControl<Scalar> > getTimeStepControl() const override
123  {return timeStepControl_;}
124  virtual Teuchos::RCP<TimeStepControl<Scalar> > getNonConstTimeStepControl() override
125  {return timeStepControl_;}
126  /// Set the TimeStepControl
127  virtual void setTimeStepControl(
128  Teuchos::RCP<TimeStepControl<Scalar> > tsc = Teuchos::null);
129  /// Get the Observer
130  virtual Teuchos::RCP<IntegratorObserverComposite<Scalar> > getObserver()
131  {return integratorObserver_;}
132  /// Set the Observer
133  virtual void setObserver(
134  Teuchos::RCP<IntegratorObserver<Scalar> > obs = Teuchos::null);
135  /// Initializes the Integrator after set* function calls
136  virtual void initialize();
137  //TODO: finish this
138  /// Returns the IntegratorTimer_ for this Integrator
139  virtual Teuchos::RCP<Teuchos::Time> getIntegratorTimer() const override
140  { return integratorTimer_;}
141  virtual Teuchos::RCP<Teuchos::Time> getStepperTimer() const override
142  { return stepperTimer_;}
143 
144  /// Get current the solution, x
145  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getX() const
146  {return solutionHistory_->getCurrentState()->getX();}
147  /// Get current the time derivative of the solution, xdot
148  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getXdot() const
149  {return solutionHistory_->getCurrentState()->getXDot();}
150  /// Get current the second time derivative of the solution, xdotdot
151  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getXdotdot() const
152  {return solutionHistory_->getCurrentState()->getXDotDot();}
153 
154  /// Get current state
155  virtual Teuchos::RCP<SolutionState<Scalar> > getCurrentState()
156  {return solutionHistory_->getCurrentState();}
157 
158  Teuchos::RCP<Teuchos::ParameterList> getIntegratorParameterList()
159  { return integratorPL_; }
160 
161  //virtual Teuchos::RCP<Teuchos::Time> getIntegratorTimer() const
162  //{return integratorTimer_;}
163 
164  virtual void setScreenOutputIndexInterval(int i)
165  { integratorPL_->set("Screen Output Index Interval", i); }
166 
167  virtual int getScreenOutputIndexInterval() const
168  { return integratorPL_->get<int>("Screen Output Index Interval"); }
169 
170  virtual void setScreenOutputIndexList(std::string s)
171  { integratorPL_->set("Screen Output Index List", s); }
172 
173  virtual std::string getScreenOutputIndexList() const
174  { return integratorPL_->get<std::string>("Screen Output Index List", ""); }
175  //@}
176 
177  /// Parse when screen output should be executed
178  void parseScreenOutput();
179 
180  /// \name Overridden from Teuchos::ParameterListAcceptor
181  //@{
182  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl)
183  override;
184  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList() override;
185  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList() override;
186  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
187  const override;
188  //@}
189 
190  /// \name Overridden from Teuchos::Describable
191  //@{
192  std::string description() const override;
193  void describe(Teuchos::FancyOStream & out,
194  const Teuchos::EVerbosityLevel verbLevel) const override;
195  //@}
196 
197 protected:
198 
199  Teuchos::RCP<Teuchos::ParameterList> tempusPL_;
200  Teuchos::RCP<Teuchos::ParameterList> integratorPL_;
201  Teuchos::RCP<SolutionHistory<Scalar> > solutionHistory_;
202  Teuchos::RCP<TimeStepControl<Scalar> > timeStepControl_;
203  Teuchos::RCP<IntegratorObserverComposite<Scalar> > integratorObserver_;
204  Teuchos::RCP<Stepper<Scalar> > stepper_;
205 
206  Teuchos::RCP<Teuchos::Time> integratorTimer_;
207  Teuchos::RCP<Teuchos::Time> stepperTimer_;
208  Scalar runtime_;
209 
210  std::vector<int> outputScreenIndices_; ///< Vector of screen output indices.
211 
212  /** The integratorStatus is primarily in the WORKING Status, and
213  * PASSED/FAILED are noted at the end of the run. A FAILED value
214  * is used to jump out of the time-integration loop.
215  */
218 };
219 
220 /// Non-member constructor
221 template<class Scalar>
222 Teuchos::RCP<IntegratorBasic<Scalar> > integratorBasic(
223  Teuchos::RCP<Teuchos::ParameterList> pList,
224  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
225 
226 /// Non-member constructor
227 template<class Scalar>
228 Teuchos::RCP<IntegratorBasic<Scalar> > integratorBasic(
229  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
230  std::string stepperType);
231 
232 /// Non-member constructor
233 template<class Scalar>
234 Teuchos::RCP<IntegratorBasic<Scalar> > integratorBasic();
235 
236 /// Non-member constructor
237 template<class Scalar>
238 Teuchos::RCP<IntegratorBasic<Scalar> > integratorBasic(
239  Teuchos::RCP<Teuchos::ParameterList> pList,
240  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models);
241 
242 
243 } // namespace Tempus
244 
245 #endif // Tempus_IntegratorBasic_decl_hpp
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
Teuchos::RCP< Stepper< Scalar > > stepper_
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const override
Get the Stepper.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Create valid IntegratorBasic ParameterList.
virtual Scalar getTime() const override
Get current time.
Teuchos::RCP< Teuchos::ParameterList > getIntegratorParameterList()
Teuchos::RCP< Teuchos::ParameterList > integratorPL_
virtual void setScreenOutputIndexList(std::string s)
Teuchos::RCP< Teuchos::Time > integratorTimer_
std::string description() const override
virtual void setTimeStepControl(Teuchos::RCP< TimeStepControl< Scalar > > tsc=Teuchos::null)
Set the TimeStepControl.
virtual void setObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs=Teuchos::null)
Set the Observer.
virtual Teuchos::RCP< SolutionState< Scalar > > getCurrentState()
Get current state.
virtual Status getStatus() const override
Get Status.
Teuchos::RCP< Teuchos::Time > stepperTimer_
IntegratorBasic()
Constructor that requires a subsequent setParameterList, setStepper, and initialize calls...
Teuchos::RCP< IntegratorObserverComposite< Scalar > > integratorObserver_
virtual std::string getScreenOutputIndexList() const
Thyra Base interface for time steppers.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getXdotdot() const
Get current the second time derivative of the solution, xdotdot.
virtual void checkTimeStep()
Check if time step has passed or failed.
virtual Teuchos::RCP< Teuchos::ParameterList > getTempusParameterList() override
Return a copy of the Tempus ParameterList.
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const override
Get the SolutionHistory.
void parseScreenOutput()
Parse when screen output should be executed.
virtual void setSolutionHistory(Teuchos::RCP< SolutionHistory< Scalar > > sh=Teuchos::null)
Set the SolutionHistory.
Teuchos::RCP< Teuchos::ParameterList > tempusPL_
Status
Status for the Integrator, the Stepper and the SolutionState.
IntegratorObserver class for time integrators.
Teuchos::RCP< TimeStepControl< Scalar > > timeStepControl_
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory_
virtual void setStepperWStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
Set the Stepper.
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
virtual int getIndex() const override
Get current index.
virtual void initializeSolutionHistory(Teuchos::RCP< SolutionState< Scalar > > state=Teuchos::null)
Set the initial state which has the initial conditions.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< IntegratorBasic< Scalar > > integratorBasic(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
virtual int getScreenOutputIndexInterval() const
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const override
Get the TimeStepControl.
virtual void initialize()
Initializes the Integrator after set* function calls.
virtual void endIntegrator()
Perform tasks after end of integrator.
virtual ~IntegratorBasic()
Destructor.
virtual void startIntegrator()
Perform tasks before start of integrator.
virtual void setStepper(Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
Thyra Base interface for time integrators. Time integrators are designed to advance the solution from...
virtual Teuchos::RCP< Teuchos::Time > getStepperTimer() const override
virtual Teuchos::RCP< TimeStepControl< Scalar > > getNonConstTimeStepControl() override
virtual void startTimeStep()
Start time step.
virtual Teuchos::RCP< IntegratorObserverComposite< Scalar > > getObserver()
Get the Observer.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getXdot() const
Get current the time derivative of the solution, xdot.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.
std::vector< int > outputScreenIndices_
Vector of screen output indices.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
virtual Teuchos::RCP< Teuchos::Time > getIntegratorTimer() const override
Returns the IntegratorTimer_ for this Integrator.
virtual void setScreenOutputIndexInterval(int i)