9#ifndef Tempus_SolutionState_impl_hpp
10#define Tempus_SolutionState_impl_hpp
12#include "Thyra_VectorStdOps.hpp"
100template<
class Scalar>
117template<
class Scalar>
122 RCP<SolutionStateMetaData<Scalar> > metaData_out;
125 RCP<Thyra::VectorBase<Scalar> > x_out;
126 if (!Teuchos::is_null(
x_)) x_out =
x_->clone_v();
128 RCP<Thyra::VectorBase<Scalar> > xdot_out;
129 if (!Teuchos::is_null(
xdot_)) xdot_out =
xdot_->clone_v();
131 RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
134 RCP<StepperState<Scalar> > sS_out;
137 RCP<PhysicsState<Scalar> > pS_out;
141 metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
147template<
class Scalar>
156template<
class Scalar>
160 if (ss->x_ == Teuchos::null)
161 x_nc_ = Teuchos::null;
163 if (
x_nc_ == Teuchos::null) {
164 x_nc_ = ss->x_->clone_v();
167 Thyra::V_V(
x_nc_.ptr(), *(ss->x_));
171 if (ss->xdot_ == Teuchos::null)
177 Thyra::V_V(
xdot_nc_.ptr(), *(ss->xdot_));
181 if (ss->xdotdot_ == Teuchos::null)
191 if (ss->stepperState_ == Teuchos::null)
201 if (ss->physicsState_ == Teuchos::null)
212template<
class Scalar>
218template<
class Scalar>
224template<
class Scalar>
230template<
class Scalar>
233 return (this->
metaData_->getTime() <= t);
236template<
class Scalar>
242template<
class Scalar>
248template<
class Scalar>
254template<
class Scalar>
257 return (this->
metaData_->getTime() >= t);
260template<
class Scalar>
266template<
class Scalar>
269 return (this->
metaData_->getTime() == t);
272template<
class Scalar>
275 std::ostringstream out;
276 out <<
"SolutionState"
277 <<
" (index =" <<std::setw(6)<< this->
getIndex()
278 <<
"; time =" <<std::setw(10)<<std::setprecision(3)<<this->
getTime()
279 <<
"; dt =" <<std::setw(10)<<std::setprecision(3)<<this->
getTimeStep()
284template<
class Scalar>
286 Teuchos::FancyOStream &out,
287 const Teuchos::EVerbosityLevel verbLevel)
const
289 auto l_out = Teuchos::fancyOStream( out.getOStream() );
290 Teuchos::OSTab ostab(*l_out, 2, this->
description());
291 l_out->setOutputToRootOnly(0);
293 *l_out <<
"\n--- " << this->
description() <<
" ---" << std::endl;
295 if (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_EXTREME)) {
298 *l_out <<
" x = " << std::endl;
299 x_->describe(*l_out,verbLevel);
301 if (
xdot_ != Teuchos::null) {
302 *l_out <<
" xdot_ = " << std::endl;
303 xdot_->describe(*l_out,verbLevel);
306 *l_out <<
" xdotdot = " << std::endl;
307 xdotdot_->describe(*l_out,verbLevel);
315 *l_out << std::string(this->
description().length()+8,
'-') <<std::endl;
320template<
class Scalar>
326 auto x = this->
getX();
329 if (ssIn != Teuchos::null) {
330 auto xIn = ssIn->getX();
333 Teuchos::RCP<Thyra::VectorBase<Scalar> > dx = Thyra::createMember(x->space());
334 Thyra::V_VmV(dx.ptr(), *x, *xIn);
335 Scalar dxNorm = Thyra::norm(*dx);
336 Scalar xInNorm = Thyra::norm(*xIn);
339 const Scalar eps = std::numeric_limits<Scalar>::epsilon();
340 const Scalar min = std::numeric_limits<Scalar>::min();
341 if ( xInNorm < min/eps ) {
354template<
class Scalar>
360 Teuchos::RCP<SolutionStateMetaData<Scalar> >
363 Teuchos::RCP<StepperState<Scalar> >
366 Teuchos::RCP<PhysicsState<Scalar> >
370 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
375template<
class Scalar>
381 Teuchos::RCP<const SolutionStateMetaData<Scalar> >
384 Teuchos::RCP<const StepperState<Scalar> >
387 Teuchos::RCP<const PhysicsState<Scalar> >
391 metaData, x, xdot, xdotdot, stepperState, physicsState));
397template<
class Scalar>
403 typedef Thyra::ModelEvaluatorBase MEB;
404 using Teuchos::rcp_const_cast;
409 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
411 TEUCHOS_TEST_FOR_EXCEPTION(inArgs.supports(MEB::IN_ARG_x) ==
false,
413 model->description() <<
"does not support an x solution vector!");
416 auto x_nc = rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x());
422 Teuchos::RCP<Thyra::VectorBase<Scalar> > xdot_nc;
423 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
424 xdot_nc = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot());
426 xdot_nc = Teuchos::null;
430 Teuchos::RCP<Thyra::VectorBase<Scalar> > xdotdot_nc;
431 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
433 rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x_dot_dot());
435 xdotdot_nc = Teuchos::null;
438 Teuchos::RCP<StepperState<Scalar> > stepperState_nc;
439 if (stepperState == Teuchos::null) {
442 stepperState_nc = stepperState;
445 Teuchos::RCP<PhysicsState<Scalar> > physicsState_nc;
446 if (physicsState == Teuchos::null) {
449 physicsState_nc = physicsState;
453 metaData_nc, x_nc, xdot_nc, xdotdot_nc, stepperState_nc, physicsState_nc));
PhysicsState is a simple class to hold information about the physics.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
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
Less than comparison for sorting based on time.
bool operator<=(const SolutionState< Scalar > &ss) const
Less than 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
Less than 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.