Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_WrapperModelEvaluatorPairIMEX_Basic_decl.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_ModelEvaluatorPairIMEX_Basic_decl_hpp
10 #define Tempus_ModelEvaluatorPairIMEX_Basic_decl_hpp
11 
13 #include "Thyra_StateFuncModelEvaluatorBase.hpp"
14 
15 
16 namespace Tempus {
17 
18 /** \brief ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
19  *
20  * This ModelEvaluator takes a state, x, and determines the explicit and
21  * implicit residuals. Additionally, it coordinates the explicit and
22  * implicit physics to ensure they are compatible, e.g.,
23  * how to translate between implicit and explicit model in and out
24  * arguments, if needed.
25  *
26  * All functions called on WrapperModelEvaluatorPairIMEX_Basic will call
27  * the same function on the implicit Model Evaluator. This was selected
28  * because the WrapperModelEvaluatorPairIMEX_Basic will be passed to the
29  * solvers which in turn make calls to solve the implicit ODE.
30  *
31  * If the explicit version of the Model Evaluator functions are needed,
32  * one should directly call it through the explicit Model Evaluator, e.g.,
33  * getExplicitModel()->get_x_space().
34  *
35  * This was taken and modified from Drekar's IMEXModelPair class.
36  */
37 template <typename Scalar>
40 {
41 public:
42 
43  /// Constructor
45  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& explicitModel,
46  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& implicitModel)
47  : timeDer_(Teuchos::null)
48  {
49  setExplicitModel(explicitModel);
50  setImplicitModel(implicitModel);
51  initialize();
52  }
53 
54  /// Destructor
56 
57  /// Initialize after setting member data.
58  virtual void initialize();
59 
60  /// \name Overridden from Tempus::WrapperModelEvaluatorPairIMEX
61  //@{
62  virtual void setAppModel(
63  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & me);
64  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
65  getAppModel() const;
66 
67  /// Set InArgs the wrapper ModelEvalutor.
68  virtual void setInArgs(Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs)
69  { wrapperImplicitInArgs_.setArgs(inArgs); }
70 
71  /// Get InArgs the wrapper ModelEvalutor.
72  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> getInArgs()
73  { return wrapperImplicitInArgs_; }
74 
75  /// Set OutArgs the wrapper ModelEvalutor.
76  virtual void setOutArgs(Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs)
77  { wrapperImplicitOutArgs_.setArgs(outArgs); }
78 
79  /// Get OutArgs the wrapper ModelEvalutor.
80  virtual Thyra::ModelEvaluatorBase::OutArgs<Scalar> getOutArgs()
81  { return wrapperImplicitOutArgs_; }
82 
83  /// Set parameters for application implicit ModelEvaluator solve.
84  virtual void setForSolve(Teuchos::RCP<TimeDerivative<Scalar> > timeDer,
85  Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs,
86  Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs,
87  EVALUATION_TYPE /* evaluationType */ = SOLVE_FOR_X)
88  {
89  timeDer_ = timeDer;
90  wrapperImplicitInArgs_.setArgs(inArgs);
91  wrapperImplicitOutArgs_.setArgs(outArgs);
92  }
93 
94  //@}
95 
96  /// \name Methods that apply to both explicit and implicit terms.
97  //@{
98  /// Get the x-solution space
99  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
100  get_x_space() const;
101 
102  /// Get the g space
103  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
104  get_g_space(int i) const;
105 
106  /// Get the p space
107  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
108  get_p_space(int i) const;
109  //@}
110 
111  //@{ \name Accessors
112  virtual void setExplicitModel(
113  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & model )
114  { explicitModel_ = model; }
115  virtual void setImplicitModel(
116  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & model )
117  { implicitModel_ = model; }
118  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
119  getExplicitModel() const { return explicitModel_; }
120  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
121  getImplicitModel() const { return implicitModel_; }
122  //@}
123 
124  /// \name Overridden from Thyra::StateFuncModelEvaluatorBase
125  //@{
126  virtual Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const
127  { return implicitModel_->create_W_op(); }
128 
129  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
130  get_W_factory() const { return implicitModel_->get_W_factory(); }
131 
132  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
133  get_f_space() const { return explicitModel_->get_f_space(); }
134 
135  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
136  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
137  virtual Thyra::ModelEvaluatorBase::OutArgs<Scalar>createOutArgsImpl() const;
138 
139  virtual void evalModelImpl(
140  const Thyra::ModelEvaluatorBase::InArgs<Scalar> & in,
141  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> & out) const;
142  //@}
143 
144 protected:
145 
146  /// Default constructor -- only allowed for derived classes
148 
149  /// Setup ME when using default constructor -- for derived classes
150  void setup(
151  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& explicitModel,
152  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& implicitModel)
153  {
154  setExplicitModel(explicitModel);
155  setImplicitModel(implicitModel);
156  initialize();
157  }
158 
159 protected:
160 
161  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > explicitModel_;
162  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > implicitModel_;
163 
164  Teuchos::RCP<TimeDerivative<Scalar> > timeDer_;
165  Thyra::ModelEvaluatorBase::InArgs<Scalar> wrapperImplicitInArgs_;
166  Thyra::ModelEvaluatorBase::OutArgs<Scalar> wrapperImplicitOutArgs_;
167 };
168 
169 } // namespace Tempus
170 
171 #endif // Tempus_ModelEvaluatorPairIMEX_Basic_decl_hpp
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > implicitModel_
WrapperModelEvaluatorPairIMEX_Basic(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &explicitModel, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &implicitModel)
Constructor.
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 > getInArgs()
Get InArgs the wrapper ModelEvalutor.
EVALUATION_TYPE
EVALUATION_TYPE indicates the evaluation to apply to the implicit ODE.
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 Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getExplicitModel() const
virtual void setInArgs(Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs)
Set InArgs the wrapper ModelEvalutor.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
virtual void setForSolve(Teuchos::RCP< TimeDerivative< Scalar > > timeDer, Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs, Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs, EVALUATION_TYPE=SOLVE_FOR_X)
Set parameters for application implicit ModelEvaluator solve.
ModelEvaluator pair for implicit and explicit (IMEX) evaluations.
void setup(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &explicitModel, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &implicitModel)
Setup ME when using default constructor – for derived classes.
virtual void setImplicitModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
virtual void initialize()
Initialize after setting member data.
virtual Thyra::ModelEvaluatorBase::OutArgs< Scalar > getOutArgs()
Get OutArgs the wrapper ModelEvalutor.
virtual void setExplicitModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
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.
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
WrapperModelEvaluatorPairIMEX_Basic()
Default constructor – only allowed for derived classes.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getImplicitModel() const
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > explicitModel_
virtual void setOutArgs(Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs)
Set OutArgs the wrapper ModelEvalutor.
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Get the x-solution space.
Solve for x and determine xDot from x.
virtual Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const