10#ifndef Tempus_SolutionState_impl_hpp
11#define Tempus_SolutionState_impl_hpp
13#include "Thyra_VectorStdOps.hpp"
17template <
class Scalar>
38template <
class Scalar>
69template <
class Scalar>
98template <
class Scalar>
115template <
class Scalar>
120 RCP<SolutionStateMetaData<Scalar> > metaData_out;
123 RCP<Thyra::VectorBase<Scalar> > x_out;
124 if (!Teuchos::is_null(
x_)) x_out =
x_->clone_v();
126 RCP<Thyra::VectorBase<Scalar> > xdot_out;
127 if (!Teuchos::is_null(
xdot_)) xdot_out =
xdot_->clone_v();
129 RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
132 RCP<StepperState<Scalar> > sS_out;
135 RCP<PhysicsState<Scalar> > pS_out;
139 metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
144template <
class Scalar>
152template <
class Scalar>
156 if (ss->x_ == Teuchos::null)
157 x_nc_ = Teuchos::null;
159 if (
x_nc_ == Teuchos::null) {
160 x_nc_ = ss->x_->clone_v();
163 Thyra::V_V(
x_nc_.ptr(), *(ss->x_));
167 if (ss->xdot_ == Teuchos::null)
173 Thyra::V_V(
xdot_nc_.ptr(), *(ss->xdot_));
177 if (ss->xdotdot_ == Teuchos::null)
187 if (ss->stepperState_ == Teuchos::null)
197 if (ss->physicsState_ == Teuchos::null)
208template <
class Scalar>
214template <
class Scalar>
220template <
class Scalar>
226template <
class Scalar>
229 return (this->
metaData_->getTime() <= t);
232template <
class Scalar>
238template <
class Scalar>
244template <
class Scalar>
250template <
class Scalar>
253 return (this->
metaData_->getTime() >= t);
256template <
class Scalar>
262template <
class Scalar>
265 return (this->
metaData_->getTime() == t);
268template <
class Scalar>
271 std::ostringstream out;
272 out <<
"SolutionState"
273 <<
" (index =" << std::setw(6) << this->
getIndex()
274 <<
"; time =" << std::setw(10) << std::setprecision(3) << this->
getTime()
275 <<
"; dt =" << std::setw(10) << std::setprecision(3)
280template <
class Scalar>
282 Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel)
const
284 auto l_out = Teuchos::fancyOStream(out.getOStream());
285 Teuchos::OSTab ostab(*l_out, 2, this->
description());
286 l_out->setOutputToRootOnly(0);
288 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
290 if (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_EXTREME)) {
292 *l_out <<
" x = " << std::endl;
293 x_->describe(*l_out, verbLevel);
295 if (
xdot_ != Teuchos::null) {
296 *l_out <<
" xdot_ = " << std::endl;
297 xdot_->describe(*l_out, verbLevel);
300 *l_out <<
" xdotdot = " << std::endl;
301 xdotdot_->describe(*l_out, verbLevel);
309 *l_out << std::string(this->
description().length() + 8,
'-') << std::endl;
313template <
class Scalar>
319 auto x = this->
getX();
322 if (ssIn != Teuchos::null) {
323 auto xIn = ssIn->getX();
326 Teuchos::RCP<Thyra::VectorBase<Scalar> > dx =
327 Thyra::createMember(x->space());
328 Thyra::V_VmV(dx.ptr(), *x, *xIn);
329 Scalar dxNorm = Thyra::norm(*dx);
330 Scalar xInNorm = Thyra::norm(*xIn);
333 const Scalar eps = std::numeric_limits<Scalar>::epsilon();
334 const Scalar min = std::numeric_limits<Scalar>::min();
335 if (xInNorm < min / eps) {
348template <
class Scalar>
354 Teuchos::RCP<SolutionStateMetaData<Scalar> > metaData_nc =
357 Teuchos::RCP<StepperState<Scalar> > stepperState_nc =
360 Teuchos::RCP<PhysicsState<Scalar> > physicsState_nc =
364 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
369template <
class Scalar>
375 Teuchos::RCP<const SolutionStateMetaData<Scalar> > metaData =
378 Teuchos::RCP<const StepperState<Scalar> > stepperState =
381 Teuchos::RCP<const PhysicsState<Scalar> > physicsState =
385 metaData, x, xdot, xdotdot, stepperState, physicsState));
390template <
class Scalar>
396 typedef Thyra::ModelEvaluatorBase MEB;
397 using Teuchos::rcp_const_cast;
402 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
404 TEUCHOS_TEST_FOR_EXCEPTION(
405 inArgs.supports(MEB::IN_ARG_x) ==
false, std::logic_error,
406 model->description() <<
"does not support an x solution vector!");
409 auto x_nc = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x());
415 Teuchos::RCP<Thyra::VectorBase<Scalar> > xdot_nc;
416 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
417 xdot_nc = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot());
420 xdot_nc = Teuchos::null;
424 Teuchos::RCP<Thyra::VectorBase<Scalar> > xdotdot_nc;
425 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
427 rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot_dot());
430 xdotdot_nc = Teuchos::null;
433 Teuchos::RCP<StepperState<Scalar> > stepperState_nc;
434 if (stepperState == Teuchos::null) {
438 stepperState_nc = stepperState;
441 Teuchos::RCP<PhysicsState<Scalar> > physicsState_nc;
442 if (physicsState == Teuchos::null) {
446 physicsState_nc = physicsState;
449 Teuchos::RCP<SolutionState<Scalar> > ss =
451 stepperState_nc, physicsState_nc));
PhysicsState is a simple class to hold information about the physics.
Solution state for integrators and steppers.
Teuchos::RCP< SolutionStateMetaData< Scalar > > metaData_nc_
Teuchos::RCP< Thyra::VectorBase< Scalar > > x_nc_
Teuchos::RCP< const Thyra::VectorBase< Scalar > > x_
Solution.
virtual Scalar getTimeStep() const
virtual bool getComputeNorms() const
virtual void copy(const Teuchos::RCP< const SolutionState< Scalar > > &ss)
This is a deep copy.
virtual void computeNorms(const Teuchos::RCP< const SolutionState< Scalar > > &ssIn=Teuchos::null)
Compute the solution norms, and solution change from ssIn, if provided.
Teuchos::RCP< StepperState< Scalar > > stepperState_nc_
Teuchos::RCP< const SolutionStateMetaData< Scalar > > metaData_
Meta Data for the solution state.
virtual void setXNormL2(Scalar xNormL2)
virtual std::string description() const
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdotdot_
Second time derivative of the solution.
virtual void copySolutionData(const Teuchos::RCP< const SolutionState< Scalar > > &s)
Deep copy solution data, but keep metaData untouched.
SolutionState()
Default Constructor – Not meant for immediate adding to SolutionHistory. This constructor does not se...
Teuchos::RCP< const PhysicsState< Scalar > > physicsState_
PhysicsState for this SolutionState.
virtual Scalar getTime() const
virtual Teuchos::RCP< Thyra::VectorBase< Scalar > > getX()
virtual int getIndex() const
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
bool operator==(const SolutionState< Scalar > &ss) const
Equality comparison for matching.
Teuchos::RCP< Thyra::VectorBase< Scalar > > xdotdot_nc_
bool operator<(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
virtual void setDxNormL2Rel(Scalar dxNormL2Rel)
bool operator>(const SolutionState< Scalar > &ss) const
Greater than comparison for sorting based on time.
bool operator<=(const SolutionState< Scalar > &ss) const
Less than or equal to comparison for sorting based on time.
Teuchos::RCP< const StepperState< Scalar > > stepperState_
StepperState for this SolutionState.
virtual void setDxNormL2Abs(Scalar dxNormL2Abs)
bool operator>=(const SolutionState< Scalar > &ss) const
Greater than or equal to comparison for sorting based on time.
Teuchos::RCP< PhysicsState< Scalar > > physicsState_nc_
virtual Teuchos::RCP< SolutionState< Scalar > > clone() const
This is a deep copy constructor.
Teuchos::RCP< const Thyra::VectorBase< Scalar > > xdot_
Time derivative of the solution.
Teuchos::RCP< Thyra::VectorBase< Scalar > > xdot_nc_
StepperState is a simple class to hold state information about the stepper.
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, const Teuchos::RCP< StepperState< Scalar > > &stepperState=Teuchos::null, const Teuchos::RCP< PhysicsState< Scalar > > &physicsState=Teuchos::null)
Nonmember constructor from Thyra ModelEvaluator.
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x.