Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_SolutionHistory_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_SolutionHistory_decl_hpp
10 #define Tempus_SolutionHistory_decl_hpp
11 
12 #include "Tempus_config.hpp"
13 #include "Tempus_SolutionState.hpp"
14 #include "Tempus_Interpolator.hpp"
15 
16 namespace Tempus {
17 
24 };
25 
115 template <class Scalar>
116 class SolutionHistory
117  : virtual public Teuchos::Describable,
118  virtual public Teuchos::VerboseObject<SolutionHistory<Scalar> > {
119  public:
121  SolutionHistory();
122 
125  std::string name,
126  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history,
127  Teuchos::RCP<Interpolator<Scalar> > interpolator, StorageType storageType,
128  int storageLimit);
129 
132 
134 
135  void addState(const Teuchos::RCP<SolutionState<Scalar> >& state,
137  bool doChecks = true); // <-- Perform internal checks.
138 
141  const bool updateTime = true);
142 
144  void removeState(const Teuchos::RCP<SolutionState<Scalar> >& state);
145 
147  void removeState(const Scalar time);
148 
150  Teuchos::RCP<SolutionState<Scalar> > findState(const Scalar time) const;
151 
154  const Scalar time) const;
155 
157  void interpolateState(const Scalar time,
158  SolutionState<Scalar>* state_out) const;
159 
161  void initWorkingState();
162 
164  void promoteWorkingState();
165 
167  void clear()
168  {
169  history_->clear();
170  isInitialized_ = false;
171  }
172 
175  void copy(Teuchos::RCP<const SolutionHistory<Scalar> > sh);
177 
179 
180  std::string getName() const { return name_; }
182 
184  void setName(std::string name) { name_ = name; }
185 
188  const
189  {
190  return history_;
191  }
192 
195  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > h)
196  {
197  history_ = h;
198  isInitialized_ = false;
199  }
200 
203  {
205  !((0 <= i) && (i < (int)history_->size())), std::out_of_range,
206  "Error - SolutionHistory index is out of range.\n"
207  << " [Min, Max] = [ 0, " << history_->size() << "]\n"
208  << " index = " << i << "\n");
209  return (*history_)[i];
210  }
211 
214  {
216  !((0 <= i) && (i < (int)history_->size())), std::out_of_range,
217  "Error - SolutionHistory index is out of range.\n"
218  << " [Min, Max] = [ 0, " << history_->size() << "]\n"
219  << " index = " << i << "\n");
220  return (*history_)[i];
221  }
222 
225  {
226  const int m = history_->size();
228  if (m == 0)
229  state = Teuchos::null;
230  else if (m == 1 || workingState_ == Teuchos::null)
231  state = (*history_)[m - 1];
232  else if (m > 1)
233  state = (*history_)[m - 2];
234  return state;
235  }
236 
239  {
240  if (workingState_ == Teuchos::null && warn) {
242  Teuchos::OSTab ostab(out, 1, "SolutionHistory::getWorkingState()");
243  *out << "Warning - WorkingState is null and likely has been promoted. "
244  << "You might want to call getCurrentState() instead.\n"
245  << std::endl;
246  }
247  return workingState_;
248  }
249 
251  int getNumStates() const { return history_->size(); }
252 
254  Scalar getCurrentTime() const { return getCurrentState()->getTime(); }
255 
257  int getCurrentIndex() const { return getCurrentState()->getIndex(); }
258 
260  void setStorageLimit(int storage_limit);
261 
263  int getStorageLimit() const { return storageLimit_; }
264 
266  void setStorageType(StorageType st);
267 
270 
272  void setStorageTypeString(std::string st);
273 
275  std::string getStorageTypeString() const;
276 
278  Scalar minTime() const { return (history_->front())->getTime(); }
279 
281  Scalar maxTime() const { return (history_->back())->getTime(); }
282 
288  bool warn = true) const;
289 
295  bool warn = true) const;
296 
302  bool warn = true) const;
303 
309  int index, bool warn = true) const;
311 
314 
317 
319 
320  virtual std::string description() const;
321  virtual void describe(Teuchos::FancyOStream& out,
322  const Teuchos::EVerbosityLevel verbLevel) const;
324 
326 
327  void setInterpolator(const Teuchos::RCP<Interpolator<Scalar> >& interpolator);
334 
336  void printHistory(std::string verb = "low") const;
337 
344  void initialize() const;
345 
347  bool isInitialized() { return isInitialized_; }
348 
349  protected:
350  std::string name_;
355 
358 
359  mutable bool isInitialized_;
360 };
361 
363 template <class Scalar>
365 
367 template <class Scalar>
370 
372 template <class Scalar>
374  const Teuchos::RCP<SolutionState<Scalar> >& state);
375 
377 template <class Scalar>
379  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model);
380 
381 } // namespace Tempus
382 
383 #endif // Tempus_SolutionHistory_decl_hpp
Teuchos::RCP< Interpolator< Scalar > > unSetInterpolator()
Unset the interpolator for this history.
Scalar minTime() const
Return the current minimum time of the SolutionStates.
std::string getName() const
Get this SolutionHistory&#39;s name.
Keep the 2 newest states for undo.
int getCurrentIndex() const
Get the current timestep index.
Teuchos::RCP< Interpolator< Scalar > > interpolator_
void initWorkingState()
Initialize the working state.
StorageType getStorageType() const
Get the enum storage type.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistory()
Nonmember constructor.
void printHistory(std::string verb="low") const
Print information on States in the SolutionHistory.
Teuchos::RCP< SolutionState< Scalar > > interpolateState(const Scalar time) const
Generate and interpolate a new solution state at requested time.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
int getNumStates() const
Get the number of states.
Teuchos::RCP< const SolutionState< Scalar > > operator[](const int i) const
Subscript operator (const version)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Return a valid non-const ParameterList with current settings.
Teuchos::RCP< Interpolator< Scalar > > getNonconstInterpolator()
Scalar getCurrentTime() const
Get the current time.
void setStorageLimit(int storage_limit)
Set the maximum storage of this history.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryPL(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember constructor from a ParameterList.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Teuchos::RCP< SolutionState< Scalar > > getWorkingState(bool warn=true) const
Return the working state.
Teuchos::RCP< SolutionState< Scalar > > workingState_
The state being worked on.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndex(int index, bool warn=true) const
Get the state with timestep index equal to &quot;index&quot;.
void initialize() const
Initialize SolutionHistory.
void setHistory(Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > h)
Set underlining history.
void promoteWorkingState()
Promote the working state to current state.
void removeState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Remove solution state.
bool isInitialized_
Bool if SolutionHistory is initialized.
Teuchos::RCP< SolutionState< Scalar > > getCurrentState() const
Return the current state, i.e., the last accepted state.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM1(bool warn=true) const
Get the state with timestep index equal to n-1.
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > getHistory() const
Get underlining history.
Base strategy class for interpolation functionality.
virtual std::string description() const
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexN(bool warn=true) const
Get the state with timestep index equal to n.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM2(bool warn=true) const
Get the state with timestep index equal to n-2.
void addState(const Teuchos::RCP< SolutionState< Scalar > > &state, bool doChecks=true)
Add solution state to history.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
std::string getStorageTypeString() const
Set the string storage type.
void setName(std::string name)
Set this SolutionHistory&#39;s name.
void setStorageType(StorageType st)
Set the storage type via enum.
void addWorkingState(const Teuchos::RCP< SolutionState< Scalar > > &state, const bool updateTime=true)
Add a working solution state to history.
Keep a fix number of states.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Nonmember contructor from a SolutionState.
void setStorageTypeString(std::string st)
Set the storage type via string.
Teuchos::RCP< const Interpolator< Scalar > > getInterpolator() const
Scalar maxTime() const
Return the current maximum time of the SolutionStates.
void setInterpolator(const Teuchos::RCP< Interpolator< Scalar > > &interpolator)
Set the interpolator for this history.
int getStorageLimit() const
Get the maximum storage of this history.
void copy(Teuchos::RCP< const SolutionHistory< Scalar > > sh)
Teuchos::RCP< SolutionState< Scalar > > findState(const Scalar time) const
Find solution state at requested time (no interpolation)
Teuchos::RCP< SolutionState< Scalar > > operator[](const int i)
Subscript operator.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
virtual RCP< FancyOStream > getOStream() const
Solution state for integrators and steppers.
bool isInitialized()
Return if SolutionHistory is initialized.
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > history_