Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
HarmonicOscillatorModel_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_HARMONIC_OSCILLATOR_MODEL_DECL_HPP
10 #define TEMPUS_TEST_HARMONIC_OSCILLATOR_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
21  * Consider the ODE:
22  * \f[
23  * m\ddot{x} + c\dot{x} + kx=f
24  * \f]
25  * where \f$k \geq 0\f$ is a constant, \f$c\f$ is a constant damping parameter, \f$f\f$ is a constant forcing parameter,
26  * and \f$m>0\f$ is a constant mass parameter, with initial conditions are:
27  * \f{eqnarray*}{
28  * x(0) & = & 0\\
29  * \dot{x}(0) & = & 1
30  * \f}
31  * It is straight-forward to show that the exact solution to this ODE is:
32  * \f{eqnarray*}{
33  * x(t) & = & t(1+0.5\tilde{f}t), \hspace{3.6cm} if \hspace{0.2cm} k = c = 0 \\
34  * & = & \frac{(\tilde{c}-\tilde{f})}{\tilde{c}^2}(1-e^{-\tilde{c}t}) + \frac{f}{c}t, \hspace{1.9cm} if \hspace{0.2cm} k = 0, c\neq 0 \\
35  * & = & \frac{1}{\sqrt{\tilde{k}}}\sin(\sqrt{\tilde{k}}t) + \frac{f}{k}\left(1-\cos(\sqrt{\tilde{k}}t) \right), \hspace{0.2cm} if \hspace{0.2cm} k > 0, c = 0
36  * \f}
37  * where \f$\tilde{c}\equiv c/m\f$, \f$\tilde{k}\equiv k/m\f$ and \f$\tilde{f}\equiv f/m\f$. While it is possible to derive the solution to this ODE for the case when \f$k > 0\f$ and \f$c \neq 0\f$,
38  * we do not consider that case here. When \f$c = k = 0\f$, \f$m=1\f$, and \f$f=-1\f$,
39  * our ODE simplies to a
40  * canonical differential equation model of a ball thrown up
41  * in the air, with a parabolic trajectory solution, namely
42  * \f[
43  * x(t) = t(1-0.5t)
44  * \f]
45  * where \f$t\in [0,2]\f$. An EpetraExt version of this simplified version of the test is implemented in
46  * Piro::MockModelEval_B (see Trilinos/packages/piro/test), where it is used to test the Piro (EpetraExt)
47  * Newmark-Beta scheme (see input_Solver_NB.xml input file). When \f$c = f = 0\f$ and \f$m=k = 1\f$,
48  * this test is equivalent to the SinCos model..
49  */
50 
51 template<class Scalar>
53  : public Thyra::StateFuncModelEvaluatorBase<Scalar>,
54  public Teuchos::ParameterListAcceptorDefaultBase
55 {
56  public:
57 
58  // Constructor
59  HarmonicOscillatorModel(Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null, const bool use_accel_IC = false);
60 
61  // Exact solution
62  Thyra::ModelEvaluatorBase::InArgs<Scalar> getExactSolution(double t) const;
63 
64  /** \name Public functions overridden from ModelEvaluator. */
65  //@{
66 
67  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const;
68  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const;
69  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
70  Teuchos::RCP<Thyra::LinearOpWithSolveBase<Scalar> > create_W() const;
71  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const;
72  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> > get_W_factory() const;
73  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
74 
75  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int l) const;
76  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int l) const;
77  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int j) const;
78 
79  //@}
80 
81  /** \name Public functions overridden from ParameterListAcceptor. */
82  //@{
83  void setParameterList(Teuchos::RCP<Teuchos::ParameterList> const& paramList);
84  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
85  //@}
86 
87 private:
88 
89  void setupInOutArgs_() const;
90 
91  /** \name Private functions overridden from ModelEvaluatorDefaultBase. */
92  //@{
93  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
94  void evalModelImpl(
95  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs_bar,
96  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs_bar
97  ) const;
98  //@}
99 
100 private:
101  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > x_space_;
102  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > p_space_;
103  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > g_space_;
104  Teuchos::RCP<Thyra::VectorBase<Scalar> > x_vec_;
105  Teuchos::RCP<Thyra::VectorBase<Scalar> > x_dot_vec_;
106  Teuchos::RCP<Thyra::VectorBase<Scalar> > x_dot_dot_vec_;
107  Teuchos::RCP<Thyra::VectorBase<Scalar> > p_init_;
108  int vecLength_; //Number of state unknowns (1)
109  int numResponses_; //Number of responses (1)
110  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs_;
111  mutable Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs_;
112  mutable Thyra::ModelEvaluatorBase::InArgs<Scalar> nominalValues_;
113  mutable bool isInitialized_;
114  double c_; //damping coefficient
115  double f_; //forcing coefficient
116  double k_; //coefficient multiplying x in ODE
117  double m_; //mass coefficient
118  Teuchos::RCP<Teuchos::FancyOStream> out_;
119 };
120 
121 
122 
123 } // namespace Tempus_Test
124 #endif // TEMPUS_TEST_HARMONIC_OSCILLATOR_MODEL_DECL_HPP
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
Teuchos::RCP< Thyra::VectorBase< Scalar > > p_init_
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_dot_vec_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > g_space_
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int l) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > getExactSolution(double t) const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int j) const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > p_space_
Teuchos::RCP< Teuchos::FancyOStream > out_
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_dot_dot_vec_
Thyra::ModelEvaluatorBase::InArgs< Scalar > nominalValues_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int l) const
Teuchos::RCP< Thyra::LinearOpWithSolveBase< Scalar > > create_W() const
void setParameterList(Teuchos::RCP< Teuchos::ParameterList > const &paramList)
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > x_space_
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
HarmonicOscillatorModel(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null, const bool use_accel_IC=false)
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_vec_
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs_
Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs_
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const