Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SinCosModel_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_SINCOS_MODEL_DECL_HPP
10 #define TEMPUS_TEST_SINCOS_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 Sine-Cosine model problem from Rythmos.
21  * This is a canonical Sine-Cosine differential equation
22  * \f[
23  * \mathbf{\ddot{x}}=-\mathbf{x}
24  * \f]
25  * with a few enhancements. We start with the exact solution to the
26  * differential equation
27  * \f{eqnarray*}{
28  * x_{0}(t) & = & a+b*\sin((f/L)*t+\phi)\\
29  * x_{1}(t) & = & b*(f/L)*\cos((f/L)*t+\phi)
30  * \f}
31  * then the form of the model is
32  * \f{eqnarray*}{
33  * \frac{d}{dt}x_{0}(t) & = & x_{1}(t)\\
34  * \frac{d}{dt}x_{1}(t) & = & \left(\frac{f}{L}\right)^{2}(a-x_{0}(t))
35  * \f}
36  * where the default parameter values are \f$a=0\f$, \f$f=1\f$, and \f$L=1\f$,
37  * and the initial conditions
38  * \f{eqnarray*}{
39  * x_{0}(t_{0}=0) & = & \gamma_{0}[=0]\\
40  * x_{1}(t_{0}=0) & = & \gamma_{1}[=1]
41  * \f}
42  * determine the remaining coefficients
43  * \f{eqnarray*}{
44  * \phi & = & \arctan(((f/L)/\gamma_{1})*(\gamma_{0}-a))-(f/L)*t_{0}[=0]\\
45  * b & = & \gamma_{1}/((f/L)*cos((f/L)*t_{0}+\phi))[=1]
46  * \f}
47 
48  * Therefore this model has three model parameters and two initial conditions
49  * which effect the exact solution as above.
50  * \f[
51  * \mathbf{p}=(a,f,L)
52  * \f]
53  * \f[
54  * \dot{\mathbf{x}}=\mathbf{F}(\mathbf{x},t,\mathbf{p})
55  * \f]
56  * where
57  * \f{eqnarray*}{
58  * F_{0} & = & x_{1}\\
59  * F_{1} & = & \left(\frac{f}{L}\right)^{2}(a-x_{0})
60  * \f}
61 
62  * The exact sensitivities, \f$\mathbf{s}=\partial\mathbf{x}/\partial\mathbf{p}\f$,
63  * for the problem are specified as
64  * \f[
65  * \mathbf{s}(t)=\left[\begin{array}{cc}
66  * 1 & 0\\
67  * \left(\frac{b}{L}\right)t\,\cos\left(\left(\frac{f}{L}\right)t+\phi\right) & \left(\frac{b}{L}\right)\cos\left(\left(\frac{f}{L}\right)t+\phi\right)-\frac{b\, f\, t}{L^{2}}\sin\left(\left(\frac{f}{L}\right)t+\phi\right)\\
68  * -\frac{b\, f\, t}{L^{2}}\cos\left(\left(\frac{f}{L}\right)t+\phi\right) & -\frac{b\, f}{L^{2}}\cos\left(\left(\frac{f}{L}\right)t+\phi\right)+\frac{b\, f^{2}\, t}{L^{3}}\sin\left(\left(\frac{f}{L}\right)t+\phi\right)
69  * \end{array}\right]
70  * \f]
71  * and for the default initial conditions, \f$\phi=0\f$ and \f$b=1\f$
72  * \f[
73  * \mathbf{s}(t=0)=\left[\begin{array}{cc}
74  * 1 & 0\\
75  * 0 & \frac{b}{L}\\
76  * 0 & -\frac{f}{L^{2}}
77  * \end{array}\right]
78  * \f]
79  * The time differentiated sensitivities, \f$\dot{\mathbf{s}}=\partial\mathbf{s}/\partial t=\partial/\partial t(\partial\mathbf{x}/\partial\mathbf{p})=\partial/\partial\mathbf{p}(\partial\mathbf{x}/\partial t)\f$
80  * are
81  * \f[
82  * \dot{\mathbf{s}}(t)=\left[\begin{array}{cc}
83  * 0 & 0\\
84  * \left(\frac{b}{L}\right)\cos\left(\left(\frac{f}{L}\right)t+\phi\right)-\frac{b\, f\, t}{L^{2}}\sin\left(\left(\frac{f}{L}\right)t+\phi\right) & -\frac{2b\, f}{L^{2}}\sin\left(\left(\frac{f}{L}\right)t+\phi\right)\left(\frac{b}{L}\right)-\frac{b\, f^{2}\, t}{L^{3}}\cos\left(\left(\frac{f}{L}\right)t+\phi\right)\\
85  * -\frac{b\, f}{L^{2}}\cos\left(\left(\frac{f}{L}\right)t+\phi\right)+\frac{b\, f^{2}\, t}{L^{3}}\sin\left(\left(\frac{f}{L}\right)t+\phi\right) & \frac{2b\, f^{2}}{L^{3}}\sin\left(\left(\frac{f}{L}\right)t+\phi\right)+\frac{b\, f^{3}\, t}{L^{4}}\cos\left(\left(\frac{f}{L}\right)t+\phi\right)
86  * \end{array}\right]
87  * \f]
88  */
89 
90 template<class Scalar>
92  : public Thyra::StateFuncModelEvaluatorBase<Scalar>,
93  public Teuchos::ParameterListAcceptorDefaultBase
94 {
95  public:
96 
97  // Constructor
98  SinCosModel(Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null);
99 
100  // Exact solution
101  Thyra::ModelEvaluatorBase::InArgs<Scalar> getExactSolution(double t) const;
102 
103  // Exact sensitivity solution
104  Thyra::ModelEvaluatorBase::InArgs<Scalar> getExactSensSolution(int j, double t) const;
105 
106  /** \name Public functions overridden from ModelEvaluator. */
107  //@{
108 
109  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
110  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
111  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
112  Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
113  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
114  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
115  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
116 
117  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
118  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
119  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
120 
121  //@}
122 
123  /** \name Public functions overridden from ParameterListAcceptor. */
124  //@{
125  void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
126  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
127  //@}
128 
129 private:
130 
131  void setupInOutArgs_() const;
132 
133  /** \name Private functions overridden from ModelEvaluatorDefaultBase. */
134  //@{
135  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
136  void evalModelImpl(
137  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs_bar,
138  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs_bar
139  ) const;
140  //@}
141 
142  void calculateCoeffFromIC_();
143 
144 private:
145  int dim_; ///< Number of state unknowns (2)
146  int Np_; ///< Number of parameter vectors (1)
147  int np_; ///< Number of parameters in this vector (2)
148  int Ng_; ///< Number of observation functions (1)
149  int ng_; ///< Number of elements in this observation function (1)
150  bool haveIC_; ///< false => no nominal values are provided (default=true)
151  bool acceptModelParams_; ///< Changes inArgs to require parameters
152  bool useDfDpAsTangent_; ///< Treat DfDp OutArg as tangent (df/dx*dx/dp+df/dp)
153  mutable bool isInitialized_;
154  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs_;
155  mutable Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs_;
156  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
157  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > x_space_;
158  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > f_space_;
159  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > p_space_;
160  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > g_space_;
161  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > DxDp_space_;
162 
163  // Parameters for the model: x_0(t) = a + b*sin(f*t+phi)
164  // x_1(t) = b*f*cos(f*t+phi)
165  Scalar a_; ///< Model parameter
166  Scalar f_; ///< Model parameter
167  Scalar L_; ///< Model parameter
168  Scalar phi_; ///< Parameter determined from the IC
169  Scalar b_; ///< Parameter determined from the IC
170  Scalar t0_ic_; ///< Time value where the initial condition is specified
171  Scalar x0_ic_; ///< Initial condition for x0
172  Scalar x1_ic_; ///< Initial condition for x1
173 };
174 
175 
176 /// Non-member constructor
177 //Teuchos::RCP<SinCosModel> sineCosineModel(
178 // Teuchos::RCP<Teuchos::ParameterList> pList_)
179 //{
180 // Teuchos::RCP<SinCosModel> model = rcp(new SinCosModel(pList_));
181 // return(model);
182 //}
183 
184 
185 } // namespace Tempus_Test
186 #endif // TEMPUS_TEST_SINCOS_MODEL_DECL_HPP
Scalar b_
Parameter determined from the IC.
Scalar L_
Model parameter.
int Ng_
Number of observation functions (1)
int ng_
Number of elements in this observation function (1)
Thyra::ModelEvaluatorBase::InArgs< Scalar > nominalValues_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > DxDp_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > p_space_
Scalar f_
Model parameter.
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
bool useDfDpAsTangent_
Treat DfDp OutArg as tangent (df/dx*dx/dp+df/dp)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > f_space_
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
int dim_
Number of state unknowns (2)
int Np_
Number of parameter vectors (1)
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
bool haveIC_
false =&gt; no nominal values are provided (default=true)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs_
bool acceptModelParams_
Changes inArgs to require parameters.
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
Scalar t0_ic_
Time value where the initial condition is specified.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSolution(double t) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs_
SinCosModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
int np_
Number of parameters in this vector (2)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > g_space_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > x_space_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
Scalar x1_ic_
Initial condition for x1.
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Scalar phi_
Parameter determined from the IC.
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSensSolution(int j, double t) const
Scalar x0_ic_
Initial condition for x0.
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Scalar a_
Model parameter.
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)