12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_SolutionHistory.hpp"
19 #include "../TestModels/SinCosModel.hpp"
20 #include "../TestModels/DahlquistTestModel.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
26 namespace Tempus_Unit_Test {
30 using Teuchos::rcp_const_cast;
31 using Teuchos::rcp_dynamic_cast;
33 using Teuchos::sublist;
34 using Teuchos::getParametersFromXmlFile;
46 auto inArgsIC = model->getNominalValues();
48 auto icState = Tempus::createSolutionStateX<double>(icSolution);
49 sh->addState(icState);
80 std::string name =
"Unit Test";
84 auto inArgsIC = model->getNominalValues();
87 icState = Tempus::createSolutionStateX<double>(icSolution);
88 history->push_back(icState);
93 int storageLimit = 99;
96 name, history, interpolator, storageType, storageLimit));
115 pl->
set<std::string>(
"Storage Type",
"Static" );
116 pl->
set<
int> (
"Storage Limit", 99);
118 pl->
sublist(
"Interpolator").
set(
"Interpolator Type",
"Lagrange");
121 auto sh = Tempus::createSolutionHistoryPL<double>(pl);
143 auto inArgsIC = model->getNominalValues();
145 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
146 state0->setTime (0.0);
149 sh->setStorageTypeString (
"Keep Newest");
150 sh->addState(state0);
164 TEUCHOS_ASSERT(sh->getStateTimeIndex (0,
false) != Teuchos::null);
166 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 0);
172 auto state1 = Tempus::createSolutionStateX<double>(icSoln);
173 state1->setTime (1.0);
175 sh->addState(state1);
187 TEUCHOS_ASSERT(sh->getStateTimeIndex (0,
false) == Teuchos::null);
188 TEUCHOS_ASSERT(sh->getStateTimeIndex (1,
false) != Teuchos::null);
190 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 1);
196 auto state2 = Tempus::createSolutionStateX<double>(icSoln);
197 state2->setTime (-1.0);
198 state2->setIndex(-1);
199 sh->addState(state2);
212 TEUCHOS_ASSERT(sh->getStateTimeIndex (0,
false) == Teuchos::null);
213 TEUCHOS_ASSERT(sh->getStateTimeIndex (1,
false) != Teuchos::null);
215 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 1);
233 auto inArgsIC = model->getNominalValues();
235 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
236 state0->setTime (0.0);
238 sh->addState(state0);
252 TEUCHOS_ASSERT(sh->getStateTimeIndex (0,
false) != Teuchos::null);
254 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 0);
260 auto state1 = Tempus::createSolutionStateX<double>(icSoln);
261 state1->setTime (1.0);
263 sh->addState(state1);
275 TEUCHOS_ASSERT(sh->getStateTimeIndex (0,
false) != Teuchos::null);
276 TEUCHOS_ASSERT(sh->getStateTimeIndex (1,
false) != Teuchos::null);
278 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 1);
279 TEST_COMPARE( sh->getStateTimeIndexNM1()->getIndex(), ==, 0);
286 auto state2 = Tempus::createSolutionStateX<double>(icSoln);
287 state2->setTime (2.0);
289 sh->addState(state2);
301 TEUCHOS_ASSERT(sh->getStateTimeIndex (1,
false) != Teuchos::null);
302 TEUCHOS_ASSERT(sh->getStateTimeIndex (2,
false) != Teuchos::null);
304 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 2);
305 TEST_COMPARE( sh->getStateTimeIndexNM1()->getIndex(), ==, 1);
312 sh->addState(state0);
325 TEUCHOS_ASSERT(sh->getStateTimeIndex (1,
false) != Teuchos::null);
326 TEUCHOS_ASSERT(sh->getStateTimeIndex (2,
false) != Teuchos::null);
328 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 2);
329 TEST_COMPARE( sh->getStateTimeIndexNM1()->getIndex(), ==, 1);
346 sh->setStorageTypeString (
"Static");
347 sh->setStorageLimit(7);
350 auto inArgsIC = model->getNominalValues();
354 for (
size_t i=0; i < 13; ++i) {
356 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
357 stateI->setTime (i*0.9);
358 stateI->setTimeStep(0.9);
360 sh->addState(stateI);
379 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 12);
382 TEST_COMPARE( sh->getStateTimeIndexNM1()->getIndex(), ==, 11);
385 TEST_COMPARE( sh->getStateTimeIndexNM2()->getIndex(), ==, 10);
388 TEST_COMPARE( sh->getStateTimeIndex (7)->getIndex(), ==, 7);
396 for (
size_t i=0; i < 3; ++i) {
398 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
399 stateI->setTime (2*i*0.9+6.3);
400 stateI->setTimeStep(0.9);
401 stateI->setIndex(2*i+7);
402 sh->addState(stateI);
404 for (
size_t i=0; i < 4; ++i) {
406 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
407 stateI->setTime (2*i*0.9+5.4);
408 stateI->setTimeStep(0.9);
409 stateI->setIndex(2*i+6);
410 sh->addState(stateI);
429 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 12);
432 TEST_COMPARE( sh->getStateTimeIndexNM1()->getIndex(), ==, 11);
435 TEST_COMPARE( sh->getStateTimeIndexNM2()->getIndex(), ==, 10);
438 TEST_COMPARE( sh->getStateTimeIndex (7)->getIndex(), ==, 7);
454 sh->setStorageTypeString (
"Static");
455 sh->setStorageLimit(7);
458 auto inArgsIC = model->getNominalValues();
461 for (
size_t i=0; i < 13; ++i) {
463 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
464 stateI->setTime (i*0.9);
465 stateI->setTimeStep(0.9);
467 sh->addState(stateI);
474 sh->removeState(sh->getStateTimeIndex(6));
475 sh->removeState( 7.2);
476 sh->removeState(sh->getStateTimeIndex(10));
477 sh->removeState(10.8);
493 TEST_COMPARE( sh->getStateTimeIndexN ()->getIndex(), ==, 11);
496 TEST_COMPARE( sh->getStateTimeIndexNM2()->getIndex(), ==, 9);
514 auto inArgsIC = model->getNominalValues();
516 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
517 state0->setTime (0.0);
518 state0->setTimeStep(1.0);
520 sh->addState(state0);
529 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexN());
532 sh->initWorkingState();
542 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
544 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
546 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 0);
549 TEST_COMPARE ( sh->getWorkingState()->getIndex(), ==, 1);
567 auto inArgsIC = model->getNominalValues();
569 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
570 state0->setTime (0.0);
571 state0->setTimeStep(1.0);
573 sh->addState(state0);
577 auto state1 = Tempus::createSolutionStateX<double>(icSoln);
578 state1->setTime (1.0);
579 state1->setTimeStep(1.0);
581 sh->addWorkingState(state1);
594 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
596 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
598 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 0);
601 TEST_COMPARE ( sh->getWorkingState()->getIndex(), ==, 1);
604 sh->initWorkingState();
615 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
617 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
619 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 0);
622 TEST_COMPARE ( sh->getWorkingState()->getIndex(), ==, 1);
640 auto inArgsIC = model->getNominalValues();
642 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
643 state0->setTime (0.0);
644 state0->setTimeStep(1.0);
646 sh->addState(state0);
649 sh->initWorkingState();
656 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
658 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
660 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 0);
663 TEST_COMPARE ( sh->getWorkingState()->getIndex(), ==, 1);
666 sh->promoteWorkingState();
671 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexN());
675 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 1);
693 auto inArgsIC = model->getNominalValues();
695 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
696 state0->setTime (0.0);
697 state0->setTimeStep(1.0);
699 sh->addState(state0);
702 sh->initWorkingState();
709 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
711 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
713 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 0);
716 TEST_COMPARE ( sh->getWorkingState()->getIndex(), ==, 1);
719 sh->promoteWorkingState();
725 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
727 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
730 TEST_COMPARE ( sh->getCurrentState()->getIndex(), ==, 0);
734 TEST_COMPARE ( sh->getWorkingState()->getIndex(), ==, 1);
Keep the 2 newest states for undo.
The classic Dahlquist Test Problem.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
static Teuchos::RCP< Interpolator< Scalar > > createInterpolator(std::string interpolatorType="")
Create default interpolator from interpolator type (e.g., "Linear").
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
ParameterList & setName(const std::string &name)
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Solution state for integrators and steppers. SolutionState contains the metadata for solutions and th...