Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_WrapperModelEvaluatorPairPartIMEX_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_ModelEvaluatorPairPartIMEX_Basic_decl_hpp
10 #define Tempus_ModelEvaluatorPairPartIMEX_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  * All functions called on WrapperModelEvaluatorPairPartIMEX_Basic will call
21  * the same function on the implicit Model Evaluator. This was selected
22  * because the WrapperModelEvaluatorPairPartIMEX_Basic will be passed to the
23  * solvers which in turn make calls to solve the implicit ODE.
24  *
25  * If the explicit version of the Model Evaluator functions are needed,
26  * one should directly call it through the explicit Model Evaluator, e.g.,
27  * getExplicitModel()->get_x_space().
28  *
29  * The one exception to this rule is for getNominalValues(), which is
30  * controlled by implicitNominalValues. During the Integrator initialization
31  * this->getNominalValues needs to return
32  * explicitModel_->getNominalValues() [implicitNominalValues=false is the
33  * default], but during the nonlinear solves this->getNominalValues needs
34  * to return implicitModel_->getNominalValues() [implicitNominalValues=true].
35  */
36 template <typename Scalar>
39 {
40 public:
41 
42  /// Default constructor -- Still requires setting the models and running initialize.
44 
45  /// Constructor
47  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& explicitModel,
48  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& implicitModel,
49  int numExplicitOnlyBlocks = 0, int parameterIndex = -1);
50 
51  /// Destructor
53 
54  /// Initialize after setting member data.
55  virtual void initialize();
56 
57  /// \name Overridden from Tempus::WrapperModelEvaluatorPairIMEX
58  //@{
59  virtual void setAppModel(
60  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & me);
61  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
62  getAppModel() const;
63 
64  /// Set InArgs the wrapper ModelEvalutor.
65  virtual void setInArgs(Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs)
66  { wrapperImplicitInArgs_.setArgs(inArgs); }
67 
68  /// Get InArgs the wrapper ModelEvalutor.
69  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> getInArgs()
70  { return wrapperImplicitInArgs_; }
71 
72  /// Set OutArgs the wrapper ModelEvalutor.
73  virtual void setOutArgs(Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs)
74  { wrapperImplicitOutArgs_.setArgs(outArgs); }
75 
76  /// Get OutArgs the wrapper ModelEvalutor.
77  virtual Thyra::ModelEvaluatorBase::OutArgs<Scalar> getOutArgs()
78  { return wrapperImplicitOutArgs_; }
79 
80  /// Set parameters for application implicit ModelEvaluator solve.
81  virtual void setForSolve(Teuchos::RCP<TimeDerivative<Scalar> > timeDer,
82  Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs,
83  Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs,
84  EVALUATION_TYPE /* evaluationType */ = SOLVE_FOR_X)
85  {
86  timeDer_ = timeDer;
87  wrapperImplicitInArgs_.setArgs(inArgs);
88  wrapperImplicitOutArgs_.setArgs(outArgs);
89  useImplicitModel_ = true;
90  }
91 
92  //@}
93 
94  /// \name Methods that apply to both explicit and implicit terms.
95  //@{
96  /// Get the x-solution space
97  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
98  get_x_space() const;
99 
100  /// Get the g space
101  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
102  get_g_space(int i) const;
103 
104  /// Get the p space
105  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
106  get_p_space(int i) const;
107  //@}
108 
109  //@{ \name Accessors
110  virtual void setNumExplicitOnlyBlocks(int numExp)
111  {numExplicitOnlyBlocks_ = numExp; }
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  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
118  getExplicitModel() const { return explicitModel_; }
119  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
120  getImplicitModel() const { return implicitModel_; }
121  virtual int getNumExplicitOnlyBlocks() const
122  { return numExplicitOnlyBlocks_; }
123 
124  /// Extract IMEX vector from a full solution vector
125  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getIMEXVector(
126  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & full) const;
127 
128  /// Extract IMEX vector for reading
129  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getIMEXVector(
130  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > & full) const;
131 
132  /// Extract explicit-only vector from a full solution vector
133  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getExplicitOnlyVector(
134  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & full) const;
135 
136  /// Extract explicit-only vector for reading
137  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> >getExplicitOnlyVector(
138  const Teuchos::RCP<const Thyra::VectorBase<Scalar> > & full) const;
139 
140  /// Set the parameter index for explicit-only vector
141  virtual void setParameterIndex(int parameterIndex = -1);
142  /// Get the parameter index for explicit-only vector
143  virtual int getParameterIndex() const { return parameterIndex_; }
144 
145  /// Set parameter to switch wrapperME base functions between explicit and implicit functions.
146  virtual void setUseImplicitModel(bool tf) { useImplicitModel_ = tf; }
147  /// Get parameter to switch wrapperME base functions between explicit and implicit functions.
148  virtual bool getUseImplicitModel() const { return useImplicitModel_; }
149  //@}
150 
151  /// \name Overridden from Thyra::StateFuncModelEvaluatorBase
152  //@{
153  virtual Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const
154  { return implicitModel_->create_W_op(); }
155 
156  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
157  get_W_factory() const { return implicitModel_->get_W_factory(); }
158 
159  virtual Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> >
160  get_f_space() const;
161 
162  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const;
163  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
164  virtual Thyra::ModelEvaluatorBase::OutArgs<Scalar>createOutArgsImpl() const;
165 
166  virtual void evalModelImpl(
167  const Thyra::ModelEvaluatorBase::InArgs<Scalar> & in,
168  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> & out) const;
169  //@}
170 
171 protected:
172 
173  /// Setup ME when using default constructor -- for derived classes
174  void setup(
175  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& explicitModel,
176  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& implicitModel,
177  int numExplicitOnlyBlocks = 0, int parameterIndex = -1);
178 
179  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > explicitModel_;
180  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > implicitModel_;
181 
182  Teuchos::RCP<TimeDerivative<Scalar> > timeDer_;
183  Thyra::ModelEvaluatorBase::InArgs<Scalar> wrapperImplicitInArgs_;
184  Thyra::ModelEvaluatorBase::OutArgs<Scalar> wrapperImplicitOutArgs_;
185 
187  int parameterIndex_; ///< implicit parameter index for explicit-only vector
188  bool useImplicitModel_; ///< if true, use implicitModel_ else explicitModel_
189 };
190 
191 } // namespace Tempus
192 
193 #endif // Tempus_ModelEvaluatorPairPartIMEX_Basic_decl_hpp
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getAppModel() const
Get the underlying application ModelEvaluator.
EVALUATION_TYPE
EVALUATION_TYPE indicates the evaluation to apply to the implicit ODE.
virtual void setInArgs(Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs)
Set InArgs the wrapper ModelEvalutor.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int i) const
Get the g space.
virtual void setExplicitModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
virtual int getParameterIndex() const
Get the parameter index for explicit-only vector.
ModelEvaluator pair for implicit and explicit (IMEX) evaluations.
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > getInArgs()
Get InArgs the wrapper ModelEvalutor.
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getExplicitOnlyVector(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &full) const
Extract explicit-only vector from a full solution vector.
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
virtual void setParameterIndex(int parameterIndex=-1)
Set the parameter index for explicit-only vector.
virtual Thyra::ModelEvaluatorBase::OutArgs< Scalar > getOutArgs()
Get OutArgs the wrapper ModelEvalutor.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Get the x-solution space.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getImplicitModel() const
virtual void setUseImplicitModel(bool tf)
Set parameter to switch wrapperME base functions between explicit and implicit functions.
virtual Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
void setup(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &explicitModel, const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &implicitModel, int numExplicitOnlyBlocks=0, int parameterIndex=-1)
Setup ME when using default constructor – for derived classes.
virtual void setOutArgs(Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs)
Set OutArgs the wrapper ModelEvalutor.
virtual Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
virtual void setImplicitModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
virtual void setAppModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &me)
Set the underlying application ModelEvaluator.
virtual Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getIMEXVector(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &full) const
Extract IMEX vector from a full solution vector.
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
WrapperModelEvaluatorPairPartIMEX_Basic()
Default constructor – Still requires setting the models and running initialize.
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getExplicitModel() const
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
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.
virtual Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int i) const
Get the p space.
virtual bool getUseImplicitModel() const
Get parameter to switch wrapperME base functions between explicit and implicit functions.
Solve for x and determine xDot from x.
virtual void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &in, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &out) const