10#ifndef Tempus_SolutionState_impl_hpp
11#define Tempus_SolutionState_impl_hpp
13#include "Thyra_VectorStdOps.hpp"
17template <
class Scalar>
26 stepperState_nc_(
Teuchos::null),
38template <
class Scalar>
46 : metaData_(metaData),
47 metaData_nc_(metaData),
54 stepperState_(stepperState),
55 stepperState_nc_(stepperState),
56 physicsState_(physicsState),
57 physicsState_nc_(physicsState)
69template <
class Scalar>
77 : metaData_(metaData),
85 stepperState_(stepperState),
86 stepperState_nc_(
Teuchos::null),
87 physicsState_(physicsState),
98template <
class Scalar>
100 : metaData_(ss_.metaData_),
101 metaData_nc_(ss_.metaData_nc_),
105 xdot_nc_(ss_.xdot_nc_),
106 xdotdot_(ss_.xdotdot_),
107 xdotdot_nc_(ss_.xdotdot_nc_),
108 stepperState_(ss_.stepperState_),
109 stepperState_nc_(ss_.stepperState_nc_),
110 physicsState_(ss_.physicsState_),
111 physicsState_nc_(ss_.physicsState_nc_)
115template <
class Scalar>
120 RCP<SolutionStateMetaData<Scalar> > metaData_out;
121 if (!Teuchos::is_null(metaData_)) metaData_out = metaData_->clone();
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;
130 if (!Teuchos::is_null(xdotdot_)) xdotdot_out = xdotdot_->clone_v();
132 RCP<StepperState<Scalar> > sS_out;
133 if (!Teuchos::is_null(stepperState_)) sS_out = stepperState_->clone();
135 RCP<PhysicsState<Scalar> > pS_out;
136 if (!Teuchos::is_null(physicsState_)) pS_out = physicsState_->clone();
139 metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
144template <
class Scalar>
148 metaData_nc_->copy(ss->metaData_);
149 this->copySolutionData(ss);
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)
168 xdot_nc_ = Teuchos::null;
170 if (xdot_nc_ == Teuchos::null)
171 xdot_nc_ = ss->xdot_->clone_v();
173 Thyra::V_V(xdot_nc_.ptr(), *(ss->xdot_));
177 if (ss->xdotdot_ == Teuchos::null)
178 xdotdot_nc_ = Teuchos::null;
180 if (xdotdot_nc_ == Teuchos::null)
181 xdotdot_nc_ = ss->xdotdot_->clone_v();
183 Thyra::V_V(xdotdot_nc_.ptr(), *(ss->xdotdot_));
185 xdotdot_ = xdotdot_nc_;
187 if (ss->stepperState_ == Teuchos::null)
188 stepperState_nc_ = Teuchos::null;
190 if (stepperState_nc_ == Teuchos::null)
191 stepperState_nc_ = ss->stepperState_->clone();
193 stepperState_nc_->copy(ss->stepperState_);
195 stepperState_ = stepperState_nc_;
197 if (ss->physicsState_ == Teuchos::null)
198 physicsState_nc_ = Teuchos::null;
200 if (physicsState_nc_ == Teuchos::null)
201 physicsState_nc_ = ss->physicsState_->clone();
203 physicsState_nc_->copy(ss->physicsState_);
205 physicsState_ = physicsState_nc_;
208template <
class Scalar>
211 return (this->metaData_->getTime() < ss.
metaData_->getTime());
214template <
class Scalar>
217 return (this->metaData_->getTime() <= ss.
metaData_->getTime());
220template <
class Scalar>
223 return (this->metaData_->getTime() < t);
226template <
class Scalar>
229 return (this->metaData_->getTime() <= t);
232template <
class Scalar>
235 return (this->metaData_->getTime() > ss.
metaData_->getTime());
238template <
class Scalar>
241 return (this->metaData_->getTime() >= ss.
metaData_->getTime());
244template <
class Scalar>
247 return (this->metaData_->getTime() > t);
250template <
class Scalar>
253 return (this->metaData_->getTime() >= t);
256template <
class Scalar>
259 return (this->metaData_->getTime() == ss.
metaData_->getTime());
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)
276 << this->getTimeStep() <<
")";
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)) {
291 metaData_->describe(*l_out, verbLevel);
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);
299 if (xdotdot_ != Teuchos::null) {
300 *l_out <<
" xdotdot = " << std::endl;
301 xdotdot_->describe(*l_out, verbLevel);
304 if (stepperState_ != Teuchos::null)
305 stepperState_->describe(*l_out, verbLevel);
306 if (physicsState_ != Teuchos::null)
307 physicsState_->describe(*l_out, verbLevel);
309 *l_out << std::string(this->description().length() + 8,
'-') << std::endl;
313template <
class Scalar>
317 if (!getComputeNorms())
return;
319 auto x = this->getX();
320 this->setXNormL2(Thyra::norm(*x));
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);
331 this->setDxNormL2Abs(dxNorm);
333 const Scalar eps = std::numeric_limits<Scalar>::epsilon();
334 const Scalar min = std::numeric_limits<Scalar>::min();
335 if (xInNorm < min / eps) {
336 this->setDxNormL2Rel(std::numeric_limits<Scalar>::infinity());
340 this->setDxNormL2Rel(dxNorm / (xInNorm * (1.0 + 1.0e4 * 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_
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 std::string description() const
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 void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
bool operator==(const SolutionState< Scalar > &ss) const
Equality comparison for matching.
bool operator<(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
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.
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.
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.