Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_CombinedForwardSensitivityModelEvaluator_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_CombinedForwardSensitivityModelEvaluator_decl_hpp
10 #define Tempus_CombinedForwardSensitivityModelEvaluator_decl_hpp
11 
13 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
14 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
15 
16 namespace Tempus {
17 
18 /** \brief Transform a ModelEvaluator's sensitivity equations to its residual
19  *
20  * This class wraps a given ModelEvalutor encapsulating f(x,p) and creates
21  * a new "residual" for it and the forward sensitivity equations:
22  * F(X) = [ f(x,p) ] = 0
23  * [ (df/dx)(x,p) * dx/dp + df/dp(x,p) ]
24  * where X = [ x; dx/dp ] (transient terms supressed for simplicity). This model
25  * evaluator can then be handed to a regular (non)linear solver to compute X.
26  * Note that even though these equations are linear in X, it is not necessarily
27  * the case that the underlying model evaluator accurately computes df/dx in its
28  * evaluation of W. Therefore this model evaluator can optionally reinterpret
29  * the model's df/dp out-arg as (df/dx)(x,p) * dx/dp + df/dp(x,p) where dx/dp is
30  * passed as another parameter (product) vector (encapsulated in the
31  * Thyra::DefaultMultiVectorProductVector). This is not standard model
32  * evaluator behavior, but is useful for models where W is only an approximation
33  * to df/dx and/or the model is capable of directly computing
34  * (df/dx)(x,p) * dx/dp + df/dp(x,p).
35  */
36 template <typename Scalar>
38  public Thyra::StateFuncModelEvaluatorBase<Scalar>,
39  public SensitivityModelEvaluatorBase<Scalar> {
40 public:
41  typedef Thyra::VectorBase<Scalar> Vector;
42  typedef Thyra::MultiVectorBase<Scalar> MultiVector;
43 
44  //! Constructor
45  /*!
46  * The optionally supplied parameter list supports the following options:
47  * <ul>
48  * <li> "Use DfDp as Tangent" (default: false) Reinterpret the df/dp
49  * out-arg as the tangent vector (df/dx)(x,p) * dx/dp + df/dp(x,p)
50  * as described above. If it is false, this implementation will
51  * compute the tangent through several calls to the models
52  * evalModel().
53  * <li> "Sensitivity Parameter Index" (default: 0) Model evaluator
54  * parameter index for which sensitivities will be computed.
55  * <li> "Sensitivity X Tangent Index" (default: 1) If "Use DfDp as Tangent"
56  * is true, the model evaluator parameter index for passing dx/dp
57  * as a Thyra::DefaultMultiVectorProductVector.
58  * <li> "Sensitivity X-Dot Tangent Index" (default: 2) If
59  * "Use DfDp as Tangent" is true, the model evaluator parameter index
60  * for passing dx_dot/dp as a Thyra::DefaultMultiVectorProductVector.
61  * <li> "Sensitivity X-Dot-Dot Tangent Index" (default: 3) If
62  * "Use DfDp as Tangent" is true, the model evaluator parameter index
63  * for passing dx_dot_dot/dp as a
64  * Thyra::DefaultMultiVectorProductVector (if the model supports
65  * x_dot_dot).
66  * </ul>
67  */
69  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & model,
70  const Teuchos::RCP<const Teuchos::ParameterList>& pList = Teuchos::null,
71  const Teuchos::RCP<MultiVector>& dxdp_init = Teuchos::null,
72  const Teuchos::RCP<MultiVector>& dx_dotdp_init = Teuchos::null,
73  const Teuchos::RCP<MultiVector>& dx_dotdot_dp_init = Teuchos::null);
74 
75  /** \name Public functions overridden from SensitivityModelEvaulator. */
76  //@{
77 
78  //! Get the underlying model 'f'
79  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > getForwardModel() const
80  { return model_; }
81 
82  //@}
83 
84  //! Get sensitivity parameter index
85  int getSensitivityParamIndex() const { return p_index_; }
86 
87  /** \name Public functions overridden from ModelEvaulator. */
88  //@{
89 
90  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int p) const;
91 
92  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int p) const;
93 
94  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
95 
96  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
97 
98  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
99 
100  Teuchos::ArrayView<const std::string> get_g_names(int j) const;
101 
102  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
103 
104  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_DgDx_dot_op(int j) const;
105 
106  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_DgDx_op(int j) const;
107 
108  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_DgDp_op(int j, int l) const;
109 
110  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
111  get_W_factory() const;
112 
113  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
114 
115  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
116 
117  //@}
118 
119  static Teuchos::RCP<const Teuchos::ParameterList> getValidParameters();
120 
121 private:
122 
123  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
124 
125  void evalModelImpl(
126  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
127  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs) const;
128 
129 
130  Thyra::ModelEvaluatorBase::InArgs<Scalar> prototypeInArgs_;
131  Thyra::ModelEvaluatorBase::OutArgs<Scalar> prototypeOutArgs_;
132 
133  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model_;
134  Teuchos::RCP<MultiVector> dxdp_init_;
135  Teuchos::RCP<MultiVector> dx_dotdp_init_;
136  Teuchos::RCP<MultiVector> dx_dotdotdp_init_;
137  int p_index_;
142 
144  Teuchos::RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > dxdp_space_;
145  Teuchos::RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > x_dxdp_space_;
146  Teuchos::RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > dfdp_space_;
147  Teuchos::RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > f_dfdp_space_;
148 
149  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdx_;
150  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdxdot_;
151  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdxdotdot_;
152 };
153 
154 } // namespace Tempus
155 
156 #endif
Transform a ModelEvaluator&#39;s sensitivity equations to its residual.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int p) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_DgDx_dot_op(int j) const
Teuchos::RCP< const Thyra::DefaultMultiVectorProductVectorSpace< Scalar > > dxdp_space_
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int p) const
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_DgDp_op(int j, int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Teuchos::RCP< const Thyra::DefaultMultiVectorProductVectorSpace< Scalar > > x_dxdp_space_
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_DgDx_op(int j) const
Teuchos::RCP< const Thyra::DefaultMultiVectorProductVectorSpace< Scalar > > f_dfdp_space_
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
Teuchos::RCP< const Thyra::DefaultMultiVectorProductVectorSpace< Scalar > > dfdp_space_
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
CombinedForwardSensitivityModelEvaluator(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< const Teuchos::ParameterList > &pList=Teuchos::null, const Teuchos::RCP< MultiVector > &dxdp_init=Teuchos::null, const Teuchos::RCP< MultiVector > &dx_dotdp_init=Teuchos::null, const Teuchos::RCP< MultiVector > &dx_dotdot_dp_init=Teuchos::null)
Constructor.
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getForwardModel() const
Get the underlying model &#39;f&#39;.
A ModelEvaluator decorator for sensitivity analysis.