Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VanDerPol_ModelEvaluator_02.cpp
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 #include "Thyra_DefaultSpmdVectorSpace.hpp"
10 #include "Thyra_DetachedVectorView.hpp"
11 #include "Thyra_DetachedMultiVectorView.hpp"
12 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
13 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
14 #include "Thyra_DefaultLinearOpSource.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 
17 #include <iostream>
18 
20 
21 
22 template<class Scalar>
25  : dim_(2),
26  t0_ic_ (Scalar(0.0)),
27  epsilon_(Scalar(1.0e-01)),
28  x0_ic_ (Scalar(2.0)),
29  x1_ic_ (Scalar(0.0))
30 {
31  using Teuchos::RCP;
32  typedef ::Thyra::ModelEvaluatorBase MEB;
33 
34  // Create x_space and f_space
35  x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
37 
38  {
39  // Set up prototypical InArgs
40  MEB::InArgsSetup<Scalar> inArgs;
41  inArgs.setModelEvalDescription(this->description());
42  inArgs.setSupports( MEB::IN_ARG_t );
43  inArgs.setSupports( MEB::IN_ARG_x );
44  inArgs.setSupports( MEB::IN_ARG_x_dot );
45  prototypicalInArgs_ = inArgs;
46  }
47 
48  {
49  // Set up prototypical OutArgs
50  MEB::OutArgsSetup<Scalar> outArgs;
51  outArgs.setModelEvalDescription(this->description());
52  outArgs.setSupports( MEB::OUT_ARG_f );
53  prototypicalOutArgs_ = outArgs;
54  }
55 
56  // Set the initial conditions
58  nominalValues_.set_t(t0_ic_);
59  const RCP<Thyra::VectorBase<Scalar> > x_ic = createMember(x_space_);
60  { // scope to delete DetachedVectorView
61  Thyra::DetachedVectorView<Scalar> x_ic_view( *x_ic );
62  x_ic_view[0] = x0_ic_;
63  x_ic_view[1] = x1_ic_;
64  }
65  nominalValues_.set_x(x_ic);
66 
67  const RCP<Thyra::VectorBase<Scalar> > xDot_ic = createMember(x_space_);
68  { // scope to delete DetachedVectorView
69  Thyra::DetachedVectorView<Scalar> xDot_ic_view( *xDot_ic );
70  xDot_ic_view[0] = x1_ic_;
71  xDot_ic_view[1] = ((1.0-x0_ic_*x0_ic_)*x1_ic_-x0_ic_)/epsilon_;
72  }
73  nominalValues_.set_x_dot(xDot_ic);
74 
75 }
76 
77 
78 template<class Scalar>
79 void
84  ) const
85 {
86  using Teuchos::RCP;
87 
88  const RCP<const Thyra::VectorBase<Scalar> > x_in =
89  inArgs.get_x().assert_not_null();
90  Thyra::ConstDetachedVectorView<Scalar> x_in_view( *x_in );
91 
92  const RCP<Thyra::VectorBase<Scalar> > f_out =
93  outArgs.get_f().assert_not_null();
94 
95  if (inArgs.get_x_dot().is_null()) {
96  // Evaluate the Explicit ODE f(x,t) [= xdot]
97  Thyra::DetachedVectorView<Scalar> f_out_view( *f_out );
98  f_out_view[0] = x_in_view[1];
99  f_out_view[1] =
100  ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])/epsilon_;
101 
102  } else {
103  // Evaluate the implicit ODE f(xdot, x, t) [= 0]
104  RCP<const Thyra::VectorBase<Scalar> > x_dot_in;
105  x_dot_in = inArgs.get_x_dot().assert_not_null();
106  Thyra::DetachedVectorView<Scalar> f_out_view( *f_out );
107  Thyra::ConstDetachedVectorView<Scalar> x_dot_in_view( *x_dot_in );
108  f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
109  f_out_view[1] = x_dot_in_view[1]
110  - ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])/epsilon_;
111  }
112 }
113 
RCP< const VectorBase< Scalar > > get_x_dot() const
Thyra::ModelEvaluatorBase::OutArgs< Scalar > prototypicalOutArgs_
Prototypical OutArgs that just supports the evaluation vector (OUT_ARG_f)
Scalar epsilon_
This is a model parameter ( )
Evaluation< VectorBase< Scalar > > get_f() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs_bar, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs_bar) const
Scalar x1_ic_
initial condition for
Scalar x0_ic_
initial condition for
virtual std::string description() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > x_space_
Solution vector space (a defaultSpmdVectorSpace of dimension 2)
ModelEvaluator implementation for the example van der Pol Problem.
int dim_
Number of state unknowns (2)
Thyra::ModelEvaluatorBase::InArgs< Scalar > nominalValues_
Thyra::ModelEvaluatorBase::InArgs< Scalar > prototypicalInArgs_
RCP< const VectorBase< Scalar > > get_x() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > f_space_
Function evaluation vector space (a defaultSpmdVectorSpace of dimension 2)