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