9 #ifndef Tempus_SolutionState_impl_hpp
10 #define Tempus_SolutionState_impl_hpp
12 #include "Thyra_VectorStdOps.hpp"
17 template<
class Scalar>
20 x_nc_ (Teuchos::null),
21 xdot_ (Teuchos::null),
22 xdot_nc_ (Teuchos::null),
23 xdotdot_ (Teuchos::null),
24 xdotdot_nc_ (Teuchos::null),
25 stepperState_ (Teuchos::null),
26 stepperState_nc_(Teuchos::null),
27 physicsState_ (Teuchos::null),
28 physicsState_nc_(Teuchos::null)
39 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
40 template<
class Scalar>
52 xdotdot_nc_ (xdotdot),
53 stepperState_ (stepperState),
54 stepperState_nc_(stepperState),
55 physicsState_ (physicsState),
56 physicsState_nc_(physicsState)
70 template<
class Scalar>
78 x_nc_ (Teuchos::null),
80 xdot_nc_ (Teuchos::null),
82 xdotdot_nc_ (Teuchos::null),
83 stepperState_ (stepperState),
84 stepperState_nc_(Teuchos::null),
85 physicsState_ (physicsState),
86 physicsState_nc_(Teuchos::null)
91 using Teuchos::rcp_const_cast;
102 template<
class Scalar>
110 : metaData_ (metaData),
111 metaData_nc_ (metaData),
117 xdotdot_nc_ (xdotdot),
118 stepperState_ (stepperState),
119 stepperState_nc_(stepperState),
120 physicsState_ (physicsState),
121 physicsState_nc_(physicsState)
133 template<
class Scalar>
141 : metaData_ (metaData),
142 metaData_nc_ (Teuchos::null),
144 x_nc_ (Teuchos::null),
146 xdot_nc_ (Teuchos::null),
148 xdotdot_nc_ (Teuchos::null),
149 stepperState_ (stepperState),
150 stepperState_nc_(Teuchos::null),
151 physicsState_ (physicsState),
152 physicsState_nc_(Teuchos::null)
163 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
164 template<
class Scalar>
171 using Teuchos::rcp_const_cast;
175 metaData_ = metaData_nc_;
177 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
181 model->description() <<
"does not support an x solution vector!");
191 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
195 xdot_nc_ = Teuchos::null;
200 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
203 xdotdot_ = xdotdot_nc_;
205 xdotdot_nc_ = Teuchos::null;
206 xdotdot_ = xdotdot_nc_;
209 if (stepperState == Teuchos::null) {
211 stepperState_ = stepperState_nc_;
213 stepperState_nc_ = stepperState;
214 stepperState_ = stepperState;
217 if (physicsState == Teuchos::null) {
219 physicsState_ = physicsState_nc_;
221 physicsState_nc_ = physicsState;
222 physicsState_ = physicsState;
227 template<
class Scalar>
229 :metaData_ (ss_.metaData_),
230 metaData_nc_ (ss_.metaData_nc_),
234 xdot_nc_ (ss_.xdot_nc_),
235 xdotdot_ (ss_.xdotdot_),
236 xdotdot_nc_ (ss_.xdotdot_nc_),
237 stepperState_ (ss_.stepperState_),
238 stepperState_nc_(ss_.stepperState_nc_),
239 physicsState_ (ss_.physicsState_),
240 physicsState_nc_(ss_.physicsState_nc_)
244 template<
class Scalar>
249 RCP<SolutionStateMetaData<Scalar> > metaData_out;
252 RCP<Thyra::VectorBase<Scalar> > x_out;
255 RCP<Thyra::VectorBase<Scalar> > xdot_out;
258 RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
261 RCP<StepperState<Scalar> > sS_out;
264 RCP<PhysicsState<Scalar> > pS_out;
268 metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
274 template<
class Scalar>
278 metaData_nc_->copy(ss->metaData_);
279 this->copySolutionData(ss);
283 template<
class Scalar>
287 if (ss->x_ == Teuchos::null)
288 x_nc_ = Teuchos::null;
290 if (x_nc_ == Teuchos::null) {
291 x_nc_ = ss->x_->clone_v();
294 Thyra::V_V(x_nc_.ptr(), *(ss->x_));
298 if (ss->xdot_ == Teuchos::null)
299 xdot_nc_ = Teuchos::null;
301 if (xdot_nc_ == Teuchos::null)
302 xdot_nc_ = ss->xdot_->clone_v();
304 Thyra::V_V(xdot_nc_.ptr(), *(ss->xdot_));
308 if (ss->xdotdot_ == Teuchos::null)
309 xdotdot_nc_ = Teuchos::null;
311 if (xdotdot_nc_ == Teuchos::null)
312 xdotdot_nc_ = ss->xdotdot_->clone_v();
314 Thyra::V_V(xdotdot_nc_.ptr(), *(ss->xdotdot_));
316 xdotdot_ = xdotdot_nc_;
318 if (ss->stepperState_ == Teuchos::null)
319 stepperState_nc_ = Teuchos::null;
321 if (stepperState_nc_ == Teuchos::null)
322 stepperState_nc_ = ss->stepperState_->clone();
324 stepperState_nc_->copy(ss->stepperState_);
326 stepperState_ = stepperState_nc_;
328 if (ss->physicsState_ == Teuchos::null)
329 physicsState_nc_ = Teuchos::null;
331 if (physicsState_nc_ == Teuchos::null)
332 physicsState_nc_ = ss->physicsState_->clone();
334 physicsState_nc_->copy(ss->physicsState_);
336 physicsState_ = physicsState_nc_;
339 template<
class Scalar>
342 return (this->metaData_->getTime() < ss.
metaData_->getTime());
345 template<
class Scalar>
348 return (this->metaData_->getTime() <= ss.
metaData_->getTime());
351 template<
class Scalar>
354 return (this->metaData_->getTime() < t);
357 template<
class Scalar>
360 return (this->metaData_->getTime() <= t);
363 template<
class Scalar>
366 return (this->metaData_->getTime() > ss.
metaData_->getTime());
369 template<
class Scalar>
372 return (this->metaData_->getTime() >= ss.
metaData_->getTime());
375 template<
class Scalar>
378 return (this->metaData_->getTime() > t);
381 template<
class Scalar>
384 return (this->metaData_->getTime() >= t);
387 template<
class Scalar>
390 return (this->metaData_->getTime() == ss.
metaData_->getTime());
393 template<
class Scalar>
396 return (this->metaData_->getTime() == t);
399 template<
class Scalar>
402 std::string name =
"Tempus::SolutionState";
406 template<
class Scalar>
412 out <<
"(index =" <<std::setw(6)<< this->getIndex()
413 <<
"; time =" <<std::setw(10)<<std::setprecision(3)<<this->getTime()
414 <<
"; dt =" <<std::setw(10)<<std::setprecision(3)<<this->getTimeStep()
419 out << description() <<
"::describe:" << std::endl
420 <<
"metaData = " << std::endl;
421 metaData_->describe(out,verbLevel);
422 out <<
"x = " << std::endl;
423 x_->describe(out,verbLevel);
424 if (xdot_ != Teuchos::null) {
425 out <<
"xdot_ = " << std::endl;
426 xdot_->describe(out,verbLevel);
428 if (xdotdot_ != Teuchos::null) {
429 out <<
"xdotdot = " << std::endl;
430 xdotdot_->describe(out,verbLevel);
432 if (stepperState_ != Teuchos::null) {
433 out <<
"stepperState = " << std::endl;
434 stepperState_->describe(out,verbLevel);
436 if (physicsState_ != Teuchos::null) {
437 out <<
"physicsState = " << std::endl;
438 physicsState_->describe(out,verbLevel);
444 template<
class Scalar>
448 if (!getComputeNorms())
return;
450 auto x = this->getX();
451 this->setXNormL2(Thyra::norm(*x));
453 if (ssIn != Teuchos::null) {
454 auto xIn = ssIn->getX();
458 Thyra::V_VmV(dx.
ptr(), *x, *xIn);
459 Scalar dxNorm = Thyra::norm(*dx);
460 Scalar xInNorm = Thyra::norm(*xIn);
461 this->setDxNormL2Abs(dxNorm);
463 const Scalar eps = std::numeric_limits<Scalar>::epsilon();
464 const Scalar min = std::numeric_limits<Scalar>::min();
465 if ( xInNorm < min/eps ) {
466 this->setDxNormL2Rel(std::numeric_limits<Scalar>::infinity());
469 this->setDxNormL2Rel(dxNorm/(xInNorm*(1.0 + 1.0e4*eps)));
478 template<
class Scalar>
494 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
499 template<
class Scalar>
515 metaData, x, xdot, xdotdot, stepperState, physicsState));
521 template<
class Scalar>
528 using Teuchos::rcp_const_cast;
533 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
537 model->description() <<
"does not support an x solution vector!");
547 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
550 xdot_nc = Teuchos::null;
555 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
559 xdotdot_nc = Teuchos::null;
563 if (stepperState == Teuchos::null) {
566 stepperState_nc = stepperState;
570 if (physicsState == Teuchos::null) {
573 physicsState_nc = physicsState;
577 metaData_nc, x_nc, xdot_nc, xdotdot_nc, stepperState_nc, physicsState_nc));
583 #endif // Tempus_SolutionState_impl_hpp
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.
PhysicsState is a simple class to hold information about the physics.
Teuchos::RCP< const SolutionStateMetaData< Scalar > > metaData_
Meta Data for the solution state.
bool is_null(const std::shared_ptr< T > &p)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< PhysicsState< Scalar > > physicsState_nc_
Teuchos::RCP< const PhysicsState< Scalar > > physicsState_
PhysicsState for this SolutionState.
StepperState is a simple class to hold state information about the stepper.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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 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
SolutionState()
Default Constructor – Not meant for immediate adding to SolutionHistory. This constructor does not se...
bool operator>=(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
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.
bool operator==(const SolutionState< Scalar > &ss) const
Equality comparison for matching.
Teuchos::RCP< StepperState< Scalar > > stepperState_nc_
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 void computeNorms(const Teuchos::RCP< const SolutionState< Scalar > > &ssIn=Teuchos::null)
Compute the solution norms, and solution change from ssIn, if provided.
bool operator<(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
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.