Tempus Version of the Day
Time Integration
Loading...
Searching...
No Matches
Tempus_SolutionHistory_decl.hpp
Go to the documentation of this file.
1//@HEADER
2// *****************************************************************************
3// Tempus: Time Integration and Sensitivity Analysis Package
4//
5// Copyright 2017 NTESS and the Tempus contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8//@HEADER
9
10#ifndef Tempus_SolutionHistory_decl_hpp
11#define Tempus_SolutionHistory_decl_hpp
12
13#include "Tempus_config.hpp"
14#include "Tempus_SolutionState.hpp"
16
17namespace Tempus {
18
26
116template <class Scalar>
118 : virtual public Teuchos::Describable,
119 virtual public Teuchos::VerboseObject<SolutionHistory<Scalar> > {
120 public:
123
126 std::string name,
127 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history,
128 Teuchos::RCP<Interpolator<Scalar> > interpolator, StorageType storageType,
129 int storageLimit);
130
133
135
136
137 void addState(const Teuchos::RCP<SolutionState<Scalar> >& state,
138 bool doChecks = true); // <-- Perform internal checks.
139
141 void addWorkingState(const Teuchos::RCP<SolutionState<Scalar> >& state,
142 const bool updateTime = true);
143
145 void removeState(const Teuchos::RCP<SolutionState<Scalar> >& state);
146
148 void removeState(const Scalar time);
149
151 Teuchos::RCP<SolutionState<Scalar> > findState(const Scalar time) const;
152
154 Teuchos::RCP<SolutionState<Scalar> > interpolateState(
155 const Scalar time) const;
156
158 void interpolateState(const Scalar time,
159 SolutionState<Scalar>* state_out) const;
160
162 void initWorkingState();
163
165 void promoteWorkingState();
166
168 void clear()
169 {
170 history_->clear();
171 isInitialized_ = false;
172 }
173
176 void copy(Teuchos::RCP<const SolutionHistory<Scalar> > sh);
178
180
181
182 std::string getName() const { return name_; }
183
185 void setName(std::string name) { name_ = name; }
186
188 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > getHistory()
189 const
190 {
191 return history_;
192 }
193
196 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > h)
197 {
198 history_ = h;
199 isInitialized_ = false;
200 }
201
203 Teuchos::RCP<SolutionState<Scalar> > operator[](const int i)
204 {
205 TEUCHOS_TEST_FOR_EXCEPTION(
206 !((0 <= i) && (i < (int)history_->size())), std::out_of_range,
207 "Error - SolutionHistory index is out of range.\n"
208 << " [Min, Max] = [ 0, " << history_->size() << "]\n"
209 << " index = " << i << "\n");
210 return (*history_)[i];
211 }
212
214 Teuchos::RCP<const SolutionState<Scalar> > operator[](const int i) const
215 {
216 TEUCHOS_TEST_FOR_EXCEPTION(
217 !((0 <= i) && (i < (int)history_->size())), std::out_of_range,
218 "Error - SolutionHistory index is out of range.\n"
219 << " [Min, Max] = [ 0, " << history_->size() << "]\n"
220 << " index = " << i << "\n");
221 return (*history_)[i];
222 }
223
225 Teuchos::RCP<SolutionState<Scalar> > getCurrentState() const
226 {
227 const int m = history_->size();
228 Teuchos::RCP<SolutionState<Scalar> > state;
229 if (m == 0)
230 state = Teuchos::null;
231 else if (m == 1 || workingState_ == Teuchos::null)
232 state = (*history_)[m - 1];
233 else if (m > 1)
234 state = (*history_)[m - 2];
235 return state;
236 }
237
239 Teuchos::RCP<SolutionState<Scalar> > getWorkingState(bool warn = true) const
240 {
241 if (workingState_ == Teuchos::null && warn) {
242 Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
243 Teuchos::OSTab ostab(out, 1, "SolutionHistory::getWorkingState()");
244 *out << "Warning - WorkingState is null and likely has been promoted. "
245 << "You might want to call getCurrentState() instead.\n"
246 << std::endl;
247 }
248 return workingState_;
249 }
250
252 int getNumStates() const { return history_->size(); }
253
255 Scalar getCurrentTime() const { return getCurrentState()->getTime(); }
256
258 int getCurrentIndex() const { return getCurrentState()->getIndex(); }
259
261 void setStorageLimit(int storage_limit);
262
264 int getStorageLimit() const { return storageLimit_; }
265
268
271
273 void setStorageTypeString(std::string st);
274
276 std::string getStorageTypeString() const;
277
279 Scalar minTime() const { return (history_->front())->getTime(); }
280
282 Scalar maxTime() const { return (history_->back())->getTime(); }
283
288 Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndexN(
289 bool warn = true) const;
290
295 Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndexNM1(
296 bool warn = true) const;
297
302 Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndexNM2(
303 bool warn = true) const;
304
309 Teuchos::RCP<SolutionState<Scalar> > getStateTimeIndex(
310 int index, bool warn = true) const;
312
314 Teuchos::RCP<const Teuchos::ParameterList> getValidParameters() const;
315
317 Teuchos::RCP<Teuchos::ParameterList> getNonconstParameterList();
318
320
321 virtual std::string description() const;
322 virtual void describe(Teuchos::FancyOStream& out,
323 const Teuchos::EVerbosityLevel verbLevel) const;
325
327
328
329 void setInterpolator(const Teuchos::RCP<Interpolator<Scalar> >& interpolator);
330 Teuchos::RCP<Interpolator<Scalar> > getNonconstInterpolator();
331 Teuchos::RCP<const Interpolator<Scalar> > getInterpolator() const;
333 Teuchos::RCP<Interpolator<Scalar> > unSetInterpolator();
335
337 void printHistory(std::string verb = "low") const;
338
345 void initialize() const;
346
348 bool isInitialized() { return isInitialized_; }
349
350 protected:
351 std::string name_;
352 Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history_;
353 Teuchos::RCP<Interpolator<Scalar> > interpolator_;
356
357 Teuchos::RCP<SolutionState<Scalar> >
359
360 mutable bool isInitialized_;
361};
362
364template <class Scalar>
365Teuchos::RCP<SolutionHistory<Scalar> > createSolutionHistory();
366
368template <class Scalar>
369Teuchos::RCP<SolutionHistory<Scalar> > createSolutionHistoryPL(
370 Teuchos::RCP<Teuchos::ParameterList> pList);
371
373template <class Scalar>
374Teuchos::RCP<SolutionHistory<Scalar> > createSolutionHistoryState(
375 const Teuchos::RCP<SolutionState<Scalar> >& state);
376
378template <class Scalar>
379Teuchos::RCP<SolutionHistory<Scalar> > createSolutionHistoryME(
380 const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model);
381
382} // namespace Tempus
383
384#endif // Tempus_SolutionHistory_decl_hpp
Base strategy class for interpolation functionality.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
std::string getName() const
Get this SolutionHistory's name.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndex(int index, bool warn=true) const
Get the state with timestep index equal to "index".
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > getHistory() const
Get underlining history.
void setName(std::string name)
Set this SolutionHistory's name.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM1(bool warn=true) const
Get the state with timestep index equal to n-1.
void initWorkingState()
Initialize the working state.
Teuchos::RCP< SolutionState< Scalar > > workingState_
The state being worked on.
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
Scalar minTime() const
Return the current minimum time of the SolutionStates.
Teuchos::RCP< const Interpolator< Scalar > > getInterpolator() const
bool isInitialized()
Return if SolutionHistory is initialized.
virtual std::string description() const
void addState(const Teuchos::RCP< SolutionState< Scalar > > &state, bool doChecks=true)
Add solution state to history.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM2(bool warn=true) const
Get the state with timestep index equal to n-2.
Teuchos::RCP< SolutionState< Scalar > > operator[](const int i)
Subscript operator.
void setStorageType(StorageType st)
Set the storage type via enum.
bool isInitialized_
Bool if SolutionHistory is initialized.
void setHistory(Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > h)
Set underlining history.
Scalar getCurrentTime() const
Get the current time.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Return a valid non-const ParameterList with current settings.
std::string getStorageTypeString() const
Set the string storage type.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
void copy(Teuchos::RCP< const SolutionHistory< Scalar > > sh)
StorageType getStorageType() const
Get the enum storage type.
Teuchos::RCP< Interpolator< Scalar > > unSetInterpolator()
Unset the interpolator for this history.
int getNumStates() const
Get the number of states.
void initialize() const
Initialize SolutionHistory.
int getCurrentIndex() const
Get the current timestep index.
void setStorageLimit(int storage_limit)
Set the maximum storage of this history.
int getStorageLimit() const
Get the maximum storage of this history.
Teuchos::RCP< SolutionState< Scalar > > getWorkingState(bool warn=true) const
Return the working state.
Teuchos::RCP< Interpolator< Scalar > > getNonconstInterpolator()
void setStorageTypeString(std::string st)
Set the storage type via string.
Teuchos::RCP< SolutionState< Scalar > > findState(const Scalar time) const
Find solution state at requested time (no interpolation)
void printHistory(std::string verb="low") const
Print information on States in the SolutionHistory.
Teuchos::RCP< SolutionState< Scalar > > getCurrentState() const
Return the current state, i.e., the last accepted state.
Teuchos::RCP< SolutionState< Scalar > > interpolateState(const Scalar time) const
Generate and interpolate a new solution state at requested time.
void removeState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Remove solution state.
void addWorkingState(const Teuchos::RCP< SolutionState< Scalar > > &state, const bool updateTime=true)
Add a working solution state to history.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexN(bool warn=true) const
Get the state with timestep index equal to n.
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > history_
void setInterpolator(const Teuchos::RCP< Interpolator< Scalar > > &interpolator)
Set the interpolator for this history.
Teuchos::RCP< const SolutionState< Scalar > > operator[](const int i) const
Subscript operator (const version)
Teuchos::RCP< Interpolator< Scalar > > interpolator_
Scalar maxTime() const
Return the current maximum time of the SolutionStates.
void promoteWorkingState()
Promote the working state to current state.
Solution state for integrators and steppers.
@ STORAGE_TYPE_STATIC
Keep a fix number of states.
@ STORAGE_TYPE_UNLIMITED
Grow the history as needed.
@ STORAGE_TYPE_INVALID
Invalid storage type.
@ STORAGE_TYPE_UNDO
Keep the 2 newest states for undo.
@ STORAGE_TYPE_KEEP_NEWEST
Keep the single newest state.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryPL(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember constructor from a ParameterList.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Nonmember contructor from a SolutionState.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistory()
Nonmember constructor.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.