9 #ifndef Tempus_UnitTest_Utils_hpp 10 #define Tempus_UnitTest_Utils_hpp 12 #include "NOX_Thyra.H" 14 #include "Tempus_StepperFactory.hpp" 17 #include "Tempus_SolutionHistory.hpp" 19 #include "Tempus_StepperIMEX_RK.hpp" 20 #include "Tempus_StepperIMEX_RK_Partition.hpp" 30 #include "../TestModels/SinCosModel.hpp" 31 #include "../TestModels/VanDerPolModel.hpp" 37 using Teuchos::rcp_const_cast;
38 using Teuchos::rcp_dynamic_cast;
39 using Teuchos::ParameterList;
52 auto stepper = sf->createStepper(stepperType, model);
53 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
55 stepper = sf->createStepper(stepperType);
56 stepper->setModel(model);
57 stepper->initialize();
58 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
62 auto stepperPL = rcp_const_cast<ParameterList>(stepper->getValidParameters());
63 stepper = sf->createStepper(stepperPL, model);
64 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
66 stepper = sf->createStepper(stepperPL);
67 stepper->setModel(model);
68 stepper->initialize();
69 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 stepper->setModel(model);
80 stepper->initialize();
81 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 bool useFSAL = stepper->getUseFSAL();
88 std::string ICConsistency = stepper->getICConsistency();
89 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
90 bool useEmbedded = stepper->getUseEmbedded();
93 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
97 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
98 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
99 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
102 std::string stepperType = stepper->getStepperType();
104 if (stepperType ==
"RK Explicit 3 Stage 3rd order") {
106 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
107 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
108 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
110 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
111 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
112 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
114 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
115 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
116 }
else if (stepperType ==
"RK Explicit 3/8 Rule") {
118 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
119 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
120 }
else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
122 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
123 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
124 }
else if (stepperType ==
"RK Explicit 4 Stage") {
126 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
127 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
128 }
else if (stepperType ==
"RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
130 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
131 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
132 }
else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
134 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
135 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
136 }
else if (stepperType ==
"RK Forward Euler") {
138 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
139 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
140 }
else if (stepperType ==
"Merson 4(5) Pair") {
142 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
143 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
144 }
else if (stepperType ==
"RK Explicit Midpoint") {
146 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
147 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
148 }
else if (stepperType ==
"RK Explicit Trapezoidal") {
150 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
151 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
153 else TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Error - unknown stepperType = "+stepperType);
163 stepper->setModel(model);
164 stepper->initialize();
165 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
174 bool useFSAL = stepper->getUseFSAL();
175 std::string ICConsistency = stepper->getICConsistency();
176 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
177 bool useEmbedded = stepper->getUseEmbedded();
178 bool zeroInitialGuess = stepper->getZeroInitialGuess();
181 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
182 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
183 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
184 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
185 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
186 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
187 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
188 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
191 std::string stepperType = stepper->getStepperType();
193 if (stepperType ==
"RK Backward Euler") {
195 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
196 useEmbedded, zeroInitialGuess, modifier));
197 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
198 }
else if (stepperType ==
"SDIRK 2 Stage 2nd order") {
199 double gamma = 0.2928932188134524;
201 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
202 useEmbedded, zeroInitialGuess, modifier, gamma));
203 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
204 }
else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
206 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
207 useEmbedded, zeroInitialGuess, modifier));
208 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
209 }
else if (stepperType ==
"SDIRK 2 Stage 3rd order") {
210 std::string gammaType =
"3rd Order A-stable";
211 double gamma = 0.7886751345948128;
213 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
214 useEmbedded, zeroInitialGuess, modifier, gammaType, gamma));
215 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
216 }
else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
218 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
219 useEmbedded, zeroInitialGuess, modifier));
220 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
221 }
else if (stepperType ==
"DIRK 1 Stage Theta Method") {
224 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
225 useEmbedded, zeroInitialGuess, modifier, theta));
226 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
227 }
else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
230 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
231 useEmbedded, zeroInitialGuess, modifier, theta));
232 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
235 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
236 }
else if (stepperType ==
"RK Trapezoidal Rule") {
238 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
239 useEmbedded, zeroInitialGuess, modifier));
240 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
241 }
else if (stepperType ==
"RK Implicit Midpoint") {
243 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
244 useEmbedded, zeroInitialGuess, modifier));
245 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
246 }
else if (stepperType ==
"SSPDIRK22") {
248 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
249 useEmbedded, zeroInitialGuess, modifier));
250 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
251 }
else if (stepperType ==
"SSPDIRK32") {
253 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
254 useEmbedded, zeroInitialGuess, modifier));
255 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
256 }
else if (stepperType ==
"SSPDIRK23") {
258 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
259 useEmbedded, zeroInitialGuess, modifier));
260 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
261 }
else if (stepperType ==
"SSPDIRK33") {
263 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
264 useEmbedded, zeroInitialGuess, modifier));
265 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
266 }
else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
268 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
269 useEmbedded, zeroInitialGuess, modifier));
270 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
271 }
else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
273 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
274 useEmbedded, zeroInitialGuess, modifier));
275 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
276 }
else if (stepperType ==
"SDIRK 5 Stage 4th order") {
278 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
279 useEmbedded, zeroInitialGuess, modifier));
280 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
281 }
else if (stepperType ==
"SDIRK 3 Stage 4th order") {
283 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
284 useEmbedded, zeroInitialGuess, modifier));
285 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
286 }
else if (stepperType ==
"SDIRK 5 Stage 5th order") {
288 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
289 useEmbedded, zeroInitialGuess, modifier));
290 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
291 }
else if (stepperType ==
"SDIRK 2(1) Pair") {
293 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
294 useEmbedded, zeroInitialGuess, modifier));
295 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
296 }
else TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Error - unknown stepperType = "+stepperType);
336 auto x = sh->getCurrentState()->getX();
338 testName = stepper->getStepperType() +
" - Modifier";
350 testDt = sh->getWorkingState()->getTimeStep()/10.0;
371 auto x = sh->getWorkingState()->getX();
376 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
377 "Error - unknown action location.\n");
430 auto x = sh->getCurrentState()->getX();
442 testDt = sh->getWorkingState()->getTimeStep()/10.0;
448 testName = stepper->getStepperType() +
" - Observer";
464 auto x = sh->getWorkingState()->getX();
469 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
470 "Error - unknown action location.\n");
516 const double time,
const double dt,
517 const int stageNumber,
524 testX = get_ele(*(x), 0);
563 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
564 "Error - unknown action location.\n");
589 Teuchos::FancyOStream &out,
bool &success)
591 auto testNameOrig = stepper->getStepperType();
595 stepper->setModel(model);
597 stepper->setAppAction(modifier);
598 stepper->initialize();
599 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
600 auto testName = testNameOrig +
" - Modifier";
606 stepper->setInitialConditions(solutionHistory);
607 solutionHistory->initWorkingState();
609 solutionHistory->getWorkingState()->setTimeStep(dt);
610 stepper->takeStep(solutionHistory);
613 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
614 TEST_COMPARE(modifier->testBEGIN_STAGE, ==,
true);
615 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
616 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
617 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
618 TEST_COMPARE(modifier->testEND_STAGE, ==,
true);
619 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
622 auto x = solutionHistory->getCurrentState()->getX();
623 TEST_FLOATING_EQUALITY(modifier->testCurrentValue,get_ele(*(x), 0),1.0e-14);
624 x = solutionHistory->getWorkingState()->getX();
625 TEST_FLOATING_EQUALITY(modifier->testWorkingValue,get_ele(*(x), 0),1.0e-14);
626 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
627 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, 1.0e-14);
629 TEST_COMPARE(modifier->testName, ==, testName);
634 stepper->setModel(model);
636 stepper->setAppAction(observer);
637 stepper->setStepperName(testNameOrig);
638 stepper->initialize();
639 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
645 stepper->setInitialConditions(solutionHistory);
646 solutionHistory->initWorkingState();
648 solutionHistory->getWorkingState()->setTimeStep(dt);
649 stepper->takeStep(solutionHistory);
652 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
653 TEST_COMPARE(observer->testBEGIN_STAGE, ==,
true);
654 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
655 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
656 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
657 TEST_COMPARE(observer->testEND_STAGE, ==,
true);
658 TEST_COMPARE(observer->testEND_STEP, ==,
true);
661 auto x = solutionHistory->getCurrentState()->getX();
662 TEST_FLOATING_EQUALITY(observer->testCurrentValue,get_ele(*(x), 0),1.0e-14);
663 x = solutionHistory->getWorkingState()->getX();
664 TEST_FLOATING_EQUALITY(observer->testWorkingValue,get_ele(*(x), 0),1.0e-14);
665 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
666 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, 1.0e-14);
668 auto testName = testNameOrig +
" - Observer";
669 TEST_COMPARE(observer->testName, ==, testName);
674 stepper->setModel(model);
676 stepper->setAppAction(modifierX);
677 stepper->setStepperName(testNameOrig);
678 stepper->initialize();
679 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
685 stepper->setInitialConditions(solutionHistory);
686 solutionHistory->initWorkingState();
688 solutionHistory->getWorkingState()->setTimeStep(dt);
689 stepper->takeStep(solutionHistory);
692 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
693 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==,
true);
694 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
695 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
696 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
697 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==,
true);
698 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
700 const double relTol = 1.0e-14;
702 auto x = solutionHistory->getCurrentState()->getX();
703 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), relTol);
704 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
705 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
707 auto time = solutionHistory->getWorkingState()->getTime();
708 TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
711 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
714 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
718 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
719 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
720 }
else if (stepper->isImplicit()) {
724 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
725 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
727 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
728 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
730 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
731 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
733 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
734 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
736 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
737 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
739 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
740 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
742 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
743 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
745 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
746 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
748 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
749 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
751 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
752 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
754 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
755 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
757 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
758 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
760 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
761 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
763 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
764 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
766 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
767 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
769 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, 1.0e-14);
770 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, 1.0e-14);
772 TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
773 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
775 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
776 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
778 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
779 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
781 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
782 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
784 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
785 "Error - unknown stepperType = "+stepper->getStepperType());
791 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
792 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
794 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
795 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
797 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
798 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
800 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
801 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
803 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
804 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
806 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
807 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
809 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
810 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
812 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
813 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
815 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
816 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
818 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
819 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
821 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
822 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
824 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
825 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
827 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
828 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
830 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
831 "Error - unknown stepperType = "+stepper->getStepperType());
839 stepper->setModel(model);
846 composite->addRKAppAction(modifier);
847 composite->addRKAppAction(observer);
848 composite->addRKAppAction(modifierX);
849 stepper->setAppAction(composite);
851 stepper->initialize();
852 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
858 stepper->setInitialConditions(solutionHistory);
859 solutionHistory->initWorkingState();
861 solutionHistory->getWorkingState()->setTimeStep(dt);
862 stepper->takeStep(solutionHistory);
864 auto xCS = solutionHistory->getCurrentState()->getX();
865 auto xWS = solutionHistory->getWorkingState()->getX();
866 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
870 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
871 TEST_COMPARE(modifier->testBEGIN_STAGE, ==,
true);
872 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
873 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
874 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
875 TEST_COMPARE(modifier->testEND_STAGE, ==,
true);
876 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
878 const double relTol = 1.0e-14;
880 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(xCS), 0),relTol);
881 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(xWS), 0),relTol);
882 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, relTol);
884 auto testName = testNameOrig +
" - Modifier";
885 TEST_COMPARE(modifier->testName, ==, testName);
890 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
891 TEST_COMPARE(observer->testBEGIN_STAGE, ==,
true);
892 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
893 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
894 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
895 TEST_COMPARE(observer->testEND_STAGE, ==,
true);
896 TEST_COMPARE(observer->testEND_STEP, ==,
true);
899 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(xCS), 0),relTol);
900 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(xWS), 0),relTol);
901 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, relTol);
903 testName = testNameOrig +
" - Observer";
904 TEST_COMPARE(observer->testName, ==, testName);
909 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
910 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==,
true);
911 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
912 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
913 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
914 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==,
true);
915 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
918 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), relTol);
919 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
921 auto time = solutionHistory->getWorkingState()->getTime();
922 TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
925 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
928 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
932 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
933 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
934 }
else if (stepper->isImplicit()) {
938 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
939 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
941 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
942 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
944 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
945 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
947 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
948 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
950 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
951 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
953 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
954 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
956 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
957 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
959 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
960 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
962 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
963 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
965 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
966 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
968 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
969 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
971 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
972 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
974 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
975 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
977 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
978 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
980 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
981 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
983 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, relTol);
984 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, relTol);
986 TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
987 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
989 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
990 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
992 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
993 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
995 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
996 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
998 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
999 "Error - unknown stepperType = "+stepper->getStepperType());
1005 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
1006 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
1008 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1009 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1011 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
1012 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
1014 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1015 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1017 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
1018 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
1020 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
1021 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1023 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
1024 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
1026 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
1027 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
1029 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
1030 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
1032 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
1033 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1035 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
1036 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
1038 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1039 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1041 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1042 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1044 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
1045 "Error - unknown stepperType = "+stepper->getStepperType());
1053 #endif // Tempus_UnitTest_Utils_hpp
At the beginning of the stage.
At the beginning of the step.
Unit test class for RK Stepper Observer AppAction.
General Implicit Runge-Kutta Butcher Tableau.
RK Implicit 2 Stage 2nd order Lobatto IIIB.
void testRKAppAction(const Teuchos::RCP< Tempus::StepperRKBase< double > > &stepper, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model, Teuchos::FancyOStream &out, bool &success)
Unit test utility for Stepper RK AppAction.
Default observer for StepperRK.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Modify RK Stepper at action location.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
Explicit Runge-Kutta time stepper.
Modify at the end of the step.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Base observer for StepperRK.
Modify after the implicit solve.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Backward Euler Runge-Kutta Butcher Tableau.
Base ModifierX for StepperRK.
General Explicit Runge-Kutta Butcher Tableau.
Modify at the beginning of the stage.
RK Explicit 5 Stage 3rd order by Kinnmark and Gray.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
RK Explicit 4 Stage 3rd order by Runge.
Unit test class for RK Stepper Modifier AppAction.
Before the implicit solve.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperRKBase< double > > stepper, const typename Tempus::StepperRKAppAction< double >::ACTION_LOCATION actLoc)
Observe RK Stepper at action location.
RK Trapezoidal Rule (A.K.A. RK Crank-Nicolson)
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
This composite AppAction loops over added AppActions.
bool testBEFORE_EXPLICIT_EVAL
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Modify before the implicit solve.
bool testBEFORE_EXPLICIT_EVAL
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Explicit RK 3/8th Rule Butcher Tableau.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Modify at the beginning of the step.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Explicit RK Bogacki-Shampine Butcher Tableau.
StepperRKModifierTest()
Constructor.
virtual ~StepperRKObserverTest()
Destructor.
EDIRK 2 Stage Theta Method.
StepperRKModifierXTest()
Constructor.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const int stageNumber, const typename Tempus::StepperRKModifierXBase< double >::MODIFIER_TYPE modType)
Observe RK Stepper at end of takeStep.
Modify at the end of the stage.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Modify before the explicit evaluation.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Default ModifierX for StepperRK.
RK Explicit 3 Stage 3rd order TVD.
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
After the implicit solve.
Before the explicit evaluation.
Default modifier for StepperRK.
Forward Euler Runge-Kutta Butcher Tableau.
virtual ~StepperRKModifierXTest()
Destructor.
Explicit RK Merson Butcher Tableau.
Runge-Kutta 4th order Butcher Tableau.
RK Explicit 3 Stage 3rd order.
RK Implicit 1 Stage 1st order Radau IA.
bool testX_BEFORE_EXPLICIT_EVAL
virtual ~StepperRKModifierTest()
Destructor.
Base modifier for StepperRK.
RK Explicit 3 Stage 3rd order by Heun.
StepperRKObserverTest()
Constructor.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.