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: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
10 #include "Thyra_DefaultSpmdVectorSpace.hpp"
11 #include "Thyra_DetachedVectorView.hpp"
12 #include "Thyra_DetachedMultiVectorView.hpp"
13 #include "Thyra_DefaultSerialDenseLinearOpWithSolveFactory.hpp"
14 #include "Thyra_DefaultMultiVectorLinearOpWithSolve.hpp"
15 #include "Thyra_DefaultLinearOpSource.hpp"
16 #include "Thyra_VectorStdOps.hpp"
17 
18 #include <iostream>
19 
21 
22 
23 template<class Scalar>
26  : dim_(2),
27  t0_ic_ (Scalar(0.0)),
28  epsilon_(Scalar(1.0e-01)),
29  x0_ic_ (Scalar(2.0)),
30  x1_ic_ (Scalar(0.0))
31 {
32  using Teuchos::RCP;
33  typedef ::Thyra::ModelEvaluatorBase MEB;
34 
35  // Create x_space and f_space
36  x_space_ = Thyra::defaultSpmdVectorSpace<Scalar>(dim_);
38 
39  {
40  // Set up prototypical InArgs
41  MEB::InArgsSetup<Scalar> inArgs;
42  inArgs.setModelEvalDescription(this->description());
43  inArgs.setSupports( MEB::IN_ARG_t );
44  inArgs.setSupports( MEB::IN_ARG_x );
45  inArgs.setSupports( MEB::IN_ARG_x_dot );
46  prototypicalInArgs_ = inArgs;
47  }
48 
49  {
50  // Set up prototypical OutArgs
51  MEB::OutArgsSetup<Scalar> outArgs;
52  outArgs.setModelEvalDescription(this->description());
53  outArgs.setSupports( MEB::OUT_ARG_f );
54  prototypicalOutArgs_ = outArgs;
55  }
56 
57  // Set the initial conditions
59  nominalValues_.set_t(t0_ic_);
60  const RCP<Thyra::VectorBase<Scalar> > x_ic = createMember(x_space_);
61  { // scope to delete DetachedVectorView
62  Thyra::DetachedVectorView<Scalar> x_ic_view( *x_ic );
63  x_ic_view[0] = x0_ic_;
64  x_ic_view[1] = x1_ic_;
65  }
66  nominalValues_.set_x(x_ic);
67 
68  const RCP<Thyra::VectorBase<Scalar> > xDot_ic = createMember(x_space_);
69  { // scope to delete DetachedVectorView
70  Thyra::DetachedVectorView<Scalar> xDot_ic_view( *xDot_ic );
71  xDot_ic_view[0] = x1_ic_;
72  xDot_ic_view[1] = ((1.0-x0_ic_*x0_ic_)*x1_ic_-x0_ic_)/epsilon_;
73  }
74  nominalValues_.set_x_dot(xDot_ic);
75 
76 }
77 
78 
79 template<class Scalar>
80 void
85  ) const
86 {
87  using Teuchos::RCP;
88 
89  const RCP<const Thyra::VectorBase<Scalar> > x_in =
90  inArgs.get_x().assert_not_null();
91  Thyra::ConstDetachedVectorView<Scalar> x_in_view( *x_in );
92 
93  const RCP<Thyra::VectorBase<Scalar> > f_out =
94  outArgs.get_f().assert_not_null();
95 
96  if (inArgs.get_x_dot().is_null()) {
97  // Evaluate the Explicit ODE f(x,t) [= xdot]
98  Thyra::DetachedVectorView<Scalar> f_out_view( *f_out );
99  f_out_view[0] = x_in_view[1];
100  f_out_view[1] =
101  ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])/epsilon_;
102 
103  } else {
104  // Evaluate the implicit ODE f(xdot, x, t) [= 0]
105  RCP<const Thyra::VectorBase<Scalar> > x_dot_in;
106  x_dot_in = inArgs.get_x_dot().assert_not_null();
107  Thyra::DetachedVectorView<Scalar> f_out_view( *f_out );
108  Thyra::ConstDetachedVectorView<Scalar> x_dot_in_view( *x_dot_in );
109  f_out_view[0] = x_dot_in_view[0] - x_in_view[1];
110  f_out_view[1] = x_dot_in_view[1]
111  - ((1.0-x_in_view[0]*x_in_view[0])*x_in_view[1]-x_in_view[0])/epsilon_;
112  }
113 }
114 
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)