Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_WrapperModelEvaluatorBasic_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_WrapperModelEvaluatorBasic_impl_hpp
11 #define Tempus_WrapperModelEvaluatorBasic_impl_hpp
12 
13 namespace Tempus {
14 
15 template <typename Scalar>
18 {
19  typedef Thyra::ModelEvaluatorBase MEB;
20  // MEB::InArgsSetup<Scalar> inArgs(appModel_->createInArgs());
21  MEB::InArgsSetup<Scalar> inArgs(appModel_->getNominalValues());
22 
23  inArgs.set_x(x_);
24  if (y_ != Teuchos::null) inArgs.set_p(index_, y_);
25  if (inArgs.supports(MEB::IN_ARG_x_dot)) inArgs.set_x_dot(xDot_);
26  if (inArgs.supports(MEB::IN_ARG_t)) inArgs.set_t(time_);
27  if (inArgs.supports(MEB::IN_ARG_step_size))
28  inArgs.set_step_size(p_->timeStepSize_);
29  if (inArgs.supports(MEB::IN_ARG_alpha)) inArgs.set_alpha(p_->alpha_);
30  if (inArgs.supports(MEB::IN_ARG_beta)) inArgs.set_beta(p_->beta_);
31  if (inArgs.supports(MEB::IN_ARG_stage_number))
32  inArgs.set_stage_number(p_->stageNumber_);
33 
34  inArgs.setModelEvalDescription(this->description());
35  return std::move(inArgs);
36 }
37 
38 template <typename Scalar>
41 {
42  typedef Thyra::ModelEvaluatorBase MEB;
43  MEB::OutArgsSetup<Scalar> outArgs(appModel_->createOutArgs());
44  outArgs.setModelEvalDescription(this->description());
45  return std::move(outArgs);
46 }
47 
48 template <typename Scalar>
51  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs) const
52 {
53  using Teuchos::RCP;
54 
55  typedef Thyra::ModelEvaluatorBase MEB;
56  MEB::InArgs<Scalar> appInArgs(inArgs);
57  MEB::OutArgs<Scalar> appOutArgs(outArgs);
58 
59  // Setup input and output arguments for application ME
60  switch (evaluationType_) {
61  case EVALUATE_RESIDUAL: {
62  // Setup input arguments
63  appInArgs.set_x(inArgs.get_x());
64  appInArgs.set_x_dot(inArgs.get_x_dot());
65 
66  // Setup output arguments
67  appOutArgs.set_f(outArgs.get_f());
68 
69  break;
70  }
71  case SOLVE_FOR_X: {
72  // This is the normal solution scheme where we are solving for x,
73  // and xDot is dependent on x through the definition of the time
74  // derivative for the Stepper.
75 
76  // Setup input arguments
77  RCP<const Thyra::VectorBase<Scalar> > x = inArgs.get_x();
78  appInArgs.set_x(x); // x is from solver.
79  RCP<Thyra::VectorBase<Scalar> > xDot =
80  Teuchos::rcp_const_cast<Thyra::VectorBase<Scalar> >(
81  appInArgs.get_x_dot()); // xDot is from the Stepper
82  timeDer_->compute(x, xDot);
83  appInArgs.set_x_dot(xDot);
84 
85  // Setup output arguments
86  // Note: For the use that Tempus does of this class, these three args
87  // *should* be enough. However, keep in mind that it *may* be
88  // necessary to add more outArgs in the future. The idea would
89  // be the same: if the underlying model supports the arg, then
90  // set it in the appOutArgs.
91  appOutArgs.set_f(outArgs.get_f());
92  appOutArgs.set_W_op(outArgs.get_W_op());
93  if (outArgs.supports(MEB::OUT_ARG_W_prec)) {
94  appOutArgs.set_W_prec(outArgs.get_W_prec());
95  }
96 
97  break;
98  }
99 
100  case SOLVE_FOR_XDOT_CONST_X: {
101  // This solution scheme is solving for xDot while keeping x constant.
102  // This is similar to evaluating an explicit ODE, xDot = f(x,t). The
103  // upside is the application does not need to write f(x,t) or worry
104  // about inverting a mass matrix. This solution scheme is mostly
105  // used for initial conditions to make the x and xDot consistent
106  // with the governing equations.
107 
108  // Setup input arguments
109  appInArgs.set_x(x_); // x is from the Stepper.
110  appInArgs.set_x_dot(inArgs.get_x()); // xDot is from the solver.
111 
112  // Setup output arguments
113  appOutArgs.set_f(outArgs.get_f());
114  appOutArgs.set_W_op(outArgs.get_W_op());
115  if (outArgs.supports(MEB::OUT_ARG_W_prec)) {
116  appOutArgs.set_W_prec(outArgs.get_W_prec());
117  }
118 
119  break;
120  }
121 
122  default: {
123  TEUCHOS_TEST_FOR_EXCEPT("Invalid EVALUATION_TYPE!");
124  }
125  }
126 
127  appModel_->evalModel(appInArgs, appOutArgs);
128 }
129 
130 } // namespace Tempus
131 
132 #endif // Tempus_WrapperModelEvaluatorBasic_impl_hpp
Evaluate residual for the implicit ODE.
RCP< const VectorBase< Scalar > > get_x_dot() const
Evaluation< VectorBase< Scalar > > get_f() const
bool supports(EOutArgsMembers arg) const
Solve for xDot keeping x constant (for ICs).
RCP< PreconditionerBase< Scalar > > get_W_prec() const
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
RCP< LinearOpBase< Scalar > > get_W_op() const
Solve for x and determine xDot from x.
RCP< const VectorBase< Scalar > > get_x() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const