Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_SolutionHistory_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_SolutionHistory_impl_hpp
10 #define Tempus_SolutionHistory_impl_hpp
11 
12 #include "Teuchos_StandardParameterEntryValidators.hpp"
13 #include "Teuchos_TimeMonitor.hpp"
14 
15 #include "Thyra_VectorStdOps.hpp"
16 
18 
19 
20 namespace Tempus {
21 
22 template<class Scalar>
24  : name_("Solution History"),
25  storageType_(STORAGE_TYPE_UNDO),
26  storageLimit_(2)
27 {
28  using Teuchos::RCP;
29  // Create history, a vector of solution states.
30  history_ = rcp(new std::vector<RCP<SolutionState<Scalar> > >);
32  isInitialized_ = false;
33 }
34 
35 
36 template<class Scalar>
38  std::string name,
39  Teuchos::RCP<std::vector<Teuchos::RCP<SolutionState<Scalar> > > > history,
40  Teuchos::RCP<Interpolator<Scalar> > interpolator,
41  StorageType storageType,
42  int storageLimit)
43 {
44  setName(name);
45  setHistory(history);
46  setInterpolator(interpolator);
47  setStorageType(storageType);
48  setStorageLimit(storageLimit);
49 
50  isInitialized_ = false;
51  if (getNumStates() > 0 ) isInitialized_ = true;
52 }
53 
54 
55 template<class Scalar>
57  const Teuchos::RCP<SolutionState<Scalar> >& state, bool doChecks)
58 {
59  // Check that we're not going to exceed our storage limit:
60  if (Teuchos::as<int>(history_->size()+1) > storageLimit_) {
61  switch (storageType_) {
62  case STORAGE_TYPE_INVALID: {
63  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
64  "Error - Storage type is STORAGE_TYPE_INVALID.\n");
65  break;
66  }
69  case STORAGE_TYPE_UNDO: {
70  if (state->getTime() >= history_->front()->getTime()) {
71  // Case: State is younger than the oldest state in history.
72  // Remove state from the beginning of history, then add new state.
73  history_->erase(history_->begin());
74  } else {
75  // Case: State is older than the oldest state in history.
76  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
77  Teuchos::OSTab ostab(out,1,"SolutionHistory::addState");
78  *out << "Warning, state is older than oldest state in history. "
79  << "State not added!" << std::endl;
80  return;
81  }
82  break;
83  }
85  break;
86  default:
87  TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error,
88  "Error - unknown storage type.\n");
89  }
90  }
91 
92  // Add new state in chronological order.
93  if (history_->size() == 0) {
94  history_->push_back(state);
95  } else {
96  typename std::vector<Teuchos::RCP<SolutionState<Scalar> > >::iterator
97  state_it = history_->begin();
98  bool equal = false;
99  const Scalar newTime = state->getTime();
100  for (; state_it < history_->end(); state_it++) {
101  const Scalar shTime = (*state_it)->getTime();
102  if (doChecks) {
103  const Scalar denom = std::max(std::fabs(shTime), std::fabs(newTime));
104  if ( std::fabs(newTime - shTime) < 1.0e-14*denom ) {
105  equal = true;
106  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
107  Teuchos::OSTab ostab(out,1,"SolutionHistory::addState");
108  *out << "Warning, state to be added matches state in history. "
109  << "State not added!" << std::endl;
110 
111  *out << "===============" << std::endl;
112  *out << "Added SolutionState -- ";
113  (*state_it)->describe(*out, Teuchos::VERB_MEDIUM);
114  *out << "===============" << std::endl;
115  this->describe(*out, Teuchos::VERB_MEDIUM);
116 
117  std::exit(-1);
118  break;
119  }
120  }
121  if (newTime < shTime) break;
122  }
123  if (!equal) history_->insert(state_it, state);
124  }
125 
126  TEUCHOS_TEST_FOR_EXCEPTION(getNumStates() <= 0, std::logic_error,
127  "Error - SolutionHistory::addState() Invalid history size!\n");
128 
129  return;
130 }
131 
132 
133 template<class Scalar>
135  const Teuchos::RCP<SolutionState<Scalar> >& state, const bool updateTime)
136 {
137  using Teuchos::RCP;
138 
139  auto cs = getCurrentState();
140  state->setSolutionStatus(Status::WORKING);
141  state->setIndex(cs->getIndex()+1);
142  if (updateTime) {
143  state->setTime(cs->getTime() + cs->getTimeStep());
144  state->setTimeStep(cs->getTimeStep());
145  }
146 
147  addState(state);
148  workingState_ = (*history_)[getNumStates()-1];
149 }
150 
151 template<class Scalar>
153  const Teuchos::RCP<SolutionState<Scalar> >& state)
154 {
155  if (history_->size() != 0) {
156  auto state_it = history_->rbegin();
157  for ( ; state_it < history_->rend(); state_it++) {
158  if (state->getTime() == (*state_it)->getTime()) break;
159  }
160 
161  TEUCHOS_TEST_FOR_EXCEPTION(state_it == history_->rend(), std::logic_error,
162  "Error - removeState() Could not remove state = "
163  // << state_it->describe()
164  );
165 
166  // Need to be careful when erasing a reverse iterator.
167  history_->erase(std::next(state_it).base());
168  }
169  return;
170 }
171 
172 
173 template<class Scalar>
175 {
176  Teuchos::RCP<SolutionState<Scalar> > tmpState = findState(time);
177  removeState(tmpState);
178 }
179 
180 
181 template<class Scalar>
183 SolutionHistory<Scalar>::findState(const Scalar time) const
184 {
186  !(minTime() <= time && time <= maxTime()), std::logic_error,
187  "Error - SolutionHistory::findState() Requested time out of range!\n"
188  " [Min, Max] = [" << minTime() << ", " << maxTime() << "]\n"
189  " time = "<< time <<"\n");
190 
191  // Use last step in solution history as the scale for comparing times
192  const Scalar scale =
193  history_->size() > 0 ? (*history_)[history_->size()-1]->getTime() : Scalar(1.0);
194  // Linear search
195  auto state_it = history_->begin();
196  for ( ; state_it < history_->end(); ++state_it) {
197  if (floating_compare_equals((*state_it)->getTime(),time,scale))
198  break;
199  }
200 
201  TEUCHOS_TEST_FOR_EXCEPTION(state_it == history_->end(), std::logic_error,
202  "Error - SolutionHistory::findState()!\n"
203  " Did not find a SolutionState with time = " <<time<< std::endl);
204 
205  return *state_it;
206 }
207 
208 
209 template<class Scalar>
212 {
213  Teuchos::RCP<SolutionState<Scalar> > state_out = getCurrentState()->clone();
214  interpolate<Scalar>(*interpolator_, history_, time, state_out.get());
215  return state_out;
216 }
217 
218 
219 template<class Scalar>
220 void
222  const Scalar time, SolutionState<Scalar>* state_out) const
223 {
224  interpolate<Scalar>(*interpolator_, history_, time, state_out);
225 }
226 
227 
229 template<class Scalar>
231 {
232  TEMPUS_FUNC_TIME_MONITOR("Tempus::SolutionHistory::initWorkingState()");
233  {
234  TEUCHOS_TEST_FOR_EXCEPTION(getCurrentState() == Teuchos::null,
235  std::logic_error,
236  "Error - SolutionHistory::initWorkingState()\n"
237  "Can not initialize working state without a current state!\n");
238 
239  // If workingState_ has a valid pointer, we are still working on it,
240  // i.e., step failed and trying again, so do not initialize it.
241  if (getWorkingState(false) != Teuchos::null) return;
242 
244  if (getNumStates() < storageLimit_) {
245  // Create newState which is duplicate of currentState
246  newState = getCurrentState()->clone();
247  } else {
248  // Recycle old state and copy currentState
249  newState = (*history_)[0];
250  history_->erase(history_->begin());
251  if (getNumStates() > 0) newState->copy(getCurrentState());
252  // When using the Griewank algorithm, we will want to select which
253  // older state to recycle.
254  }
255 
256  addWorkingState(newState);
257 
258  }
259  return;
260 }
261 
262 
263 template<class Scalar>
265 {
266  auto ws = getWorkingState();
267 
268  if ( ws->getSolutionStatus() == Status::PASSED ) {
269  ws->setNFailures(std::max(0,ws->getNFailures()-1));
270  ws->setNConsecutiveFailures(0);
271  ws->setSolutionStatus(Status::PASSED);
272  //ws->setIsSynced(true);
273  ws->setIsInterpolated(false);
274  workingState_ = Teuchos::null;
275  } else {
276  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
277  Teuchos::OSTab ostab(out,1,"SolutionHistory::promoteWorkingState()");
278  *out << "Warning - WorkingState is not passing, so not promoted!\n"
279  << std::endl;
280  }
281 }
282 
283 
284 template<class Scalar>
286 {
287  this->setName(sh->getName());
288 
289  this->clear();
290  auto sh_history = sh->getHistory();
291  typename std::vector<Teuchos::RCP<SolutionState<Scalar> > >::iterator
292  state_it = sh_history->begin();
293  for (; state_it < sh_history->end(); state_it++)
294  this->addState( *state_it );
295 
296  auto interpolator = Teuchos::rcp_const_cast<Interpolator<Scalar> >(sh->getInterpolator());
297  this->setInterpolator(interpolator);
298 
299  this->setStorageType(sh->getStorageType());
300  this->setStorageLimit(sh->getStorageLimit());
301 }
302 
303 
304 template<class Scalar>
306 {
307  storageLimit_ = std::max(1,storage_limit);
308 
309  if ( storageType_ == STORAGE_TYPE_INVALID ||
310  storageType_ == STORAGE_TYPE_KEEP_NEWEST ) {
311  if (storage_limit != 1) {
312  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
313  Teuchos::OSTab ostab(out,1,"SolutionHistory::setStorageLimit");
314  *out << "Warning - 'Storage Limit' for 'Keep Newest' is 1.\n"
315  << " (Storage Limit = "<<storage_limit<<"). Resetting to 1."
316  << std::endl;
317  storageLimit_ = 1;
318  }
319  } else if ( storageType_ == STORAGE_TYPE_UNDO ) {
320  if (storage_limit != 2) {
321  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
322  Teuchos::OSTab ostab(out,1,"SolutionHistory::setStorageLimit");
323  *out << "Warning - 'Storage Limit' for 'Undo' is 2.\n"
324  << " (Storage Limit = "<<storage_limit<<"). Resetting to 2."
325  << std::endl;
326  storageLimit_ = 2;
327  }
328  } else if ( storageType_ == STORAGE_TYPE_STATIC ) {
329  storageLimit_ = storage_limit;
330  } else if ( storageType_ == STORAGE_TYPE_UNLIMITED ) {
331  storageLimit_ = std::numeric_limits<int>::max();
332  }
333 
335  (Teuchos::as<int>(history_->size()) > storageLimit_), std::logic_error,
336  "Error - requested storage limit = " << storageLimit_
337  << " is smaller than the current number of states stored = "
338  << history_->size() << "!\n");
339 
340  isInitialized_ = false;
341 }
342 
343 
344 template<class Scalar>
346 {
347  storageType_ = st;
348  if ( storageType_ == STORAGE_TYPE_KEEP_NEWEST ) setStorageLimit(1);
349  else if ( storageType_ == STORAGE_TYPE_UNDO ) setStorageLimit(2);
350  else if ( storageType_ == STORAGE_TYPE_UNLIMITED )
351  setStorageLimit(std::numeric_limits<int>::max());
352  isInitialized_ = false;
353 }
354 
355 
356 template<class Scalar>
358 {
359  if ( s == "Keep Newest" ) { // Keep the single newest state
360  storageType_ = STORAGE_TYPE_KEEP_NEWEST;
361  storageLimit_ = 1;
362  } else if ( s == "Undo" ) { // Keep the 2 newest states for undo
363  storageType_ = STORAGE_TYPE_UNDO;
364  storageLimit_ = 2;
365  } else if ( s == "Static" ) { // Keep a fix number of states
366  storageType_ = STORAGE_TYPE_STATIC;
367  } else if ( s == "Unlimited" ) { // Grow the history as needed
368  storageType_ = STORAGE_TYPE_UNLIMITED;
369  } else {
370  TEUCHOS_TEST_FOR_EXCEPTION( true, std::logic_error,
371  "Error - Unknown 'Storage Type' = '" << s << "'\n");
372  }
373  isInitialized_ = false;
374 }
375 
376 
377 template<class Scalar>
379 {
380  std::string s = "Invalid";
381  if ( storageType_ == STORAGE_TYPE_KEEP_NEWEST ) s = "Keep Newest";
382  else if ( storageType_ == STORAGE_TYPE_UNDO ) s = "Undo";
383  else if ( storageType_ == STORAGE_TYPE_STATIC ) s = "Static";
384  else if ( storageType_ == STORAGE_TYPE_UNLIMITED ) s = "Unlimited";
385  return s;
386 }
387 
388 
389 template<class Scalar>
392 {
393  Teuchos::RCP<SolutionState<Scalar> > state = Teuchos::null;
394  const int m = history_->size();
395  if ( m < 1 ) {
396  if ( warn ) {
397  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
398  Teuchos::OSTab ostab(out,1,"SolutionHistory::getStateTimeIndexN");
399  *out << "Warning - getStateTimeIndexN() No states in SolutionHistory!"
400  << std::endl;
401  }
402  } else {
403  state = (*history_)[m-1];
404  }
405  return state;
406 }
407 
408 
409 template<class Scalar>
412 {
413  Teuchos::RCP<SolutionState<Scalar> > state = Teuchos::null;
414  const int m = history_->size();
415  if ( m < 2 ) {
416  if ( warn ) {
417  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
418  Teuchos::OSTab ostab(out,1,"SolutionHistory::getStateTimeIndexNM1");
419  *out << "Warning - getStateTimeIndexNM1() Not enough states in "
420  << "SolutionHistory! Size of history = " << getNumStates()
421  << std::endl;
422  }
423  } else {
424  const int n = (*history_)[m-1]->getIndex();
425  const int nm1 = (*history_)[m-2]->getIndex();
426 
427  // No need to search SolutionHistory as states n and nm1 should be
428  // next to each other.
429  if ( nm1 != n-1 ) {
430  if ( warn ) {
431  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
432  Teuchos::OSTab ostab(out,1,"SolutionHistory::getStateTimeIndexNM1");
433  *out << "Warning - getStateTimeIndexNM1() Timestep index n-1 is not in "
434  << "SolutionHistory!\n"
435  << " (n)th index = " << n << "\n"
436  << " (n-1)th index = " << nm1 << std::endl;
437  }
438  } else {
439  state = (*history_)[m-2];
440  }
441  }
442 
443  return state;
444 }
445 
446 
447 template<class Scalar>
450 {
451  Teuchos::RCP<SolutionState<Scalar> > state = Teuchos::null;
452  const int m = history_->size();
453  if ( m < 3 ) {
454  if ( warn ) {
455  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
456  Teuchos::OSTab ostab(out,1,"SolutionHistory::getStateTimeIndexNM2");
457  *out << "Warning - getStateTimeIndexNM2() Not enough states in "
458  << "SolutionHistory! Size of history = " << getNumStates()
459  << std::endl;
460  }
461  } else {
462  const int n = (*history_)[m-1]->getIndex();
463  const int nm2 = (*history_)[m-3]->getIndex();
464 
465  // Assume states n and nm2 are one away from each other.
466  if ( nm2 != n-2 ) {
467  // Check if it is at nm1
468  const int nm1 = (*history_)[m-2]->getIndex();
469  if ( nm1 == n-2 ) {
470  state = (*history_)[m-2];
471  } else if ( warn ) {
472  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
473  Teuchos::OSTab ostab(out,1,"SolutionHistory::getStateTimeIndexNM2");
474  *out << "Warning - getStateTimeIndexNM2() Timestep index n-2 is not in "
475  << "SolutionHistory!\n"
476  << " (n)th index = " << n << "\n"
477  << " (n-2)th index = " << nm2 << std::endl;
478  }
479  } else {
480  state = (*history_)[m-3];
481  }
482  }
483 
484  return state;
485 }
486 
487 
488 template<class Scalar>
491 {
492  typename std::vector<Teuchos::RCP<SolutionState<Scalar> > >::iterator
493  state_it = history_->begin();
494  for (; state_it < history_->end(); state_it++) {
495  if ((*state_it)->getIndex() == index) break;
496  }
497 
498  Teuchos::RCP<SolutionState<Scalar> > state = Teuchos::null;
499  if ( state_it == history_->end() ) {
500  if ( warn ) {
501  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
502  Teuchos::OSTab ostab(out,1,"SolutionHistory::getStateTimeIndex");
503  *out << "Warning - getStateTimeIndex() Timestep index is not in "
504  << "SolutionHistory!\n"
505  << " index = " << index << std::endl;
506  }
507  } else {
508  state = *state_it;
509  }
510  return state;
511 }
512 
513 
514 template<class Scalar>
516 {
517  return ("Tempus::SolutionHistory - name = '" + name_ + "'");
518 }
519 
520 
521 template<class Scalar>
524  const Teuchos::EVerbosityLevel verbLevel) const
525 {
526  if ((Teuchos::as<int>(verbLevel)==Teuchos::as<int>(Teuchos::VERB_DEFAULT)) ||
527  (Teuchos::as<int>(verbLevel)>=Teuchos::as<int>(Teuchos::VERB_LOW) ) ){
528  out << description() << std::endl;
529  //out << "interpolator = " << interpolator->description() << std::endl;
530  out << "storageLimit = " << storageLimit_ << std::endl;
531  out << "storageType = " << getStorageTypeString() << std::endl;
532  out << "number of states = " << history_->size() << std::endl;
533  out << "time range = (" << history_->front()->getTime() << ", "
534  << history_->back()->getTime() << ")"
535  << std::endl;
536  }
537 
538  if (Teuchos::as<int>(verbLevel) >= Teuchos::as<int>(Teuchos::VERB_MEDIUM)) {
539  for (int i=0; i<(int)history_->size() ; ++i) {
540  out << "SolutionState[" << i << "] -- ";
541  (*history_)[i]->describe(out, verbLevel);
542  }
543  }
544 }
545 
546 
547 template<class Scalar>
550 {
552  Teuchos::parameterList("Solution History");
553 
554  pl->setName(getName());
555 
556  pl->set("Storage Type", getStorageTypeString(),
557  "'Storage Type' sets the memory storage. "
558  "'Keep Newest' - will retain the single newest solution state. "
559  "'Undo' - will retain two solution states in order to do a single undo. "
560  "'Static' - will retain 'Storage Limit' number of solution states. "
561  "'Unlimited' - will not remove any solution states!");
562 
563  pl->set("Storage Limit", getStorageLimit(),
564  "Limit on the number of SolutionStates that SolutionHistory can have.");
565 
566  pl->set("Interpolator", *interpolator_->getNonconstParameterList());
567 
568  return pl;
569 }
570 
571 
572 template <class Scalar>
575 {
576  return Teuchos::rcp_const_cast<Teuchos::ParameterList>(getValidParameters());
577 }
578 
579 
580 template<class Scalar>
582  const Teuchos::RCP<Interpolator<Scalar> >& interpolator)
583 {
584  if (interpolator == Teuchos::null) {
586  } else {
587  interpolator_ = interpolator;
588  }
589  isInitialized_ = false;
590 }
591 
592 template<class Scalar>
595 {
596  return interpolator_;
597 }
598 
599 template<class Scalar>
602 {
603  return interpolator_;
604 }
605 
606 template<class Scalar>
609 {
610  Teuchos::RCP<Interpolator<Scalar> > old_interpolator = interpolator_;
611  interpolator_ = lagrangeInterpolator<Scalar>();
612  return old_interpolator;
613 }
614 
615 
616 template<class Scalar>
617 void SolutionHistory<Scalar>::printHistory(std::string verb) const
618 {
619  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
620  Teuchos::OSTab ostab(out,1,"SolutionHistory::printHistory");
621  *out << name_ << " (size=" << history_->size() << ")"
622  << " (w - working; c - current; i - interpolated)" << std::endl;
623  for (int i=0; i<(int)history_->size() ; ++i) {
624  auto state = (*history_)[i];
625  *out << " ";
626  if (state == getWorkingState()) *out << "w - ";
627  else if (state == getCurrentState()) *out << "c - ";
628  else if (state->getIsInterpolated() == true) *out<<"i - ";
629  else *out << " ";
630  *out << "[" << i << "] = " << state << std::endl;
631  if (verb == "medium" || verb == "high") {
632  if (state != Teuchos::null) {
633  auto x = state->getX();
634  *out << " x = " << x << std::endl
635  << " norm(x) = " << Thyra::norm(*x) << std::endl;
636  }
637  }
638  if (verb == "high") {
639  (*history_)[i]->describe(*out,this->getVerbLevel());
640  }
641  }
642 }
643 
644 
645 template<class Scalar>
647 {
648  TEUCHOS_TEST_FOR_EXCEPTION(getNumStates() <= 0, std::logic_error,
649  "Error - SolutionHistory::initialize() Invalid history size!\n");
650 
651  TEUCHOS_TEST_FOR_EXCEPTION(interpolator_ == Teuchos::null, std::logic_error,
652  "Error - SolutionHistory::initialize() Interpolator is not set!\n");
653 
654  TEUCHOS_TEST_FOR_EXCEPTION(storageLimit_ < 1, std::logic_error,
655  "Error - SolutionHistory::initialize() Storage Limit needs to a positive integer!\n"
656  << " Storage Limit = " << storageLimit_ << "\n");
657 
659  ( storageType_ == STORAGE_TYPE_INVALID ), std::logic_error,
660  "Error - SolutionHistory::initialize() Storage Type is invalid!\n");
661 
663  ( storageType_ == STORAGE_TYPE_KEEP_NEWEST && storageLimit_ != 1 ),
664  std::logic_error,
665  "Error - SolutionHistory::initialize() \n"
666  << " For Storage Type = '" << getStorageTypeString()
667  << "', Storage Limit needs to be one.\n"
668  << " Storage Limit = " << storageLimit_ << "\n");
669 
671  ( storageType_ == STORAGE_TYPE_UNDO && storageLimit_ != 2 ),
672  std::logic_error,
673  "Error - SolutionHistory::initialize() \n"
674  << " For Storage Type = '" << getStorageTypeString()
675  << "', Storage Limit needs to be two.\n"
676  << " Storage Limit = " << storageLimit_ << "\n");
677 
678  isInitialized_ = true; // Only place where this is set to true!
679 }
680 
681 
682 // Nonmember constructors.
683 // ------------------------------------------------------------------------
684 
685 template<class Scalar>
688 {
689  auto sh = rcp(new SolutionHistory<Scalar>());
690 
691  if (pl == Teuchos::null) return sh; // Return default SolutionHistory.
692 
693  pl->validateParametersAndSetDefaults(*sh->getValidParameters());
694 
695  sh->setName(pl->name());
696  sh->setStorageTypeString(pl->get("Storage Type", "Undo"));
697  sh->setStorageLimit(pl->get("Storage Limit", 2));
698 
700  Teuchos::sublist(pl, "Interpolator")));
701 
702  return sh;
703 }
704 
705 
706 template<class Scalar>
709 {
710  auto sh = rcp(new SolutionHistory<Scalar>());
711  sh->setName("From createSolutionHistoryState");
712  sh->addState(state);
713  return sh;
714 }
715 
716 
717 template<class Scalar>
720  const Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> >& model)
721 {
722  // Setup initial condition SolutionState --------------------
723  auto state = createSolutionStateME(model);
724  state->setTime (0.0);
725  state->setIndex (0);
726  state->setTimeStep(0.0);
727  state->setOrder (1);
728 
729  // Setup SolutionHistory ------------------------------------
730  auto sh = rcp(new SolutionHistory<Scalar>());
731  sh->setName("From createSolutionHistoryME");
732  sh->addState(state);
733 
734  return sh;
735 }
736 
737 
738 } // namespace Tempus
739 #endif // Tempus_SolutionHistory_impl_hpp
Teuchos::RCP< Interpolator< Scalar > > unSetInterpolator()
Unset the interpolator for this history.
const std::string & name() const
Keep the 2 newest states for undo.
Teuchos::RCP< Interpolator< Scalar > > interpolator_
void initWorkingState()
Initialize the working state.
void printHistory(std::string verb="low") const
Print information on States in the SolutionHistory.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Teuchos::RCP< SolutionState< Scalar > > interpolateState(const Scalar time) const
Generate and interpolate a new solution state at requested time.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList()
Return a valid non-const ParameterList with current settings.
T * get() const
Teuchos::RCP< Interpolator< Scalar > > getNonconstInterpolator()
void setStorageLimit(int storage_limit)
Set the maximum storage of this history.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryPL(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember constructor from a ParameterList.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndex(int index, bool warn=true) const
Get the state with timestep index equal to &quot;index&quot;.
void initialize() const
Initialize SolutionHistory.
static Teuchos::RCP< Interpolator< Scalar > > createInterpolator(std::string interpolatorType="")
Create default interpolator from interpolator type (e.g., &quot;Linear&quot;).
void promoteWorkingState()
Promote the working state to current state.
void removeState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Remove solution state.
bool isInitialized_
Bool if SolutionHistory is initialized.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM1(bool warn=true) const
Get the state with timestep index equal to n-1.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Base strategy class for interpolation functionality.
virtual std::string description() const
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexN(bool warn=true) const
Get the state with timestep index equal to n.
Teuchos::RCP< SolutionState< Scalar > > getStateTimeIndexNM2(bool warn=true) const
Get the state with timestep index equal to n-2.
void addState(const Teuchos::RCP< SolutionState< Scalar > > &state, bool doChecks=true)
Add solution state to history.
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
virtual void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
std::string getStorageTypeString() const
Set the string storage type.
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.
void setStorageType(StorageType st)
Set the storage type via enum.
void addWorkingState(const Teuchos::RCP< SolutionState< Scalar > > &state, const bool updateTime=true)
Add a working solution state to history.
Keep a fix number of states.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryState(const Teuchos::RCP< SolutionState< Scalar > > &state)
Nonmember contructor from a SolutionState.
void setStorageTypeString(std::string st)
Set the storage type via string.
Teuchos::RCP< const Interpolator< Scalar > > getInterpolator() const
bool floating_compare_equals(const Scalar &a, const Scalar &b, const Scalar &scale)
Helper function for comparing times.
void setInterpolator(const Teuchos::RCP< Interpolator< Scalar > > &interpolator)
Set the interpolator for this history.
ParameterList & setName(const std::string &name)
void copy(Teuchos::RCP< const SolutionHistory< Scalar > > sh)
Make a shallow copy of SolutionHistory (i.e., only RCPs to states and interpolator).
Teuchos::RCP< SolutionState< Scalar > > findState(const Scalar time) const
Find solution state at requested time (no interpolation)
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const
Return a valid ParameterList with current settings.
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Teuchos::RCP< std::vector< Teuchos::RCP< SolutionState< Scalar > > > > history_