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
134 SolutionHistory(Teuchos::RCP<Teuchos::ParameterList> shPL = Teuchos::null);
146 const bool updateTime =
true);
155 Teuchos::RCP<SolutionState<Scalar> >
findState(
const Scalar time)
const;
158 Teuchos::RCP<SolutionState<Scalar> >
interpolateState(
const Scalar time)
const;
182 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > >
186 Teuchos::RCP<SolutionState<Scalar> >
operator[](
const int i) {
187 TEUCHOS_TEST_FOR_EXCEPTION(
188 !((0 <= i) and (i < (
int)
history_->size())), std::out_of_range,
189 "Error - SolutionHistory index is out of range.\n"
190 <<
" [Min, Max] = [ 0, " <<
history_->size()<<
"]\n"
191 <<
" index = " << i <<
"\n");
196 Teuchos::RCP<const SolutionState<Scalar> >
operator[](
const int i)
const {
197 TEUCHOS_TEST_FOR_EXCEPTION(
198 !((0 <= i) and (i < (
int)
history_->size())), std::out_of_range,
199 "Error - SolutionHistory index is out of range.\n"
200 <<
" [Min, Max] = [ 0, " <<
history_->size()<<
"]\n"
201 <<
" index = " << i <<
"\n");
209 Teuchos::RCP<SolutionState<Scalar> > state;
210 if (m == 0) state=Teuchos::null;
211 else if (m == 1 or
workingState_ == Teuchos::null) state=(*history_)[m-1];
212 else if (m > 1) state=(*history_)[m-2];
220 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
221 Teuchos::OSTab ostab(out,1,
"SolutionHistory::getWorkingState()");
222 *out <<
"Warning - WorkingState is null and likely has been promoted. "
223 <<
"You might want to call getCurrentState() instead.\n"
277 virtual void describe(Teuchos::FancyOStream & out,
278 const Teuchos::EVerbosityLevel verbLevel)
const;
293 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
294 Teuchos::OSTab ostab(out,1,
"SolutionHistory::printHistory");
296 <<
" (w - working; c - current; i - interpolated)" << std::endl;
297 for (
int i=0; i<(int)
history_->size() ; ++i) {
298 auto state = (*history_)[i];
302 else if (state->getMetaData()->getIsInterpolated() ==
true) *out<<
"i - ";
304 *out <<
"[" << i <<
"] = " << state << std::endl;
305 if (verb ==
"medium" or verb ==
"high") {
306 if (state != Teuchos::null) {
307 auto x = state->getX();
308 *out <<
" x = " << x << std::endl
309 <<
" norm(x) = " << Thyra::norm(*x) << std::endl;
312 if (verb ==
"high") {
313 (*history_)[i]->describe(*out,this->getVerbLevel());
321 Teuchos::RCP<Teuchos::ParameterList>
shPL_;
322 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > >
history_;
331 template<
class Scalar>
332 Teuchos::RCP<SolutionHistory<Scalar> >
333 solutionHistory(Teuchos::RCP<Teuchos::ParameterList> pList = Teuchos::null);
338 #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.
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< 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)
Teuchos::RCP< SolutionHistory< Scalar > > solutionHistory(Teuchos::RCP< Teuchos::ParameterList > pList=Teuchos::null)
Nonmember constructor.
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< SolutionState< Scalar > > getStateTimeIndex(int index) const
Get the state with timestep index equal to "index".
SolutionHistory(Teuchos::RCP< Teuchos::ParameterList > shPL=Teuchos::null)
Contructor.
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_