12 #include "Tempus_SolutionHistory.hpp"
15 #include "../TestModels/DahlquistTestModel.hpp"
17 namespace Tempus_Unit_Test {
22 using Teuchos::rcp_const_cast;
23 using Teuchos::rcp_dynamic_cast;
24 using Teuchos::sublist;
35 auto inArgsIC = model->getNominalValues();
38 auto icState = Tempus::createSolutionStateX<double>(icSolution);
39 sh->addState(icState);
50 sh->setName(
"Testing");
55 sh->setStorageTypeString(
"Static");
58 sh->setStorageLimit(99);
75 std::string name =
"Unit Test";
79 auto inArgsIC = model->getNominalValues();
83 Tempus::createSolutionStateX<double>(icSolution);
84 history->push_back(icState);
89 int storageLimit = 99;
92 storageType, storageLimit));
109 pl->
set<std::string>(
"Storage Type",
"Static");
110 pl->
set<
int>(
"Storage Limit", 99);
112 pl->
sublist(
"Interpolator").
set(
"Interpolator Type",
"Lagrange");
115 auto sh = Tempus::createSolutionHistoryPL<double>(pl);
135 auto inArgsIC = model->getNominalValues();
137 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
138 state0->setTime(0.0);
141 sh->setStorageTypeString(
"Keep Newest");
142 sh->addState(state0);
158 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 0);
164 auto state1 = Tempus::createSolutionStateX<double>(icSoln);
165 state1->setTime(1.0);
167 sh->addState(state1);
182 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 1);
188 auto state2 = Tempus::createSolutionStateX<double>(icSoln);
189 state2->setTime(-1.0);
190 state2->setIndex(-1);
191 sh->addState(state2);
207 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 1);
223 auto inArgsIC = model->getNominalValues();
225 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
226 state0->setTime(0.0);
228 sh->addState(state0);
244 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 0);
250 auto state1 = Tempus::createSolutionStateX<double>(icSoln);
251 state1->setTime(1.0);
253 sh->addState(state1);
268 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 1);
269 TEST_COMPARE(sh->getStateTimeIndexNM1()->getIndex(), ==, 0);
276 auto state2 = Tempus::createSolutionStateX<double>(icSoln);
277 state2->setTime(2.0);
279 sh->addState(state2);
294 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 2);
295 TEST_COMPARE(sh->getStateTimeIndexNM1()->getIndex(), ==, 1);
302 sh->addState(state0);
318 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 2);
319 TEST_COMPARE(sh->getStateTimeIndexNM1()->getIndex(), ==, 1);
334 sh->setStorageTypeString(
"Static");
335 sh->setStorageLimit(7);
338 auto inArgsIC = model->getNominalValues();
342 for (
size_t i = 0; i < 13; ++i) {
344 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
345 stateI->setTime(i * 0.9);
346 stateI->setTimeStep(0.9);
348 sh->addState(stateI);
367 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 12);
370 TEST_COMPARE(sh->getStateTimeIndexNM1()->getIndex(), ==, 11);
373 TEST_COMPARE(sh->getStateTimeIndexNM2()->getIndex(), ==, 10);
376 TEST_COMPARE(sh->getStateTimeIndex(7)->getIndex(), ==, 7);
384 for (
size_t i = 0; i < 3; ++i) {
386 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
387 stateI->setTime(2 * i * 0.9 + 6.3);
388 stateI->setTimeStep(0.9);
389 stateI->setIndex(2 * i + 7);
390 sh->addState(stateI);
392 for (
size_t i = 0; i < 4; ++i) {
394 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
395 stateI->setTime(2 * i * 0.9 + 5.4);
396 stateI->setTimeStep(0.9);
397 stateI->setIndex(2 * i + 6);
398 sh->addState(stateI);
417 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 12);
420 TEST_COMPARE(sh->getStateTimeIndexNM1()->getIndex(), ==, 11);
423 TEST_COMPARE(sh->getStateTimeIndexNM2()->getIndex(), ==, 10);
426 TEST_COMPARE(sh->getStateTimeIndex(7)->getIndex(), ==, 7);
440 sh->setStorageTypeString(
"Static");
441 sh->setStorageLimit(7);
444 auto inArgsIC = model->getNominalValues();
447 for (
size_t i = 0; i < 13; ++i) {
449 auto stateI = Tempus::createSolutionStateX<double>(icSoln);
450 stateI->setTime(i * 0.9);
451 stateI->setTimeStep(0.9);
453 sh->addState(stateI);
460 sh->removeState(sh->getStateTimeIndex(6));
461 sh->removeState(7.2);
462 sh->removeState(sh->getStateTimeIndex(10));
463 sh->removeState(10.8);
479 TEST_COMPARE(sh->getStateTimeIndexN()->getIndex(), ==, 11);
482 TEST_COMPARE(sh->getStateTimeIndexNM2()->getIndex(), ==, 9);
498 auto inArgsIC = model->getNominalValues();
500 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
501 state0->setTime(0.0);
502 state0->setTimeStep(1.0);
504 sh->addState(state0);
513 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexN());
516 sh->initWorkingState();
526 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
528 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
549 auto inArgsIC = model->getNominalValues();
551 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
552 state0->setTime(0.0);
553 state0->setTimeStep(1.0);
555 sh->addState(state0);
559 auto currentSoln = icSoln->clone_v();
560 Thyra::V_S(currentSoln.ptr(), std::numeric_limits<double>::quiet_NaN());
561 auto state1 = Tempus::createSolutionStateX<double>(currentSoln);
562 state1->setTime(1.0);
563 state1->setTimeStep(1.0);
565 sh->addWorkingState(state1);
578 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
579 TEUCHOS_ASSERT(get_ele(*(sh->getCurrentState()->getX()), 0) == 1.0);
582 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
583 TEUCHOS_ASSERT(std::isnan(get_ele(*(sh->getWorkingState()->getX()), 0)));
591 sh->initWorkingState();
603 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
604 TEUCHOS_ASSERT(get_ele(*(sh->getCurrentState()->getX()), 0) == 1.0);
607 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
608 TEUCHOS_ASSERT(get_ele(*(sh->getWorkingState()->getX()), 0) == 1.0);
629 auto inArgsIC = model->getNominalValues();
631 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
632 state0->setTime(0.0);
633 state0->setTimeStep(1.0);
635 sh->addState(state0);
638 sh->initWorkingState();
645 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
647 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
655 sh->promoteWorkingState();
660 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexN());
680 auto inArgsIC = model->getNominalValues();
682 auto state0 = Tempus::createSolutionStateX<double>(icSoln);
683 state0->setTime(0.0);
684 state0->setTimeStep(1.0);
686 sh->addState(state0);
689 sh->initWorkingState();
696 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
698 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
706 sh->promoteWorkingState();
712 TEUCHOS_ASSERT(sh->getCurrentState() == sh->getStateTimeIndexNM1());
714 TEUCHOS_ASSERT(sh->getWorkingState() == sh->getStateTimeIndexN());
Keep the 2 newest states for undo.
The classic Dahlquist Test Problem.
#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...
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.