Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
VanDerPolModel_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_MODEL_DECL_HPP
10 #define TEMPUS_TEST_VANDERPOL_MODEL_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 problem for nonlinear electrical circuit.
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  * \mathcal{F}_0 & = & \dot{x}_0(t) - x_1(t) = 0 \\
28  * \mathcal{F}_1 & = & \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  * Hairer and Wanner suggest the output times of \f$t = 1,2,3,4,...,11\f$,
41  * and \f$\epsilon = 10^{-6}\f$ to make the problem very stiff.
42  * For \f$\epsilon = 0\f$, the solution becomes
43  * \f{eqnarray*}{
44  * \ln \left|x_0\right| - \frac{x_0^2}{2} & = & t + C \\
45  * x_1 & = & \frac{x_0}{1-x_0^2}
46  * \f}
47  * where \f$C =\ln \left|x_0(t=0)\right| - \frac{x_0^2(t=0)}{2} =-1.306853.\f$
48  *
49  * The components of iteration matrix, \f$W\f$, are defined to be
50  * \f[
51  * W_{ij} \equiv \frac{d\mathcal{F}_i}{dx_j} = \frac{d}{dx_j}
52  * \mathcal{F}_i (\dot{x}_i, x_0, \ldots, x_k, \ldots, x_K, t)
53  * \f]
54  * (not using Einstein summation). Using the chain rule, we can write
55  * \f[
56  * \frac{d\mathcal{F}_i}{dx_j} =
57  * \frac{\partial\dot{x}_i}{\partial x_j}
58  * \frac{\partial\mathcal{F}_i}{\partial \dot{x}_i}
59  * + \sum_{k=0}^K \frac{\partial x_k}{\partial x_j}
60  * \frac{\partial\mathcal{F}_i}{\partial x_k}
61  * + \frac{\partial t}{\partial x_j}
62  * \frac{\partial\mathcal{F}_i}{\partial t}
63  * \f]
64  * but noting that \f$\partial t/\partial x_j = 0\f$ and
65  * \f[
66  * \frac{\partial x_k}{\partial x_j} = \left\{
67  * \begin{array}{c}
68  * 1 \mbox{ if } j = k \\
69  * 0 \mbox{ if } j \neq k
70  * \end{array}
71  * \right.
72  * \f]
73  * we can write
74  * \f[
75  * \frac{d\mathcal{F}_i}{dx_j} =
76  * \alpha \frac{\partial\mathcal{F}_i}{\partial \dot{x}_j}
77  * + \beta \frac{\partial\mathcal{F}_i}{\partial x_j}
78  * \f]
79  * where
80  * \f[
81  * \alpha = \left\{
82  * \begin{array}{cl}
83  * \frac{\partial\dot{x}_i}{\partial x_j} & \mbox{ if } i = j \\
84  * 0 & \mbox{ if } i \neq j
85  * \end{array} \right.
86  * \;\;\;\; \mbox{ and } \;\;\;\;
87  * \beta = \left\{
88  * \begin{array}{cl}
89  * \frac{\partial x_k}{\partial x_j} = 1 & \mbox{ if } j = k \\
90  * 0 & \mbox{ if } j \neq k
91  * \end{array} \right.
92  * \f]
93  * Thus for the van der Pol problem, we have
94  * \f{eqnarray*}{
95  * W_{00} = \alpha \frac{\partial\mathcal{F}_0}{\partial \dot{x}_0}
96  * + \beta \frac{\partial\mathcal{F}_0}{\partial x_0}
97  * & = & \alpha \\
98  * W_{01} = \alpha \frac{\partial\mathcal{F}_0}{\partial \dot{x}_1}
99  * + \beta \frac{\partial\mathcal{F}_0}{\partial x_1}
100  * & = & -\beta \\
101  * W_{10} = \alpha \frac{\partial\mathcal{F}_1}{\partial \dot{x}_0}
102  * + \beta \frac{\partial\mathcal{F}_1}{\partial x_0}
103  * & = & \beta (2 x_0 x_1 + 1)/\epsilon \\
104  * W_{11} = \alpha \frac{\partial\mathcal{F}_1}{\partial \dot{x}_1}
105  * + \beta \frac{\partial\mathcal{F}_1}{\partial x_1}
106  * & = & \alpha + \beta (x^2_0 - 1)/\epsilon \\
107  * \f}
108  */
109 
110 template<class Scalar>
112  : public Thyra::StateFuncModelEvaluatorBase<Scalar>,
113  public Teuchos::ParameterListAcceptorDefaultBase
114 {
115  public:
116 
117  // Constructor
118  VanDerPolModel(Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null);
119 
120  // Exact solution
121  Thyra::ModelEvaluatorBase::InArgs<Scalar> getExactSolution(double t) const;
122 
123  // Exact sensitivity solution
124  Thyra::ModelEvaluatorBase::InArgs<Scalar> getExactSensSolution(int j, double t) const;
125 
126  /** \name Public functions overridden from ModelEvaluator. */
127  //@{
128 
129  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
130  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
131  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
132  Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
133  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
134  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
135  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
136 
137  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
138  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
139  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
140 
141  //@}
142 
143  /** \name Public functions overridden from ParameterListAcceptor. */
144  //@{
145  void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
146  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
147  //@}
148 
149 private:
150 
151  void setupInOutArgs_() const;
152 
153  /** \name Private functions overridden from ModelEvaluatorDefaultBase. */
154  //@{
155  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
156  void evalModelImpl(
157  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs_bar,
158  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs_bar
159  ) const;
160  //@}
161 
162  int dim_; ///< Number of state unknowns (2)
163  int Np_; ///< Number of parameter vectors (1)
164  int np_; ///< Number of parameters in this vector (1)
165  int Ng_; ///< Number of observation functions (0)
166  int ng_; ///< Number of elements in this observation function (0)
167  bool haveIC_; ///< false => no nominal values are provided (default=true)
168  bool acceptModelParams_; ///< Changes inArgs to require parameters
169  mutable bool isInitialized_;
170  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs_;
171  mutable Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs_;
172  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
173  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > x_space_;
174  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > f_space_;
175  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > p_space_;
176  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > g_space_;
177 
178  // Parameters for the model:
179  Scalar epsilon_; ///< This is a model parameter
180  Scalar t0_ic_; ///< initial time
181  Scalar x0_ic_; ///< initial condition for x0
182  Scalar x1_ic_; ///< initial condition for x1
183 };
184 
185 
186 } // namespace Tempus_Test
187 #endif // TEMPUS_TEST_VANDERPOL_MODEL_DECL_HPP
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > p_space_
Thyra::ModelEvaluatorBase::InArgs< Scalar > nominalValues_
int Ng_
Number of observation functions (0)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs_
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > g_space_
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSolution(double t) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
int Np_
Number of parameter vectors (1)
bool haveIC_
false =&gt; no nominal values are provided (default=true)
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
VanDerPolModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > f_space_
Scalar x1_ic_
initial condition for x1
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > x_space_
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs_
Scalar epsilon_
This is a model parameter.
bool acceptModelParams_
Changes inArgs to require parameters.
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
int dim_
Number of state unknowns (2)
van der Pol model problem for nonlinear electrical circuit.
int np_
Number of parameters in this vector (1)
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSensSolution(int j, double t) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
int ng_
Number of elements in this observation function (0)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Scalar x0_ic_
initial condition for x0
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const