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