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 template<
class Scalar>
47 : metaData_ (metaData),
48 metaData_nc_ (metaData),
54 xdotdot_nc_ (xdotdot),
55 stepperState_ (stepperState),
56 stepperState_nc_(stepperState),
57 physicsState_ (physicsState),
58 physicsState_nc_(physicsState)
70 template<
class Scalar>
78 : metaData_ (metaData),
79 metaData_nc_ (Teuchos::null),
81 x_nc_ (Teuchos::null),
83 xdot_nc_ (Teuchos::null),
85 xdotdot_nc_ (Teuchos::null),
86 stepperState_ (stepperState),
87 stepperState_nc_(Teuchos::null),
88 physicsState_ (physicsState),
89 physicsState_nc_(Teuchos::null)
100 template<
class Scalar>
102 :metaData_ (ss_.metaData_),
103 metaData_nc_ (ss_.metaData_nc_),
107 xdot_nc_ (ss_.xdot_nc_),
108 xdotdot_ (ss_.xdotdot_),
109 xdotdot_nc_ (ss_.xdotdot_nc_),
110 stepperState_ (ss_.stepperState_),
111 stepperState_nc_(ss_.stepperState_nc_),
112 physicsState_ (ss_.physicsState_),
113 physicsState_nc_(ss_.physicsState_nc_)
117 template<
class Scalar>
122 RCP<SolutionStateMetaData<Scalar> > metaData_out;
125 RCP<Thyra::VectorBase<Scalar> > x_out;
128 RCP<Thyra::VectorBase<Scalar> > xdot_out;
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));
147 template<
class Scalar>
151 metaData_nc_->copy(ss->metaData_);
152 this->copySolutionData(ss);
156 template<
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)
172 xdot_nc_ = Teuchos::null;
174 if (xdot_nc_ == Teuchos::null)
175 xdot_nc_ = ss->xdot_->clone_v();
177 Thyra::V_V(xdot_nc_.ptr(), *(ss->xdot_));
181 if (ss->xdotdot_ == Teuchos::null)
182 xdotdot_nc_ = Teuchos::null;
184 if (xdotdot_nc_ == Teuchos::null)
185 xdotdot_nc_ = ss->xdotdot_->clone_v();
187 Thyra::V_V(xdotdot_nc_.ptr(), *(ss->xdotdot_));
189 xdotdot_ = xdotdot_nc_;
191 if (ss->stepperState_ == Teuchos::null)
192 stepperState_nc_ = Teuchos::null;
194 if (stepperState_nc_ == Teuchos::null)
195 stepperState_nc_ = ss->stepperState_->clone();
197 stepperState_nc_->copy(ss->stepperState_);
199 stepperState_ = stepperState_nc_;
201 if (ss->physicsState_ == Teuchos::null)
202 physicsState_nc_ = Teuchos::null;
204 if (physicsState_nc_ == Teuchos::null)
205 physicsState_nc_ = ss->physicsState_->clone();
207 physicsState_nc_->copy(ss->physicsState_);
209 physicsState_ = physicsState_nc_;
212 template<
class Scalar>
215 return (this->metaData_->getTime() < ss.
metaData_->getTime());
218 template<
class Scalar>
221 return (this->metaData_->getTime() <= ss.
metaData_->getTime());
224 template<
class Scalar>
227 return (this->metaData_->getTime() < t);
230 template<
class Scalar>
233 return (this->metaData_->getTime() <= t);
236 template<
class Scalar>
239 return (this->metaData_->getTime() > ss.
metaData_->getTime());
242 template<
class Scalar>
245 return (this->metaData_->getTime() >= ss.
metaData_->getTime());
248 template<
class Scalar>
251 return (this->metaData_->getTime() > t);
254 template<
class Scalar>
257 return (this->metaData_->getTime() >= t);
260 template<
class Scalar>
263 return (this->metaData_->getTime() == ss.
metaData_->getTime());
266 template<
class Scalar>
269 return (this->metaData_->getTime() == t);
272 template<
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()
284 template<
class Scalar>
289 auto l_out = Teuchos::fancyOStream( out.
getOStream() );
291 l_out->setOutputToRootOnly(0);
293 *l_out <<
"\n--- " << this->description() <<
" ---" << std::endl;
297 metaData_->describe(*l_out,verbLevel);
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);
305 if (xdotdot_ != Teuchos::null) {
306 *l_out <<
" xdotdot = " << std::endl;
307 xdotdot_->describe(*l_out,verbLevel);
310 if (stepperState_ != Teuchos::null)
311 stepperState_->describe(*l_out,verbLevel);
312 if (physicsState_ != Teuchos::null)
313 physicsState_->describe(*l_out,verbLevel);
315 *l_out << std::string(this->description().length()+8,
'-') <<std::endl;
320 template<
class Scalar>
324 if (!getComputeNorms())
return;
326 auto x = this->getX();
327 this->setXNormL2(Thyra::norm(*x));
329 if (ssIn != Teuchos::null) {
330 auto xIn = ssIn->getX();
334 Thyra::V_VmV(dx.
ptr(), *x, *xIn);
335 Scalar dxNorm = Thyra::norm(*dx);
336 Scalar xInNorm = Thyra::norm(*xIn);
337 this->setDxNormL2Abs(dxNorm);
339 const Scalar
eps = std::numeric_limits<Scalar>::epsilon();
340 const Scalar min = std::numeric_limits<Scalar>::min();
341 if ( xInNorm < min/eps ) {
342 this->setDxNormL2Rel(std::numeric_limits<Scalar>::infinity());
345 this->setDxNormL2Rel(dxNorm/(xInNorm*(1.0 + 1.0e4*eps)));
354 template<
class Scalar>
370 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
375 template<
class Scalar>
391 metaData, x, xdot, xdotdot, stepperState, physicsState));
397 template<
class Scalar>
404 using Teuchos::rcp_const_cast;
409 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
413 model->description() <<
"does not support an x solution vector!");
423 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
426 xdot_nc = Teuchos::null;
431 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
435 xdotdot_nc = Teuchos::null;
439 if (stepperState == Teuchos::null) {
442 stepperState_nc = stepperState;
446 if (physicsState == Teuchos::null) {
449 physicsState_nc = physicsState;
453 metaData_nc, x_nc, xdot_nc, xdotdot_nc, stepperState_nc, physicsState_nc));
459 #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.