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