Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StaggeredForwardSensitivityModelEvaluator_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_StaggeredForwardSensitivityModelEvaluator_decl_hpp
10 #define Tempus_StaggeredForwardSensitivityModelEvaluator_decl_hpp
11 
13 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
14 #include "Thyra_DefaultMultiVectorProductVectorSpace.hpp"
15 #include "NOX_Thyra.H"
16 
17 #include "Tempus_SolutionHistory.hpp"
18 
19 namespace Tempus {
20 
21 /** \brief Transform a ModelEvaluator's sensitivity equations to its residual
22  *
23  * This class wraps a given ModelEvalutor encapsulating f(x,p) and creates
24  * a new "residual" for the forward sensitivity equations:
25  * F(X) = (df/dx)(x,p) * X + df/dp(x,p) = 0
26  * where X = dx/dp (transient terms supressed for simplicity). This model
27  * evaluator can then be handed to a regular (non)linear solver to compute X.
28  * Note that even though these equations are linear in X, it is not necessarily
29  * the case that the underlying model evaluator accurately computes df/dx in its
30  * evaluation of W. Therefore this model evaluator can optionally reinterpret
31  * the model's df/dp out-arg as (df/dx)(x,p) * dx/dp + df/dp(x,p) where dx/dp is
32  * passed as another parameter (product) vector (encapsulated in the
33  * Thyra::DefaultMultiVectorProductVector). This is not standard model
34  * evaluator behavior, but is useful for models where W is only an approximation
35  * to df/dx and/or the model is capable of directly computing
36  * (df/dx)(x,p) * dx/dp + df/dp(x,p).
37  *
38  * This model evaluator differes from CombinedForwardSensitivityModelEvaluator
39  * in that it doesn't include the state equations in the residual, just the
40  * sensitivity equations. Therefore it provides methods to set the state
41  * solution vector (x) and time derivatives (x_dot, x_dot_dot) for use in
42  * evaluating the senstivity residual. It also provides methods for setting
43  * the linear operator (W a.k.a. alpha*df/dx + beta*df/dx_dot) and its
44  * preconditioner in cases where they can be reused from the state model
45  * evaluations.
46  */
47 template <typename Scalar>
49  public Thyra::StateFuncModelEvaluatorBase<Scalar>,
50  public SensitivityModelEvaluatorBase<Scalar> {
51 public:
52  typedef Thyra::VectorBase<Scalar> Vector;
53  typedef Thyra::MultiVectorBase<Scalar> MultiVector;
54 
55  //! Constructor
56  /*!
57  * The optionally supplied parameter list supports the following options:
58  * <ul>
59  * <li> "Use DfDp as Tangent" (default: false) Reinterpret the df/dp
60  * out-arg as the tangent vector (df/dx)(x,p) * dx/dp + df/dp(x,p)
61  * as described above. If it is false, this implementation will
62  * compute the tangent through several calls to the models
63  * evalModel().
64  * <li> "Sensitivity Parameter Index" (default: 0) Model evaluator
65  * parameter index for which sensitivities will be computed.
66  * <li> "Sensitivity X Tangent Index" (default: 1) If "Use DfDp as Tangent"
67  * is true, the model evaluator parameter index for passing dx/dp
68  * as a Thyra::DefaultMultiVectorProductVector.
69  * <li> "Sensitivity X-Dot Tangent Index" (default: 2) If
70  * "Use DfDp as Tangent" is true, the model evaluator parameter index
71  * for passing dx_dot/dp as a Thyra::DefaultMultiVectorProductVector.
72  * <li> "Sensitivity X-Dot-Dot Tangent Index" (default: 3) If
73  * "Use DfDp as Tangent" is true, the model evaluator parameter index
74  * for passing dx_dot_dot/dp as a
75  * Thyra::DefaultMultiVectorProductVector (if the model supports
76  * x_dot_dot).
77  * </ul>
78  */
80  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & model,
81  const Teuchos::RCP<const Teuchos::ParameterList>& pList = Teuchos::null,
82  const Teuchos::RCP<MultiVector>& dxdp_init = Teuchos::null,
83  const Teuchos::RCP<MultiVector>& dx_dotdp_init = Teuchos::null,
84  const Teuchos::RCP<MultiVector>& dx_dotdot_dp_init = Teuchos::null);
85 
86  /** \name Public functions overridden from SensitivityModelEvaulator. */
87  //@{
88 
89  //! Get the underlying model 'f'
90  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > getForwardModel() const
91  { return model_; }
92 
93  //! Set solution history from forward state evaluation (for interpolation)
95  const Teuchos::RCP<const Tempus::SolutionHistory<Scalar> >& sh);
96 
97  //! Set solution state from forward state evaluation (for frozen state)
98  virtual void setForwardSolutionState(
99  const Teuchos::RCP<const Tempus::SolutionState<Scalar> >& s);
100 
101  //! Set the solver of the underlying model if you want to reuse it
102  virtual void setSolver(
103  const Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> >& solver,
104  const bool force_W_update) {
105  Teuchos::RCP<Thyra::NOXNonlinearSolver> nox_solver =
106  Teuchos::rcp_dynamic_cast<Thyra::NOXNonlinearSolver>(solver,true);
107  lo_ = nox_solver->get_nonconst_W_op(force_W_update);
108  po_ = nox_solver->get_nonconst_prec_op();
109  }
110 
111  //@}
112 
113  /** \name Public functions overridden from ModelEvaulator. */
114  //@{
115 
116  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int p) const;
117 
118  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int p) const;
119 
120  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
121 
122  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
123 
124  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
125 
126  Teuchos::ArrayView<const std::string> get_g_names(int j) const;
127 
128  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
129 
130  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_DgDx_dot_op(int j) const;
131 
132  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_DgDx_op(int j) const;
133 
134  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_DgDp_op(int j, int l) const;
135 
136  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
137  get_W_factory() const;
138 
139  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
140 
141  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
142 
143  //@}
144 
145  static Teuchos::RCP<const Teuchos::ParameterList> getValidParameters();
146 
147 private:
148 
149  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
150 
151  void evalModelImpl(
152  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
153  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs) const;
154 
155 
156  Thyra::ModelEvaluatorBase::InArgs<Scalar> prototypeInArgs_;
157  Thyra::ModelEvaluatorBase::OutArgs<Scalar> prototypeOutArgs_;
158 
159  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > model_;
160  Teuchos::RCP<MultiVector> dxdp_init_;
161  Teuchos::RCP<MultiVector> dx_dotdp_init_;
162  Teuchos::RCP<MultiVector> dx_dotdotdp_init_;
163  int p_index_;
168 
170  Teuchos::RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > dxdp_space_;
171  Teuchos::RCP<const Thyra::DefaultMultiVectorProductVectorSpace<Scalar> > dfdp_space_;
172  Teuchos::RCP<const Tempus::SolutionHistory<Scalar> > sh_;
173 
174  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > lo_;
175  Teuchos::RCP<Thyra::PreconditionerBase<Scalar> > po_;
176 
177  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdx_;
178  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdxdot_;
179  mutable Teuchos::RCP<Thyra::LinearOpBase<Scalar> > my_dfdxdotdot_;
180  mutable Teuchos::RCP<const Tempus::SolutionState<Scalar> > forward_state_;
181  mutable Teuchos::RCP<Tempus::SolutionState<Scalar> > nc_forward_state_;
182  mutable Scalar t_interp_;
183 };
184 
185 } // namespace Tempus
186 
187 #endif
void setForwardSolutionHistory(const Teuchos::RCP< const Tempus::SolutionHistory< Scalar > > &sh)
Set solution history from forward state evaluation (for interpolation)
virtual void setForwardSolutionState(const Teuchos::RCP< const Tempus::SolutionState< Scalar > > &s)
Set solution state from forward state evaluation (for frozen state)
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int p) const
Teuchos::RCP< const Thyra::DefaultMultiVectorProductVectorSpace< Scalar > > dxdp_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int p) const
StaggeredForwardSensitivityModelEvaluator(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< Thyra::LinearOpBase< Scalar > > create_DgDx_dot_op(int j) const
Teuchos::RCP< const Thyra::DefaultMultiVectorProductVectorSpace< Scalar > > dfdp_space_
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getForwardModel() const
Get the underlying model &#39;f&#39;.
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_DgDp_op(int j, int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
virtual void setSolver(const Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > &solver, const bool force_W_update)
Set the solver of the underlying model if you want to reuse it.
Transform a ModelEvaluator&#39;s sensitivity equations to its residual.
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_DgDx_op(int j) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
A ModelEvaluator decorator for sensitivity analysis.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const