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