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  * - Constructs with a default ParameterList.
46  * - Can reset ParameterList with setParameterList().
47  * - Requires subsequent addStepper() and initialize() calls before calling
48  * takeStep().
49  */
51 
52  /// Constructor
54  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > appModels,
55  Teuchos::RCP<Teuchos::ParameterList> pList);
56 
57  /// \name Basic stepper methods
58  //@{
59  virtual void setModel(
60  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& appModel);
61  virtual void setNonConstModel(
62  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& appModel);
63  virtual Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >
64  getModel();
65 
66  virtual void setSolver(std::string solverName);
67  virtual void setSolver(
68  Teuchos::RCP<Teuchos::ParameterList> solverPL=Teuchos::null);
69  virtual void setSolver(
70  Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > solver);
71  virtual Teuchos::RCP<Thyra::NonlinearSolverBase<Scalar> > getSolver() const
72  { return Teuchos::null; }
73  virtual void setObserver(
74  Teuchos::RCP<StepperObserver<Scalar> > obs = Teuchos::null);
75  virtual void setTempState(Teuchos::RCP<Tempus::SolutionState<Scalar>> state)
76  { tempState_ = state; }
77 
78  /// Initialize during construction and after changing input parameters.
79  virtual void initialize();
80 
81  /// Set the initial conditions and make them consistent.
82  virtual void setInitialConditions (
83  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
84 
85  /// Take the specified timestep, dt, and return true if successful.
86  virtual void takeStep(
87  const Teuchos::RCP<SolutionHistory<Scalar> >& solutionHistory);
88 
89  /// Pass initial guess to Newton solver
90  virtual void setInitialGuess(
91  Teuchos::RCP<const Thyra::VectorBase<Scalar> > /* initial_guess */){}
92 
93  virtual std::string getStepperType() const
94  { return stepperPL_->get<std::string>("Stepper Type"); }
95 
96  /// Get a default (initial) StepperState
97  virtual Teuchos::RCP<Tempus::StepperState<Scalar> > getDefaultStepperState();
98  virtual Scalar getOrder() const
99  {return stepperPL_->get<int>("Order");}
100  virtual Scalar getOrderMin() const
101  {return stepperPL_->get<int>("Minimum Order");}
102  virtual Scalar getOrderMax() const
103  {return stepperPL_->get<int>("Maximum Order");}
104  virtual Scalar getInitTimeStep(
105  const Teuchos::RCP<SolutionHistory<Scalar> >& /* solutionHistory */) const
106  {return Scalar(1.0e+99);}
107  virtual void setOrder (Scalar ord)
108  {stepperPL_->set<int>("Order", ord);}
109  virtual void setOrderMin(Scalar ord)
110  {stepperPL_->set<int>("Minimum Order", ord);}
111  virtual void setOrderMax(Scalar ord)
112  {stepperPL_->set<int>("Maximum Order", ord);}
113 
114  virtual bool isExplicit() const
115  {
116  bool isExplicit = false;
117  typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
118  subStepperIter = subStepperList_.begin();
119  for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
120  if ( (*subStepperIter)->isExplicit() ) isExplicit = true;
121  }
122  return isExplicit;
123  }
124  virtual bool isImplicit() const
125  {
126  bool isImplicit = false;
127  typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
128  subStepperIter = subStepperList_.begin();
129  for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
130  if ( (*subStepperIter)->isImplicit() ) isImplicit = true;
131  }
132  return isImplicit;
133  }
134  virtual bool isExplicitImplicit() const
135  {return isExplicit() and isImplicit();}
136  virtual bool isOneStepMethod() const
137  {
138  bool isOneStepMethod = true;
139  typename std::vector<Teuchos::RCP<Stepper<Scalar> > >::const_iterator
140  subStepperIter = subStepperList_.begin();
141  for (; subStepperIter < subStepperList_.end(); subStepperIter++) {
142  if ( !(*subStepperIter)->isOneStepMethod() ) isOneStepMethod = false;
143  }
144  return isOneStepMethod;
145  }
146  virtual bool isMultiStepMethod() const {return !isOneStepMethod();}
147 
148  virtual OrderODE getOrderODE() const {return FIRST_ORDER_ODE;}
149 
150  virtual void setUseFSAL(bool a) {stepperPL_->set<bool>("Use FSAL", a);}
151  virtual bool getUseFSAL() const
152  {return stepperPL_->get<bool>("Use FSAL", false);}
153 
154  virtual void setICConsistency(std::string s)
155  {stepperPL_->set<std::string>("Initial Condition Consistency", s);}
156  virtual std::string getICConsistency() const
157  {return stepperPL_->get<std::string>("Initial Condition Consistency",
158  "None");}
159 
160  virtual void setICConsistencyCheck(bool c)
161  {stepperPL_->set<bool>("Initial Condition Consistency Check", c);}
162  virtual bool getICConsistencyCheck() const
163  {return stepperPL_->get<bool>("Initial Condition Consistency Check",
164  false);}
165  //@}
166 
167  /// \name ParameterList methods
168  //@{
169  void setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & pl);
170  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
171  Teuchos::RCP<Teuchos::ParameterList> unsetParameterList();
172  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
173  Teuchos::RCP<Teuchos::ParameterList> getDefaultParameters() const;
174  //@}
175 
176  /// \name Overridden from Teuchos::Describable
177  //@{
178  virtual std::string description() const;
179  virtual void describe(Teuchos::FancyOStream & out,
180  const Teuchos::EVerbosityLevel verbLevel) const;
181  //@}
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  /** \brief Add Stepper to subStepper list.
188  * In most cases, subSteppers cannot use xDotOld (thus the default),
189  * but in some cases, the xDotOld can be used and save compute cycles.
190  * The user can set this when adding to the subStepper list.
191  */
192  virtual void addStepper(Teuchos::RCP<Stepper<Scalar> > stepper,
193  bool useFSAL = false)
194  {
195  stepper->setUseFSAL(useFSAL);
196  subStepperList_.push_back(stepper);
197  }
198  virtual void clearStepperList() { subStepperList_.clear(); }
199  /// Take models and ParameterList and create subSteppers
200  virtual void createSubSteppers(
201  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > appModels);
202 
203 protected:
204 
205  Teuchos::RCP<Teuchos::ParameterList> stepperPL_;
206  std::vector<Teuchos::RCP<Stepper<Scalar> > > subStepperList_;
207  Teuchos::RCP<SolutionHistory<Scalar> > OpSpSolnHistory_;
208  Teuchos::RCP<SolutionState<Scalar> > tempState_;
209  Teuchos::RCP<StepperOperatorSplitObserver<Scalar> > stepperOSObserver_;
210 
211 };
212 
213 } // namespace Tempus
214 
215 #endif // Tempus_StepperOperatorSplit_decl_hpp
virtual Teuchos::RCP< Thyra::NonlinearSolverBase< Scalar > > getSolver() const
Get solver.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
virtual void setSolver(std::string solverName)
Set solver via ParameterList solver name.
virtual void setInitialGuess(Teuchos::RCP< const Thyra::VectorBase< Scalar > >)
Pass initial guess to Newton solver.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
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 createSubSteppers(std::vector< Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > > appModels)
Take models and ParameterList and create subSteppers.
virtual Teuchos::RCP< Tempus::StepperState< Scalar > > getDefaultStepperState()
Get a default (initial) StepperState.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
Teuchos::RCP< Teuchos::ParameterList > stepperPL_
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< Teuchos::ParameterList > getDefaultParameters() const
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 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)...