Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_StepperOperatorSplit_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_StepperOperatorSplit_decl_hpp
10 #define Tempus_StepperOperatorSplit_decl_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_Stepper.hpp"
14 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
16 #endif
18 
19 namespace Tempus {
20 
21 /** \brief OperatorSplit stepper loops through the Stepper list.
22  *
23  * OperatorSplit stepper loops through the provided list of SubSteppers,
24  * and passes the SolutionHistory sequentially between them. This is
25  * simply a first-order splitting. It should be noted that specially
26  * constructed sequence of SubSteppers could obtain higher orders.
27  *
28  * The OperatorSplit Stepper does not have any model, but the SubSteppers
29  * do. The OperatorSplit Stepper does not have a solver either, but the
30  * SubSteppers may or may not have a solver depending if they are implicit
31  * or explicit.
32  *
33  * Operator Split is only defined for one-step methods, so multi-step
34  * methods (e.g., BDF) should not be used with StepperOperatorSplit.
35  *
36  * Note that steppers in general can not use FSAL (useFSAL=true) with
37  * operator splitting as \f$\dot{x}_{n-1}\f$ will usually be modified
38  * by other operators.
39  */
40 template<class Scalar>
41 class StepperOperatorSplit : virtual public Tempus::Stepper<Scalar>
42 {
43 public:
44 
45  /** \brief Default constructor.
46  *
47  * Requires subsequent setModel(), setSolver() and initialize()
48  * calls before calling takeStep().
49  */
51 
52 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
53  /// Constructor
55  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > appModels,
56  std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList,
57  const Teuchos::RCP<StepperObserver<Scalar> >& obs,
58  bool useFSAL,
59  std::string ICConsistency,
60  bool ICConsistencyCheck,
61  int order,
62  int orderMin,
63  int orderMax);
64 #endif
65 
66  /// Constructor
68  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > appModels,
69  std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList,
70  bool useFSAL,
71  std::string ICConsistency,
72  bool ICConsistencyCheck,
73  int order,
74  int orderMin,
75  int orderMax,
76  const Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> >& stepperOSAppAction);
77 
78  /// \name Basic stepper methods
79  //@{
80  virtual void setModel(
81  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel);
82 
83  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
84  getModel();
85 
86  virtual void setSolver(
87  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver);
88 
89  virtual Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > getSolver() const
90  { return Teuchos::null; }
91 
92 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
93  virtual void setObserver(
94  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null);
95 
96  virtual Teuchos::RCP<StepperObserver<Scalar> > getObserver() const
97  { return this->stepperOSObserver_; }
98 #endif
99 
100  virtual void setAppAction(Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> > appAction);
101 
102  virtual Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> > getAppAction() const
103  { return stepperOSAppAction_; }
104 
105  virtual void setTempState(Teuchos::RCP<Tempus::SolutionState<Scalar>> state)
106  { tempState_ = state; }
107 
108  /// Initialize during construction and after changing input parameters.
109  virtual void initialize();
110 
111  /// Set the initial conditions and make them consistent.
112  virtual void setInitialConditions (
113  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
114 
115  /// Take the specified timestep, dt, and return true if successful.
116  virtual void takeStep(
117  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
118 
119  /// Pass initial guess to Newton solver
120  virtual void setInitialGuess(
121  Teuchos::RCP<const Thyra::VectorBase<Scalar> > /* initial_guess */){}
122 
123  /// Get a default (initial) StepperState
124  virtual Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState();
125  virtual Scalar getOrder() const {return order_;}
126  virtual Scalar getOrderMin() const {return orderMin_;}
127  virtual Scalar getOrderMax() const {return orderMax_;}
128 
129  virtual Scalar getInitTimeStep(
130  const Teuchos::RCP<SolutionHistory<Scalar> >& /* solutionHistory */) const
131  {return Scalar(1.0e+99);}
132  virtual void setOrder (Scalar o) { order_ = o;}
133  virtual void setOrderMin(Scalar o) { orderMin_ = o;}
134  virtual void setOrderMax(Scalar o) { orderMax_ = o;}
135 
136  virtual bool isExplicit() const
137  {
138  bool isExplicit = false;
139  typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
140  subStepperIter = subStepperList_.begin();
141  for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
142  if ( (*subStepperIter)->isExplicit() ) isExplicit = true;
143  }
144  return isExplicit;
145  }
146  virtual bool isImplicit() const
147  {
148  bool isImplicit = false;
149  typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
150  subStepperIter = subStepperList_.begin();
151  for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
152  if ( (*subStepperIter)->isImplicit() ) isImplicit = true;
153  }
154  return isImplicit;
155  }
156  virtual bool isExplicitImplicit() const
157  {return isExplicit() and isImplicit();}
158  virtual bool isOneStepMethod() const
159  {
160  bool isOneStepMethod = true;
161  typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
162  subStepperIter = subStepperList_.begin();
163  for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
164  if ( !(*subStepperIter)->isOneStepMethod() ) isOneStepMethod = false;
165  }
166  return isOneStepMethod;
167  }
168  virtual bool isMultiStepMethod() const {return !isOneStepMethod();}
169 
170  virtual OrderODE getOrderODE() const {return FIRST_ORDER_ODE;}
171  //@}
172 
173  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
174 
175  /// \name Overridden from Teuchos::Describable
176  //@{
177  virtual void describe(Teuchos::FancyOStream & out,
178  const Teuchos::EVerbosityLevel verbLevel) const;
179  //@}
180 
181  virtual bool isValidSetup(Teuchos::FancyOStream & out) const;
182 
183  virtual std::vector<Teuchos::RCP<Stepper<Scalar> > > getStepperList() const
184  { return subStepperList_; }
185  virtual void setStepperList(std::vector<Teuchos::RCP<Stepper<Scalar> > > sl)
186  { subStepperList_ = sl; }
187 
188  /** \brief Add Stepper to subStepper list.
189  * In most cases, subSteppers cannot use xDotOld (thus the default),
190  * but in some cases, the xDotOld can be used and save compute cycles.
191  * The user can set this when adding to the subStepper list.
192  */
193  virtual void addStepper(Teuchos::RCP<Stepper<Scalar> > stepper,
194  bool useFSAL = false);
195 
196  virtual void setSubStepperList(
197  std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList);
198 
199  virtual void clearSubStepperList() { subStepperList_.clear(); }
200 
201  virtual void setModels(
202  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > appModels);
203 
204 protected:
205 
206  Scalar order_;
207  Scalar orderMin_;
208  Scalar orderMax_;
209 
210  std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList_;
211  Teuchos::RCP<SolutionHistory<Scalar> > OpSpSolnHistory_;
212  Teuchos::RCP<SolutionState<Scalar> > tempState_;
213 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
214  Teuchos::RCP<StepperOperatorSplitObserver<Scalar> > stepperOSObserver_;
215 #endif
216  Teuchos::RCP<StepperOperatorSplitAppAction<Scalar> > stepperOSAppAction_;
217 };
218 
219 } // namespace Tempus
220 
221 #endif // Tempus_StepperOperatorSplit_decl_hpp
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > >)
Pass initial guess to Newton solver.
virtual Teuchos::RCP< StepperOperatorSplitAppAction< Scalar > > getAppAction() const
virtual void addStepper(Teuchos::RCP< Stepper< Scalar > > stepper, bool useFSAL=false)
Add Stepper to subStepper list. In most cases, subSteppers cannot use xDotOld (thus the default)...
virtual Scalar getInitTimeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &) const
virtual Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > getModel()
virtual void setObserver(Teuchos::RCP< StepperObserver< Scalar > > obs=Teuchos::null)
Set Observer.
std::vector< Teuchos::RCP< Stepper< Scalar > > > subStepperList_
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual void setModel(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &appModel)
virtual void setSolver(Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > solver)
Set solver.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
virtual void setModels(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels)
OperatorSplit stepper loops through the Stepper list.
Thyra Base interface for time steppers.
Teuchos::RCP< SolutionState< Scalar > > tempState_
virtual void setAppAction(Teuchos::RCP< StepperOperatorSplitAppAction< Scalar > > appAction)
virtual void setTempState(Teuchos::RCP< Tempus::SolutionState< Scalar >> state)
Teuchos::RCP< StepperOperatorSplitAppAction< Scalar > > stepperOSAppAction_
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
StepperObserver class for Stepper class.
virtual void setStepperList(std::vector< Teuchos::RCP< Stepper< Scalar > > > sl)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Teuchos::RCP< StepperOperatorSplitObserver< Scalar > > stepperOSObserver_
virtual void setInitialConditions(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Set the initial conditions and make them consistent.
Teuchos::RCP< SolutionHistory< Scalar > > OpSpSolnHistory_
Stepper integrates first-order ODEs.
StepperOperatorSplitAppAction class for StepperOperatorSplit.
virtual Teuchos::RCP< StepperObserver< Scalar > > getObserver() const
Get Observer.
virtual bool isValidSetup(Teuchos::FancyOStream &out) const
virtual void takeStep(const Teuchos::RCP< SolutionHistory< Scalar > > &solutionHistory)
Take the specified timestep, dt, and return true if successful.
virtual void initialize()
Initialize during construction and after changing input parameters.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
virtual std::vector< Teuchos::RCP< Stepper< Scalar > > > getStepperList() const
virtual void setSubStepperList(std::vector< Teuchos::RCP< Stepper< Scalar > > > subStepperList)