Tempus  Version of the Day
Time Integration
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 
17 namespace Tempus {
18 
25 };
26 
27 
117 template<class Scalar>
118 class SolutionHistory
119  : virtual public Teuchos::Describable,
120  virtual public Teuchos::VerboseObject<SolutionHistory<Scalar> >
121 {
122 public:
123 
125  SolutionHistory();
126 
129  std::string name,
130  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history,
131  Teuchos::RCP<Interpolator<Scalar> > interpolator,
132  StorageType storageType,
133  int storageLimit);
134 
137 
139 
140  void addState(const Teuchos::RCP<SolutionState<Scalar> >& state,
142  bool doChecks = true); // <-- Perform internal checks.
143 
145  void addWorkingState(const Teuchos::RCP<SolutionState<Scalar> >& state,
146  const bool updateTime = true);
147 
149  void removeState(const Teuchos::RCP<SolutionState<Scalar> >& state);
150 
152  void removeState(const Scalar time);
153 
155  Teuchos::RCP<SolutionState<Scalar> > findState(const Scalar time) const;
156 
158  Teuchos::RCP<SolutionState<Scalar> > interpolateState(const Scalar time) const;
159 
161  void interpolateState(const Scalar time,
162  SolutionState<Scalar>* state_out) const;
163 
165  void initWorkingState();
166 
168  void promoteWorkingState();
169 
171  void clear() {history_->clear(); isInitialized_ = false;}
172 
174  void copy(Teuchos::RCP<const SolutionHistory<Scalar> > sh);
176 
178 
179  std::string getName() const {return name_;}
181 
183  void setName(std::string name) {name_ = name;}
184 
186  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > >
187  getHistory() const {return history_;}
188 
191  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > h)
192  { history_ = h; isInitialized_ = false; }
193 
195  Teuchos::RCP<SolutionState<Scalar> > operator[](const int i) {
196  TEUCHOS_TEST_FOR_EXCEPTION(
197  !((0 <= i) && (i < (int)history_->size())), std::out_of_range,
198  "Error - SolutionHistory index is out of range.\n"
199  << " [Min, Max] = [ 0, " << history_->size()<< "]\n"
200  << " index = " << i << "\n");
201  return (*history_)[i];
202  }
203 
205  Teuchos::RCP<const SolutionState<Scalar> > operator[](const int i) const {
206  TEUCHOS_TEST_FOR_EXCEPTION(
207  !((0 <= i) && (i < (int)history_->size())), std::out_of_range,
208  "Error - SolutionHistory index is out of range.\n"
209  << " [Min, Max] = [ 0, " << history_->size()<< "]\n"
210  << " index = " << i << "\n");
211  return (*history_)[i];
212  }
213 
215  Teuchos::RCP<SolutionState<Scalar> > getCurrentState() const
216  {
217  const int m = history_->size();
218  Teuchos::RCP<SolutionState<Scalar> > state;
219  if (m == 0) state=Teuchos::null;
220  else if (m == 1 || workingState_ == Teuchos::null) state=(*history_)[m-1];
221  else if (m > 1) state=(*history_)[m-2];
222  return state;
223  }
224 
226  Teuchos::RCP<SolutionState<Scalar> > getWorkingState(bool warn=true) const
227  {
228  if (workingState_ == Teuchos::null && warn) {
229  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
230  Teuchos::OSTab ostab(out,1,"SolutionHistory::getWorkingState()");
231  *out << "Warning - WorkingState is null and likely has been promoted. "
232  << "You might want to call getCurrentState() instead.\n"
233  << std::endl;
234  }
235  return workingState_;
236  }
237 
239  int getNumStates() const {return history_->size();}
240 
242  Scalar getCurrentTime() const {return getCurrentState()->getTime();}
243 
245  int getCurrentIndex() const {return getCurrentState()->getIndex();}
246 
248  void setStorageLimit(int storage_limit);
249 
251  int getStorageLimit() const {return storageLimit_;}
252 
254  void setStorageType(StorageType st);
255 
258 
260  void setStorageTypeString(std::string st);
261 
263  std::string getStorageTypeString() const;
264 
266  Scalar minTime() const {return (history_->front())->getTime();}
267 
269  Scalar maxTime() const {return (history_->back())->getTime();}
270 
275  Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndexN(bool warn = true) const;
276 
281  Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndexNM1(bool warn = true) const;
282 
287  Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndexNM2(bool warn = true) const;
288 
293  Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndex(int index, bool warn = true) const;
295 
297  Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
298 
300  Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
301 
303 
304  virtual std::string description() const;
305  virtual void describe(Teuchos::FancyOStream & out,
306  const Teuchos::EVerbosityLevel verbLevel) const;
308 
310 
311  void setInterpolator(
313  const Teuchos::RCP<Interpolator<Scalar> >& interpolator);
314  Teuchos::RCP<Interpolator<Scalar> > getNonconstInterpolator();
315  Teuchos::RCP<const Interpolator<Scalar> > getInterpolator() const;
317  Teuchos::RCP<Interpolator<Scalar> > unSetInterpolator();
319 
321  void printHistory(std::string verb="low") const;
322 
329  void initialize() const;
330 
332  bool isInitialized() { return isInitialized_; }
333 
334 
335 protected:
336 
337  std::string name_;
338  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history_;
339  Teuchos::RCP<Interpolator<Scalar> > interpolator_;
342 
343  Teuchos::RCP<SolutionState<Scalar> > workingState_;
344 
345  mutable bool isInitialized_;
346 
347 };
348 
349 
351 template<class Scalar>
352 Teuchos::RCP<SolutionHistory<Scalar> >
354 
356 template<class Scalar>
357 Teuchos::RCP<SolutionHistory<Scalar> >
358 createSolutionHistoryPL(Teuchos::RCP<Teuchos::ParameterList> pList);
359 
361 template<class Scalar>
362 Teuchos::RCP<SolutionHistory<Scalar> >
363 createSolutionHistoryState(const Teuchos::RCP<SolutionState<Scalar> >& state);
364 
366 template<class Scalar>
367 Teuchos::RCP<SolutionHistory<Scalar> >
369  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model);
370 
371 
372 } // namespace Tempus
373 
374 #endif // Tempus_SolutionHistory_decl_hpp
Teuchos::RCP< Interpolator< Scalar > > unSetInterpolator()
Unset the interpolator for this history.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM2(bool warn=true) const
Get the state with timestep index equal to n-2.
Keep the 2 newest states for undo.
Teuchos::RCP< Interpolator< Scalar > > interpolator_
virtual std::string description() const
void initWorkingState()
Initialize the working state.
std::string getStorageTypeString() const
Set the string storage type.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistory()
Nonmember constructor.
StorageType getStorageType() const
Get the enum storage type.
Teuchos::RCP< const Interpolator< Scalar > > getInterpolator() const
Teuchos::RCP< SolutionState< Scalar > > findState(const Scalar time) const
Find solution state at requested time (no interpolation)
Scalar getCurrentTime() const
Get the current time.
Teuchos::RCP< SolutionState< Scalar > > interpolateState(const Scalar time) const
Generate and interpolate a new solution state at requested time.
std::string getName() const
Get this SolutionHistory&#39;s name.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Return a valid non-const ParameterList with current settings.
Teuchos::RCP< Interpolator< Scalar > > getNonconstInterpolator()
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< SolutionState< Scalar > > getStateTimeIndexN(bool warn=true) const
Get the state with timestep index equal to n.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Teuchos::RCP< SolutionState< Scalar > > workingState_
The state being worked on.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndex(int index, bool warn=true) const
Get the state with timestep index equal to "index".
int getNumStates() const
Get the number of states.
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.
void printHistory(std::string verb="low") const
Print information on States in the SolutionHistory.
bool isInitialized_
Bool if SolutionHistory is initialized.
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > getHistory() const
Get underlining history.
Base strategy class for interpolation functionality.
void addState(const Teuchos::RCP< SolutionState< Scalar > > &state, bool doChecks=true)
Add solution state to history.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM1(bool warn=true) const
Get the state with timestep index equal to n-1.
Scalar minTime() const
Return the current minimum time of the SolutionStates.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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.
Teuchos::RCP< const SolutionState< Scalar > > operator[](const int i) const
Subscript operator (const version)
Scalar maxTime() const
Return the current maximum time of the SolutionStates.
void setStorageTypeString(std::string st)
Set the storage type via string.
int getCurrentIndex() const
Get the current timestep index.
Teuchos::RCP< SolutionState< Scalar > > getWorkingState(bool warn=true) const
Return the working state.
Teuchos::RCP< SolutionState< Scalar > > getCurrentState() const
Return the current state, i.e., the last accepted state.
void setInterpolator(const Teuchos::RCP< Interpolator< Scalar > > &interpolator)
Set the interpolator for this history.
void copy(Teuchos::RCP< const SolutionHistory< Scalar > > sh)
Make a shallow copy of SolutionHistory (i.e., only RCPs to states and interpolator).
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
Teuchos::RCP< SolutionState< Scalar > > operator[](const int i)
Subscript operator.
int getStorageLimit() const
Get the maximum storage of this history.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
bool isInitialized()
Return if SolutionHistory is initialized.
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > history_
void initialize() const
Initialize SolutionHistory.