Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_SolutionState_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_SolutionState_decl_hpp
10 #define Tempus_SolutionState_decl_hpp
11 
12 // Teuchos
13 #include "Teuchos_VerboseObject.hpp"
14 #include "Teuchos_Describable.hpp"
15 // Thrya
16 #include "Thyra_VectorBase.hpp"
17 #include "Thyra_ModelEvaluator.hpp"
18 // Tempus
19 #include "Tempus_config.hpp"
20 #include "Tempus_SolutionStateMetaData.hpp"
21 #include "Tempus_StepperState.hpp"
22 #include "Tempus_PhysicsState.hpp"
23 
24 namespace Tempus {
25 
26 /** \brief Solution state for integrators and steppers.
27  * SolutionState contains the metadata for solutions and the solutions
28  * themselves.
29  *
30  * For simple time integration, the SolutionState is sufficient for
31  * checkpointing, restart and undo operations (i.e., it is the Memento
32  * object).
33  *
34  * For more complex time integration where the physics has additional
35  * state information or the time integrator is not a one-step method
36  * (i.e., can not accurately start from a single time step), this class
37  * can be inherited and the physics state or additional time-integration
38  * parameters can be managed.
39  *
40  * SolutionStates can be interpolated to generate solutions at various
41  * times (see SolutionHistory). However not all metadata or state
42  * information can be interpolated. Thus interpolated solutions may not
43  * be suitable for checkpointing, restart and undo operations, but may
44  * be useful for adjoint sensitivities.
45  *
46  * The solution vectors, \f$x\f$, \f$\dot{x}\f$, and \f$\ddot{x}\f$, in
47  * SolutionState can be null pointers. This indicates that the
48  * application does not need them, so do not storage them. This can be
49  * a huge savings when saving many states in the solution history.
50  * Some Steppers will need temporary memory to store time derivative(s)
51  * (\f$\dot{x}\f$, or \f$\ddot{x}\f$) for evaluation of the ODE/DAE
52  * (\f$f(x, \dot{x}, \ddot{x},t)\f$), but each individual Stepper will
53  * manage that.
54  */
55 template<class Scalar>
57  public Teuchos::Describable,
58  public Teuchos::VerboseObject<Tempus::SolutionState<Scalar> >
59 {
60 public:
61 
62  /** \brief Default Constructor -- Not meant for immediate adding to SolutionHistory.
63  * This constructor does not set the solution vectors, x, xdot and xdotdot.
64  * which should be set via setX(), setXDot(), and/or setXDotDot() prior
65  * to being added to SolutionHistory.
66  */
67  SolutionState();
68 
70  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
71  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot = Teuchos::null,
72  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xddot = Teuchos::null,
73  const Teuchos::RCP<StepperState<Scalar> >& stepperState = Teuchos::null,
74  const Teuchos::RCP<PhysicsState<Scalar> >& physicsState = Teuchos::null);
75 
77  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& x,
78  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdot = Teuchos::null,
79  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xddot= Teuchos::null,
80  const Teuchos::RCP<const StepperState<Scalar> >& stepperSt = Teuchos::null,
81  const Teuchos::RCP<const PhysicsState<Scalar> >& physicsSt = Teuchos::null);
82 
84  const Teuchos::RCP<SolutionStateMetaData<Scalar> > ssmd,
85  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
86  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot,
87  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdotdot,
88  const Teuchos::RCP<StepperState<Scalar> >& stepperState,
89  const Teuchos::RCP<PhysicsState<Scalar> >& physicsState = Teuchos::null);
90 
92  const Teuchos::RCP<const SolutionStateMetaData<Scalar> > ssmd,
93  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& x,
94  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdot,
95  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdotdot,
96  const Teuchos::RCP<const StepperState<Scalar> >& stepperState,
97  const Teuchos::RCP<const PhysicsState<Scalar> >& physicsState = Teuchos::null);
98 
100  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
101  const Teuchos::RCP<StepperState<Scalar> >& stepperState = Teuchos::null,
102  const Teuchos::RCP<PhysicsState<Scalar> >& physicsState = Teuchos::null);
103 
104  /// This is a shallow copy constructor, use clone for a deep copy constructor
106 
107  /// This is a deep copy constructor
108  virtual Teuchos::RCP<SolutionState<Scalar> > clone() const;
109 
110  /// This is a deep copy
111  virtual void copy(const Teuchos::RCP<const SolutionState<Scalar> >& ss);
112 
113  /// Deep copy solution data, but keep metaData untouched.
114  virtual void copySolutionData(
115  const Teuchos::RCP<const SolutionState<Scalar> >& s);
116 
117  /// Destructor
118  virtual ~SolutionState() {}
119 
120  /// \name Get MetaData values
121  //@{
122  virtual Teuchos::RCP<const SolutionStateMetaData<Scalar> >
123  getMetaData() const { return metaData_; }
124  virtual Teuchos::RCP<SolutionStateMetaData<Scalar> > getMetaData()
125  { TEUCHOS_ASSERT(metaData_nc_ != Teuchos::null);
126  return metaData_nc_; }
127 
128  virtual Scalar getTime() const {return metaData_->getTime();}
129  virtual Scalar getIndex() const {return metaData_->getIStep();}
130  virtual Scalar getTimeStep() const {return metaData_->getDt();}
131  virtual Scalar getOrder() const {return metaData_->getOrder();}
132  virtual Scalar getNRunningFailures() const
133  { return metaData_->getNRunningFailures(); }
134  virtual Scalar getNConsecutiveFailures() const
135  { return metaData_->getNConsecutiveFailures(); }
136  virtual Status getSolutionStatus() const
137  { return metaData_->getSolutionStatus(); }
138  virtual bool getOutput() const {return metaData_->getOutput();}
139  virtual bool getIsSynced() const {return metaData_->getIsSynced();}
140  //@}
141 
142  /// \name Set MetaData values
143  //@{
144  virtual void setMetaData(
145  Teuchos::RCP<const SolutionStateMetaData<Scalar> > md)
146  { metaData_ = md; metaData_nc_ = Teuchos::null; }
147  virtual void setMetaData(Teuchos::RCP<SolutionStateMetaData<Scalar> > md)
148  { metaData_nc_ = md; metaData_ = metaData_nc_; }
149 
150  virtual void setTime(Scalar time) {metaData_nc_->setTime(time);}
151  virtual void setIndex(Scalar index) {metaData_nc_->setIStep(index);}
152  virtual void setTimeStep(Scalar dt) {metaData_nc_->setDt(dt);}
153  virtual void setOrder(Scalar order)
154  { TEUCHOS_ASSERT(metaData_nc_ != Teuchos::null);
155  metaData_nc_->setOrder(order); }
156  virtual void setSolutionStatus(Status s)
157  { metaData_nc_->setSolutionStatus(s); }
158 
159  virtual void setSolutionStatus(const Thyra::SolveStatus<Scalar> sStatus)
160  {
161  if (sStatus.solveStatus == Thyra::SOLVE_STATUS_CONVERGED )
162  metaData_nc_->setSolutionStatus(Status::PASSED);
163  else
164  metaData_nc_->setSolutionStatus(Status::FAILED);
165  }
166 
167  virtual void setOutput(bool output)
168  { TEUCHOS_ASSERT(metaData_nc_ != Teuchos::null);
169  metaData_nc_->setOutput(output); }
170  virtual void setIsSynced(bool isSynced)
171  { TEUCHOS_ASSERT(metaData_nc_ != Teuchos::null);
172  metaData_nc_->setIsSynced(isSynced); }
173  //@}
174 
175  /// \name Get State Data
176  //@{
177  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getX()
178  { TEUCHOS_ASSERT(x_nc_ != Teuchos::null);
179  return x_nc_; }
180  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getX() const
181  { return x_; }
182  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getXDot()
183  { return xdot_nc_; }
184  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getXDot() const
185  { return xdot_; }
186  virtual Teuchos::RCP<Thyra::VectorBase<Scalar> > getXDotDot()
187  { return xdotdot_nc_; }
188  virtual Teuchos::RCP<const Thyra::VectorBase<Scalar> > getXDotDot() const
189  { return xdotdot_; }
190 
191  virtual Teuchos::RCP<StepperState<Scalar> > getStepperState()
192  { TEUCHOS_ASSERT(stepperState_nc_ != Teuchos::null);
193  return stepperState_nc_; }
194  virtual Teuchos::RCP<const StepperState<Scalar> > getStepperState() const
195  { return stepperState_; }
196 
197  virtual Teuchos::RCP<PhysicsState<Scalar> > getPhysicsState()
198  { return physicsState_nc_; }
199  virtual Teuchos::RCP<const PhysicsState<Scalar> > getPhysicsState() const
200  { return physicsState_; }
201  //@}
202 
203  /// \name Set State Data
204  //@{
205  virtual void setX(Teuchos::RCP<Thyra::VectorBase<Scalar> > x)
206  { x_nc_ = x; x_ = x; }
207  virtual void setX(Teuchos::RCP<const Thyra::VectorBase<Scalar> > x)
208  { x_nc_ = Teuchos::null; x_ = x; }
209  virtual void setXDot(Teuchos::RCP<Thyra::VectorBase<Scalar> > xdot)
210  { xdot_nc_ = xdot; xdot_ = xdot; }
211  virtual void setXDot(Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot)
212  { xdot_nc_ = Teuchos::null; xdot_ = xdot; }
213  virtual void setXDotDot(Teuchos::RCP<Thyra::VectorBase<Scalar> > xdotdot)
214  { xdotdot_nc_ = xdotdot; xdotdot_ = xdotdot; }
215  virtual void setXDotDot(Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot)
216  { xdotdot_nc_ = Teuchos::null; xdotdot_ = xdotdot; }
217 
218  virtual void setPhysicsState(const Teuchos::RCP<PhysicsState<Scalar> >& ps)
220  //@}
221 
222 
223  /// \name Comparison methods
224  //@{
225  /// Less than comparison for sorting based on time
226  bool operator< (const SolutionState<Scalar>& ss) const;
227 
228  /// Less than comparison for sorting based on time
229  bool operator<= (const SolutionState<Scalar>& ss) const;
230 
231  /// Less than comparison for sorting based on time
232  bool operator< (const Scalar& t) const;
233 
234  /// Less than comparison for sorting based on time
235  bool operator<= (const Scalar& t) const;
236 
237  /// Less than comparison for sorting based on time
238  bool operator> (const SolutionState<Scalar>& ss) const;
239 
240  /// Less than comparison for sorting based on time
241  bool operator>= (const SolutionState<Scalar>& ss) const;
242 
243  /// Less than comparison for sorting based on time
244  bool operator> (const Scalar& t) const;
245 
246  /// Less than comparison for sorting based on time
247  bool operator>= (const Scalar& t) const;
248 
249  /// Equality comparison for matching
250  bool operator== (const SolutionState<Scalar>& ss) const;
251 
252  /// Equality comparison for matching
253  bool operator== (const Scalar& t) const;
254  //@}
255 
256  /// \name Overridden from Teuchos::Describable
257  //@{
258  virtual std::string description() const;
259  virtual void describe(Teuchos::FancyOStream &out,
260  const Teuchos::EVerbosityLevel verbLevel) const;
261  //@}
262 
263 private:
264  // Member Data
265 
266  /// Meta Data for the solution state
267  Teuchos::RCP<const SolutionStateMetaData<Scalar> > metaData_;
268  Teuchos::RCP<SolutionStateMetaData<Scalar> > metaData_nc_;
269 
270  /// Solution
271  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x_;
272  Teuchos::RCP<Thyra::VectorBase<Scalar> > x_nc_;
273 
274  /// Time derivative of the solution
275  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot_;
276  Teuchos::RCP<Thyra::VectorBase<Scalar> > xdot_nc_;
277 
278  /// Second time derivative of the solution
279  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot_;
280  Teuchos::RCP<Thyra::VectorBase<Scalar> > xdotdot_nc_;
281 
282  /// StepperState for this SolutionState
283  Teuchos::RCP<const Tempus::StepperState<Scalar> > stepperState_;
284  Teuchos::RCP<Tempus::StepperState<Scalar> > stepperState_nc_;
285 
286  /// PhysicsState for this SolutionState
287  Teuchos::RCP<const Tempus::PhysicsState<Scalar> > physicsState_;
288  Teuchos::RCP<Tempus::PhysicsState<Scalar> > physicsState_nc_;
289 
290 };
291 } // namespace Tempus
292 
293 #endif // Tempus_SolutionState_decl_hpp
virtual Scalar getOrder() const
PhysicsState is a simple class to hold information about the physics.
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXDot() const
virtual Teuchos::RCP< StepperState< Scalar > > getStepperState()
virtual Scalar getNRunningFailures() const
Teuchos::RCP< Thyra::VectorBase< Scalar > > xdot_nc_
virtual Scalar getNConsecutiveFailures() const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getXDot()
virtual void setXDot(Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdot)
Teuchos::RCP< const SolutionStateMetaData< Scalar > > metaData_
Meta Data for the solution state.
Teuchos::RCP< Tempus::PhysicsState< Scalar > > physicsState_nc_
virtual Scalar getIndex() const
Teuchos::RCP< const Tempus::StepperState< Scalar > > stepperState_
StepperState for this SolutionState.
virtual void setIsSynced(bool isSynced)
virtual void setXDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xdot)
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getX() const
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdotdot_
Second time derivative of the solution.
Teuchos::RCP< const Tempus::PhysicsState< Scalar > > physicsState_
PhysicsState for this SolutionState.
virtual Teuchos::RCP< PhysicsState< Scalar > > getPhysicsState()
Teuchos::RCP< Thyra::VectorBase< Scalar > > xdotdot_nc_
StepperState is a simple class to hold state information about the stepper.
virtual void setIndex(Scalar index)
virtual Scalar getTime() const
bool operator>(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
Status
Status for the Integrator, the Stepper and the SolutionState.
virtual void setSolutionStatus(const Thyra::SolveStatus< Scalar > sStatus)
virtual void setTimeStep(Scalar dt)
virtual void copySolutionData(const Teuchos::RCP< const SolutionState< Scalar > > &s)
Deep copy solution data, but keep metaData untouched.
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getXDotDot()
virtual void setSolutionStatus(Status s)
virtual Teuchos::RCP< const PhysicsState< Scalar > > getPhysicsState() const
SolutionState()
Default Constructor – Not meant for immediate adding to SolutionHistory. This constructor does not se...
virtual void setX(Teuchos::RCP< const Thyra::VectorBase< Scalar > > x)
virtual Teuchos::RCP< const StepperState< Scalar > > getStepperState() const
virtual bool getIsSynced() const
bool operator>=(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
virtual void setXDotDot(Teuchos::RCP< Thyra::VectorBase< Scalar > > xdotdot)
Teuchos::RCP< const Thyra::VectorBase< Scalar > > x_
Solution.
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_nc_
bool operator==(const SolutionState< Scalar > &ss) const
Equality comparison for matching.
virtual Teuchos::RCP< SolutionStateMetaData< Scalar > > getMetaData()
virtual ~SolutionState()
Destructor.
bool operator<=(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
virtual Teuchos::RCP< SolutionState< Scalar > > clone() const
This is a deep copy constructor.
virtual Teuchos::RCP< const SolutionStateMetaData< Scalar > > getMetaData() const
bool operator<(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
virtual void setX(Teuchos::RCP< Thyra::VectorBase< Scalar > > x)
virtual void setPhysicsState(const Teuchos::RCP< PhysicsState< Scalar > > &ps)
virtual void setXDotDot(Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdotdot)
virtual void setMetaData(Teuchos::RCP< SolutionStateMetaData< Scalar > > md)
virtual Status getSolutionStatus() const
virtual void setMetaData(Teuchos::RCP< const SolutionStateMetaData< Scalar > > md)
virtual void setOrder(Scalar order)
virtual Scalar getTimeStep() const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getX()
virtual void setTime(Scalar time)
Teuchos::RCP< Tempus::StepperState< Scalar > > stepperState_nc_
virtual Teuchos::RCP< const Thyra::VectorBase< Scalar > > getXDotDot() const
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdot_
Time derivative of the solution.
virtual void setOutput(bool output)
virtual std::string description() const
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Teuchos::RCP< SolutionStateMetaData< Scalar > > metaData_nc_
virtual void copy(const Teuchos::RCP< const SolutionState< Scalar > > &ss)
This is a deep copy.