Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_IntegratorPseudoTransientAdjointSensitivity_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_IntegratorPseudoTransientAdjointSensitivity_decl_hpp
10 #define Tempus_IntegratorPseudoTransientAdjointSensitivity_decl_hpp
11 
12 // Tempus
13 #include "Tempus_IntegratorBasic.hpp"
14 #include "Tempus_AdjointSensitivityModelEvaluator.hpp"
15 
16 namespace Tempus {
17 
18 
19 /** \brief Time integrator suitable for pseudotransient adjoint sensitivity
20  * analysis */
21 /**
22  * For some problems, time integrators are used to compute steady-state
23  * solutions (also known as pseudo-transient solvers). When computing
24  * sensitivities, it is not necessary in these cases to propagate sensitivities
25  * all the way through the forward time integration. Instead the steady-state
26  * is first computed as usual, and then the sensitivities are computed using
27  * a similar pseudo-transient time integration applied to the adjoint
28  * sensitivity equations with the state frozen to the computed steady-state.
29  * This integrator specializes the transient sensitivity methods implemented by
30  * Tempus::IntegratorAdjointSensitivity to this case.
31  *
32  * Consider an implicit ODE f(x_dot,x,p) = 0 with a stable steady-state solution
33  * x = x^s, x_dot = 0 where f(0,x^s,p) = 0 and all of the eigenvalues of
34  * df/dx(0,x^s,p) are in the right half-plane (for an explicit ODE, the
35  * eigenvalues must be in the left half-plane). In the pseudo-transient method
36  * a time-integrator is applied to f(x_dot,x,p) = 0 until x_dot is sufficiently
37  * small. Now consider the adjoint sensitivity equations for some response
38  * function g(x,p):
39  * df/dx_dot^T*y_dot + df/dx^T*y - dg/dx^T = 0
40  * after the transformation tau = T - t has been applied, where T is the final
41  * time. For pseudo-transient adjoint sensitivities, the above is integrated
42  * from y(0) = 0 until y_dot is sufficiently small, in which case
43  * y^s = (df/dx)^{-T}*(dg/dx)^T.
44  * Then the final sensitivity of g is
45  * dg/dp^T - df/dp^T*y^s.
46  * One can see that y^s is the only steady-state solution of the adjoint
47  * equations, since df/dx and dg/dx are constant, and must be linearly stable
48  * (since the eigenvalues of df/dx^T are the same as df/dx).
49  */
50 template<class Scalar>
52  virtual public Tempus::Integrator<Scalar>
53 {
54 public:
55 
56  /** \brief Constructor with ParameterList and model, and will be fully
57  * initialized. */
58  /*!
59  * In addition to all of the regular integrator options, the supplied
60  * parameter list supports the following options contained within a sublist
61  * "Sensitivities" from the top-level parameter list:
62  * <ul>
63  * <li> "Sensitivity Parameter Index", (default: 0) The model evaluator
64  * parameter index for which sensitivities will be computed.
65  * <li> "Response Function Index", (default: 0) The model evaluator
66  * response index for which sensitivities will be computed.
67  * <li> "Mass Matrix Is Constant" (default: true) Whether the mass matrix
68  * df/dx_dot is a constant matrix. As describe above, this is
69  * currently required to be true.
70  * <li> "Mass Matrix Is Identity" (default: false) Whether the mass matrix
71  * is the identity matrix, in which some computations can be skipped.
72  * </ul>
73  */
75  Teuchos::RCP<Teuchos::ParameterList> pList,
76  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
77 
78  /** \brief Constructor with model and "Stepper Type" and is fully initialized with default settings. */
80  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
81  std::string stepperType);
82 
83  /// Destructor
84  /** \brief Constructor that requires a subsequent setParameterList, setStepper, and initialize calls. */
86 
87  /// Destructor
89 
90  /// \name Basic integrator methods
91  //@{
92 
93  /// Advance the solution to timeMax, and return true if successful.
94  virtual bool advanceTime();
95  /// Advance the solution to timeFinal, and return true if successful.
96  virtual bool advanceTime(const Scalar timeFinal) override;
97  /// Get current time
98  virtual Scalar getTime() const override;
99  /// Get current index
100  virtual int getIndex() const override;
101  /// Get Status
102  virtual Status getStatus() const override;
103  /// Get the Stepper
104  virtual Teuchos::RCP<Stepper<Scalar> > getStepper() const override;
105  /// Return a copy of the Tempus ParameterList
106  virtual Teuchos::RCP<Teuchos::ParameterList> getTempusParameterList() override;
107  virtual void setTempusParameterList(Teuchos::RCP<Teuchos::ParameterList> pl) override;
108  /// Get the SolutionHistory
109  virtual Teuchos::RCP<const SolutionHistory<Scalar> > getSolutionHistory() const override;
110  /// Get the TimeStepControl
111  virtual Teuchos::RCP<const TimeStepControl<Scalar> > getTimeStepControl() const override;
112  virtual Teuchos::RCP<TimeStepControl<Scalar> > getNonConstTimeStepControl() override;
113  /// Returns the IntegratorTimer_ for this Integrator
114  virtual Teuchos::RCP<Teuchos::Time> getIntegratorTimer() const override
115  {return state_integrator_->getIntegratorTimer();}
116  virtual Teuchos::RCP<Teuchos::Time> getStepperTimer() const override
117  {return state_integrator_->getStepperTimer();}
118 
119  //@}
120 
121  /// Set the initial state from Thyra::VectorBase(s)
122  virtual void initializeSolutionHistory(
123  Scalar t0,
124  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x0,
125  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot0 = Teuchos::null,
126  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot0 = Teuchos::null,
127  Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > y0 = Teuchos::null,
128  Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > ydot0 = Teuchos::null,
129  Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > ydotdot0 = Teuchos::null);
130 
131  /// Get current the solution, x
132  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getX() const;
133  /// Get current the time derivative of the solution, xdot
134  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getXdot() const;
135  /// Get current the second time derivative of the solution, xdotdot
136  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getXdotdot() const;
137 
138  /// Return adjoint sensitivity stored in gradient format
139  virtual Teuchos::RCP<const Thyra::MultiVectorBase<Scalar> > getDgDp() const;
140 
141  /// \name Overridden from Teuchos::ParameterListAcceptor
142  //@{
143  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl)
144  override;
145  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList() override;
146  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList() override;
147 
148  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters()
149  const override;
150  //@}
151 
152  /// \name Overridden from Teuchos::Describable
153  //@{
154  std::string description() const override;
155  void describe(Teuchos::FancyOStream & out,
156  const Teuchos::EVerbosityLevel verbLevel) const override;
157  //@}
158 
159 protected:
160  typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
161 
162  // Create sensitivity model evaluator from application model
163  Teuchos::RCP<AdjointSensitivityModelEvaluator<Scalar> >
165  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
166  const Teuchos::RCP<Teuchos::ParameterList>& inputPL);
167 
168  void buildSolutionHistory();
169 
170  Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > model_;
171  Teuchos::RCP<AdjointSensitivityModelEvaluator<Scalar> > sens_model_;
172  Teuchos::RCP<IntegratorBasic<Scalar> > state_integrator_;
173  Teuchos::RCP<IntegratorBasic<Scalar> > sens_integrator_;
174  Teuchos::RCP<SolutionHistory<Scalar> > solutionHistory_;
175  Teuchos::RCP<DMVPV> dgdp_;
176 };
177 
178 /// Non-member constructor
179 template<class Scalar>
180 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> >
182  Teuchos::RCP<Teuchos::ParameterList> pList,
183  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model);
184 
185 /// Non-member constructor
186 template<class Scalar>
187 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> >
189  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
190  std::string stepperType);
191 
192 /// Non-member constructor
193 template<class Scalar>
194 Teuchos::RCP<Tempus::IntegratorPseudoTransientAdjointSensitivity<Scalar> >
196 
197 } // namespace Tempus
198 
199 #endif // Tempus_IntegratorPseudoTransientAdjointSensitivity_decl_hpp
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
virtual Teuchos::RCP< Teuchos::Time > getIntegratorTimer() const override
Returns the IntegratorTimer_ for this Integrator.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
Teuchos::RCP< Tempus::IntegratorPseudoTransientAdjointSensitivity< Scalar > > integratorPseudoTransientAdjointSensitivity(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
virtual Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > getDgDp() const
Return adjoint sensitivity stored in gradient format.
Time integrator suitable for pseudotransient adjoint sensitivity analysis.
virtual Teuchos::RCP< TimeStepControl< Scalar > > getNonConstTimeStepControl() override
Status
Status for the Integrator, the Stepper and the SolutionState.
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdot() const
Get current the time derivative of the solution, xdot.
virtual void initializeSolutionHistory(Scalar t0, Teuchos::RCP< const Thyra::VectorBase< Scalar > > x0, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdot0=Teuchos::null, Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdotdot0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > y0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > ydot0=Teuchos::null, Teuchos::RCP< const Thyra::MultiVectorBase< Scalar > > ydotdot0=Teuchos::null)
Set the initial state from Thyra::VectorBase(s)
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXdotdot() const
Get current the second time derivative of the solution, xdotdot.
Teuchos::RCP< AdjointSensitivityModelEvaluator< Scalar > > createSensitivityModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< Teuchos::ParameterList > &inputPL)
virtual Teuchos::RCP< Teuchos::ParameterList > getTempusParameterList() override
Return a copy of the Tempus ParameterList.
Thyra Base interface for time integrators. Time integrators are designed to advance the solution from...
virtual Teuchos::RCP< Stepper< Scalar > > getStepper() const override
Get the Stepper.
virtual Teuchos::RCP< const SolutionHistory< Scalar > > getSolutionHistory() const override
Get the SolutionHistory.
virtual Teuchos::RCP< const TimeStepControl< Scalar > > getTimeStepControl() const override
Get the TimeStepControl.
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Get current the solution, x.