Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_AdjointAuxSensitivityModelEvaluator_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_AdjointAuxSensitivityModelEvaluator_decl_hpp
10 #define Tempus_AdjointAuxSensitivityModelEvaluator_decl_hpp
11 
12 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
13 #include "Thyra_DefaultProductVectorSpace.hpp"
14 #include "Thyra_DefaultProductVector.hpp"
15 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
16 #include "Thyra_DefaultMultiVectorProductVector.hpp"
17 
18 #include "Tempus_SolutionHistory.hpp"
19 
20 namespace Tempus {
21 
22 /** \brief ModelEvaluator for forming adjoint sensitivity equations. */
23 /**
24  * This class wraps a given ModelEvalutor encapsulating f(x_dot,x,p) and creates
25  * a new "residual" for the adjoint sensitivity equations:
26  * F(y,z) = [ d/dt( df/dx_dot^T*y ) - df/dx^T*y ] = 0
27  * [ dz/dt - df/dp^T*y ]
28  * where y is the adjoint variable and z is an auxiliary variable. Nominally
29  * y is a multi-vector belonging to the vector space of the residual f and a
30  * given number of columns and z is a multi-vector beling to the vector space
31  * p and the same number of columns. To satisfy the model evaluator interface,
32  * y and z are converted to a product vector formed by their columns. This is
33  * the form of the adjoint equations suitable for computing sensitivities of a
34  * response function g(x(T),p).
35  *
36  * To compute adjoint sensitivities, the equations f(x_dot,x,p) = 0 are
37  * integrated forward in time to some final time T, with the adjoint equations
38  * above integrated backward in time starting at T. Since the tempus
39  * integrator can only integrate forward in time, we define tau = T - t and
40  * transform the adjoint equations to:
41  * F(y) = d/dtau( df/dx_dot^T*y ) + df/dx^T*y = 0.
42  * The initial conditions at t = T for y are
43  * y(T) = df/dx_dot(x_dot(T),x(T),p)^{-T} * dg/dx(x(T),p)^T.
44  * along with z(T) = 0. The sensitivity of g(T) is then
45  * dg/dp(T) - int_{0}^T(df/dp^T*y)dt + dx/dp(0)^T*df/dx_dot(0)^T*y(0)
46  * = dg/dp(T) - z(0) + dx/dp(0)^T*df/dx_dot(0)^T*y(0)
47  *
48  * This model evaluator supports both implicit and explict forms of the
49  * governing equations. However it assumes df/dx_dot is constant with respect
50  * to x_dot, x, and t so that the adjoint equations become
51  * F(y) = df/dxdot^T*y_dot + df/dx^T*y = 0.
52  * Moving beyond this assumption will require modifications to the steppers
53  * in how they generate time-derivative terms.
54  */
55 template <typename Scalar>
57  public Thyra::StateFuncModelEvaluatorBase<Scalar> {
58 public:
59  typedef Thyra::VectorBase<Scalar> Vector;
60  typedef Thyra::MultiVectorBase<Scalar> MultiVector;
61 
62  //! Constructor
63  /*!
64  * t_final is the final integration time used to implement the time
65  * transformation described above. num_adjoint is the number of adjoint
66  * variables defining the number of columns in y, which is determined by
67  * the number of elements in the vector space for the response g.
68  * The optionally supplied parameter list supports the following options:
69  * <ul>
70  * <li> "Sensitivity Parameter Index", (default: 0) The model evaluator
71  * parameter index for which sensitivities will be computed.
72  * <li> "Response Function Index", (default: 0) The model evaluator
73  * response index for which sensitivities will be computed.
74  * <li> "Mass Matrix Is Constant" (default: true) Whether the mass matrix
75  * df/dx_dot is a constant matrix. As describe above, this is
76  * currently required to be true.
77  * <li> "Mass Matrix Is Identity" (default: false) Whether the mass matrix
78  * is the identity matrix, in which some computations can be skipped.
79  * </ul>
80  */
82  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & model,
83  const Scalar& t_final,
84  const Teuchos::RCP<const Teuchos::ParameterList>& pList = Teuchos::null);
85 
86  //! Get the underlying model 'f'
87  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > getModel() const
88  { return model_; }
89 
90  //! Set solution history from forward evaluation
92  const Teuchos::RCP<const Tempus::SolutionHistory<Scalar> >& sh);
93 
94  /** \name Public functions overridden from ModelEvaulator. */
95  //@{
96 
97  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int p) const;
98 
99  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int p) const;
100 
101  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
102 
103  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
104 
105  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
106 
107  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
108  get_W_factory() const;
109 
110  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
111 
112  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
113 
114  //@}
115 
116  static Teuchos::RCP<const Teuchos::ParameterList> getValidParameters();
117 
118 private:
119 
120  typedef Thyra::DefaultProductVectorSpace<Scalar> DPVS;
121  typedef Thyra::DefaultProductVector<Scalar> DPV;
122  typedef Thyra::DefaultMultiVectorProductVectorSpace<Scalar> DMVPVS;
123  typedef Thyra::DefaultMultiVectorProductVector<Scalar> DMVPV;
124 
125  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
126 
127  void evalModelImpl(
128  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
129  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs) const;
130 
131 
132  Thyra::ModelEvaluatorBase::InArgs<Scalar> prototypeInArgs_;
133  Thyra::ModelEvaluatorBase::OutArgs<Scalar> prototypeOutArgs_;
134 
135  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model_;
136 
137  Teuchos::RCP<const DMVPVS> adjoint_space_;
138  Teuchos::RCP<const DMVPVS> residual_space_;
139  Teuchos::RCP<const DMVPVS> response_space_;
140  Teuchos::RCP<const DPVS> x_prod_space_;
141  Teuchos::RCP<const DPVS> f_prod_space_;
142  Teuchos::RCP<const Tempus::SolutionHistory<Scalar> > sh_;
143  Scalar t_final_;
146  int p_index_;
147  int g_index_;
149 
151  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdx_;
152  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdxdot_;
153  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdp_op_;
154  mutable Teuchos::RCP<Thyra::MultiVectorBase<Scalar> > my_dfdp_mv_;
155  mutable Teuchos::RCP<Tempus::SolutionState<Scalar> > forward_state_;
156  mutable Scalar t_interp_;
157 };
158 
159 } // namespace Tempus
160 
161 #endif
Thyra::DefaultMultiVectorProductVectorSpace< Scalar > DMVPVS
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
static Teuchos::RCP< const Teuchos::ParameterList > getValidParameters()
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
ModelEvaluator for forming adjoint sensitivity equations.
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int p) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel() const
Get the underlying model &#39;f&#39;.
void setForwardSolutionHistory(const Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > &sh)
Set solution history from forward evaluation.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int p) const
AdjointAuxSensitivityModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Scalar &t_final, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null)
Constructor.
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > model_
Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > sh_