Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_WrapperModelEvaluatorSecondOrder_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_WrapperModelEvaluatorSecondOrder_decl_hpp
10 #define Tempus_WrapperModelEvaluatorSecondOrder_decl_hpp
11 
12 #include <functional>
14 #include "Thyra_VectorBase.hpp"
15 #include "Thyra_VectorStdOps.hpp"
16 
17 //#define VERBOSE_DEBUG_OUTPUT
18 
19 namespace Tempus {
20 
21 /** \brief A ModelEvaluator for residual evaluations given a state.
22  * This ModelEvaluator takes a state, x, and determines its residual,
23  * \f$ g(x) \f$, which is suitable for a nonlinear solve. This is
24  * accomplished by computing the time derivative of the state, x_dot,
25  * (through Lambda functions), supplying the current time, and calling
26  * the application application ModelEvaluator, \f$ f(\dot{x},x,t) \f$.
27  *
28  * This class breaks the primary design principle for ModelEvaluators;
29  * it is not stateless!
30  */
31 template <typename Scalar>
33  : public Tempus::WrapperModelEvaluator<Scalar>
34 {
35 public:
36  typedef Thyra::VectorBase<Scalar> Vector;
37 
38  /// Constructor
40  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel, const std::string schemeName)
41  : appModel_(appModel),
42  out_(Teuchos::VerboseObjectBase::getDefaultOStream())
43  {
44 #ifdef VERBOSE_DEBUG_OUTPUT
45  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
46  *out_ << " schemeName = " << schemeName << "\n";
47 #endif
48  if (schemeName == "Newmark Implicit a-Form" || schemeName == "HHT-Alpha") {
50  }
51  else if (schemeName == "Newmark Implicit d-Form") {
53  }
54  else {
55  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
56  "Error: WrapperModelEvaluatorSecondOrder called with unsopported schemeName = " << schemeName
57  <<"! Supported schemeNames are: 'Newmark Implicit a-Form' and 'HHT-Alpha'.\n");
58  }
59  }
60 
61  /// Set the underlying application ModelEvaluator
63  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > & me)
64  {
65 #ifdef VERBOSE_DEBUG_OUTPUT
66  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
67 #endif
68  appModel_ = me;
69  }
70 
71  /// Get the underlying application model 'f'
72  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > getAppModel() const
73  {
74 #ifdef VERBOSE_DEBUG_OUTPUT
75  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
76 #endif
77  return appModel_;
78  }
79 
80  /// Set values needed in evalModelImpl
81  void initializeNewmark(Teuchos::RCP<const Vector> v_pred,
82  Teuchos::RCP<const Vector> d_pred, Scalar delta_t,
83  Scalar t, Scalar beta, Scalar gamma)
84  {
85 #ifdef VERBOSE_DEBUG_OUTPUT
86  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
87 #endif
88  v_pred_ = v_pred; d_pred_ = d_pred;
89  delta_t_ = delta_t; t_ = t; beta_ = beta; gamma_ = gamma;
90  }
91 
92  /// \name Overridden from Thyra::StateFuncModelEvaluatorBase
93  //@{
94  Teuchos::RCP<Thyra::LinearOpBase<Scalar> > create_W_op() const
95  {
96 #ifdef VERBOSE_DEBUG_OUTPUT
97  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
98 #endif
99  return appModel_->create_W_op();
100  }
101 
102  Teuchos::RCP<const Thyra::LinearOpWithSolveFactoryBase<Scalar> >
104  {
105 #ifdef VERBOSE_DEBUG_OUTPUT
106  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
107 #endif
108  return appModel_->get_W_factory();
109  }
110 
111  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_f_space() const
112  {
113 #ifdef VERBOSE_DEBUG_OUTPUT
114  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
115 #endif
116  return appModel_->get_f_space();
117  }
118 
119  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_p_space(int p) const
120  {
121 #ifdef VERBOSE_DEBUG_OUTPUT
122  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
123 #endif
124  return appModel_->get_p_space(p);
125  };
126 
127  Teuchos::RCP<const Teuchos::Array<std::string> > get_p_names(int p) const
128  {
129 #ifdef VERBOSE_DEBUG_OUTPUT
130  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
131 #endif
132  return appModel_->get_p_names(p);
133  }
134 
135  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_x_space() const
136  {
137 #ifdef VERBOSE_DEBUG_OUTPUT
138  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
139 #endif
140  return appModel_->get_x_space();
141  }
142 
143  Teuchos::RCP<const Thyra::VectorSpaceBase<Scalar> > get_g_space(int i) const
144  { return appModel_->get_g_space(i); }
145 
146  Thyra::ModelEvaluatorBase::InArgs<Scalar> getNominalValues() const
147  {
148 #ifdef VERBOSE_DEBUG_OUTPUT
149  *out_ << "DEBUG: " << __PRETTY_FUNCTION__ << "\n";
150 #endif
151  return appModel_->getNominalValues();
152  }
153 
154  /// Set InArgs the wrapper ModelEvalutor.
155  virtual void setInArgs(Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs)
156  { wrapperInArgs_.setArgs(inArgs); }
157 
158  /// Get InArgs the wrapper ModelEvalutor.
159  virtual Thyra::ModelEvaluatorBase::InArgs<Scalar> getInArgs()
160  { return wrapperInArgs_; }
161 
162  /// Set OutArgs the wrapper ModelEvalutor.
163  virtual void setOutArgs(Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs)
164  { wrapperOutArgs_.setArgs(outArgs); }
165 
166  /// Get OutArgs the wrapper ModelEvalutor.
167  virtual Thyra::ModelEvaluatorBase::OutArgs<Scalar> getOutArgs()
168  { return wrapperOutArgs_; }
169 
170  /// Set parameters for application implicit ModelEvaluator solve.
171  virtual void setForSolve(Teuchos::RCP<TimeDerivative<Scalar> > timeDer,
172  Thyra::ModelEvaluatorBase::InArgs<Scalar> inArgs,
173  Thyra::ModelEvaluatorBase::OutArgs<Scalar> outArgs,
174  EVALUATION_TYPE /* evaluationType */ = SOLVE_FOR_X)
175  {
176  timeDer_ = timeDer;
177  wrapperInArgs_.setArgs(inArgs);
178  wrapperOutArgs_.setArgs(outArgs);
179  }
180 
181  Thyra::ModelEvaluatorBase::InArgs<Scalar> createInArgs() const;
182  Thyra::ModelEvaluatorBase::OutArgs<Scalar> createOutArgsImpl() const;
183 
184  void evalModelImpl(
185  const Thyra::ModelEvaluatorBase::InArgs<Scalar> &inArgs,
186  const Thyra::ModelEvaluatorBase::OutArgs<Scalar> &outArgs) const;
187  //@}
188 
190 
191 private:
192 
193  /// Default constructor - not allowed
195 
196 private:
197 
198  Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > appModel_;
199  Scalar t_;
200  Scalar gamma_;
201  Scalar beta_;
202  Scalar delta_t_;
203  Teuchos::RCP<const Vector> d_pred_;
204  Teuchos::RCP<const Vector> v_pred_;
205  Teuchos::RCP<Teuchos::FancyOStream> out_;
207 
208  Teuchos::RCP<TimeDerivative<Scalar> > timeDer_;
209  Thyra::ModelEvaluatorBase::InArgs<Scalar> wrapperInArgs_;
210  Thyra::ModelEvaluatorBase::OutArgs<Scalar> wrapperOutArgs_;
211 
212 };
213 
214 } // namespace Tempus
215 
216 #endif // Tempus_WrapperModelEvaluatorSecondOrder_hpp
EVALUATION_TYPE
EVALUATION_TYPE indicates the evaluation to apply to the implicit ODE.
virtual Thyra::ModelEvaluatorBase::OutArgs< Scalar > getOutArgs()
Get OutArgs the wrapper ModelEvalutor.
Thyra::ModelEvaluatorBase::OutArgs< Scalar > createOutArgsImpl() const
void initializeNewmark(Teuchos::RCP< const Vector > v_pred, Teuchos::RCP< const Vector > d_pred, Scalar delta_t, Scalar t, Scalar beta, Scalar gamma)
Set values needed in evalModelImpl.
void setAppModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &me)
Set the underlying application ModelEvaluator.
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getAppModel() const
Get the underlying application model &#39;f&#39;.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_p_space(int p) const
Get the p space.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_x_space() const
Get the x-solution space.
A ModelEvaluator for residual evaluations given a state. This ModelEvaluator takes a state...
Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > appModel_
Teuchos::RCP< const Thyra::LinearOpWithSolveFactoryBase< Scalar > > get_W_factory() const
WrapperModelEvaluatorSecondOrder(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel, const std::string schemeName)
Constructor.
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_f_space() const
A ModelEvaluator which wraps the application ModelEvaluator.
Thyra::ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const
Teuchos::RCP< Thyra::LinearOpBase< Scalar > > create_W_op() const
Teuchos::RCP< const Teuchos::Array< std::string > > get_p_names(int p) const
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
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 Thyra::ModelEvaluatorBase::InArgs< Scalar > getInArgs()
Get InArgs the wrapper ModelEvalutor.
WrapperModelEvaluatorSecondOrder()
Default constructor - not allowed.
virtual void setInArgs(Thyra::ModelEvaluatorBase::InArgs< Scalar > inArgs)
Set InArgs the wrapper ModelEvalutor.
void evalModelImpl(const Thyra::ModelEvaluatorBase::InArgs< Scalar > &inArgs, const Thyra::ModelEvaluatorBase::OutArgs< Scalar > &outArgs) const
Solve for x and determine xDot from x.
Thyra::ModelEvaluatorBase::InArgs< Scalar > createInArgs() const
Teuchos::RCP< const Thyra::VectorSpaceBase< Scalar > > get_g_space(int i) const
Get the g space.
virtual void setOutArgs(Thyra::ModelEvaluatorBase::OutArgs< Scalar > outArgs)
Set OutArgs the wrapper ModelEvalutor.