Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperImplicit_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_StepperImplicit_decl_hpp
10 #define Tempus_StepperImplicit_decl_hpp
11 
12 // Tempus
13 #include "Tempus_Stepper.hpp"
14 #include "Tempus_WrapperModelEvaluatorBasic.hpp"
15 
16 
17 namespace Tempus {
18 
19 
20 template<class Scalar>
22 {
23  public:
24  /// Constructor
26  : timeDer_(Teuchos::null), timeStepSize_(Scalar(0.0)), stageNumber_(0),
27  alpha_(Scalar(0.0)), beta_(Scalar(0.0)), evaluationType_(SOLVE_FOR_X)
28  {}
29  /// Constructor
31  Scalar timeStepSize, Scalar alpha, Scalar beta,
32  EVALUATION_TYPE evaluationType = SOLVE_FOR_X)
33  : timeDer_(timeDer), timeStepSize_(timeStepSize), stageNumber_(0),
34  alpha_(alpha), beta_(beta), evaluationType_(evaluationType)
35  {}
36 
37  Teuchos::RCP<TimeDerivative<Scalar> > timeDer_;
38  Scalar timeStepSize_;
40  Scalar alpha_;
41  Scalar beta_;
43 };
44 
45 /** \brief Thyra Base interface for implicit time steppers.
46  *
47  */
48 template<class Scalar>
49 class StepperImplicit : virtual public Tempus::Stepper<Scalar>
50 {
51 public:
52 
53  /// \name Basic implicit stepper methods
54  //@{
55  virtual void setModel(
56  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel);
57  virtual void setNonConstModel(
58  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel);
59  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
60  getModel(){return wrapperModel_->getAppModel();}
61  virtual Teuchos::RCP<const WrapperModelEvaluator<Scalar> >
63 
64  /// Set solver via ParameterList solver name.
65  virtual void setSolver(std::string solverName);
66  /// Set solver via solver ParameterList.
67  virtual void setSolver(
68  Teuchos::RCP<Teuchos::ParameterList> solverPL=Teuchos::null);
69  /// Set solver.
70  virtual void setSolver(
71  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver);
72  virtual Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > getSolver() const
73  { return solver_; }
74 
75  virtual std::string getStepperType() const
76  { return stepperPL_->get<std::string>("Stepper Type"); }
77 
78  /// Set the initial conditions and make them consistent.
79  virtual void setInitialConditions (
80  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
81 
82  /// Return alpha = d(xDot)/dx.
83  virtual Scalar getAlpha(const Scalar dt) const = 0;
84  /// Return beta = d(x)/dx.
85  virtual Scalar getBeta (const Scalar dt) const = 0;
86 
87  /// Solve problem using x in-place. (Needs to be deprecated!)
88  const Thyra::SolveStatus<Scalar> solveImplicitODE(
89  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x);
90 
91  /// Solve implicit ODE, f(x, xDot, t, p) = 0.
92  const Thyra::SolveStatus<Scalar> solveImplicitODE(
93  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x,
94  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & xDot,
95  const Scalar time,
96  const Teuchos::RCP<ImplicitODEParameters<Scalar> > & p );
97 
98  /// Evaluate implicit ODE, f(x, xDot, t, p), residual.
100  Teuchos::RCP<Thyra::VectorBase<Scalar> > & f,
101  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x,
102  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & xDot,
103  const Scalar time,
104  const Teuchos::RCP<ImplicitODEParameters<Scalar> > & p );
105 
106  /// Pass initial guess to Newton solver (only relevant for implicit solvers)
107  virtual void setInitialGuess(
108  Teuchos::RCP<const Thyra::VectorBase<Scalar> > initial_guess)
109  {initial_guess_ = initial_guess;}
110 
111  /// Set parameter so that the initial guess is set to zero (=True) or use last timestep (=False).
112  virtual void setZeroInitialGuess(bool zIG)
113  { stepperPL_->set<bool>("Zero Initial Guess", zIG); }
114  virtual bool getZeroInitialGuess() const
115  { return stepperPL_->get<bool>("Zero Initial Guess", false); }
116  virtual Scalar getInitTimeStep(
117  const Teuchos::RCP<SolutionHistory<Scalar> >& /* solutionHistory */) const
118  {return Scalar(1.0e+99);}
119 
120  virtual bool getEmbedded() const
121  { return stepperPL_->get<bool>("Use Embedded", false); }
122 
123  virtual void setUseFSAL(bool a) {stepperPL_->set<bool>("Use FSAL", a);}
124  virtual bool getUseFSAL() const
125  {
126  bool defaultUseFSAL =
127  this->getDefaultParameters()->template get<bool>("Use FSAL");
128  return stepperPL_->get<bool>("Use FSAL", defaultUseFSAL);
129  }
130 
131  virtual void setICConsistency(std::string s)
132  {stepperPL_->set<std::string>("Initial Condition Consistency", s);}
133  virtual std::string getICConsistency() const
134  {
135  std::string defaultICConsistency = this->getDefaultParameters()->
136  template get<std::string>("Initial Condition Consistency");
137  return stepperPL_->get<std::string>("Initial Condition Consistency",
138  defaultICConsistency);
139  }
140 
141  virtual void setICConsistencyCheck(bool c)
142  {stepperPL_->set<bool>("Initial Condition Consistency Check", c);}
143  virtual bool getICConsistencyCheck() const
144  {
145  bool defaultICConsistencyCheck = this->getDefaultParameters()->
146  template get<bool>("Initial Condition Consistency Check");
147  return stepperPL_->get<bool>("Initial Condition Consistency Check",
148  defaultICConsistencyCheck);
149  }
150 
151  /// Set xDot for Stepper storage.
152  virtual void setStepperXDot(Teuchos::RCP<Thyra::VectorBase<Scalar> > xDot)
153  { stepperXDot_ = xDot; }
154 
155  /// Get xDot from SolutionState or Stepper storage.
156  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperXDot(
157  Teuchos::RCP<SolutionState<Scalar> > state);
158 
159  /// Get xDotDot from SolutionState or Stepper storage.
160  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperXDotDot(
161  Teuchos::RCP<SolutionState<Scalar> > state);
162  //@}
163 
164 protected:
165 
166  Teuchos::RCP<Teuchos::ParameterList> stepperPL_;
167  Teuchos::RCP<WrapperModelEvaluator<Scalar> > wrapperModel_;
168  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver_;
169  Teuchos::RCP<const Thyra::VectorBase<Scalar> > initial_guess_;
170 
171  Teuchos::RCP<StepperObserver<Scalar> > stepperObserver_;
172 
173  // RCP to state or temporary storage if needed.
174  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperXDot_;
175  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperXDotDot_;
176 };
177 
178 } // namespace Tempus
179 #endif // Tempus_StepperImplicit_decl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
virtual std::string getICConsistency() const
const Thyra::SolveStatus< Scalar > solveImplicitODE(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x)
Solve problem using x in-place. (Needs to be deprecated!)
EVALUATION_TYPE
EVALUATION_TYPE indicates the evaluation to apply to the implicit ODE.
virtual bool getICConsistencyCheck() const
Teuchos::RCP< WrapperModelEvaluator< Scalar > > wrapperModel_
virtual void setICConsistencyCheck(bool c)
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperXDot_
ImplicitODEParameters(Teuchos::RCP< TimeDerivative< Scalar > > timeDer, Scalar timeStepSize, Scalar alpha, Scalar beta, EVALUATION_TYPE evaluationType=SOLVE_FOR_X)
Constructor.
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperXDotDot_
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual Teuchos::RCP< const WrapperModelEvaluator< Scalar > > getWrapperModel()
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
Teuchos::RCP< Teuchos::ParameterList > stepperPL_
virtual Scalar getBeta(const Scalar dt) const =0
Return beta = d(x)/dx.
virtual void setStepperXDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xDot)
Set xDot for Stepper storage.
Teuchos::RCP< TimeDerivative< Scalar > > timeDer_
Thyra Base interface for time steppers.
void evaluateImplicitODE(Teuchos::RCP< Thyra::VectorBase< Scalar > > &f, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xDot, const Scalar time, const Teuchos::RCP< ImplicitODEParameters< Scalar > > &p)
Evaluate implicit ODE, f(x, xDot, t, p), residual.
Thyra Base interface for implicit time steppers.
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &) const
virtual void setNonConstModel(const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &appModel)
Teuchos::RCP< StepperObserver< Scalar > > stepperObserver_
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperXDot(Teuchos::RCP< SolutionState< Scalar > > state)
Get xDot from SolutionState or Stepper storage.
virtual void setSolver(std::string solverName)
Set solver via ParameterList solver name.
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
virtual void setZeroInitialGuess(bool zIG)
Set parameter so that the initial guess is set to zero (=True) or use last timestep (=False)...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel()
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > > initial_guess)
Pass initial guess to Newton solver (only relevant for implicit solvers)
This interface defines the time derivative connection between an implicit Stepper and WrapperModelEva...
virtual void setICConsistency(std::string s)
virtual Teuchos::RCP< Teuchos::ParameterList > getDefaultParameters() const =0
virtual std::string getStepperType() const
Teuchos::RCP< const Thyra::VectorBase< Scalar > > initial_guess_
virtual Scalar getAlpha(const Scalar dt) const =0
Return alpha = d(xDot)/dx.
Solve for x and determine xDot from x.
Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver_
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
virtual bool getZeroInitialGuess() const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getStepperXDotDot(Teuchos::RCP< SolutionState< Scalar > > state)
Get xDotDot from SolutionState or Stepper storage.