Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_WrapperModelEvaluatorPairIMEX_Basic_impl.hpp
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 #ifndef Tempus_ModelEvaluatorIMEXPair_Basic_impl_hpp
11 #define Tempus_ModelEvaluatorIMEXPair_Basic_impl_hpp
12 
13 #include "Thyra_ProductVectorBase.hpp"
14 #include "Thyra_ProductVectorSpaceBase.hpp"
15 
16 namespace Tempus {
17 
18 template <typename Scalar>
20 {
21  using Teuchos::RCP;
22  using Teuchos::rcp_const_cast;
23 
25  index_ = -1;
26 
27  typedef Thyra::ModelEvaluatorBase MEB;
28  MEB::InArgs<Scalar> inArgs = implicitModel_->getNominalValues();
29  x_ = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x());
30 
31  if (inArgs.supports(MEB::IN_ARG_x_dot)) {
32  xDot_ = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot());
33  }
34  else {
35  xDot_ = Teuchos::null;
36  }
37 
38  // A Thyra::VectorSpace requirement
40  !(explicitModel_->get_x_space()->isCompatible(
41  *(implicitModel_->get_x_space()))),
42  std::logic_error,
43  "Error - WrapperModelEvaluatorPairIMEX_Basic::initialize()\n"
44  << " Explicit and Implicit vector x spaces are incompatible!\n"
45  << " Explicit vector x space = "
46  << *(explicitModel_->get_x_space())
47  << "\n Implicit vector x space = "
48  << *(implicitModel_->get_x_space()) << "\n");
49 
50  // A Thyra::VectorSpace requirement
52  !(explicitModel_->get_f_space()->isCompatible(
53  *(implicitModel_->get_f_space()))),
54  std::logic_error,
55  "Error - WrapperModelEvaluatorPairIMEX_Basic::initialize()\n"
56  << " Explicit and Implicit vector f spaces are incompatible!\n"
57  << " Explicit vector f space = "
58  << *(explicitModel_->get_f_space())
59  << "\n Implicit vector f space = "
60  << *(implicitModel_->get_f_space()) << "\n");
61 }
62 
63 template <typename Scalar>
65  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& /* me */)
66 {
68  true, std::logic_error,
69  "Error - WrapperModelEvaluatorPairIMEX_Basic<Scalar>::setAppModel\n"
70  " should not be used. One should instead use setExplicitModel,\n"
71  " setImplicitModel, or create a new WrapperModelEvaluatorPairIMEX.\n");
72 }
73 
74 template <typename Scalar>
77 {
79  true, std::logic_error,
80  "Error - WrapperModelEvaluatorPairIMEX_Basic<Scalar>::getAppModel\n"
81  " should not be used. One should instead use getExplicitModel,\n"
82  " getImplicitModel, or directly use this WrapperModelEvaluatorPairIMEX\n"
83  " object.\n");
84 }
85 
86 template <typename Scalar>
89 {
90  return this->implicitModel_->get_x_space();
91 }
92 
93 template <typename Scalar>
96 {
97  return this->implicitModel_->get_g_space(i);
98 }
99 
100 template <typename Scalar>
103 {
104  return this->implicitModel_->get_p_space(i);
105 }
106 
107 template <typename Scalar>
110 {
111  typedef Thyra::ModelEvaluatorBase MEB;
112  MEB::InArgsSetup<Scalar> inArgs = this->createInArgs();
113  return std::move(inArgs);
114 }
115 
116 template <typename Scalar>
119 {
120  typedef Thyra::ModelEvaluatorBase MEB;
121  // MEB::InArgsSetup<Scalar> inArgs(implicitModel_->createInArgs());
122  MEB::InArgsSetup<Scalar> inArgs(implicitModel_->getNominalValues());
123 
124  inArgs.set_x(x_);
125  if (y_ != Teuchos::null) inArgs.set_p(index_, y_);
126  if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(xDot_);
127  if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(time_);
128  if (inArgs.supports(MEB::IN_ARG_step_size))
129  inArgs.set_step_size(p_->timeStepSize_);
130  if (inArgs.supports(MEB::IN_ARG_alpha)) inArgs.set_alpha(p_->alpha_);
131  if (inArgs.supports(MEB::IN_ARG_beta)) inArgs.set_beta(p_->beta_);
132  if (inArgs.supports(MEB::IN_ARG_stage_number))
133  inArgs.set_stage_number(p_->stageNumber_);
134 
135  inArgs.setModelEvalDescription(this->description());
136  return std::move(inArgs);
137 }
138 
139 template <typename Scalar>
142 {
143  typedef Thyra::ModelEvaluatorBase MEB;
144  MEB::OutArgsSetup<Scalar> outArgs(implicitModel_->createOutArgs());
145  outArgs.setModelEvalDescription(this->description());
146  return std::move(outArgs);
147 }
148 
149 template <typename Scalar>
152  const Thyra::ModelEvaluatorBase::OutArgs<Scalar>& outArgs) const
153 {
154  typedef Thyra::ModelEvaluatorBase MEB;
155  using Teuchos::RCP;
156 
157  RCP<const Thyra::VectorBase<Scalar> > x = inArgs.get_x();
158  RCP<Thyra::VectorBase<Scalar> > x_dot = Thyra::createMember(get_x_space());
159  timeDer_->compute(x, x_dot);
160 
161  MEB::InArgs<Scalar> appImplicitInArgs(inArgs);
162  MEB::OutArgs<Scalar> appImplicitOutArgs(outArgs);
163  appImplicitInArgs.set_x_dot(x_dot);
164 
165  implicitModel_->evalModel(appImplicitInArgs, appImplicitOutArgs);
166 }
167 
168 } // end namespace Tempus
169 
170 #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
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
virtual void initialize()
Initialize after setting member data.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
RCP< const VectorBase< Scalar > > get_x() const