10 #ifndef Tempus_SolutionState_impl_hpp
11 #define Tempus_SolutionState_impl_hpp
13 #include "Thyra_VectorStdOps.hpp"
17 template <
class Scalar>
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)
38 template <
class Scalar>
46 : metaData_(metaData),
47 metaData_nc_(metaData),
54 stepperState_(stepperState),
55 stepperState_nc_(stepperState),
56 physicsState_(physicsState),
57 physicsState_nc_(physicsState)
69 template <
class Scalar>
77 : metaData_(metaData),
78 metaData_nc_(Teuchos::null),
82 xdot_nc_(Teuchos::null),
84 xdotdot_nc_(Teuchos::null),
85 stepperState_(stepperState),
86 stepperState_nc_(Teuchos::null),
87 physicsState_(physicsState),
88 physicsState_nc_(Teuchos::null)
98 template <
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_)
115 template <
class Scalar>
120 RCP<SolutionStateMetaData<Scalar> > metaData_out;
123 RCP<Thyra::VectorBase<Scalar> > x_out;
126 RCP<Thyra::VectorBase<Scalar> > xdot_out;
129 RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
132 RCP<StepperState<Scalar> > sS_out;
135 RCP<PhysicsState<Scalar> > pS_out;
139 metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
144 template <
class Scalar>
148 metaData_nc_->copy(ss->metaData_);
149 this->copySolutionData(ss);
152 template <
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_;
208 template <
class Scalar>
211 return (this->metaData_->getTime() < ss.
metaData_->getTime());
214 template <
class Scalar>
217 return (this->metaData_->getTime() <= ss.
metaData_->getTime());
220 template <
class Scalar>
223 return (this->metaData_->getTime() < t);
226 template <
class Scalar>
229 return (this->metaData_->getTime() <= t);
232 template <
class Scalar>
235 return (this->metaData_->getTime() > ss.
metaData_->getTime());
238 template <
class Scalar>
241 return (this->metaData_->getTime() >= ss.
metaData_->getTime());
244 template <
class Scalar>
247 return (this->metaData_->getTime() > t);
250 template <
class Scalar>
253 return (this->metaData_->getTime() >= t);
256 template <
class Scalar>
259 return (this->metaData_->getTime() == ss.
metaData_->getTime());
262 template <
class Scalar>
265 return (this->metaData_->getTime() == t);
268 template <
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() <<
")";
280 template <
class Scalar>
284 auto l_out = Teuchos::fancyOStream(out.
getOStream());
286 l_out->setOutputToRootOnly(0);
288 *l_out <<
"\n--- " << this->description() <<
" ---" << std::endl;
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;
313 template <
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();
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)));
348 template <
class Scalar>
364 metaData_nc, x, xdot, xdotdot, stepperState_nc, physicsState_nc));
369 template <
class Scalar>
385 metaData, x, xdot, xdotdot, stepperState, physicsState));
390 template <
class Scalar>
397 using Teuchos::rcp_const_cast;
402 MEB::InArgs<Scalar> inArgs = model->getNominalValues();
405 inArgs.supports(MEB::IN_ARG_x) ==
false, std::logic_error,
406 model->description() <<
"does not support an x solution vector!");
416 if (inArgs.supports(MEB::IN_ARG_x_dot)) {
420 xdot_nc = Teuchos::null;
425 if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
430 xdotdot_nc = Teuchos::null;
434 if (stepperState == Teuchos::null) {
438 stepperState_nc = stepperState;
442 if (physicsState == Teuchos::null) {
446 physicsState_nc = physicsState;
451 stepperState_nc, physicsState_nc));
457 #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.