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)),
27  alpha_(Scalar(0.0)), beta_(Scalar(0.0)), evaluationType_(SOLVE_FOR_X),
28  stageNumber_(0)
29  {}
30  /// Constructor
32  Scalar timeStepSize, Scalar alpha, Scalar beta,
33  EVALUATION_TYPE evaluationType = SOLVE_FOR_X,
34  int stageNumber = 0)
35  : timeDer_(timeDer), timeStepSize_(timeStepSize),
36  alpha_(alpha), beta_(beta), evaluationType_(evaluationType),
37  stageNumber_(stageNumber)
38  {}
39 
40  Teuchos::RCP<TimeDerivative<Scalar> > timeDer_;
41  Scalar timeStepSize_;
42  Scalar alpha_;
43  Scalar beta_;
46 };
47 
48 /** \brief Thyra Base interface for implicit time steppers.
49  *
50  */
51 template<class Scalar>
52 class StepperImplicit : virtual public Tempus::Stepper<Scalar>
53 {
54 public:
55 
56  /// \name Basic implicit stepper methods
57  //@{
58  virtual void setModel(
59  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel);
60  virtual void setNonConstModel(
61  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel);
62  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
63  getModel(){return wrapperModel_->getAppModel();}
64  virtual Teuchos::RCP<const WrapperModelEvaluator<Scalar> >
66 
67  /// Set solver.
68  virtual void setSolver(
69  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver = Teuchos::null);
70  virtual Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > getSolver() const
71  { return solver_; }
72 
73  /// Set the initial conditions and make them consistent.
74  virtual void setInitialConditions (
75  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
76 
77  /// Return alpha = d(xDot)/dx.
78  virtual Scalar getAlpha(const Scalar dt) const = 0;
79  /// Return beta = d(x)/dx.
80  virtual Scalar getBeta (const Scalar dt) const = 0;
81 
82  /// Solve problem using x in-place. (Needs to be deprecated!)
83  const Thyra::SolveStatus<Scalar> solveImplicitODE(
84  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x);
85 
86  /// Solve implicit ODE, f(x, xDot, t, p) = 0.
87  const Thyra::SolveStatus<Scalar> solveImplicitODE(
88  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x,
89  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & xDot,
90  const Scalar time,
91  const Teuchos::RCP<ImplicitODEParameters<Scalar> > & p );
92 
93  /// Evaluate implicit ODE residual, f(x, xDot, t, p).
95  Teuchos::RCP<Thyra::VectorBase<Scalar> > & f,
96  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & x,
97  const Teuchos::RCP<Thyra::VectorBase<Scalar> > & xDot,
98  const Scalar time,
99  const Teuchos::RCP<ImplicitODEParameters<Scalar> > & p );
100 
101  /// Pass initial guess to Newton solver (only relevant for implicit solvers)
102  virtual void setInitialGuess(
103  Teuchos::RCP<const Thyra::VectorBase<Scalar> > initial_guess)
104  {initial_guess_ = initial_guess;}
105 
106  /// Set parameter so that the initial guess is set to zero (=True) or use last timestep (=False).
107  virtual void setZeroInitialGuess(bool zIG) { zeroInitialGuess_ = zIG; }
108  virtual bool getZeroInitialGuess() const { return zeroInitialGuess_; }
109 
110  virtual Scalar getInitTimeStep(
111  const Teuchos::RCP<SolutionHistory<Scalar> >& /* solutionHistory */) const
112  {return Scalar(1.0e+99);}
113 
114  /// Set xDot for Stepper storage.
115  virtual void setStepperXDot(Teuchos::RCP<Thyra::VectorBase<Scalar> > xDot)
116  { stepperXDot_ = xDot; }
117 
118  /// Get xDot from SolutionState or Stepper storage.
119  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperXDot(
120  Teuchos::RCP<SolutionState<Scalar> > state);
121 
122  /// Get xDotDot from SolutionState or Stepper storage.
123  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getStepperXDotDot(
124  Teuchos::RCP<SolutionState<Scalar> > state);
125  //@}
126 
127 protected:
128 
129  Teuchos::RCP<WrapperModelEvaluator<Scalar> > wrapperModel_;
130  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver_;
131  Teuchos::RCP<const Thyra::VectorBase<Scalar> > initial_guess_;
133 
134  Teuchos::RCP<StepperObserver<Scalar> > stepperObserver_;
135 
136  // RCP to state or temporary storage if needed.
137  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperXDot_;
138  Teuchos::RCP<Thyra::VectorBase<Scalar> > stepperXDotDot_;
139 };
140 
141 } // namespace Tempus
142 #endif // Tempus_StepperImplicit_decl_hpp
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
ImplicitODEParameters(Teuchos::RCP< TimeDerivative< Scalar > > timeDer, Scalar timeStepSize, Scalar alpha, Scalar beta, EVALUATION_TYPE evaluationType=SOLVE_FOR_X, int stageNumber=0)
Constructor.
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.
Teuchos::RCP< WrapperModelEvaluator< Scalar > > wrapperModel_
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperXDot_
Teuchos::RCP< Thyra::VectorBase< Scalar > > stepperXDotDot_
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver=Teuchos::null)
Set solver.
virtual Teuchos::RCP< const WrapperModelEvaluator< Scalar > > getWrapperModel()
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
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 residual, f(x, xDot, t, p).
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.
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...
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.