9 #ifndef Tempus_SolutionHistory_decl_hpp
10 #define Tempus_SolutionHistory_decl_hpp
13 #include "Teuchos_VerboseObject.hpp"
14 #include "Teuchos_Describable.hpp"
15 #include "Teuchos_ParameterListAcceptorDefaultBase.hpp"
17 #include "Thyra_VectorStdOps.hpp"
19 #include "Tempus_config.hpp"
20 #include "Tempus_SolutionState.hpp"
124 template<
class Scalar>
125 class SolutionHistory
126 :
virtual public Teuchos::Describable,
127 virtual public Teuchos::VerboseObject<SolutionHistory<Scalar> >,
128 virtual public Teuchos::ParameterListAcceptor
139 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history,
140 Teuchos::RCP<Interpolator<Scalar> > interpolator,
157 const bool updateTime =
true);
166 Teuchos::RCP<SolutionState<Scalar> >
findState(
const Scalar time)
const;
169 Teuchos::RCP<SolutionState<Scalar> >
interpolateState(
const Scalar time)
const;
193 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > >
197 Teuchos::RCP<SolutionState<Scalar> >
operator[](
const int i) {
198 TEUCHOS_TEST_FOR_EXCEPTION(
199 !((0 <= i) and (i < (
int)
history_->size())), std::out_of_range,
200 "Error - SolutionHistory index is out of range.\n"
201 <<
" [Min, Max] = [ 0, " <<
history_->size()<<
"]\n"
202 <<
" index = " << i <<
"\n");
207 Teuchos::RCP<const SolutionState<Scalar> >
operator[](
const int i)
const {
208 TEUCHOS_TEST_FOR_EXCEPTION(
209 !((0 <= i) and (i < (
int)
history_->size())), std::out_of_range,
210 "Error - SolutionHistory index is out of range.\n"
211 <<
" [Min, Max] = [ 0, " <<
history_->size()<<
"]\n"
212 <<
" index = " << i <<
"\n");
220 Teuchos::RCP<SolutionState<Scalar> > state;
221 if (m == 0) state=Teuchos::null;
222 else if (m == 1 or
workingState_ == Teuchos::null) state=(*history_)[m-1];
223 else if (m > 1) state=(*history_)[m-2];
231 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
232 Teuchos::OSTab ostab(out,1,
"SolutionHistory::getWorkingState()");
233 *out <<
"Warning - WorkingState is null and likely has been promoted. "
234 <<
"You might want to call getCurrentState() instead.\n"
288 virtual void describe(Teuchos::FancyOStream & out,
289 const Teuchos::EVerbosityLevel verbLevel)
const;
304 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
305 Teuchos::OSTab ostab(out,1,
"SolutionHistory::printHistory");
307 <<
" (w - working; c - current; i - interpolated)" << std::endl;
308 for (
int i=0; i<(int)
history_->size() ; ++i) {
309 auto state = (*history_)[i];
313 else if (state->getIsInterpolated() ==
true) *out<<
"i - ";
315 *out <<
"[" << i <<
"] = " << state << std::endl;
316 if (verb ==
"medium" or verb ==
"high") {
317 if (state != Teuchos::null) {
318 auto x = state->getX();
319 *out <<
" x = " << x << std::endl
320 <<
" norm(x) = " << Thyra::norm(*x) << std::endl;
323 if (verb ==
"high") {
324 (*history_)[i]->describe(*out,this->getVerbLevel());
332 Teuchos::RCP<Teuchos::ParameterList>
shPL_;
333 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > >
history_;
343 template<
class Scalar>
344 Teuchos::RCP<SolutionHistory<Scalar> >
348 template<
class Scalar>
349 Teuchos::RCP<SolutionHistory<Scalar> >
353 template<
class Scalar>
354 Teuchos::RCP<SolutionHistory<Scalar> >
356 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& model);
361 #endif // Tempus_SolutionHistory_decl_hpp
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM2() const
Get the state with timestep index equal to n-2.
Teuchos::RCP< Interpolator< Scalar > > unSetInterpolator()
Unset the interpolator for this history.
SolutionHistory()
Default Contructor.
Scalar minTime() const
Return the current minimum time of the SolutionStates.
std::string getName() const
Get this SolutionHistory's name.
Keep the 2 newest states for undo.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList()
int getCurrentIndex() const
Get the current timestep index.
Teuchos::RCP< Interpolator< Scalar > > interpolator_
void initWorkingState()
Initialize the working state.
void printHistory(std::string verb="low") const
Teuchos::RCP< SolutionState< Scalar > > interpolateState(const Scalar time) const
Generate and interpolate a new solution state at requested time.
int getNumStates() const
Get the number of states.
Teuchos::RCP< const SolutionState< Scalar > > operator[](const int i) const
Subscript operator (const version)
Keep the single newest state.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
StorageType getStorageType()
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 > > getStateTimeIndexNM1() const
Get the state with timestep index equal to n-1.
void promoteWorkingState()
Promote the working state to current state.
void removeState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Remove solution state.
Teuchos::RCP< SolutionState< Scalar > > getCurrentState() const
Return the current state, i.e., the last accepted state.
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > getHistory() const
Get underlining history.
Base strategy class for interpolation functionality.
virtual std::string description() const
~SolutionHistory()
Destructor.
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void addState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Add solution state to history.
Teuchos::RCP< Teuchos::ParameterList > shPL_
void setName(std::string name)
Set this SolutionHistory's name.
void setStorageType(StorageType st)
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< SolutionState< Scalar > > getStateTimeIndex(int index) const
Get the state with timestep index equal to "index".
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexN() const
Get the state with timestep index equal to n.
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.
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
Grow the history as needed.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > history_