9 #ifndef Tempus_SolutionState_impl_hpp
10 #define Tempus_SolutionState_impl_hpp
12 #include "Thyra_VectorStdOps.hpp"
16 template <
class Scalar>
21 xdot_nc_(Teuchos::null),
22 xdotdot_(Teuchos::null),
23 xdotdot_nc_(Teuchos::null),
24 stepperState_(Teuchos::null),
25 stepperState_nc_(Teuchos::null),
26 physicsState_(Teuchos::null),
27 physicsState_nc_(Teuchos::null)
37 template <
class Scalar>
45 : metaData_(metaData),
46 metaData_nc_(metaData),
53 stepperState_(stepperState),
54 stepperState_nc_(stepperState),
55 physicsState_(physicsState),
56 physicsState_nc_(physicsState)
68 template <
class Scalar>
76 : metaData_(metaData),
77 metaData_nc_(Teuchos::null),
81 xdot_nc_(Teuchos::null),
83 xdotdot_nc_(Teuchos::null),
84 stepperState_(stepperState),
85 stepperState_nc_(Teuchos::null),
86 physicsState_(physicsState),
87 physicsState_nc_(Teuchos::null)
97 template <
class Scalar>
99 : metaData_(ss_.metaData_),
100 metaData_nc_(ss_.metaData_nc_),
104 xdot_nc_(ss_.xdot_nc_),
105 xdotdot_(ss_.xdotdot_),
106 xdotdot_nc_(ss_.xdotdot_nc_),
107 stepperState_(ss_.stepperState_),
108 stepperState_nc_(ss_.stepperState_nc_),
109 physicsState_(ss_.physicsState_),
110 physicsState_nc_(ss_.physicsState_nc_)
114 template <
class Scalar>
119 RCP<SolutionStateMetaData<Scalar> > metaData_out;
122 RCP<Thyra::VectorBase<Scalar> > x_out;
125 RCP<Thyra::VectorBase<Scalar> > xdot_out;
128 RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
131 RCP<StepperState<Scalar> > sS_out;
134 RCP<PhysicsState<Scalar> > pS_out;
138 metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
143 template <
class Scalar>
147 metaData_nc_->copy(ss->metaData_);
148 this->copySolutionData(ss);
151 template <
class Scalar>
155 if (ss->x_ == Teuchos::null)
156 x_nc_ = Teuchos::null;
158 if (x_nc_ == Teuchos::null) {
159 x_nc_ = ss->x_->clone_v();
162 Thyra::V_V(x_nc_.ptr(), *(ss->x_));
166 if (ss->xdot_ == Teuchos::null)
167 xdot_nc_ = Teuchos::null;
169 if (xdot_nc_ == Teuchos::null)
170 xdot_nc_ = ss->xdot_->clone_v();
172 Thyra::V_V(xdot_nc_.ptr(), *(ss->xdot_));
176 if (ss->xdotdot_ == Teuchos::null)
177 xdotdot_nc_ = Teuchos::null;
179 if (xdotdot_nc_ == Teuchos::null)
180 xdotdot_nc_ = ss->xdotdot_->clone_v();
182 Thyra::V_V(xdotdot_nc_.ptr(), *(ss->xdotdot_));
184 xdotdot_ = xdotdot_nc_;
186 if (ss->stepperState_ == Teuchos::null)
187 stepperState_nc_ = Teuchos::null;
189 if (stepperState_nc_ == Teuchos::null)
190 stepperState_nc_ = ss->stepperState_->clone();
192 stepperState_nc_->copy(ss->stepperState_);
194 stepperState_ = stepperState_nc_;
196 if (ss->physicsState_ == Teuchos::null)
197 physicsState_nc_ = Teuchos::null;
199 if (physicsState_nc_ == Teuchos::null)
200 physicsState_nc_ = ss->physicsState_->clone();
202 physicsState_nc_->copy(ss->physicsState_);
204 physicsState_ = physicsState_nc_;
207 template <
class Scalar>
210 return (this->metaData_->getTime() < ss.
metaData_->getTime());
213 template <
class Scalar>
216 return (this->metaData_->getTime() <= ss.
metaData_->getTime());
219 template <
class Scalar>
222 return (this->metaData_->getTime() < t);
225 template <
class Scalar>
228 return (this->metaData_->getTime() <= t);
231 template <
class Scalar>
234 return (this->metaData_->getTime() > ss.
metaData_->getTime());
237 template <
class Scalar>
240 return (this->metaData_->getTime() >= ss.
metaData_->getTime());
243 template <
class Scalar>
246 return (this->metaData_->getTime() > t);
249 template <
class Scalar>
252 return (this->metaData_->getTime() >= t);
255 template <
class Scalar>
258 return (this->metaData_->getTime() == ss.
metaData_->getTime());
261 template <
class Scalar>
264 return (this->metaData_->getTime() == t);
267 template <
class Scalar>
270 std::ostringstream out;
271 out <<
"SolutionState"
272 <<
" (index =" << std::setw(6) << this->getIndex()
273 <<
"; time =" << std::setw(10) << std::setprecision(3) << this->getTime()
274 <<
"; dt =" << std::setw(10) << std::setprecision(3)
275 << this->getTimeStep() <<
")";
279 template <
class Scalar>
283 auto l_out = Teuchos::fancyOStream(out.
getOStream());
285 l_out->setOutputToRootOnly(0);
287 *l_out <<
"\n--- " << this->description() <<
" ---" << std::endl;
290 metaData_->describe(*l_out, verbLevel);
291 *l_out <<
" x = " << std::endl;
292 x_->describe(*l_out, verbLevel);
294 if (xdot_ != Teuchos::null) {
295 *l_out <<
" xdot_ = " << std::endl;
296 xdot_->describe(*l_out, verbLevel);
298 if (xdotdot_ != Teuchos::null) {
299 *l_out <<
" xdotdot = " << std::endl;
300 xdotdot_->describe(*l_out, verbLevel);
303 if (stepperState_ != Teuchos::null)
304 stepperState_->describe(*l_out, verbLevel);
305 if (physicsState_ != Teuchos::null)
306 physicsState_->describe(*l_out, verbLevel);
308 *l_out << std::string(this->description().length() + 8,
'-') << std::endl;
312 template <
class Scalar>
316 if (!getComputeNorms())
return;
318 auto x = this->getX();
319 this->setXNormL2(Thyra::norm(*x));
321 if (ssIn != Teuchos::null) {
322 auto xIn = ssIn->getX();
326 Thyra::createMember(x->space());
327 Thyra::V_VmV(dx.
ptr(), *x, *xIn);
328 Scalar dxNorm = Thyra::norm(*dx);
329 Scalar xInNorm = Thyra::norm(*xIn);
330 this->setDxNormL2Abs(dxNorm);
332 const Scalar
eps = std::numeric_limits<Scalar>::epsilon();
333 const Scalar min = std::numeric_limits<Scalar>::min();
334 if (xInNorm < min / eps) {
335 this->setDxNormL2Rel(std::numeric_limits<Scalar>::infinity());
339 this->setDxNormL2Rel(dxNorm / (xInNorm * (1.0 + 1.0e4 * eps)));
347 template <
class Scalar>
363 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
368 template <
class Scalar>
384 metaData, x, xdot, xdotdot, stepperState, physicsState));
389 template <
class Scalar>
396 using Teuchos::rcp_const_cast;
401 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
404 inArgs.supports(MEB::IN_ARG_x) ==
false, std::logic_error,
405 model->description() <<
"does not support an x solution vector!");
415 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
419 xdot_nc = Teuchos::null;
424 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
429 xdotdot_nc = Teuchos::null;
433 if (stepperState == Teuchos::null) {
437 stepperState_nc = stepperState;
441 if (physicsState == Teuchos::null) {
445 physicsState_nc = physicsState;
450 stepperState_nc, physicsState_nc));
456 #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
Greater 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
Greater than or equal to 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_
RCP< std::basic_ostream< char_type, traits_type > > getOStream()
bool operator<=(const SolutionState< Scalar > &ss) const
Less than or equal to 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.
Teuchos::RCP< SolutionStateMetaData< Scalar > > metaData_nc_
virtual void copy(const Teuchos::RCP< const SolutionState< Scalar > > &ss)
This is a deep copy.