Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VanDerPol_IMEXPart_ImplicitModel_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_TEST_VANDERPOL_IMEXPart_ImplicitMODEL_DECL_HPP
10 #define TEMPUS_TEST_VANDERPOL_IMEXPart_ImplicitMODEL_DECL_HPP
11 
12 #include "Thyra_ModelEvaluator.hpp" // Interface
13 #include "Thyra_StateFuncModelEvaluatorBase.hpp" // Implementation
14 
15 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
16 #include "Teuchos_ParameterList.hpp"
17 
18 namespace Tempus_Test {
19 
20 /** \brief van der Pol model formulated for the partitioned IMEX-RK.
21  *
22  * This is a canonical equation of a nonlinear oscillator (Hairer, Norsett,
23  * and Wanner, pp. 111-115, and Hairer and Wanner, pp. 4-5) for an electrical
24  * circuit. In implicit ODE form, \f$ \mathcal{F}(\dot{x},x,t) = 0 \f$,
25  * the scaled problem can be written as
26  * \f{eqnarray*}{
27  * \dot{x}_0(t) - x_1(t) & = & 0 \\
28  * \dot{x}_1(t) - [(1-x_0^2)x_1-x_0]/\epsilon & = & 0
29  * \f}
30  * where the initial conditions are
31  * \f{eqnarray*}{
32  * x_0(t_0=0) & = & 2 \\
33  * x_1(t_0=0) & = & 0
34  * \f}
35  * and the initial time derivatives are
36  * \f{eqnarray*}{
37  * \dot{x}_0(t_0=0) & = & x_1(t_0=0) = 0 \\
38  * \dot{x}_1(t_0=0) & = & [(1-x_0^2)x_1-x_0]/\epsilon = -2/\epsilon
39  * \f}
40  * For a partitioned IMEX-RK time stepper, we need to rewrite this in the
41  * following form
42  * \f{eqnarray*}{
43  * M(z,t)\, \dot{z} + G(z,t) + F(z,t) & = & 0, \\
44  * \mathcal{G}(\dot{z},z,t) + F(z,t) & = & 0,
45  * \f}
46  * where \f$\mathcal{G}(\dot{z},z,t) = M(z,t)\, \dot{z} + G(z,t)\f$,
47  * \f$M(z,t)\f$ is the mass matrix, \f$F(z,t)\f$ is the operator
48  * representing the "slow" physics (and evolved explicitly), and
49  * \f$G(z,t)\f$ is the operator representing the "fast" physics.
50  * For the van der Pol problem, we can separate the terms as follows
51  * \f[
52  * z = \left\{\begin{array}{c} y \\ x \end{array}\right\}
53  * = \left\{\begin{array}{c} x_0 \\ x_1 \end{array}\right\},\;\;\;
54  * F(z,t) = \left\{\begin{array}{c} F^y(x,y,t)\\F^x(x,y,t)\end{array}\right\}
55  * = \left\{\begin{array}{c} -x_1 \\ x_0/\epsilon\end{array}\right\},
56  * \mbox{ and }
57  * G(z,t) = \left\{\begin{array}{c} 0 \\ G^x(x,y,t)\end{array}\right\}
58  * = \left\{\begin{array}{c} 0 \\
59  * -(1-x_0^2)x_1/\epsilon \end{array}\right\}
60  * \f]
61  * where \f$M(z,t)=I\f$ is the identity matrix.
62  *
63  * Thus the explicit van der Pol model (VanDerPol_IMEX_ExplicitModel)
64  * formulated for the partitioned IMEX-RK is
65  * \f{eqnarray*}{
66  * F^y(x,y,t) & = & \dot{x}_0(t) - x_1(t) = 0 \\
67  * F^x(x,y,t) & = & \dot{x}_1(t) + x_0/\epsilon = 0
68  * \f}
69  * and the implicit van der Pol model (VanDerPol_IMEXPart_ImplicitModel)
70  * formulated for the partitioned IMEX-RK is
71  * \f[
72  * G^x(x,y,t) = \dot{x}_1(t) - (1-x_0^2)x_1/\epsilon = 0
73  * \f]
74  * Noting that \f$G^y(x,y,t) = \dot{x}_0(t) = 0\f$ is not needed.
75  *
76  * Recalling the defintion of the iteration matrix, \f$W\f$,
77  * \f[
78  * W_{ij} \equiv \frac{d\mathcal{G}^x_i}{dx_j} =
79  * \alpha \frac{\partial\mathcal{G}^x_i}{\partial \dot{x}_j}
80  * + \beta \frac{\partial\mathcal{G}^x_i}{\partial x_j}
81  * \f]
82  * where
83  * \f[
84  * \alpha = \left\{
85  * \begin{array}{cl}
86  * \frac{\partial\dot{x}_i}{\partial x_j} & \mbox{ if } i = j \\
87  * 0 & \mbox{ if } i \neq j
88  * \end{array} \right.
89  * \;\;\;\; \mbox{ and } \;\;\;\;
90  * \beta = 1
91  * \f]
92  * we can write for the implicit van der Pol model
93  * (VanDerPol_IMEXPart_ImplicitModel)
94  * \f{eqnarray*}{
95  * W_{00} = \alpha \frac{\partial\mathcal{G}^x_0}{\partial \dot{x}_1}
96  * + \beta \frac{\partial\mathcal{G}^x_0}{\partial x_1}
97  * & = & \alpha + \beta (x^2_0 - 1)/\epsilon \\
98  * \f}
99  */
100 
101 template<class Scalar>
103  : public Thyra::StateFuncModelEvaluatorBase<Scalar>,
104  public Teuchos::ParameterListAcceptorDefaultBase
105 {
106  public:
107 
108  // Constructor
110  Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null);
111 
112  /** \name Public functions overridden from ModelEvaluator. */
113  //@{
114  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
115  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
116  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
117  Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
118  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
119  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
120  get_W_factory() const;
121  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
122 
123  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
124  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
125  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
126  //@}
127 
128  /** \name Public functions overridden from ParameterListAcceptor. */
129  //@{
130  void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
131  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
132  //@}
133 
134 private:
135 
136  void setupInOutArgs_() const;
137 
138  /** \name Private functions overridden from ModelEvaluatorDefaultBase. */
139  //@{
140  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
141  void evalModelImpl(
142  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs_bar,
143  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs_bar
144  ) const;
145  //@}
146 
147  int dim_; ///< Number of state unknowns (1)
148  int Np_; ///< Number of parameter vectors (1)
149  int np_; ///< Number of parameters in this vector (1)
150  int Ng_; ///< Number of observation functions (0)
151  int ng_; ///< Number of elements in this observation function (0)
152  bool haveIC_; ///< false => no nominal values are provided (default=true)
153  bool useDfDpAsTangent_; ///< Treat DfDp OutArg as tangent (df/dx*dx/dp+df/dp)
154  mutable bool isInitialized_;
155  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs_;
156  mutable Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs_;
157  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
158  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > x_space_;
159  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > f_space_;
160  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > p_space_;
161  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > y_space_;
162  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > dxdp_space_;
163  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > dydp_space_;
164  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > g_space_;
165 
166  // Parameters for the model:
167  Scalar epsilon_; ///< This is a model parameter
168  Scalar t0_ic_; ///< initial time
169  Scalar x0_ic_; ///< initial condition for x0
170  Scalar x1_ic_; ///< initial condition for x1
171 };
172 
173 
174 } // namespace Tempus_Test
175 #endif // TEMPUS_TEST_VANDERPOL_IMEXPart_ImplicitMODEL_DECL_HPP
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
van der Pol model formulated for the partitioned IMEX-RK.
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
int ng_
Number of elements in this observation function (0)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > p_space_
VanDerPol_IMEXPart_ImplicitModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > f_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > dxdp_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
bool haveIC_
false =&gt; no nominal values are provided (default=true)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > dydp_space_
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > x_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > g_space_
bool useDfDpAsTangent_
Treat DfDp OutArg as tangent (df/dx*dx/dp+df/dp)
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > y_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const