Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_SolutionState_impl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ****************************************************************************
3 // Tempus: Copyright (2017) Sandia Corporation
4 //
5 // Distributed under BSD 3-clause license (See accompanying file Copyright.txt)
6 // ****************************************************************************
7 // @HEADER
8 
9 #ifndef Tempus_SolutionState_impl_hpp
10 #define Tempus_SolutionState_impl_hpp
11 
12 #include "Thyra_VectorStdOps.hpp"
13 
14 namespace Tempus {
15 
16 
17 template<class Scalar>
19  : x_ (Teuchos::null),
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)
29 {
30  metaData_nc_ = Teuchos::rcp(new SolutionStateMetaData<Scalar>());
32  stepperState_nc_ = Teuchos::rcp(new StepperState<Scalar>("Default"));
34  physicsState_nc_ = Teuchos::rcp(new PhysicsState<Scalar> ());
36 }
37 
38 
39 template<class Scalar>
41  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
42  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot,
43  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdotdot,
44  const Teuchos::RCP<StepperState<Scalar> >& stepperState,
45  const Teuchos::RCP<PhysicsState<Scalar> >& physicsState)
46  : x_ (x),
47  x_nc_ (x),
48  xdot_ (xdot),
49  xdot_nc_ (xdot),
50  xdotdot_ (xdotdot),
51  xdotdot_nc_ (xdotdot),
52  stepperState_ (stepperState),
53  stepperState_nc_(stepperState),
54  physicsState_ (physicsState),
55  physicsState_nc_(physicsState)
56 {
57  metaData_nc_ = Teuchos::rcp(new SolutionStateMetaData<Scalar>());
59  if (stepperState_nc_ == Teuchos::null) {
60  stepperState_nc_ = Teuchos::rcp(new StepperState<Scalar>("Default"));
62  }
63  if (physicsState_nc_ == Teuchos::null) {
64  physicsState_nc_ = Teuchos::rcp(new PhysicsState<Scalar> ());
66  }
67 }
68 
69 template<class Scalar>
71  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& x,
72  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdot,
73  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdotdot,
74  const Teuchos::RCP<const StepperState<Scalar> >& stepperState,
75  const Teuchos::RCP<const PhysicsState<Scalar> >& physicsState)
76  : x_ (x),
77  x_nc_ (Teuchos::null),
78  xdot_ (xdot),
79  xdot_nc_ (Teuchos::null),
80  xdotdot_ (xdotdot),
81  xdotdot_nc_ (Teuchos::null),
82  stepperState_ (stepperState),
83  stepperState_nc_(Teuchos::null),
84  physicsState_ (physicsState),
85  physicsState_nc_(Teuchos::null)
86 {
87  metaData_nc_ = Teuchos::rcp(new SolutionStateMetaData<Scalar>());
89 
90  using Teuchos::rcp_const_cast;
91  if (stepperState_ == Teuchos::null) {
92  stepperState_nc_ = Teuchos::rcp(new StepperState<Scalar>("Default"));
94  } else {
96  }
97  if (physicsState_ == Teuchos::null) {
98  physicsState_nc_ = Teuchos::rcp(new PhysicsState<Scalar> ());
100  } else {
102  }
103 }
104 
105 
106 template<class Scalar>
108  const Teuchos::RCP<SolutionStateMetaData<Scalar> > metaData,
109  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& x,
110  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdot,
111  const Teuchos::RCP<Thyra::VectorBase<Scalar> >& xdotdot,
112  const Teuchos::RCP<StepperState<Scalar> >& stepperState,
113  const Teuchos::RCP<PhysicsState<Scalar> >& physicsState)
114  : metaData_ (metaData),
115  metaData_nc_ (metaData),
116  x_ (x),
117  x_nc_ (x),
118  xdot_ (xdot),
119  xdot_nc_ (xdot),
120  xdotdot_ (xdotdot),
121  xdotdot_nc_ (xdotdot),
122  stepperState_ (stepperState),
123  stepperState_nc_(stepperState),
124  physicsState_ (physicsState),
125  physicsState_nc_(physicsState)
126 {
127  if (stepperState_nc_ == Teuchos::null) {
128  stepperState_nc_ = Teuchos::rcp(new StepperState<Scalar>("Default"));
130  }
131  if (physicsState_nc_ == Teuchos::null) {
132  physicsState_nc_ = Teuchos::rcp(new PhysicsState<Scalar> ());
134  }
135 }
136 
137 template<class Scalar>
139  const Teuchos::RCP<const SolutionStateMetaData<Scalar> > metaData,
140  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& x,
141  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdot,
142  const Teuchos::RCP<const Thyra::VectorBase<Scalar> >& xdotdot,
143  const Teuchos::RCP<const StepperState<Scalar> >& stepperState,
144  const Teuchos::RCP<const PhysicsState<Scalar> >& physicsState)
145  : metaData_ (metaData),
146  metaData_nc_ (Teuchos::null),
147  x_ (x),
148  x_nc_ (Teuchos::null),
149  xdot_ (xdot),
150  xdot_nc_ (Teuchos::null),
151  xdotdot_ (xdotdot),
152  xdotdot_nc_ (Teuchos::null),
153  stepperState_ (stepperState),
154  stepperState_nc_(Teuchos::null),
155  physicsState_ (physicsState),
156  physicsState_nc_(Teuchos::null)
157 {
158  if (stepperState_ == Teuchos::null) {
159  stepperState_nc_ = Teuchos::rcp(new StepperState<Scalar>("Default"));
161  }
162  if (physicsState_ == Teuchos::null) {
163  physicsState_nc_ = Teuchos::rcp(new PhysicsState<Scalar> ());
165  }
166 }
167 
168 
169 template<class Scalar>
171  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model,
172  const Teuchos::RCP<StepperState<Scalar> >& stepperState,
173  const Teuchos::RCP<PhysicsState<Scalar> >& physicsState)
174 {
175  typedef Thyra::ModelEvaluatorBase MEB;
176  using Teuchos::rcp_const_cast;
177 
178  metaData_nc_ = Teuchos::rcp(new SolutionStateMetaData<Scalar>());
179  metaData_nc_->setSolutionStatus(Status::PASSED);
180  metaData_ = metaData_nc_;
181 
182  MEB::InArgs<Scalar> inArgs = model->getNominalValues();
183 
184  // The solution vector, x, is required (usually).
185  x_nc_ = rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x());
186  x_ = x_nc_;
187 
188  // The solution derivative, xdot, can be optional provided, based on
189  // application needs. Here we will base it on "supports" IN_ARG_x_dot.
190  // Depending on the stepper used, a temporary xdot vector may be created
191  // within the Stepper, but not moved to the SolutionState.
192  if (inArgs.supports(MEB::IN_ARG_x_dot)) {
193  xdot_nc_ = rcp_const_cast<Thyra::VectorBase<Scalar> >(inArgs.get_x_dot());
194  xdot_ = xdot_nc_;
195  } else {
196  xdot_nc_ = Teuchos::null;
197  xdot_ = xdot_nc_;
198  }
199 
200  // Similar as xdot.
201  if (inArgs.supports(MEB::IN_ARG_x_dot_dot)) {
202  xdotdot_nc_ =
203  rcp_const_cast<Thyra::VectorBase<Scalar> > (inArgs.get_x_dot_dot());
204  xdotdot_ = xdotdot_nc_;
205  } else {
206  xdotdot_nc_ = Teuchos::null;
207  xdotdot_ = xdotdot_nc_;
208  }
209 
210  if (stepperState_ == Teuchos::null) {
211  stepperState_nc_ = Teuchos::rcp(new StepperState<Scalar> ()); // Use default
212  stepperState_ = stepperState_nc_;
213  } else {
214  stepperState_nc_ = stepperState;
215  stepperState_ = stepperState;
216  }
217 
218  if (physicsState_ == Teuchos::null) {
219  physicsState_nc_ = Teuchos::rcp(new PhysicsState<Scalar> ()); // Use default
220  physicsState_ = physicsState_nc_;
221  } else {
222  physicsState_nc_ = physicsState;
223  physicsState_ = physicsState;
224  }
225 }
226 
227 template<class Scalar>
229  :metaData_ (ss_.metaData_),
230  metaData_nc_ (ss_.metaData_nc_),
231  x_ (ss_.x_),
232  x_nc_ (ss_.x_nc_),
233  xdot_ (ss_.xdot_),
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_)
241 {}
242 
243 
244 template<class Scalar>
245 Teuchos::RCP<SolutionState<Scalar> > SolutionState<Scalar>::clone() const
246 {
247  using Teuchos::RCP;
248 
249  RCP<SolutionStateMetaData<Scalar> > metaData_out;
250  if (!Teuchos::is_null(metaData_)) metaData_out = metaData_->clone();
251 
252  RCP<Thyra::VectorBase<Scalar> > x_out;
253  if (!Teuchos::is_null(x_)) x_out = x_->clone_v();
254 
255  RCP<Thyra::VectorBase<Scalar> > xdot_out;
256  if (!Teuchos::is_null(xdot_)) xdot_out = xdot_->clone_v();
257 
258  RCP<Thyra::VectorBase<Scalar> > xdotdot_out;
259  if (!Teuchos::is_null(xdotdot_)) xdotdot_out = xdotdot_->clone_v();
260 
261  RCP<StepperState<Scalar> > sS_out;
262  if (!Teuchos::is_null(stepperState_)) sS_out=stepperState_->clone();
263 
264  RCP<PhysicsState<Scalar> > pS_out;
265  if (!Teuchos::is_null(physicsState_)) pS_out=physicsState_->clone();
266 
267  RCP<SolutionState<Scalar> > ss_out = Teuchos::rcp(new SolutionState<Scalar> (
268  metaData_out, x_out, xdot_out, xdotdot_out, sS_out, pS_out));
269 
270  return ss_out;
271 }
272 
273 
274 template<class Scalar>
276 copy(const Teuchos::RCP<const SolutionState<Scalar> >& ss)
277 {
278  metaData_nc_->copy(ss->metaData_);
279  this->copySolutionData(ss);
280 }
281 
282 
283 template<class Scalar>
285 copySolutionData(const Teuchos::RCP<const SolutionState<Scalar> >& ss)
286 {
287  if (ss->x_ == Teuchos::null)
288  x_nc_ = Teuchos::null;
289  else {
290  if (x_nc_ == Teuchos::null) {
291  x_nc_ = ss->x_->clone_v();
292  }
293  else
294  Thyra::V_V(x_nc_.ptr(), *(ss->x_));
295  }
296  x_ = x_nc_;
297 
298  if (ss->xdot_ == Teuchos::null)
299  xdot_nc_ = Teuchos::null;
300  else {
301  if (xdot_nc_ == Teuchos::null)
302  xdot_nc_ = ss->xdot_->clone_v();
303  else
304  Thyra::V_V(xdot_nc_.ptr(), *(ss->xdot_));
305  }
306  xdot_ = xdot_nc_;
307 
308  if (ss->xdotdot_ == Teuchos::null)
309  xdotdot_nc_ = Teuchos::null;
310  else {
311  if (xdotdot_nc_ == Teuchos::null)
312  xdotdot_nc_ = ss->xdotdot_->clone_v();
313  else
314  Thyra::V_V(xdotdot_nc_.ptr(), *(ss->xdotdot_));
315  }
316  xdotdot_ = xdotdot_nc_;
317 
318  stepperState_nc_->copy(ss->stepperState_);
319  physicsState_nc_->copy(ss->physicsState_);
320 }
321 
322 template<class Scalar>
324 {
325  return (this->metaData_->getTime() < ss.metaData_->getTime());
326 }
327 
328 template<class Scalar>
330 {
331  return (this->metaData_->getTime() <= ss.metaData_->getTime());
332 }
333 
334 template<class Scalar>
335 bool SolutionState<Scalar>::operator< (const Scalar& t) const
336 {
337  return (this->metaData_->getTime() < t);
338 }
339 
340 template<class Scalar>
341 bool SolutionState<Scalar>::operator<= (const Scalar& t) const
342 {
343  return (this->metaData_->getTime() <= t);
344 }
345 
346 template<class Scalar>
348 {
349  return (this->metaData_->getTime() > ss.metaData_->getTime());
350 }
351 
352 template<class Scalar>
354 {
355  return (this->metaData_->getTime() >= ss.metaData_->getTime());
356 }
357 
358 template<class Scalar>
359 bool SolutionState<Scalar>::operator> (const Scalar& t) const
360 {
361  return (this->metaData_->getTime() > t);
362 }
363 
364 template<class Scalar>
365 bool SolutionState<Scalar>::operator>= (const Scalar& t) const
366 {
367  return (this->metaData_->getTime() >= t);
368 }
369 
370 template<class Scalar>
372 {
373  return (this->metaData_->getTime() == ss.metaData_->getTime());
374 }
375 
376 template<class Scalar>
377 bool SolutionState<Scalar>::operator== (const Scalar& t) const
378 {
379  return (this->metaData_->getTime() == t);
380 }
381 
382 template<class Scalar>
384 {
385  std::string name = "Tempus::SolutionState";
386  return (name);
387 }
388 
389 template<class Scalar>
391  Teuchos::FancyOStream &out,
392  const Teuchos::EVerbosityLevel verbLevel) const
393 {
394  if (verbLevel == Teuchos::VERB_EXTREME) {
395  out << description() << "::describe:" << std::endl
396  << "metaData = " << std::endl;
397  metaData_->describe(out,verbLevel);
398  out << "x = " << std::endl;
399  x_->describe(out,verbLevel);
400  if (xdot_ != Teuchos::null) {
401  out << "xdot_ = " << std::endl;
402  xdot_->describe(out,verbLevel);
403  }
404  if (xdotdot_ != Teuchos::null) {
405  out << "xdotdot = " << std::endl;
406  xdotdot_->describe(out,verbLevel);
407  }
408  if (stepperState_ != Teuchos::null) {
409  out << "stepperState = " << std::endl;
410  stepperState_->describe(out,verbLevel);
411  }
412  if (physicsState_ != Teuchos::null) {
413  out << "stepperState = " << std::endl;
414  physicsState_->describe(out,verbLevel);
415  }
416  }
417 }
418 
419 } // namespace Tempus
420 #endif // Tempus_SolutionState_impl_hpp
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< Tempus::PhysicsState< Scalar > > physicsState_nc_
Teuchos::RCP< const Tempus::StepperState< Scalar > > stepperState_
StepperState for this SolutionState.
Teuchos::RCP< const Tempus::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.
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.
bool operator==(const SolutionState< Scalar > &ss) const
Equality comparison for matching.
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.
bool operator<(const SolutionState< Scalar > &ss) const
Less than comparison for sorting based on time.
Teuchos::RCP< Tempus::StepperState< Scalar > > stepperState_nc_
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.