Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Tempus_IntegratorBasic_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_IntegratorBasic_impl_hpp
10 #define Tempus_IntegratorBasic_impl_hpp
11 
12 #include "Teuchos_VerboseObjectParameterListHelpers.hpp"
13 #include "Teuchos_TimeMonitor.hpp"
15 #include "Tempus_TimeStepControl.hpp"
16 #include <ctime>
17 
18 
19 namespace Tempus {
20 
21 template<class Scalar>
23  Teuchos::RCP<Teuchos::ParameterList> inputPL,
24  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
25  : integratorObserver_(Teuchos::null),
26  integratorStatus_(WORKING), isInitialized_(false)
27 {
28  this->setTempusParameterList(inputPL);
29  this->setStepper(model);
30  this->initialize();
31 }
32 
33 
34 template<class Scalar>
36  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
37  std::string stepperType)
38  : integratorObserver_(Teuchos::null),
39  integratorStatus_(WORKING), isInitialized_(false)
40 {
41  using Teuchos::RCP;
42  RCP<StepperFactory<Scalar> > sf = Teuchos::rcp(new StepperFactory<Scalar>());
43  RCP<Stepper<Scalar> > stepper = sf->createStepper(stepperType, model);
44 
45  this->setTempusParameterList(Teuchos::null);
46  this->setStepperWStepper(stepper);
47  this->initialize();
48 }
49 
50 
51 template<class Scalar>
53  : integratorObserver_(Teuchos::null),
54  integratorStatus_(WORKING), isInitialized_(false)
55 {
56  this->setTempusParameterList(Teuchos::null);
57 }
58 
59 
60 template<class Scalar>
62  Teuchos::RCP<Teuchos::ParameterList> inputPL,
63  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models)
64  : integratorObserver_(Teuchos::null),
65  integratorStatus_(WORKING), isInitialized_(false)
66 {
67  this->setTempusParameterList(inputPL);
68  this->setStepper(models);
69  this->initialize();
70 }
71 
72 
73 template<class Scalar>
75  Teuchos::RCP<Thyra::ModelEvaluator<Scalar> > model)
76 {
77  using Teuchos::RCP;
78  using Teuchos::ParameterList;
79 
80  if (stepper_ == Teuchos::null) {
81  // Construct from Integrator ParameterList
82  RCP<StepperFactory<Scalar> > sf =Teuchos::rcp(new StepperFactory<Scalar>());
83  std::string stepperName = integratorPL_->get<std::string>("Stepper Name");
84 
85  RCP<ParameterList> stepperPL = Teuchos::sublist(tempusPL_,stepperName,true);
86  stepper_ = sf->createStepper(stepperPL, model);
87  } else {
88  stepper_->setModel(model);
89  }
90 }
91 
92 
93 template<class Scalar>
95  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models)
96 {
97  using Teuchos::RCP;
98  using Teuchos::ParameterList;
99 
100  if (stepper_ == Teuchos::null) {
101  // Construct from Integrator ParameterList
102  RCP<StepperFactory<Scalar> > sf =Teuchos::rcp(new StepperFactory<Scalar>());
103  std::string stepperName = integratorPL_->get<std::string>("Stepper Name");
104 
105  RCP<ParameterList> stepperPL = Teuchos::sublist(tempusPL_,stepperName,true);
106  stepper_ = sf->createStepper(stepperPL, models);
107  } else {
108  stepper_->createSubSteppers(models);
109  }
110 }
111 
112 
113 template<class Scalar>
115  Teuchos::RCP<Stepper<Scalar> > newStepper)
116 {
117  using Teuchos::RCP;
118  using Teuchos::ParameterList;
119 
120  // Make integratorPL_ consistent with new stepper.
121  RCP<ParameterList> newStepperPL = newStepper->getNonconstParameterList();
122  integratorPL_->set("Stepper Name", newStepperPL->name());
123  tempusPL_->set(newStepperPL->name(), *newStepperPL);
124  stepper_ = newStepper;
125 }
126 
127 /// This resets the SolutionHistory and sets the first SolutionState as the IC.
128 template<class Scalar>
131 {
132  using Teuchos::RCP;
133  using Teuchos::ParameterList;
134 
135  // Construct from Integrator ParameterList
136  RCP<ParameterList> shPL =
137  Teuchos::sublist(integratorPL_, "Solution History", true);
138  solutionHistory_ = rcp(new SolutionHistory<Scalar>(shPL));
139 
140  if (state == Teuchos::null) {
141  // Construct default IC from the application model
142  RCP<SolutionState<Scalar> > newState = rcp(new SolutionState<Scalar>(
143  stepper_->getModel(), stepper_->getDefaultStepperState(), Teuchos::null));
144 
145  // Set SolutionState MetaData from TimeStepControl
146  newState->setTime (timeStepControl_->getInitTime());
147  newState->setIndex (timeStepControl_->getInitIndex());
148  newState->setTimeStep(timeStepControl_->getInitTimeStep());
149  newState->getMetaData()->setTolRel(timeStepControl_->getMaxRelError());
150  newState->getMetaData()->setTolAbs(timeStepControl_->getMaxAbsError());
151  int order = timeStepControl_->getInitOrder();
152  if (order == 0) order = stepper_->getOrder();
153  if (order < stepper_->getOrderMin()) order = stepper_->getOrderMin();
154  if (order > stepper_->getOrderMax()) order = stepper_->getOrderMax();
155  newState->setOrder(order);
156  newState->setSolutionStatus(Status::PASSED); // ICs are considered passing.
157 
158  solutionHistory_->addState(newState);
159 
160  } else {
161  // Use state as IC
162  solutionHistory_->addState(state);
163  }
164 
165  // Get IC from the application model via the stepper and ensure consistency.
166  stepper_->setInitialConditions(solutionHistory_);
167 }
168 
169 
170 template<class Scalar>
173  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x0,
174  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot0,
175  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot0)
176 {
177  using Teuchos::RCP;
178  using Teuchos::ParameterList;
179 
180  // Construct from Integrator ParameterList
181  RCP<ParameterList> shPL =
182  Teuchos::sublist(integratorPL_, "Solution History", true);
183  solutionHistory_ = rcp(new SolutionHistory<Scalar>(shPL));
184 
185  // Create and set xdot and xdotdot.
186  RCP<Thyra::VectorBase<Scalar> > xdot = x0->clone_v();
187  RCP<Thyra::VectorBase<Scalar> > xdotdot = x0->clone_v();
188  if (xdot0 == Teuchos::null)
189  Thyra::assign(xdot.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
190  else
191  Thyra::assign(xdot.ptr(), *(xdot0));
192  if (xdotdot0 == Teuchos::null)
193  Thyra::assign(xdotdot.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
194  else
195  Thyra::assign(xdotdot.ptr(), *(xdotdot0));
196 
197  RCP<SolutionState<Scalar> > newState = rcp(new SolutionState<Scalar>(
198  x0->clone_v(), xdot, xdotdot, stepper_->getDefaultStepperState()));
199 
200  // Set SolutionState MetaData from TimeStepControl
201  //newState->setTime (timeStepControl_->getInitTime());
202  newState->setTime (t0);
203  newState->setIndex (timeStepControl_->getInitIndex());
204  newState->setTimeStep(timeStepControl_->getInitTimeStep());
205  int order = timeStepControl_->getInitOrder();
206  if (order == 0) order = stepper_->getOrder();
207  if (order < stepper_->getOrderMin()) order = stepper_->getOrderMin();
208  if (order > stepper_->getOrderMax()) order = stepper_->getOrderMax();
209  newState->setOrder(order);
210 
211  newState->setSolutionStatus(Status::PASSED); // ICs are considered passing.
212 
213  solutionHistory_->addState(newState);
214 
215  // Get IC from the application model via the stepper and ensure consistency.
216  stepper_->setInitialConditions(solutionHistory_);
217 }
218 
219 
220 template<class Scalar>
222  Teuchos::RCP<SolutionHistory<Scalar> > sh)
223 {
224  using Teuchos::RCP;
225  using Teuchos::ParameterList;
226 
227  if (sh == Teuchos::null) {
228  // Create default SolutionHistory, otherwise keep current history.
229  if (solutionHistory_ == Teuchos::null) initializeSolutionHistory();
230  } else {
231 
232  TEUCHOS_TEST_FOR_EXCEPTION( sh->getNumStates() < 1,
233  std::out_of_range,
234  "Error - setSolutionHistory requires at least one SolutionState.\n"
235  << " Supplied SolutionHistory has only " << sh->getNumStates()
236  << " SolutionStates.\n");
237 
238  // Make integratorPL_ consistent with new SolutionHistory.
239  RCP<ParameterList> shPL = sh->getNonconstParameterList();
240  integratorPL_->set("Solution History", shPL->name());
241  integratorPL_->set(shPL->name(), *shPL);
242 
243  solutionHistory_ = sh;
244  }
245 }
246 
247 
248 template<class Scalar>
250  Teuchos::RCP<TimeStepControl<Scalar> > tsc)
251 {
252  using Teuchos::RCP;
253  using Teuchos::ParameterList;
254 
255  if (tsc == Teuchos::null) {
256  // Create timeStepControl_ if null, otherwise keep current parameters.
257  if (timeStepControl_ == Teuchos::null) {
258  if (integratorPL_->isSublist("Time Step Control")) {
259  // Construct from Integrator ParameterList
260  RCP<ParameterList> tscPL =
261  Teuchos::sublist(integratorPL_,"Time Step Control",true);
262  timeStepControl_ = rcp(new TimeStepControl<Scalar>(tscPL));
263  } else {
264  // Construct default TimeStepControl
265  timeStepControl_ = rcp(new TimeStepControl<Scalar>());
266  RCP<ParameterList> tscPL = timeStepControl_->getNonconstParameterList();
267  integratorPL_->set("Time Step Control", tscPL->name());
268  integratorPL_->set(tscPL->name(), *tscPL);
269  }
270  }
271 
272  } else {
273  // Make integratorPL_ consistent with new TimeStepControl.
274  RCP<ParameterList> tscPL = tsc->getNonconstParameterList();
275  integratorPL_->set("Time Step Control", tscPL->name());
276  integratorPL_->set(tscPL->name(), *tscPL);
277  timeStepControl_ = tsc;
278  }
279 
280 }
281 
282 
283 template<class Scalar>
285  Teuchos::RCP<IntegratorObserver<Scalar> > obs)
286 {
287 
288  if (obs == Teuchos::null) {
289  // Create default IntegratorObserverBasic, otherwise keep current observer.
290  if (integratorObserver_ == Teuchos::null) {
291  integratorObserver_ =
292  Teuchos::rcp(new IntegratorObserverComposite<Scalar>);
293  // Add basic observer to output time step info
294  Teuchos::RCP<IntegratorObserverBasic<Scalar> > basicObs =
295  Teuchos::rcp(new IntegratorObserverBasic<Scalar>);
296  integratorObserver_->addObserver(basicObs);
297  }
298  } else {
299  if (integratorObserver_ == Teuchos::null) {
300  integratorObserver_ =
301  Teuchos::rcp(new IntegratorObserverComposite<Scalar>);
302  }
303  integratorObserver_->addObserver(obs);
304  }
305 
306 }
307 
308 
309 template<class Scalar>
311 {
312  TEUCHOS_TEST_FOR_EXCEPTION( stepper_ == Teuchos::null, std::logic_error,
313  "Error - Need to set the Stepper, setStepper(), before calling "
314  "IntegratorBasic::initialize()\n");
315 
316  this->setTimeStepControl();
317  this->parseScreenOutput();
318  this->setSolutionHistory();
319  this->setObserver();
320 
321  // Set initial conditions, make them consistent, and set stepper memory.
322  stepper_->setInitialConditions(solutionHistory_);
323 
324  // Ensure TimeStepControl orders match the Stepper orders.
325  if (timeStepControl_->getMinOrder() < stepper_->getOrderMin())
326  timeStepControl_->setMinOrder(stepper_->getOrderMin());
327  if (timeStepControl_->getMinOrder() > stepper_->getOrderMax())
328  timeStepControl_->setMinOrder(stepper_->getOrderMax());
329 
330  if (timeStepControl_->getMaxOrder() == 0 ||
331  timeStepControl_->getMaxOrder() > stepper_->getOrderMax())
332  timeStepControl_->setMaxOrder(stepper_->getOrderMax());
333  if (timeStepControl_->getMaxOrder() < timeStepControl_->getMinOrder())
334  timeStepControl_->setMaxOrder(timeStepControl_->getMinOrder());
335 
336  if (timeStepControl_->getInitOrder() < timeStepControl_->getMinOrder())
337  timeStepControl_->setInitOrder(timeStepControl_->getMinOrder());
338  if (timeStepControl_->getInitOrder() > timeStepControl_->getMaxOrder())
339  timeStepControl_->setInitOrder(timeStepControl_->getMaxOrder());
340 
341  TEUCHOS_TEST_FOR_EXCEPTION(
342  timeStepControl_->getMinOrder() > timeStepControl_->getMaxOrder(),
343  std::out_of_range,
344  "Error - Invalid TimeStepControl min order greater than max order.\n"
345  << " Min order = " << timeStepControl_->getMinOrder() << "\n"
346  << " Max order = " << timeStepControl_->getMaxOrder() << "\n");
347 
348  TEUCHOS_TEST_FOR_EXCEPTION(
349  timeStepControl_->getInitOrder() < timeStepControl_->getMinOrder() ||
350  timeStepControl_->getInitOrder() > timeStepControl_->getMaxOrder(),
351  std::out_of_range,
352  "Error - Initial TimeStepControl order is out of min/max range.\n"
353  << " Initial order = " << timeStepControl_->getInitOrder() << "\n"
354  << " Min order = " << timeStepControl_->getMinOrder() << "\n"
355  << " Max order = " << timeStepControl_->getMaxOrder() << "\n");
356 
357  if (integratorTimer_ == Teuchos::null)
358  integratorTimer_ = rcp(new Teuchos::Time("Integrator Timer"));
359  if (stepperTimer_ == Teuchos::null)
360  stepperTimer_ = rcp(new Teuchos::Time("Stepper Timer"));
361 
362  if (Teuchos::as<int>(this->getVerbLevel()) >=
363  Teuchos::as<int>(Teuchos::VERB_HIGH)) {
364  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
365  Teuchos::OSTab ostab(out,1,"IntegratorBasic::IntegratorBasic");
366  *out << this->description() << std::endl;
367  }
368 
369  isInitialized_ = true;
370 }
371 
372 
373 template<class Scalar>
375 {
376  std::string name = "Tempus::IntegratorBasic";
377  return(name);
378 }
379 
380 
381 template<class Scalar>
383  Teuchos::FancyOStream &out,
384  const Teuchos::EVerbosityLevel verbLevel) const
385 {
386  out << description() << "::describe" << std::endl;
387  out << "solutionHistory= " << solutionHistory_->description()<<std::endl;
388  out << "timeStepControl= " << timeStepControl_->description()<<std::endl;
389  out << "stepper = " << stepper_ ->description()<<std::endl;
390 
391  if (Teuchos::as<int>(verbLevel) >=
392  Teuchos::as<int>(Teuchos::VERB_HIGH)) {
393  out << "solutionHistory= " << std::endl;
394  solutionHistory_->describe(out,verbLevel);
395  out << "timeStepControl= " << std::endl;
396  timeStepControl_->describe(out,verbLevel);
397  out << "stepper = " << std::endl;
398  stepper_ ->describe(out,verbLevel);
399  }
400 }
401 
402 
403 template <class Scalar>
404 bool IntegratorBasic<Scalar>::advanceTime(const Scalar timeFinal)
405 {
406  if (timeStepControl_->timeInRange(timeFinal))
407  timeStepControl_->setFinalTime(timeFinal);
408  bool itgrStatus = advanceTime();
409  return itgrStatus;
410 }
411 
412 
413 template <class Scalar>
415 {
416  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
417  if (isInitialized_ == false) {
418  Teuchos::OSTab ostab(out,1,"StartIntegrator");
419  *out << "Failure - IntegratorBasic is not initialized." << std::endl;
420  integratorStatus_ = Status::FAILED;
421  return;
422  }
423  integratorTimer_->start();
424  // get optimal initial time step
425  const Scalar initDt =
426  std::min(timeStepControl_->getInitTimeStep(),
427  stepper_->getInitTimeStep(solutionHistory_));
428  // update initial time step
429  timeStepControl_->setInitTimeStep(initDt);
430  integratorStatus_ = WORKING;
431 }
432 
433 
434 template <class Scalar>
436 {
437  TEMPUS_FUNC_TIME_MONITOR("Tempus::IntegratorBasic::advanceTime()");
438  {
439  startIntegrator();
440  integratorObserver_->observeStartIntegrator(*this);
441 
442  while (integratorStatus_ == WORKING and
443  timeStepControl_->timeInRange (solutionHistory_->getCurrentTime()) and
444  timeStepControl_->indexInRange(solutionHistory_->getCurrentIndex())){
445 
446  stepperTimer_->reset();
447  stepperTimer_->start();
448  solutionHistory_->initWorkingState();
449 
450  startTimeStep();
451  integratorObserver_->observeStartTimeStep(*this);
452 
453  timeStepControl_->getNextTimeStep(solutionHistory_, integratorStatus_);
454  integratorObserver_->observeNextTimeStep(*this);
455 
456  if (integratorStatus_ == Status::FAILED) break;
457  solutionHistory_->getWorkingState()->getMetaData()->
458  setSolutionStatus(WORKING);
459 
460  integratorObserver_->observeBeforeTakeStep(*this);
461 
462  stepper_->takeStep(solutionHistory_);
463 
464  integratorObserver_->observeAfterTakeStep(*this);
465 
466  stepperTimer_->stop();
467  checkTimeStep();
468  integratorObserver_->observeAfterCheckTimeStep(*this);
469 
470  solutionHistory_->promoteWorkingState();
471  integratorObserver_->observeEndTimeStep(*this);
472  }
473 
474  endIntegrator();
475  integratorObserver_->observeEndIntegrator(*this);
476  }
477 
478  return (integratorStatus_ == Status::PASSED);
479 }
480 
481 
482 template <class Scalar>
484 {
485  Teuchos::RCP<SolutionStateMetaData<Scalar> > wsmd =
486  solutionHistory_->getWorkingState()->getMetaData();
487 
488  //set the Abs/Rel tolerance
489  wsmd->setTolRel(timeStepControl_->getMaxRelError());
490  wsmd->setTolAbs(timeStepControl_->getMaxAbsError());
491 
492  // Check if we need to dump screen output this step
493  std::vector<int>::const_iterator it =
494  std::find(outputScreenIndices_.begin(),
495  outputScreenIndices_.end(),
496  wsmd->getIStep());
497  if (it == outputScreenIndices_.end())
498  wsmd->setOutputScreen(false);
499  else
500  wsmd->setOutputScreen(true);
501 
502  const int initial = timeStepControl_->getInitIndex();
503  const int interval = integratorPL_->get<int>("Screen Output Index Interval");
504  if ( (wsmd->getIStep() - initial) % interval == 0)
505  wsmd->setOutputScreen(true);
506 }
507 
508 
509 template <class Scalar>
511 {
512  using Teuchos::RCP;
513  RCP<SolutionStateMetaData<Scalar> > wsmd =
514  solutionHistory_->getWorkingState()->getMetaData();
515 
516  // Too many TimeStep failures, Integrator fails.
517  if (wsmd->getNFailures() >= timeStepControl_->getMaxFailures()) {
518  RCP<Teuchos::FancyOStream> out = this->getOStream();
519  Teuchos::OSTab ostab(out,2,"checkTimeStep");
520  *out << "Failure - Stepper has failed more than the maximum allowed.\n"
521  << " (nFailures = "<<wsmd->getNFailures()<< ") >= (nFailuresMax = "
522  << timeStepControl_->getMaxFailures()<<")" << std::endl;
523  integratorStatus_ = Status::FAILED;
524  return;
525  }
526  if (wsmd->getNConsecutiveFailures()
527  >= timeStepControl_->getMaxConsecFailures()){
528  RCP<Teuchos::FancyOStream> out = this->getOStream();
529  Teuchos::OSTab ostab(out,1,"checkTimeStep");
530  *out << "Failure - Stepper has failed more than the maximum "
531  << "consecutive allowed.\n"
532  << " (nConsecutiveFailures = "<<wsmd->getNConsecutiveFailures()
533  << ") >= (nConsecutiveFailuresMax = "
534  << timeStepControl_->getMaxConsecFailures()
535  << ")" << std::endl;
536  integratorStatus_ = Status::FAILED;
537  return;
538  }
539 
540  // Check Stepper failure.
541  if (wsmd->getSolutionStatus() == Status::FAILED or
542  // Constant time step failure
543  ((timeStepControl_->getStepType() == "Constant") and
544  (wsmd->getDt() != timeStepControl_->getInitTimeStep()) and
545  (wsmd->getOutput() != true) and
546  (wsmd->getTime() != timeStepControl_->getFinalTime())
547  )
548  )
549  {
550  RCP<Teuchos::FancyOStream> out = this->getOStream();
551  Teuchos::OSTab ostab(out,0,"checkTimeStep");
552  *out <<std::scientific
553  <<std::setw( 6)<<std::setprecision(3)<<wsmd->getIStep()
554  <<std::setw(11)<<std::setprecision(3)<<wsmd->getTime()
555  <<std::setw(11)<<std::setprecision(3)<<wsmd->getDt()
556  << " STEP FAILURE!! - ";
557  if (wsmd->getSolutionStatus() == Status::FAILED) {
558  *out << "Solution Status = " << toString(wsmd->getSolutionStatus())
559  << std::endl;
560  } else if ((timeStepControl_->getStepType() == "Constant") and
561  (wsmd->getDt() != timeStepControl_->getInitTimeStep())) {
562  *out << "dt != Constant dt (="<<timeStepControl_->getInitTimeStep()<<")"
563  << std::endl;
564  }
565 
566  wsmd->setNFailures(wsmd->getNFailures()+1);
567  wsmd->setNRunningFailures(wsmd->getNRunningFailures()+1);
568  wsmd->setNConsecutiveFailures(wsmd->getNConsecutiveFailures()+1);
569  wsmd->setSolutionStatus(Status::FAILED);
570  return;
571  }
572 
573  // TIME STEP PASSED basic tests! Ensure it is set as such.
574  wsmd->setSolutionStatus(Status::PASSED);
575 
576 }
577 
578 
579 template <class Scalar>
581 {
582  std::string exitStatus;
583  if (solutionHistory_->getCurrentState()->getSolutionStatus() ==
584  Status::FAILED or integratorStatus_ == Status::FAILED) {
585  exitStatus = "Time integration FAILURE!";
586  } else {
587  integratorStatus_ = Status::PASSED;
588  exitStatus = "Time integration complete.";
589  }
590 
591  integratorTimer_->stop();
592  runtime_ = integratorTimer_->totalElapsedTime();
593 }
594 
595 
596 template <class Scalar>
598 {
599  // This has been delayed until timeStepControl has been constructed.
600 
601  // Parse output indices
602  outputScreenIndices_.clear();
603  std::string str =
604  integratorPL_->get<std::string>("Screen Output Index List", "");
605  std::string delimiters(",");
606  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
607  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
608  while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
609  std::string token = str.substr(lastPos,pos-lastPos);
610  outputScreenIndices_.push_back(int(std::stoi(token)));
611  if(pos==std::string::npos)
612  break;
613 
614  lastPos = str.find_first_not_of(delimiters, pos);
615  pos = str.find_first_of(delimiters, lastPos);
616  }
617 
618  // order output indices and remove duplicates.
619  std::sort(outputScreenIndices_.begin(),outputScreenIndices_.end());
620  outputScreenIndices_.erase(std::unique(outputScreenIndices_.begin(),
621  outputScreenIndices_.end() ),
622  outputScreenIndices_.end() );
623  return;
624 }
625 
626 
627 template <class Scalar>
629  const Teuchos::RCP<Teuchos::ParameterList> & inputPL)
630 {
631  if (inputPL == Teuchos::null) {
632  if (tempusPL_->isParameter("Integrator Name")) {
633  // Set Integrator PL from Tempus PL
634  std::string integratorName_ =
635  tempusPL_->get<std::string>("Integrator Name");
636  integratorPL_ = Teuchos::sublist(tempusPL_, integratorName_, true);
637  } else {
638  // Build default Integrator PL
639  integratorPL_ = Teuchos::parameterList();
640  integratorPL_->setName("Default Integrator");
641  *integratorPL_ = *(this->getValidParameters());
642  tempusPL_->set("Integrator Name", "Default Integrator");
643  tempusPL_->set("Default Integrator", *integratorPL_);
644  }
645  } else {
646  *integratorPL_ = *inputPL;
647  tempusPL_->set("Integrator Name", integratorPL_->name());
648  tempusPL_->set(integratorPL_->name(), *integratorPL_);
649  }
650 
651  integratorPL_->validateParametersAndSetDefaults(*this->getValidParameters());
652 
653  std::string integratorType =
654  integratorPL_->get<std::string>("Integrator Type");
655  TEUCHOS_TEST_FOR_EXCEPTION( integratorType != "Integrator Basic",
656  std::logic_error,
657  "Error - Inconsistent Integrator Type for IntegratorBasic\n"
658  << " Integrator Type = " << integratorType << "\n");
659 
660  return;
661 }
662 
663 
664 /** \brief Create valid IntegratorBasic ParameterList.
665  */
666 template<class Scalar>
667 Teuchos::RCP<const Teuchos::ParameterList>
669 {
670  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
671 
672  std::ostringstream tmp;
673  tmp << "'Integrator Type' must be 'Integrator Basic'.";
674  pl->set("Integrator Type", "Integrator Basic", tmp.str());
675 
676  tmp.clear();
677  tmp << "Screen Output Index List. Required to be in TimeStepControl range "
678  << "['Minimum Time Step Index', 'Maximum Time Step Index']";
679  pl->set("Screen Output Index List", "", tmp.str());
680  pl->set("Screen Output Index Interval", 1000000,
681  "Screen Output Index Interval (e.g., every 100 time steps)");
682 
683  pl->set("Stepper Name", "",
684  "'Stepper Name' selects the Stepper block to construct (Required).");
685 
686  // Solution History
687  pl->sublist("Solution History",false,"solutionHistory_docs")
688  .disableRecursiveValidation();
689 
690  // Time Step Control
691  pl->sublist("Time Step Control",false,"solutionHistory_docs")
692  .disableRecursiveValidation();
693 
694  return pl;
695 }
696 
697 
698 template <class Scalar>
699 Teuchos::RCP<Teuchos::ParameterList>
701 {
702  return(integratorPL_);
703 }
704 
705 
706 template <class Scalar>
707 Teuchos::RCP<Teuchos::ParameterList>
709 {
710  Teuchos::RCP<Teuchos::ParameterList> temp_param_list = integratorPL_;
711  integratorPL_ = Teuchos::null;
712  return(temp_param_list);
713 }
714 
715 /// Non-member constructor
716 template<class Scalar>
717 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
718  Teuchos::RCP<Teuchos::ParameterList> pList,
719  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
720 {
721  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
722  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>(pList, model));
723  return(integrator);
724 }
725 
726 /// Non-member constructor
727 template<class Scalar>
728 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
729  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
730  std::string stepperType)
731 {
732  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
733  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>(model, stepperType));
734  return(integrator);
735 }
736 
737 /// Non-member constructor
738 template<class Scalar>
739 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic()
740 {
741  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
742  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>());
743  return(integrator);
744 }
745 
746 /// Non-member constructor
747 template<class Scalar>
748 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
749  Teuchos::RCP<Teuchos::ParameterList> pList,
750  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models)
751 {
752  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
753  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>(pList, models));
754  return(integrator);
755 }
756 
757 } // namespace Tempus
758 #endif // Tempus_IntegratorBasic_impl_hpp
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Create valid IntegratorBasic ParameterList.
const std::string toString(const Status status)
Convert Status to string.
std::string description() const override
virtual void setTimeStepControl(Teuchos::RCP< TimeStepControl< Scalar > > tsc=Teuchos::null)
Set the TimeStepControl.
virtual void setObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs=Teuchos::null)
Set the Observer.
IntegratorObserverBasic class for time integrators. This basic class has simple no-op functions...
IntegratorBasic()
Constructor that requires a subsequent setParameterList, setStepper, and initialize calls...
Thyra Base interface for time steppers.
virtual void checkTimeStep()
Check if time step has passed or failed.
Teuchos::RCP< Tempus::IntegratorBasic< Scalar > > integratorBasic(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
void parseScreenOutput()
Parse when screen output should be executed.
virtual void setSolutionHistory(Teuchos::RCP< SolutionHistory< Scalar > > sh=Teuchos::null)
Set the SolutionHistory.
IntegratorObserver class for time integrators.
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
virtual void setStepperWStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
Set the Stepper.
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
virtual void initializeSolutionHistory(Teuchos::RCP< SolutionState< Scalar > > state=Teuchos::null)
Set the initial state which has the initial conditions.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void initialize()
Initializes the Integrator after set* function calls.
virtual void endIntegrator()
Perform tasks after end of integrator.
virtual void startIntegrator()
Perform tasks before start of integrator.
virtual void startTimeStep()
Start time step.
virtual void setStepper(Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...