Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_WrapperModelEvaluatorPairIMEX_Basic_impl.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_ModelEvaluatorIMEXPair_Basic_impl_hpp
10 #define Tempus_ModelEvaluatorIMEXPair_Basic_impl_hpp
11 
12 #include "Thyra_ProductVectorBase.hpp"
13 #include "Thyra_ProductVectorSpaceBase.hpp"
14 
15 
16 namespace Tempus {
17 
18 template <typename Scalar>
19 void
22 {
23  using Teuchos::RCP;
24 
25  wrapperImplicitInArgs_ = this->createInArgs();
26  wrapperImplicitOutArgs_ = this->createOutArgs();
27 
28  // A Thyra::VectorSpace requirement
29  TEUCHOS_TEST_FOR_EXCEPTION( !(explicitModel_->get_x_space()->isCompatible(
30  *(implicitModel_->get_x_space()))),
31  std::logic_error,
32  "Error - WrapperModelEvaluatorPairIMEX_Basic::initialize()\n"
33  " Explicit and Implicit vector x spaces are incompatible!\n"
34  " Explicit vector x space = " << *(explicitModel_->get_x_space())<< "\n"
35  " Implicit vector x space = " << *(implicitModel_->get_x_space())<< "\n");
36 
37  // A Thyra::VectorSpace requirement
38  TEUCHOS_TEST_FOR_EXCEPTION( !(explicitModel_->get_f_space()->isCompatible(
39  *(implicitModel_->get_f_space()))),
40  std::logic_error,
41  "Error - WrapperModelEvaluatorPairIMEX_Basic::initialize()\n"
42  " Explicit and Implicit vector f spaces are incompatible!\n"
43  " Explicit vector f space = " << *(explicitModel_->get_f_space())<< "\n"
44  " Implicit vector f space = " << *(implicitModel_->get_f_space())<< "\n");
45 }
46 
47 template <typename Scalar>
48 void
51  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & /* me */)
52 {
53  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
54  "Error - WrapperModelEvaluatorPairIMEX_Basic<Scalar>::setAppModel\n"
55  " should not be used. One should instead use setExplicitModel,\n"
56  " setImplicitModel, or create a new WrapperModelEvaluatorPairIMEX.\n");
57 }
58 
59 template <typename Scalar>
60 Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
62 getAppModel() const
63 {
64  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
65  "Error - WrapperModelEvaluatorPairIMEX_Basic<Scalar>::getAppModel\n"
66  " should not be used. One should instead use getExplicitModel,\n"
67  " getImplicitModel, or directly use this WrapperModelEvaluatorPairIMEX\n"
68  " object.\n");
69 }
70 
71 template <typename Scalar>
72 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
74 get_x_space() const
75 {
76  return this->implicitModel_->get_x_space();
77 }
78 
79 template <typename Scalar>
80 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
82 get_g_space(int i) const
83 {
84  return this->implicitModel_->get_g_space(i);
85 }
86 
87 template <typename Scalar>
88 Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
90 get_p_space(int i) const
91 {
92  return this->implicitModel_->get_p_space(i);
93 }
94 
95 template <typename Scalar>
96 Thyra::ModelEvaluatorBase::InArgs<Scalar>
99 {
100  typedef Thyra::ModelEvaluatorBase MEB;
101  MEB::InArgsSetup<Scalar> inArgs = this->createInArgs();
102  return inArgs;
103 }
104 
105 template <typename Scalar>
106 Thyra::ModelEvaluatorBase::InArgs<Scalar>
109 {
110  typedef Thyra::ModelEvaluatorBase MEB;
111  //MEB::InArgsSetup<Scalar> inArgs(implicitModel_->createInArgs());
112  MEB::InArgsSetup<Scalar> inArgs(implicitModel_->getNominalValues());
113  inArgs.setModelEvalDescription(this->description());
114  return inArgs;
115 }
116 
117 template <typename Scalar>
118 Thyra::ModelEvaluatorBase::OutArgs<Scalar>
121 {
122  typedef Thyra::ModelEvaluatorBase MEB;
123  MEB::OutArgsSetup<Scalar> outArgs(implicitModel_->createOutArgs());
124  outArgs.setModelEvalDescription(this->description());
125  return outArgs;
126 }
127 
128 template <typename Scalar>
130 evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs<Scalar> & inArgs,
131  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> & outArgs) const
132 {
133  typedef Thyra::ModelEvaluatorBase MEB;
134  using Teuchos::RCP;
135 
136  RCP<const Thyra::VectorBase<Scalar> > x = inArgs.get_x();
137  RCP<Thyra::VectorBase<Scalar> > x_dot = Thyra::createMember(get_x_space());
138  timeDer_->compute(x, x_dot);
139 
140  MEB::InArgs<Scalar> appImplicitInArgs (wrapperImplicitInArgs_);
141  MEB::OutArgs<Scalar> appImplicitOutArgs(wrapperImplicitOutArgs_);
142  appImplicitInArgs.set_x(x);
143  appImplicitInArgs.set_x_dot(x_dot);
144  for (int i=0; i<implicitModel_->Np(); ++i) {
145  if (inArgs.get_p(i) != Teuchos::null)
146  appImplicitInArgs.set_p(i, inArgs.get_p(i));
147  }
148 
149  appImplicitOutArgs.set_f(outArgs.get_f());
150  appImplicitOutArgs.set_W_op(outArgs.get_W_op());
151 
152  implicitModel_->evalModel(appImplicitInArgs,appImplicitOutArgs);
153 }
154 
155 } // end namespace Tempus
156 
157 #endif // Tempus_ModelEvaluatorIMEXPair_Basic_impl_hpp
virtual Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getAppModel() const
Get the underlying application ModelEvaluator.
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int i) const
Get the g space.
virtual void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &in, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &out) const
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
virtual void initialize()
Initialize after setting member data.
virtual void setAppModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &me)
Set the underlying application ModelEvaluator.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int i) const
Get the p space.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Get the x-solution space.