Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_IntegratorForwardSensitivity_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_IntegratorForwardSensitivity_decl_hpp
10 #define Tempus_IntegratorForwardSensitivity_decl_hpp
11 
12 // Tempus
13 #include "Tempus_IntegratorBasic.hpp"
15 #include "Tempus_StepperStaggeredForwardSensitivity.hpp"
16 
17 namespace Tempus {
18 
19 
20 /** \brief Time integrator implementing forward sensitivity analysis */
21 /**
22  * This integrator implements forward parameter sensitivity analysis by
23  * propagating the derivative of the solution with respect to model parameters
24  * alongside the solution. It supports sensitivity propagation methods:
25  * <ul>
26  * <li> "Combined" where the sensitivity and state equations are solved
27  * simultaneously. This is most appropriate for explicit time
28  * integration methods or implicit methods where a very-lightweight
29  * nonlinear solution strategy is used.
30  * <li> "Staggered" where the sensitivity equations are solved at each time
31  * step immediately after the state equations are solved. This is
32  * useful for implicit methods since it saves the cost of solving the
33  * sensitivity equations while the state equations are being solved. It
34  * generally does not work for explicit methods (and wouldn't be more
35  * efficient than the combined method even if it did).
36  * </ul>
37  *
38  * Note that this integrator implements all of the same functions as the
39  * IntegratorBasic, but is not derived from IntegratorBasic. It also provides
40  * functions for setting the sensitivity initial conditions and extracting the
41  * sensitivity at the final time. Also the vectors stored in the solution
42  * history store product vectors of the state and sensitivities using
43  * Thyra;:DefaultMultiVectorProductVector.
44  */
45 template<class Scalar>
46 class IntegratorForwardSensitivity : virtual public Tempus::Integrator<Scalar>
47 {
48 public:
49 
50  /** \brief Constructor with ParameterList and model, and will be fully
51  * initialized. */
52  /*!
53  * In addition to all of the regular integrator options, the supplied
54  * parameter list supports the following options contained within a sublist
55  * "Sensitivities" from the top-level parameter list:
56  * <ul>
57  * <li> "Sensitivity Method" (default: "Combined") The sensitivity
58  * analysis method as described above.
59  * <li> "Reuse State Linear Solver" (default: false) For the staggered
60  * method, whether to reuse the model's W matrix, solver, and
61  * preconditioner when solving the sensitivity equations. If they
62  * can be reused, substantial savings in compute time are possible.
63  * <li> "Use DfDp as Tangent" (default: false) Reinterpret the df/dp
64  * out-arg as the tangent vector (df/dx)(x,p) * dx/dp + df/dp(x,p)
65  * as described in the Tempus::CombinedForwardSensitivityModelEvaluator
66  * documentation.
67  * <li> "Sensitivity Parameter Index" (default: 0) Model evaluator
68  * parameter index for which sensitivities will be computed.
69  * <li> "Sensitivity X Tangent Index" (default: 1) If "Use DfDp as Tangent"
70  * is true, the model evaluator parameter index for passing dx/dp
71  * as a Thyra::DefaultMultiVectorProductVector.
72  * <li> "Sensitivity X-Dot Tangent Index" (default: 2) If
73  * "Use DfDp as Tangent" is true, the model evaluator parameter index
74  * for passing dx_dot/dp as a Thyra::DefaultMultiVectorProductVector.
75  * <li> "Sensitivity X-Dot-Dot Tangent Index" (default: 3) If
76  * "Use DfDp as Tangent" is true, the model evaluator parameter index
77  * for passing dx_dot_dot/dp as a
78  * Thyra::DefaultMultiVectorProductVector (if the model supports
79  * x_dot_dot).
80  * </ul>
81  */
83  Teuchos::RCP<Teuchos::ParameterList> pList,
84  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
85 
86  /** \brief Constructor with model and "Stepper Type" and is fully initialized with default settings. */
88  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
89  std::string stepperType);
90 
91  /// Destructor
92  /** \brief Constructor that requires a subsequent setParameterList, setStepper, and initialize calls. */
94 
95  /// Destructor
97 
98  /// \name Basic integrator methods
99  //@{
100  /// Advance the solution to timeMax, and return true if successful.
101  virtual bool advanceTime()
102  { return integrator_->advanceTime(); }
103  /// Advance the solution to timeFinal, and return true if successful.
104  virtual bool advanceTime(const Scalar timeFinal) override
105  { return integrator_->advanceTime(timeFinal); }
106  /// Perform tasks before start of integrator.
107  virtual void startIntegrator()
108  { integrator_->startIntegrator(); }
109  /// Start time step.
110  virtual void startTimeStep()
111  { integrator_->startTimeStep(); }
112  /// Check if time step has passed or failed.
113  virtual void checkTimeStep()
114  { integrator_->checkTimeStep(); }
115  /// Perform tasks after end of integrator.
116  virtual void endIntegrator()
117  { integrator_->endIntegrator(); }
118  /// Return a copy of the Tempus ParameterList
119  virtual Teuchos::RCP<Teuchos::ParameterList> getTempusParameterList() override
120  { return integrator_->getTempusParameterList(); }
121  virtual void setTempusParameterList(Teuchos::RCP<Teuchos::ParameterList> pl) override
122  { integrator_->setTempusParameterList(pl); }
123  //@}
124 
125  /// \name Accessor methods
126  //@{
127  /// Get current time
128  virtual Scalar getTime() const override
129  { return integrator_->getTime(); }
130  /// Get current index
131  virtual int getIndex() const override
132  { return integrator_->getIndex(); }
133  /// Get Status
134  virtual Status getStatus() const override
135  { return integrator_->getStatus(); }
136  /// Get the Stepper
137  virtual Teuchos::RCP<Stepper<Scalar> > getStepper() const override
138  { return integrator_->getStepper(); }
139 
140  /// Set the Stepper
141  virtual void setStepper(Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > model);
142 
143  /// Set the Stepper
144  virtual void setStepperWStepper(Teuchos::RCP<Stepper<Scalar> > stepper)
145  { integrator_->setStepperWStepper(stepper); }
146  /// Set the initial state which has the initial conditions
148  Teuchos::RCP<SolutionState<Scalar> > state = Teuchos::null)
149  { integrator_->initializeSolutionHistory(state); }
150 
151  /// Set the initial state from Thyra::VectorBase(s)
152  virtual void initializeSolutionHistory(
153  Scalar t0,
154  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x0,
155  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot0 = Teuchos::null,
156  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot0 = Teuchos::null,
157  Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > DxDp0 = Teuchos::null,
158  Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > DxdotDp0 = Teuchos::null,
159  Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > DxdotdotDp0 = Teuchos::null);
160 
161  /// Get the SolutionHistory
162  virtual Teuchos::RCP<const SolutionHistory<Scalar> > getSolutionHistory() const override
163  { return integrator_->getSolutionHistory(); }
164  /// Set the SolutionHistory
165  virtual void setSolutionHistory(
166  Teuchos::RCP<SolutionHistory<Scalar> > sh = Teuchos::null)
167  { integrator_->setSolutionHistory(sh); }
168  /// Get the TimeStepControl
169  virtual Teuchos::RCP<const TimeStepControl<Scalar> > getTimeStepControl() const override
170  { return integrator_->getTimeStepControl(); }
171  virtual Teuchos::RCP<TimeStepControl<Scalar> > getNonConstTimeStepControl() override
172  { return integrator_->getNonConstTimeStepControl(); }
173  /// Set the TimeStepControl
174  virtual void setTimeStepControl(
175  Teuchos::RCP<TimeStepControl<Scalar> > tsc = Teuchos::null)
176  { integrator_->setTimeStepControl(tsc); }
177  /// Get the Observer
178  virtual Teuchos::RCP<IntegratorObserver<Scalar> > getObserver()
179  { return integrator_->getObserver(); }
180  /// Set the Observer
181  virtual void setObserver(
182  Teuchos::RCP<IntegratorObserver<Scalar> > obs = Teuchos::null)
183  { integrator_->setObserver(obs); }
184  /// Initializes the Integrator after set* function calls
185  virtual void initialize()
186  { integrator_->initialize(); }
187  virtual Teuchos::RCP<Teuchos::Time> getIntegratorTimer() const override
188  { return integrator_->getIntegratorTimer(); }
189  virtual Teuchos::RCP<Teuchos::Time> getStepperTimer() const override
190  { return integrator_->getStepperTimer(); }
191 
192  /// Get current the solution, x
193  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getX() const;
194  virtual Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > getDxDp() const;
195  /// Get current the time derivative of the solution, xdot
196  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getXdot() const;
197  virtual Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > getDxdotDp() const;
198  /// Get current the second time derivative of the solution, xdotdot
199  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getXdotdot() const;
200  virtual Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > getDxdotdotDp() const;
201 
202  /// Get current state
203  virtual Teuchos::RCP<SolutionState<Scalar> > getCurrentState()
204  {return integrator_->getCurrentState();}
205  //@}
206 
207  /// Parse when screen output should be executed
208  void parseScreenOutput() { integrator_->parseScreenOutput(); }
209 
210  /// \name Overridden from Teuchos::ParameterListAcceptor
211  //@{
212  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl)
213  override;
214  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList() override
215  { return tempus_pl_; }
216  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList() override;
217 
218  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
219  const override;
220  //@}
221 
222  /// \name Overridden from Teuchos::Describable
223  //@{
224  std::string description() const override;
225  void describe(Teuchos::FancyOStream & out,
226  const Teuchos::EVerbosityLevel verbLevel) const override;
227  //@}
228 
229 protected:
230 
231  // Create sensitivity model evaluator from application model
232  void
234  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
235 
236  Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > model_;
237  Teuchos::RCP<SensitivityModelEvaluatorBase<Scalar> > sens_model_;
238  Teuchos::RCP<StepperStaggeredForwardSensitivity<Scalar> > sens_stepper_;
239  Teuchos::RCP<IntegratorBasic<Scalar> > integrator_;
240  Teuchos::RCP<Teuchos::ParameterList> tempus_pl_;
241  Teuchos::RCP<Teuchos::ParameterList> sens_pl_;
242  Teuchos::RCP<Teuchos::ParameterList> stepper_pl_;
244 };
245 
246 /// Non-member constructor
247 template<class Scalar>
248 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> >
250  Teuchos::RCP<Teuchos::ParameterList> pList,
251  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
252 
253 /// Non-member constructor
254 template<class Scalar>
255 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> >
257  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
258  std::string stepperType);
259 
260 /// Non-member constructor
261 template<class Scalar>
262 Teuchos::RCP<IntegratorForwardSensitivity<Scalar> >
264 
265 } // namespace Tempus
266 
267 #endif // Tempus_IntegratorForwardSensitivity_decl_hpp
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const override
Get the SolutionHistory.
Teuchos::RCP< IntegratorBasic< Scalar > > integrator_
virtual Teuchos::RCP< Teuchos::Time > getIntegratorTimer() const override
Returns the IntegratorTimer_ for this Integrator.
virtual int getIndex() const override
Get current index.
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdot() const
Get current the time derivative of the solution, xdot.
virtual void initializeSolutionHistory(Teuchos::RCP< SolutionState< Scalar > > state=Teuchos::null)
Set the initial state which has the initial conditions.
virtual void setTimeStepControl(Teuchos::RCP< TimeStepControl< Scalar > > tsc=Teuchos::null)
Set the TimeStepControl.
virtual Teuchos::RCP< IntegratorObserver< Scalar > > getObserver()
Get the Observer.
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const override
Get the TimeStepControl.
virtual void endIntegrator()
Perform tasks after end of integrator.
virtual void setSolutionHistory(Teuchos::RCP< SolutionHistory< Scalar > > sh=Teuchos::null)
Set the SolutionHistory.
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxdotDp() const
Teuchos::RCP< StepperStaggeredForwardSensitivity< Scalar > > sens_stepper_
virtual void setStepper(Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxdotdotDp() const
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdotdot() const
Get current the second time derivative of the solution, xdotdot.
virtual Teuchos::RCP< SolutionState< Scalar > > getCurrentState()
Get current state.
virtual Status getStatus() const override
Get Status.
virtual Teuchos::RCP< Teuchos::ParameterList > getTempusParameterList() override
Return a copy of the Tempus ParameterList.
Thyra Base interface for time steppers.
void createSensitivityModelAndStepper(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Teuchos::RCP< IntegratorForwardSensitivity< Scalar > > integratorForwardSensitivity(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
virtual void startIntegrator()
Perform tasks before start of integrator.
virtual void checkTimeStep()
Check if time step has passed or failed.
virtual Teuchos::RCP< Teuchos::Time > getStepperTimer() const override
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDxDp() const
virtual void initialize()
Initializes the Integrator after set* function calls.
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const override
Get the Stepper.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model_
Status
Status for the Integrator, the Stepper and the SolutionState.
IntegratorObserver class for time integrators.
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
void parseScreenOutput()
Parse when screen output should be executed.
virtual Scalar getTime() const override
Get current time.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.
Thyra Base interface for time integrators. Time integrators are designed to advance the solution from...
virtual void setStepperWStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
Set the Stepper.
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
virtual void setObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs=Teuchos::null)
Set the Observer.
virtual Teuchos::RCP< TimeStepControl< Scalar > > getNonConstTimeStepControl() override
Teuchos::RCP< SensitivityModelEvaluatorBase< Scalar > > sens_model_
Time integrator implementing forward sensitivity analysis.
virtual bool advanceTime(const Scalar timeFinal) override
Advance the solution to timeFinal, and return true if successful.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override