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