Tempus  Version of the Day
Time Integration
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(model, stepperType);
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(model, stepperPL);
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(models, stepperPL);
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 
166 
167 template<class Scalar>
169 setInitialState(Scalar t0,
170  Teuchos::RCP<const Thyra::VectorBase<Scalar> > x0,
171  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdot0,
172  Teuchos::RCP<const Thyra::VectorBase<Scalar> > xdotdot0)
173 {
174  using Teuchos::RCP;
175  using Teuchos::ParameterList;
176 
177  // Construct from Integrator ParameterList
178  RCP<ParameterList> shPL =
179  Teuchos::sublist(integratorPL_, "Solution History", true);
180  solutionHistory_ = rcp(new SolutionHistory<Scalar>(shPL));
181 
182  // Create and set xdot and xdotdot.
183  RCP<Thyra::VectorBase<Scalar> > xdot = x0->clone_v();
184  RCP<Thyra::VectorBase<Scalar> > xdotdot = x0->clone_v();
185  if (xdot0 == Teuchos::null)
186  Thyra::assign(xdot.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
187  else
188  Thyra::assign(xdot.ptr(), *(xdot0));
189  if (xdotdot0 == Teuchos::null)
190  Thyra::assign(xdotdot.ptr(), Teuchos::ScalarTraits<Scalar>::zero());
191  else
192  Thyra::assign(xdotdot.ptr(), *(xdotdot0));
193 
194  RCP<SolutionState<Scalar> > newState = rcp(new SolutionState<Scalar>(
195  x0->clone_v(), xdot, xdotdot, stepper_->getDefaultStepperState()));
196 
197  // Set SolutionState MetaData from TimeStepControl
198  newState->setTime (timeStepControl_->getInitTime());
199  newState->setIndex (timeStepControl_->getInitIndex());
200  newState->setTimeStep(timeStepControl_->getInitTimeStep());
201  int order = timeStepControl_->getInitOrder();
202  if (order == 0) order = stepper_->getOrder();
203  if (order < stepper_->getOrderMin()) order = stepper_->getOrderMin();
204  if (order > stepper_->getOrderMax()) order = stepper_->getOrderMax();
205  newState->setOrder(order);
206 
207  newState->setSolutionStatus(Status::PASSED); // ICs are considered passing.
208 
209  solutionHistory_->addState(newState);
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) setInitialState();
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  // Ensure TimeStepControl orders match the Stepper orders.
315  if (timeStepControl_->getMinOrder() < stepper_->getOrderMin())
316  timeStepControl_->setMinOrder(stepper_->getOrderMin());
317  if (timeStepControl_->getMinOrder() > stepper_->getOrderMax())
318  timeStepControl_->setMinOrder(stepper_->getOrderMax());
319 
320  if (timeStepControl_->getMaxOrder() == 0 ||
321  timeStepControl_->getMaxOrder() > stepper_->getOrderMax())
322  timeStepControl_->setMaxOrder(stepper_->getOrderMax());
323  if (timeStepControl_->getMaxOrder() < timeStepControl_->getMinOrder())
324  timeStepControl_->setMaxOrder(timeStepControl_->getMinOrder());
325 
326  if (timeStepControl_->getInitOrder() < timeStepControl_->getMinOrder())
327  timeStepControl_->setInitOrder(timeStepControl_->getMinOrder());
328  if (timeStepControl_->getInitOrder() > timeStepControl_->getMaxOrder())
329  timeStepControl_->setInitOrder(timeStepControl_->getMaxOrder());
330 
331  TEUCHOS_TEST_FOR_EXCEPTION(
332  timeStepControl_->getMinOrder() > timeStepControl_->getMaxOrder(),
333  std::out_of_range,
334  "Error - Invalid TimeStepControl min order greater than max order.\n"
335  << " Min order = " << timeStepControl_->getMinOrder() << "\n"
336  << " Max order = " << timeStepControl_->getMaxOrder() << "\n");
337 
338  TEUCHOS_TEST_FOR_EXCEPTION(
339  timeStepControl_->getInitOrder() < timeStepControl_->getMinOrder() ||
340  timeStepControl_->getInitOrder() > timeStepControl_->getMaxOrder(),
341  std::out_of_range,
342  "Error - Initial TimeStepControl order is out of min/max range.\n"
343  << " Initial order = " << timeStepControl_->getInitOrder() << "\n"
344  << " Min order = " << timeStepControl_->getMinOrder() << "\n"
345  << " Max order = " << timeStepControl_->getMaxOrder() << "\n");
346 
347  if (integratorTimer_ == Teuchos::null)
348  integratorTimer_ = rcp(new Teuchos::Time("Integrator Timer"));
349  if (stepperTimer_ == Teuchos::null)
350  stepperTimer_ = rcp(new Teuchos::Time("Stepper Timer"));
351 
352  if (Teuchos::as<int>(this->getVerbLevel()) >=
353  Teuchos::as<int>(Teuchos::VERB_HIGH)) {
354  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
355  Teuchos::OSTab ostab(out,1,"IntegratorBasic::IntegratorBasic");
356  *out << this->description() << std::endl;
357  }
358 
359  isInitialized_ = true;
360 }
361 
362 
363 template<class Scalar>
365 {
366  std::string name = "Tempus::IntegratorBasic";
367  return(name);
368 }
369 
370 
371 template<class Scalar>
373  Teuchos::FancyOStream &out,
374  const Teuchos::EVerbosityLevel verbLevel) const
375 {
376  out << description() << "::describe" << std::endl;
377  out << "solutionHistory= " << solutionHistory_->description()<<std::endl;
378  out << "timeStepControl= " << timeStepControl_->description()<<std::endl;
379  out << "stepper = " << stepper_ ->description()<<std::endl;
380 
381  if (Teuchos::as<int>(verbLevel) >=
382  Teuchos::as<int>(Teuchos::VERB_HIGH)) {
383  out << "solutionHistory= " << std::endl;
384  solutionHistory_->describe(out,verbLevel);
385  out << "timeStepControl= " << std::endl;
386  timeStepControl_->describe(out,verbLevel);
387  out << "stepper = " << std::endl;
388  stepper_ ->describe(out,verbLevel);
389  }
390 }
391 
392 
393 template <class Scalar>
394 bool IntegratorBasic<Scalar>::advanceTime(const Scalar timeFinal)
395 {
396  if (timeStepControl_->timeInRange(timeFinal))
397  timeStepControl_->setFinalTime(timeFinal);
398  bool itgrStatus = advanceTime();
399  return itgrStatus;
400 }
401 
402 
403 template <class Scalar>
405 {
406  Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream();
407  if (isInitialized_ == false) {
408  Teuchos::OSTab ostab(out,1,"StartIntegrator");
409  *out << "Failure - IntegratorBasic is not initialized." << std::endl;
410  integratorStatus_ = FAILED;
411  return;
412  }
413  integratorTimer_->start();
414  // get optimal initial time step
415  const Scalar initDt =
416  std::min(timeStepControl_->getInitTimeStep(),
417  stepper_->getInitTimeStep(solutionHistory_));
418  // update initial time step
419  timeStepControl_->setInitTimeStep(initDt);
420  integratorStatus_ = WORKING;
421 }
422 
423 
424 template <class Scalar>
426 {
427  TEMPUS_FUNC_TIME_MONITOR("Tempus::IntegratorBasic::advanceTime()");
428  {
429  startIntegrator();
430  integratorObserver_->observeStartIntegrator(*this);
431 
432  while (integratorStatus_ == WORKING and
433  timeStepControl_->timeInRange (solutionHistory_->getCurrentTime()) and
434  timeStepControl_->indexInRange(solutionHistory_->getCurrentIndex())){
435 
436  stepperTimer_->reset();
437  stepperTimer_->start();
438  solutionHistory_->initWorkingState();
439 
440  startTimeStep();
441  integratorObserver_->observeStartTimeStep(*this);
442 
443  timeStepControl_->getNextTimeStep(solutionHistory_, integratorStatus_);
444  integratorObserver_->observeNextTimeStep(*this);
445 
446  if (integratorStatus_ == FAILED) break;
447  solutionHistory_->getWorkingState()->getMetaData()->
448  setSolutionStatus(WORKING);
449 
450  integratorObserver_->observeBeforeTakeStep(*this);
451 
452  stepper_->takeStep(solutionHistory_);
453 
454  integratorObserver_->observeAfterTakeStep(*this);
455 
456  stepperTimer_->stop();
457  acceptTimeStep();
458  integratorObserver_->observeAcceptedTimeStep(*this);
459  }
460 
461  endIntegrator();
462  integratorObserver_->observeEndIntegrator(*this);
463  }
464 
465  return (integratorStatus_ == Status::PASSED);
466 }
467 
468 
469 template <class Scalar>
471 {
472  Teuchos::RCP<SolutionStateMetaData<Scalar> > wsmd =
473  solutionHistory_->getWorkingState()->getMetaData();
474 
475  //set the Abs/Rel tolerance
476  wsmd->setTolRel(timeStepControl_->getMaxRelError());
477  wsmd->setTolAbs(timeStepControl_->getMaxAbsError());
478 
479  // Check if we need to dump screen output this step
480  std::vector<int>::const_iterator it =
481  std::find(outputScreenIndices_.begin(),
482  outputScreenIndices_.end(),
483  wsmd->getIStep());
484  if (it == outputScreenIndices_.end())
485  wsmd->setOutputScreen(false);
486  else
487  wsmd->setOutputScreen(true);
488 }
489 
490 
491 template <class Scalar>
493 {
494  using Teuchos::RCP;
495  RCP<SolutionStateMetaData<Scalar> > wsmd =
496  solutionHistory_->getWorkingState()->getMetaData();
497 
498  // Too many failures
499  if (wsmd->getNFailures() >= timeStepControl_->getMaxFailures()) {
500  RCP<Teuchos::FancyOStream> out = this->getOStream();
501  Teuchos::OSTab ostab(out,2,"acceptTimeStep");
502  *out << "Failure - Stepper has failed more than the maximum allowed.\n"
503  << " (nFailures = "<<wsmd->getNFailures()<< ") >= (nFailuresMax = "
504  << timeStepControl_->getMaxFailures()<<")" << std::endl;
505  integratorStatus_ = FAILED;
506  return;
507  }
508  if (wsmd->getNConsecutiveFailures()
509  >= timeStepControl_->getMaxConsecFailures()){
510  RCP<Teuchos::FancyOStream> out = this->getOStream();
511  Teuchos::OSTab ostab(out,1,"acceptTimeStep");
512  *out << "Failure - Stepper has failed more than the maximum "
513  << "consecutive allowed.\n"
514  << " (nConsecutiveFailures = "<<wsmd->getNConsecutiveFailures()
515  << ") >= (nConsecutiveFailuresMax = "
516  << timeStepControl_->getMaxConsecFailures()
517  << ")" << std::endl;
518  integratorStatus_ = FAILED;
519  return;
520  }
521 
522  // Stepper failure
523  if ( solutionHistory_->getWorkingState()->getSolutionStatus() == FAILED or
524  // Constant time step failure
525  ((timeStepControl_->getStepType() == "Constant") and
526  (wsmd->getDt() != timeStepControl_->getInitTimeStep()) and
527  (wsmd->getOutput() != true) and
528  (wsmd->getTime() != timeStepControl_->getFinalTime())
529  )
530  )
531  {
532  RCP<Teuchos::FancyOStream> out = this->getOStream();
533  Teuchos::OSTab ostab(out,0,"acceptTimeStep");
534  *out <<std::scientific
535  <<std::setw( 6)<<std::setprecision(3)<<wsmd->getIStep()
536  <<std::setw(11)<<std::setprecision(3)<<wsmd->getTime()
537  <<std::setw(11)<<std::setprecision(3)<<wsmd->getDt()
538  << " STEP FAILURE!! - ";
539  if ( solutionHistory_->getWorkingState()->getSolutionStatus() == FAILED) {
540  *out << "Solution Status = "
541  << toString(solutionHistory_->getWorkingState()->getSolutionStatus())
542  << std::endl;
543  } else if ((timeStepControl_->getStepType() == "Constant") and
544  (wsmd->getDt() != timeStepControl_->getInitTimeStep())) {
545  *out << "dt != Constant dt (="<<timeStepControl_->getInitTimeStep()<<")"
546  << std::endl;
547  }
548 
549  wsmd->setNFailures(wsmd->getNFailures()+1);
550  wsmd->setNRunningFailures(wsmd->getNRunningFailures()+1);
551  wsmd->setNConsecutiveFailures(wsmd->getNConsecutiveFailures()+1);
552  wsmd->setSolutionStatus(FAILED);
553  return;
554  }
555 
556  // =======================================================================
557  // Made it here! Accept this time step
558 
559  solutionHistory_->promoteWorkingState();
560 
561  RCP<SolutionStateMetaData<Scalar> > csmd =
562  solutionHistory_->getCurrentState()->getMetaData();
563 
564  // Output and screen output
565  if (csmd->getOutput() == true) {
566  // Dump solution!
567  }
568 }
569 
570 
571 template <class Scalar>
573 {
574  std::string exitStatus;
575  if (solutionHistory_->getCurrentState()->getSolutionStatus() ==
576  Status::FAILED or integratorStatus_ == Status::FAILED) {
577  exitStatus = "Time integration FAILURE!";
578  } else {
579  integratorStatus_ = Status::PASSED;
580  exitStatus = "Time integration complete.";
581  }
582 
583  integratorTimer_->stop();
584  runtime_ = integratorTimer_->totalElapsedTime();
585 }
586 
587 
588 template <class Scalar>
590 {
591  // This has been delayed until timeStepControl has been constructed.
592 
593  // Parse output indices
594  outputScreenIndices_.clear();
595  std::string str =
596  integratorPL_->get<std::string>("Screen Output Index List", "");
597  std::string delimiters(",");
598  std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
599  std::string::size_type pos = str.find_first_of(delimiters, lastPos);
600  while ((pos != std::string::npos) || (lastPos != std::string::npos)) {
601  std::string token = str.substr(lastPos,pos-lastPos);
602  outputScreenIndices_.push_back(int(std::stoi(token)));
603  if(pos==std::string::npos)
604  break;
605 
606  lastPos = str.find_first_not_of(delimiters, pos);
607  pos = str.find_first_of(delimiters, lastPos);
608  }
609 
610  int outputScreenIndexInterval =
611  integratorPL_->get<int>("Screen Output Index Interval", 1000000);
612  int outputScreen_i = timeStepControl_->getInitIndex();
613  const int finalIStep = timeStepControl_->getFinalIndex();
614  while (outputScreen_i <= finalIStep) {
615  outputScreenIndices_.push_back(outputScreen_i);
616  outputScreen_i += outputScreenIndexInterval;
617  }
618 
619  // order output indices
620  std::sort(outputScreenIndices_.begin(),outputScreenIndices_.end());
621 
622  return;
623 }
624 
625 
626 template <class Scalar>
628  const Teuchos::RCP<Teuchos::ParameterList> & inputPL)
629 {
630  if (inputPL == Teuchos::null) {
631  if (tempusPL_->isParameter("Integrator Name")) {
632  // Set Integrator PL from Tempus PL
633  std::string integratorName_ =
634  tempusPL_->get<std::string>("Integrator Name");
635  integratorPL_ = Teuchos::sublist(tempusPL_, integratorName_, true);
636  } else {
637  // Build default Integrator PL
638  integratorPL_ = Teuchos::parameterList();
639  integratorPL_->setName("Default Integrator");
640  *integratorPL_ = *(this->getValidParameters());
641  tempusPL_->set("Integrator Name", "Default Integrator");
642  tempusPL_->set("Default Integrator", *integratorPL_);
643  }
644  } else {
645  *integratorPL_ = *inputPL;
646  tempusPL_->set("Integrator Name", integratorPL_->name());
647  tempusPL_->set(integratorPL_->name(), *integratorPL_);
648  }
649 
650  integratorPL_->validateParametersAndSetDefaults(*this->getValidParameters());
651 
652  std::string integratorType =
653  integratorPL_->get<std::string>("Integrator Type");
654  TEUCHOS_TEST_FOR_EXCEPTION( integratorType != "Integrator Basic",
655  std::logic_error,
656  "Error - Inconsistent Integrator Type for IntegratorBasic\n"
657  << " Integrator Type = " << integratorType << "\n");
658 
659  return;
660 }
661 
662 
663 /** \brief Create valid IntegratorBasic ParameterList.
664  */
665 template<class Scalar>
666 Teuchos::RCP<const Teuchos::ParameterList>
668 {
669  Teuchos::RCP<Teuchos::ParameterList> pl = Teuchos::parameterList();
670 
671  std::ostringstream tmp;
672  tmp << "'Integrator Type' must be 'Integrator Basic'.";
673  pl->set("Integrator Type", "Integrator Basic", tmp.str());
674 
675  tmp.clear();
676  tmp << "Screen Output Index List. Required to be in TimeStepControl range "
677  << "['Minimum Time Step Index', 'Maximum Time Step Index']";
678  pl->set("Screen Output Index List", "", tmp.str());
679  pl->set("Screen Output Index Interval", 1000000,
680  "Screen Output Index Interval (e.g., every 100 time steps)");
681 
682  pl->set("Stepper Name", "",
683  "'Stepper Name' selects the Stepper block to construct (Required).");
684 
685  // Solution History
686  pl->sublist("Solution History",false,"solutionHistory_docs")
687  .disableRecursiveValidation();
688 
689  // Time Step Control
690  pl->sublist("Time Step Control",false,"solutionHistory_docs")
691  .disableRecursiveValidation();
692 
693  return pl;
694 }
695 
696 
697 template <class Scalar>
698 Teuchos::RCP<Teuchos::ParameterList>
700 {
701  return(integratorPL_);
702 }
703 
704 
705 template <class Scalar>
706 Teuchos::RCP<Teuchos::ParameterList>
708 {
709  Teuchos::RCP<Teuchos::ParameterList> temp_param_list = integratorPL_;
710  integratorPL_ = Teuchos::null;
711  return(temp_param_list);
712 }
713 
714 /// Non-member constructor
715 template<class Scalar>
716 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
717  Teuchos::RCP<Teuchos::ParameterList> pList,
718  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model)
719 {
720  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
721  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>(pList, model));
722  return(integrator);
723 }
724 
725 /// Non-member constructor
726 template<class Scalar>
727 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
728  const Teuchos::RCP<Thyra::ModelEvaluator<Scalar> >& model,
729  std::string stepperType)
730 {
731  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
732  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>(model, stepperType));
733  return(integrator);
734 }
735 
736 /// Non-member constructor
737 template<class Scalar>
738 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic()
739 {
740  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
741  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>());
742  return(integrator);
743 }
744 
745 /// Non-member constructor
746 template<class Scalar>
747 Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integratorBasic(
748  Teuchos::RCP<Teuchos::ParameterList> pList,
749  std::vector<Teuchos::RCP<const Thyra::ModelEvaluator<Scalar> > > models)
750 {
751  Teuchos::RCP<Tempus::IntegratorBasic<Scalar> > integrator =
752  Teuchos::rcp(new Tempus::IntegratorBasic<Scalar>(pList, models));
753  return(integrator);
754 }
755 
756 } // namespace Tempus
757 #endif // Tempus_IntegratorBasic_impl_hpp
Tempus::IntegratorObserverComposite
This observer.
Definition: Tempus_IntegratorObserverComposite_decl.hpp:21
Tempus::IntegratorBasic::parseScreenOutput
void parseScreenOutput()
Parse when screen output should be executed.
Definition: Tempus_IntegratorBasic_impl.hpp:589
Tempus::IntegratorBasic::setStepper
virtual void setStepper(Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > model)
Set the Stepper.
Definition: Tempus_IntegratorBasic_impl.hpp:74
Tempus::IntegratorBasic::setParameterList
void setParameterList(const Teuchos::RCP< Teuchos::ParameterList > &pl) override
Definition: Tempus_IntegratorBasic_impl.hpp:627
Tempus::WORKING
Definition: Tempus_Types.hpp:19
Tempus::IntegratorBasic::setTempusParameterList
virtual void setTempusParameterList(Teuchos::RCP< Teuchos::ParameterList > pl) override
Definition: Tempus_IntegratorBasic_decl.hpp:77
Tempus::IntegratorBasic::setObserver
virtual void setObserver(Teuchos::RCP< IntegratorObserver< Scalar > > obs=Teuchos::null)
Set the Observer.
Definition: Tempus_IntegratorBasic_impl.hpp:277
Tempus::IntegratorBasic::setInitialState
virtual void setInitialState(Teuchos::RCP< SolutionState< Scalar > > state=Teuchos::null)
Set the initial state which has the initial conditions.
Definition: Tempus_IntegratorBasic_impl.hpp:130
Tempus::IntegratorBasic::setSolutionHistory
virtual void setSolutionHistory(Teuchos::RCP< SolutionHistory< Scalar > > sh=Teuchos::null)
Set the SolutionHistory.
Definition: Tempus_IntegratorBasic_impl.hpp:214
Tempus::IntegratorBasic
Basic time integrator.
Definition: Tempus_IntegratorBasic_decl.hpp:35
Tempus
Definition: Tempus_AdjointAuxSensitivityModelEvaluator_decl.hpp:20
Tempus::IntegratorBasic::setStepperWStepper
virtual void setStepperWStepper(Teuchos::RCP< Stepper< Scalar > > stepper)
Set the Stepper.
Definition: Tempus_IntegratorBasic_impl.hpp:114
Tempus::IntegratorBasic::startIntegrator
virtual void startIntegrator()
Perform tasks before start of integrator.
Definition: Tempus_IntegratorBasic_impl.hpp:404
Tempus::IntegratorBasic::startTimeStep
virtual void startTimeStep()
Start time step.
Definition: Tempus_IntegratorBasic_impl.hpp:470
Tempus::IntegratorBasic::advanceTime
virtual bool advanceTime()
Advance the solution to timeMax, and return true if successful.
Definition: Tempus_IntegratorBasic_impl.hpp:425
Tempus::IntegratorBasic::unsetParameterList
Teuchos::RCP< Teuchos::ParameterList > unsetParameterList() override
Definition: Tempus_IntegratorBasic_impl.hpp:707
Tempus::IntegratorBasic::endIntegrator
virtual void endIntegrator()
Perform tasks after end of integrator.
Definition: Tempus_IntegratorBasic_impl.hpp:572
Tempus::IntegratorObserverBasic
IntegratorObserverBasic class for time integrators. This basic class has simple no-op functions,...
Definition: Tempus_IntegratorObserverBasic_decl.hpp:23
Tempus::IntegratorBasic::acceptTimeStep
virtual void acceptTimeStep()
Only accept step after meeting time step criteria.
Definition: Tempus_IntegratorBasic_impl.hpp:492
Tempus::IntegratorBasic::getValidParameters
Teuchos::RCP< const Teuchos::ParameterList > getValidParameters() const override
Create valid IntegratorBasic ParameterList.
Definition: Tempus_IntegratorBasic_impl.hpp:667
Tempus::SolutionState
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...
Definition: Tempus_SolutionState_decl.hpp:56
Tempus::IntegratorBasic::initialize
virtual void initialize()
Initializes the Integrator after set* function calls.
Definition: Tempus_IntegratorBasic_impl.hpp:303
Tempus::TimeStepControl
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
Definition: Tempus_Integrator.hpp:26
Tempus::PASSED
Definition: Tempus_Types.hpp:17
Tempus::IntegratorBasic::description
std::string description() const override
Definition: Tempus_IntegratorBasic_impl.hpp:364
Tempus::IntegratorObserver
IntegratorObserver class for time integrators.
Definition: Tempus_IntegratorObserver.hpp:41
Tempus::SolutionHistory
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Definition: Tempus_Integrator.hpp:25
Tempus::IntegratorBasic::setTimeStepControl
virtual void setTimeStepControl(Teuchos::RCP< TimeStepControl< Scalar > > tsc=Teuchos::null)
Set the TimeStepControl.
Definition: Tempus_IntegratorBasic_impl.hpp:242
Tempus::Stepper
Thyra Base interface for time steppers.
Definition: Tempus_Integrator.hpp:24
Tempus::StepperFactory
Stepper factory.
Definition: Tempus_StepperBackwardEuler_impl.hpp:22
Tempus::FAILED
Definition: Tempus_Types.hpp:18
Tempus::integratorBasic
Teuchos::RCP< Tempus::IntegratorBasic< Scalar > > integratorBasic(Teuchos::RCP< Teuchos::ParameterList > pList, const Teuchos::RCP< Thyra::ModelEvaluator< Scalar > > &model)
Non-member constructor.
Definition: Tempus_IntegratorBasic_impl.hpp:716
Tempus_StepperFactory.hpp
Teuchos
Definition: Tempus_Integrator.hpp:19
Tempus::IntegratorBasic::IntegratorBasic
IntegratorBasic()
Constructor that requires a subsequent setParameterList, setStepper, and initialize calls.
Definition: Tempus_IntegratorBasic_impl.hpp:52
Tempus::IntegratorBasic::describe
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel) const override
Definition: Tempus_IntegratorBasic_impl.hpp:372
Tempus::toString
const char * toString(const Status status)
Convert Status to string.
Definition: Tempus_Types.hpp:25
Tempus::IntegratorBasic::getNonconstParameterList
Teuchos::RCP< Teuchos::ParameterList > getNonconstParameterList() override
Definition: Tempus_IntegratorBasic_impl.hpp:699