9#ifndef Tempus_UnitTest_RK_Utils_hpp
10#define Tempus_UnitTest_RK_Utils_hpp
17#include "Tempus_StepperIMEX_RK.hpp"
18#include "Tempus_StepperIMEX_RK_Partition.hpp"
33using Teuchos::rcp_const_cast;
34using Teuchos::rcp_dynamic_cast;
35using Teuchos::ParameterList;
45 stepper->setModel(model);
46 stepper->initialize();
47 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
53 bool useFSAL = stepper->getUseFSAL();
54 std::string ICConsistency = stepper->getICConsistency();
55 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
56 bool useEmbedded = stepper->getUseEmbedded();
59 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
60 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
62 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
64 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
68 std::string stepperType = stepper->getStepperType();
70 if (stepperType ==
"RK Explicit 3 Stage 3rd order") {
72 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
73 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
74 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
76 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
77 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
78 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
80 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
81 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
82 }
else if (stepperType ==
"RK Explicit 3/8 Rule") {
84 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
85 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
86 }
else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
88 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
89 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
90 }
else if (stepperType ==
"RK Explicit 4 Stage") {
92 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
93 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
94 }
else if (stepperType ==
"RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
96 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
97 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
98 }
else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
100 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
101 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
102 }
else if (stepperType ==
"RK Forward Euler") {
104 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
105 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
106 }
else if (stepperType ==
"Merson 4(5) Pair") {
108 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
109 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
110 }
else if (stepperType ==
"RK Explicit Midpoint") {
112 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
113 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
114 }
else if (stepperType ==
"RK Explicit Trapezoidal") {
116 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
117 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
119 else TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Error - unknown stepperType = "+stepperType);
129 stepper->setModel(model);
130 stepper->initialize();
131 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
140 bool useFSAL = stepper->getUseFSAL();
141 std::string ICConsistency = stepper->getICConsistency();
142 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
143 bool useEmbedded = stepper->getUseEmbedded();
144 bool zeroInitialGuess = stepper->getZeroInitialGuess();
147 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
148 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
149 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
150 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
151 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
152 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
153 stepper->setUseEmbedded(useEmbedded); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
154 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
157 std::string stepperType = stepper->getStepperType();
159 if (stepperType ==
"RK Backward Euler") {
161 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
162 useEmbedded, zeroInitialGuess, modifier));
163 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
164 }
else if (stepperType ==
"SDIRK 2 Stage 2nd order") {
165 double gamma = 0.2928932188134524;
167 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
168 useEmbedded, zeroInitialGuess, modifier, gamma));
169 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
170 }
else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
172 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
173 useEmbedded, zeroInitialGuess, modifier));
174 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
175 }
else if (stepperType ==
"SDIRK 2 Stage 3rd order") {
176 std::string gammaType =
"3rd Order A-stable";
177 double gamma = 0.7886751345948128;
179 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
180 useEmbedded, zeroInitialGuess, modifier, gammaType, gamma));
181 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
182 }
else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
184 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
185 useEmbedded, zeroInitialGuess, modifier));
186 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
187 }
else if (stepperType ==
"DIRK 1 Stage Theta Method") {
190 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
191 useEmbedded, zeroInitialGuess, modifier, theta));
192 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
193 }
else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
196 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
197 useEmbedded, zeroInitialGuess, modifier, theta));
198 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
201 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
202 }
else if (stepperType ==
"RK Trapezoidal Rule") {
204 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
205 useEmbedded, zeroInitialGuess, modifier));
206 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
207 }
else if (stepperType ==
"RK Implicit Midpoint") {
209 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
210 useEmbedded, zeroInitialGuess, modifier));
211 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
212 }
else if (stepperType ==
"SSPDIRK22") {
214 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
215 useEmbedded, zeroInitialGuess, modifier));
216 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
217 }
else if (stepperType ==
"SSPDIRK32") {
219 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
220 useEmbedded, zeroInitialGuess, modifier));
221 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
222 }
else if (stepperType ==
"SSPDIRK23") {
224 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
225 useEmbedded, zeroInitialGuess, modifier));
226 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
227 }
else if (stepperType ==
"SSPDIRK33") {
229 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
230 useEmbedded, zeroInitialGuess, modifier));
231 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
232 }
else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
234 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
235 useEmbedded, zeroInitialGuess, modifier));
236 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
237 }
else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
239 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
240 useEmbedded, zeroInitialGuess, modifier));
241 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
242 }
else if (stepperType ==
"SDIRK 5 Stage 4th order") {
244 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
245 useEmbedded, zeroInitialGuess, modifier));
246 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
247 }
else if (stepperType ==
"SDIRK 3 Stage 4th order") {
249 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
250 useEmbedded, zeroInitialGuess, modifier));
251 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
252 }
else if (stepperType ==
"SDIRK 5 Stage 5th order") {
254 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
255 useEmbedded, zeroInitialGuess, modifier));
256 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
257 }
else if (stepperType ==
"SDIRK 2(1) Pair") {
259 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
260 useEmbedded, zeroInitialGuess, modifier));
261 TEUCHOS_TEST_FOR_EXCEPT(!s->isInitialized());
262 }
else TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
"Error - unknown stepperType = "+stepperType);
299 case StepperRKAppAction<double>::BEGIN_STEP:
302 auto x = sh->getCurrentState()->getX();
304 testName = stepper->getStepperType() +
" - Modifier";
308 case StepperRKAppAction<double>::BEGIN_STAGE:
313 case StepperRKAppAction<double>::BEFORE_SOLVE:
316 testDt = sh->getWorkingState()->getTimeStep()/10.0;
319 case StepperRKAppAction<double>::AFTER_SOLVE:
324 case StepperRKAppAction<double>::BEFORE_EXPLICIT_EVAL:
329 case StepperRKAppAction<double>::END_STAGE:
334 case StepperRKAppAction<double>::END_STEP:
337 auto x = sh->getWorkingState()->getX();
342 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
343 "Error - unknown action location.\n");
393 case StepperRKAppAction<double>::BEGIN_STEP:
396 auto x = sh->getCurrentState()->getX();
400 case StepperRKAppAction<double>::BEGIN_STAGE:
405 case StepperRKAppAction<double>::BEFORE_SOLVE:
408 testDt = sh->getWorkingState()->getTimeStep()/10.0;
411 case StepperRKAppAction<double>::AFTER_SOLVE:
414 testName = stepper->getStepperType() +
" - Observer";
417 case StepperRKAppAction<double>::BEFORE_EXPLICIT_EVAL:
422 case StepperRKAppAction<double>::END_STAGE:
427 case StepperRKAppAction<double>::END_STEP:
430 auto x = sh->getWorkingState()->getX();
435 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
436 "Error - unknown action location.\n");
482 const double time,
const double dt,
483 const int stageNumber,
487 case StepperRKModifierXBase<double>::X_BEGIN_STEP:
490 testX = get_ele(*(x), 0);
493 case StepperRKModifierXBase<double>::X_BEGIN_STAGE:
498 case StepperRKModifierXBase<double>::X_BEFORE_SOLVE:
504 case StepperRKModifierXBase<double>::X_AFTER_SOLVE:
509 case StepperRKModifierXBase<double>::X_BEFORE_EXPLICIT_EVAL:
516 case StepperRKModifierXBase<double>::X_END_STAGE:
522 case StepperRKModifierXBase<double>::X_END_STEP:
529 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
530 "Error - unknown action location.\n");
555 Teuchos::FancyOStream &out,
bool &success)
557 auto testNameOrig = stepper->getStepperType();
561 stepper->setModel(model);
563 stepper->setAppAction(modifier);
564 stepper->initialize();
565 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
566 auto testName = testNameOrig +
" - Modifier";
572 stepper->setInitialConditions(solutionHistory);
573 solutionHistory->initWorkingState();
575 solutionHistory->getWorkingState()->setTimeStep(dt);
576 stepper->takeStep(solutionHistory);
579 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
580 TEST_COMPARE(modifier->testBEGIN_STAGE, ==,
true);
581 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
582 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
583 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
584 TEST_COMPARE(modifier->testEND_STAGE, ==,
true);
585 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
588 auto x = solutionHistory->getCurrentState()->getX();
589 TEST_FLOATING_EQUALITY(modifier->testCurrentValue,get_ele(*(x), 0),1.0e-14);
590 x = solutionHistory->getWorkingState()->getX();
591 TEST_FLOATING_EQUALITY(modifier->testWorkingValue,get_ele(*(x), 0),1.0e-14);
592 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
593 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, 1.0e-14);
595 TEST_COMPARE(modifier->testName, ==, testName);
600 stepper->setModel(model);
602 stepper->setAppAction(observer);
603 stepper->setStepperName(testNameOrig);
604 stepper->initialize();
605 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
611 stepper->setInitialConditions(solutionHistory);
612 solutionHistory->initWorkingState();
614 solutionHistory->getWorkingState()->setTimeStep(dt);
615 stepper->takeStep(solutionHistory);
618 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
619 TEST_COMPARE(observer->testBEGIN_STAGE, ==,
true);
620 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
621 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
622 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
623 TEST_COMPARE(observer->testEND_STAGE, ==,
true);
624 TEST_COMPARE(observer->testEND_STEP, ==,
true);
627 auto x = solutionHistory->getCurrentState()->getX();
628 TEST_FLOATING_EQUALITY(observer->testCurrentValue,get_ele(*(x), 0),1.0e-14);
629 x = solutionHistory->getWorkingState()->getX();
630 TEST_FLOATING_EQUALITY(observer->testWorkingValue,get_ele(*(x), 0),1.0e-14);
631 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
632 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, 1.0e-14);
634 auto testName = testNameOrig +
" - Observer";
635 TEST_COMPARE(observer->testName, ==, testName);
640 stepper->setModel(model);
642 stepper->setAppAction(modifierX);
643 stepper->setStepperName(testNameOrig);
644 stepper->initialize();
645 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
651 stepper->setInitialConditions(solutionHistory);
652 solutionHistory->initWorkingState();
654 solutionHistory->getWorkingState()->setTimeStep(dt);
655 stepper->takeStep(solutionHistory);
658 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
659 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==,
true);
660 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
661 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
662 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
663 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==,
true);
664 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
666 const double relTol = 1.0e-14;
668 auto x = solutionHistory->getCurrentState()->getX();
669 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), relTol);
670 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
671 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
673 auto time = solutionHistory->getWorkingState()->getTime();
674 TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
677 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
680 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
684 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
685 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
686 }
else if (stepper->isImplicit()) {
690 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
691 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
693 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
694 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
696 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
697 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
699 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
700 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
702 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
703 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
705 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
706 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
708 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
709 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
711 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
712 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
714 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
715 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
717 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
718 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
720 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
721 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
723 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
724 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
726 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
727 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
729 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
730 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
732 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
733 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
735 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, 1.0e-14);
736 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, 1.0e-14);
738 TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
739 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
741 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
742 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
744 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
745 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
747 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
748 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
750 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
751 "Error - unknown stepperType = "+stepper->getStepperType());
757 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
758 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
760 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
761 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
763 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
764 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
766 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
767 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
769 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
770 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
772 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
773 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
775 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
776 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
778 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
779 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
781 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
782 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
784 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
785 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
787 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
788 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
790 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
791 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
793 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
794 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
796 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
797 "Error - unknown stepperType = "+stepper->getStepperType());
805 stepper->setModel(model);
812 composite->addRKAppAction(modifier);
813 composite->addRKAppAction(observer);
814 composite->addRKAppAction(modifierX);
815 stepper->setAppAction(composite);
817 stepper->initialize();
818 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
824 stepper->setInitialConditions(solutionHistory);
825 solutionHistory->initWorkingState();
827 solutionHistory->getWorkingState()->setTimeStep(dt);
828 stepper->takeStep(solutionHistory);
830 auto xCS = solutionHistory->getCurrentState()->getX();
831 auto xWS = solutionHistory->getWorkingState()->getX();
832 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
836 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
837 TEST_COMPARE(modifier->testBEGIN_STAGE, ==,
true);
838 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
839 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
840 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
841 TEST_COMPARE(modifier->testEND_STAGE, ==,
true);
842 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
844 const double relTol = 1.0e-14;
846 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(xCS), 0),relTol);
847 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(xWS), 0),relTol);
848 TEST_FLOATING_EQUALITY(modifier->testDt, Dt/10.0, relTol);
850 auto testName = testNameOrig +
" - Modifier";
851 TEST_COMPARE(modifier->testName, ==, testName);
856 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
857 TEST_COMPARE(observer->testBEGIN_STAGE, ==,
true);
858 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
859 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
860 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
861 TEST_COMPARE(observer->testEND_STAGE, ==,
true);
862 TEST_COMPARE(observer->testEND_STEP, ==,
true);
865 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(xCS), 0),relTol);
866 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(xWS), 0),relTol);
867 TEST_FLOATING_EQUALITY(observer->testDt, Dt/10.0, relTol);
869 testName = testNameOrig +
" - Observer";
870 TEST_COMPARE(observer->testName, ==, testName);
875 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
876 TEST_COMPARE(modifierX->testX_BEGIN_STAGE, ==,
true);
877 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
878 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
879 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
880 TEST_COMPARE(modifierX->testXDOT_END_STAGE, ==,
true);
881 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
884 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(xCS), 0), relTol);
885 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, relTol);
887 auto time = solutionHistory->getWorkingState()->getTime();
888 TEST_FLOATING_EQUALITY(modifierX->testTime, time, relTol);
891 TEST_COMPARE(stepper->getStageNumber(), ==, -1);
894 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
898 TEST_FLOATING_EQUALITY(modifierX->testStageX, 2.0, relTol);
899 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 2.0,relTol);
900 }
else if (stepper->isImplicit()) {
904 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
905 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
907 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
908 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
910 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.049921670528461, relTol);
911 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.049921670528461, relTol);
913 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.02171123447937569, relTol);
914 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.02171123447937569, relTol);
916 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06659267480577136, relTol);
917 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06659267480577136, relTol);
919 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
920 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
922 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
923 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
925 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
926 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
928 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
929 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
931 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0748907323303947, relTol);
932 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0748907323303947, relTol);
934 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08321767099874625, relTol);
935 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08321767099874625, relTol);
937 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.07878078755122744, relTol);
938 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.07878078755122744, relTol);
940 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.08525184184135257, relTol);
941 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.08525184184135257, relTol);
943 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09900990099009901, relTol);
944 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09900990099009901, relTol);
946 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.04987531172069826, relTol);
947 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.04987531172069826, relTol);
949 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983340822548158, relTol);
950 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983340822548158, relTol);
952 TEST_FLOATING_EQUALITY(modifierX->testStageX, -0.009988159068259408, relTol);
953 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, -0.009988159068259408, relTol);
955 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06446224812649308, relTol);
956 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06446224812649308, relTol);
958 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.001960592098813843, relTol);
959 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.001960592098813843, relTol);
961 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09979317463412091, relTol);
962 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09979317463412091, relTol);
964 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
965 "Error - unknown stepperType = "+stepper->getStepperType());
971 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09966666666666668, relTol);
972 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09966666666666668, relTol);
974 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
975 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
977 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06666666666666667, relTol);
978 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06666666666666667, relTol);
980 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
981 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
983 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0995, relTol);
984 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0995, relTol);
986 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
987 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
989 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.06662222222222222, relTol);
990 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.06662222222222222, relTol);
992 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333333, relTol);
993 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333333, relTol);
995 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.0, relTol);
996 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.0, relTol);
998 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09975, relTol);
999 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09975, relTol);
1001 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.09983333333333332, relTol);
1002 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.09983333333333332, relTol);
1004 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.05, relTol);
1005 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.05, relTol);
1007 TEST_FLOATING_EQUALITY(modifierX->testStageX, 0.1, relTol);
1008 TEST_FLOATING_EQUALITY(modifierX->testEndStageX, 0.1, relTol);
1010 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
1011 "Error - unknown stepperType = "+stepper->getStepperType());
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
RK Implicit 1 Stage 1st order Radau IA.
RK Implicit 2 Stage 2nd order Lobatto IIIB.
Backward Euler Runge-Kutta Butcher Tableau.
General Implicit Runge-Kutta Butcher Tableau.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
EDIRK 2 Stage Theta Method.
RK Trapezoidal Rule (A.K.A. RK Crank-Nicolson)
RK Explicit 3 Stage 3rd order by Heun.
RK Explicit 3 Stage 3rd order TVD.
RK Explicit 3 Stage 3rd order.
Explicit RK 3/8th Rule Butcher Tableau.
RK Explicit 4 Stage 3rd order by Runge.
Runge-Kutta 4th order Butcher Tableau.
RK Explicit 5 Stage 3rd order by Kinnmark and Gray.
Explicit RK Bogacki-Shampine Butcher Tableau.
Forward Euler Runge-Kutta Butcher Tableau.
General Explicit Runge-Kutta Butcher Tableau.
Explicit RK Merson Butcher Tableau.
Explicit Runge-Kutta time stepper.
Partitioned Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
This composite AppAction loops over added AppActions.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Base modifier for StepperRK.
Default modifier for StepperRK.
Base ModifierX for StepperRK.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Default ModifierX for StepperRK.
Base observer for StepperRK.
Default observer for StepperRK.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation.
Unit test class for RK Stepper Modifier AppAction.
bool testBEFORE_EXPLICIT_EVAL
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.
StepperRKModifierTest()
Constructor.
virtual ~StepperRKModifierTest()
Destructor.
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.
bool testX_BEFORE_EXPLICIT_EVAL
StepperRKModifierXTest()
Constructor.
virtual ~StepperRKModifierXTest()
Destructor.
Unit test class for RK Stepper Observer AppAction.
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.
virtual ~StepperRKObserverTest()
Destructor.
bool testBEFORE_EXPLICIT_EVAL
StepperRKObserverTest()
Constructor.
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double > > &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
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.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.