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>
42 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
43 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot,
44 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdotdot,
52 xdotdot_nc_ (xdotdot),
53 stepperState_ (stepperState),
54 stepperState_nc_(stepperState),
55 physicsState_ (physicsState),
56 physicsState_nc_(physicsState)
70 template<
class Scalar>
72 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& x,
73 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& xdot,
74 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& xdotdot,
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>
105 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
106 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot,
107 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdotdot,
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>
136 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& x,
137 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& xdot,
138 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& xdotdot,
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>
166 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& model,
170 typedef Thyra::ModelEvaluatorBase MEB;
171 using Teuchos::rcp_const_cast;
175 metaData_ = metaData_nc_;
177 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
179 TEUCHOS_TEST_FOR_EXCEPTION(inArgs.supports(MEB::IN_ARG_x) ==
false,
181 model->description() <<
"does not support an x solution vector!");
184 x_nc_ = rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x());
191 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
192 xdot_nc_ = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot());
195 xdot_nc_ = Teuchos::null;
200 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
202 rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_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;
250 if (!Teuchos::is_null(metaData_)) metaData_out = metaData_->clone();
252 RCP<Thyra::VectorBase<Scalar> > x_out;
253 if (!Teuchos::is_null(x_)) x_out = x_->clone_v();
255 RCP<Thyra::VectorBase<Scalar> > xdot_out;
256 if (!Teuchos::is_null(xdot_)) xdot_out = xdot_->clone_v();
258 RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
259 if (!Teuchos::is_null(xdotdot_)) xdotdot_out = xdotdot_->clone_v();
261 RCP<StepperState<Scalar> > sS_out;
262 if (!Teuchos::is_null(stepperState_)) sS_out=stepperState_->clone();
264 RCP<PhysicsState<Scalar> > pS_out;
265 if (!Teuchos::is_null(physicsState_)) pS_out=physicsState_->clone();
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>
408 Teuchos::FancyOStream &out,
409 const Teuchos::EVerbosityLevel verbLevel)
const
411 if (verbLevel == Teuchos::VERB_EXTREME) {
412 out << description() <<
"::describe:" << std::endl
413 <<
"metaData = " << std::endl;
414 metaData_->describe(out,verbLevel);
415 out <<
"x = " << std::endl;
416 x_->describe(out,verbLevel);
417 if (xdot_ != Teuchos::null) {
418 out <<
"xdot_ = " << std::endl;
419 xdot_->describe(out,verbLevel);
421 if (xdotdot_ != Teuchos::null) {
422 out <<
"xdotdot = " << std::endl;
423 xdotdot_->describe(out,verbLevel);
425 if (stepperState_ != Teuchos::null) {
426 out <<
"stepperState = " << std::endl;
427 stepperState_->describe(out,verbLevel);
429 if (physicsState_ != Teuchos::null) {
430 out <<
"physicsState = " << std::endl;
431 physicsState_->describe(out,verbLevel);
437 template<
class Scalar>
441 if (!getComputeNorms())
return;
443 auto x = this->getX();
444 this->setXNormL2(Thyra::norm(*x));
446 if (ssIn != Teuchos::null) {
447 auto xIn = ssIn->getX();
450 Teuchos::RCP<Thyra::VectorBase<Scalar> > dx = Thyra::createMember(x->space());
451 Thyra::V_VmV(dx.ptr(), *x, *xIn);
452 Scalar dxNorm = Thyra::norm(*dx);
453 Scalar xInNorm = Thyra::norm(*xIn);
454 this->setDxNormL2Abs(dxNorm);
456 const Scalar eps = std::numeric_limits<Scalar>::epsilon();
457 const Scalar min = std::numeric_limits<Scalar>::min();
458 if ( xInNorm < min/eps ) {
459 this->setDxNormL2Rel(std::numeric_limits<Scalar>::infinity());
462 this->setDxNormL2Rel(dxNorm/(xInNorm*(1.0 + 1.0e4*eps)));
471 template<
class Scalar>
473 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
474 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot,
475 const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdotdot)
477 Teuchos::RCP<SolutionStateMetaData<Scalar> >
480 Teuchos::RCP<StepperState<Scalar> >
483 Teuchos::RCP<PhysicsState<Scalar> >
487 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
492 template<
class Scalar>
494 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& x,
495 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& xdot,
496 const Teuchos::RCP<
const Thyra::VectorBase<Scalar> >& xdotdot)
498 Teuchos::RCP<const SolutionStateMetaData<Scalar> >
501 Teuchos::RCP<const StepperState<Scalar> >
504 Teuchos::RCP<const PhysicsState<Scalar> >
508 metaData, x, xdot, xdotdot, stepperState, physicsState));
514 template<
class Scalar>
516 const Teuchos::RCP<
const Thyra::ModelEvaluator<Scalar> >& model,
520 typedef Thyra::ModelEvaluatorBase MEB;
521 using Teuchos::rcp_const_cast;
526 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
528 TEUCHOS_TEST_FOR_EXCEPTION(inArgs.supports(MEB::IN_ARG_x) ==
false,
530 model->description() <<
"does not support an x solution vector!");
533 auto x_nc = rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x());
539 Teuchos::RCP<Thyra::VectorBase<Scalar> > xdot_nc;
540 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
541 xdot_nc = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot());
543 xdot_nc = Teuchos::null;
547 Teuchos::RCP<Thyra::VectorBase<Scalar> > xdotdot_nc;
548 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
550 rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x_dot_dot());
552 xdotdot_nc = Teuchos::null;
555 Teuchos::RCP<StepperState<Scalar> > stepperState_nc;
556 if (stepperState == Teuchos::null) {
559 stepperState_nc = stepperState;
562 Teuchos::RCP<PhysicsState<Scalar> > physicsState_nc;
563 if (physicsState == Teuchos::null) {
566 physicsState_nc = physicsState;
570 metaData_nc, x_nc, xdot_nc, xdotdot_nc, stepperState_nc, physicsState_nc));
576 #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.
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.
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.