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 Scalar 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<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  /// Set the TimeStepControl
125  virtual void setTimeStepControl(
126  Teuchos::RCP<TimeStepControl<Scalar> > tsc = Teuchos::null);
127  /// Get the Observer
128  virtual Teuchos::RCP<IntegratorObserverComposite<Scalar> > getObserver()
129  {return integratorObserver_;}
130  /// Set the Observer
131  virtual void setObserver(
132  Teuchos::RCP<IntegratorObserver<Scalar> > obs = Teuchos::null);
133  /// Initializes the Integrator after set* function calls
134  virtual void initialize();
135  //TODO: finish this
136  /// Returns the IntegratorTimer_ for this Integrator
137  virtual Teuchos::RCP<Teuchos::Time> getIntegratorTimer() const override
138  { return integratorTimer_;}
139  virtual Teuchos::RCP<Teuchos::Time> getStepperTimer() const override
140  { return stepperTimer_;}
141 
142  /// Get current the solution, x
143  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getX() const
144  {return solutionHistory_->getCurrentState()->getX();}
145  /// Get current the time derivative of the solution, xdot
146  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getXdot() const
147  {return solutionHistory_->getCurrentState()->getXDot();}
148  /// Get current the second time derivative of the solution, xdotdot
149  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getXdotdot() const
150  {return solutionHistory_->getCurrentState()->getXDotDot();}
151 
152  /// Get current state
153  virtual Teuchos::RCP<SolutionState<Scalar> > getCurrentState()
154  {return solutionHistory_->getCurrentState();}
155 
156  Teuchos::RCP<Teuchos::ParameterList> getIntegratorParameterList()
157  { return integratorPL_; }
158 
159  //virtual Teuchos::RCP<Teuchos::Time> getIntegratorTimer() const
160  //{return integratorTimer_;}
161  //@}
162 
163  /// Parse when screen output should be executed
164  void parseScreenOutput();
165 
166  /// \name Overridden from Teuchos::ParameterListAcceptor
167  //@{
168  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl)
169  override;
170  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList() override;
171  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList() override;
172  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
173  const override;
174  //@}
175 
176  /// \name Overridden from Teuchos::Describable
177  //@{
178  std::string description() const override;
179  void describe(Teuchos::FancyOStream & out,
180  const Teuchos::EVerbosityLevel verbLevel) const override;
181  //@}
182 
183 protected:
184 
185  Teuchos::RCP<Teuchos::ParameterList> tempusPL_;
186  Teuchos::RCP<Teuchos::ParameterList> integratorPL_;
187  Teuchos::RCP<SolutionHistory<Scalar> > solutionHistory_;
188  Teuchos::RCP<TimeStepControl<Scalar> > timeStepControl_;
189  Teuchos::RCP<IntegratorObserverComposite<Scalar> > integratorObserver_;
190  Teuchos::RCP<Stepper<Scalar> > stepper_;
191 
192  Teuchos::RCP<Teuchos::Time> integratorTimer_;
193  Teuchos::RCP<Teuchos::Time> stepperTimer_;
194  Scalar runtime_;
195 
196  std::vector<int> outputScreenIndices_; ///< Vector of screen output indices.
197 
198  /** The integratorStatus is primarily in the WORKING Status, and
199  * PASSED/FAILED are noted at the end of the run. A FAILED value
200  * is used to jump out of the time-integration loop.
201  */
204 };
205 
206 /// Non-member constructor
207 template<class Scalar>
208 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
209  Teuchos::RCP<Teuchos::ParameterList> pList,
210  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
211 
212 /// Non-member constructor
213 template<class Scalar>
214 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
215  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
216  std::string stepperType);
217 
218 /// Non-member constructor
219 template<class Scalar>
220 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic();
221 
222 /// Non-member constructor
223 template<class Scalar>
224 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
225  Teuchos::RCP<Teuchos::ParameterList> pList,
226  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models);
227 
228 
229 } // namespace Tempus
230 
231 #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_
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_
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.
Teuchos::RCP< Tempus::IntegratorBasic< Scalar > > integratorBasic(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
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 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...
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.
Thyra Base interface for time integrators. Time integrators are designed to advance the solution from...
virtual Teuchos::RCP< Teuchos::Time > getStepperTimer() const override
virtual void startTimeStep()
Start time step.
virtual void setStepper(Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
virtual Teuchos::RCP< IntegratorObserverComposite< Scalar > > getObserver()
Get the Observer.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual Scalar getIndex() const override
Get current index.
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.