10 #ifndef Tempus_UnitTest_RK_Utils_hpp
11 #define Tempus_UnitTest_RK_Utils_hpp
17 #include "Tempus_StepperIMEX_RK.hpp"
18 #include "Tempus_StepperIMEX_RK_Partition.hpp"
28 namespace Tempus_Unit_Test {
33 using Teuchos::rcp_const_cast;
34 using Teuchos::rcp_dynamic_cast;
44 stepper->setModel(model);
45 stepper->initialize();
52 bool useFSAL = stepper->getUseFSAL();
53 std::string ICConsistency = stepper->getICConsistency();
54 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
55 bool useEmbedded = stepper->getUseEmbedded();
58 stepper->setAppAction(modifier);
59 stepper->initialize();
61 stepper->setAppAction(modifierX);
62 stepper->initialize();
64 stepper->setAppAction(observer);
65 stepper->initialize();
67 stepper->setUseFSAL(useFSAL);
68 stepper->initialize();
70 stepper->setICConsistency(ICConsistency);
71 stepper->initialize();
73 stepper->setICConsistencyCheck(ICConsistencyCheck);
74 stepper->initialize();
76 stepper->setUseEmbedded(useEmbedded);
77 stepper->initialize();
80 std::string stepperType = stepper->getStepperType();
82 if (stepperType ==
"RK Explicit 3 Stage 3rd order") {
84 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
88 else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
90 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
94 else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
96 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
100 else if (stepperType ==
"RK Explicit 3/8 Rule") {
102 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
106 else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
108 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
112 else if (stepperType ==
"RK Explicit 4 Stage") {
114 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
118 else if (stepperType ==
119 "RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
121 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
125 else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
127 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
131 else if (stepperType ==
"RK Forward Euler") {
133 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
137 else if (stepperType ==
"Merson 4(5) Pair") {
139 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
143 else if (stepperType ==
"RK Explicit Midpoint") {
145 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
149 else if (stepperType ==
"RK Explicit Trapezoidal") {
151 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
157 "Error - unknown stepperType = " + stepperType);
166 stepper->setModel(model);
167 stepper->initialize();
177 bool useFSAL = stepper->getUseFSAL();
178 std::string ICConsistency = stepper->getICConsistency();
179 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
180 bool useEmbedded = stepper->getUseEmbedded();
181 bool zeroInitialGuess = stepper->getZeroInitialGuess();
184 stepper->setAppAction(modifierX);
185 stepper->initialize();
187 stepper->setAppAction(observer);
188 stepper->initialize();
190 stepper->setSolver(solver);
191 stepper->initialize();
193 stepper->setUseFSAL(useFSAL);
194 stepper->initialize();
196 stepper->setICConsistency(ICConsistency);
197 stepper->initialize();
199 stepper->setICConsistencyCheck(ICConsistencyCheck);
200 stepper->initialize();
202 stepper->setUseEmbedded(useEmbedded);
203 stepper->initialize();
205 stepper->setZeroInitialGuess(zeroInitialGuess);
206 stepper->initialize();
209 std::string stepperType = stepper->getStepperType();
211 if (stepperType ==
"RK Backward Euler") {
213 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
214 zeroInitialGuess, modifier));
217 else if (stepperType ==
"SDIRK 2 Stage 2nd order") {
218 double gamma = 0.2928932188134524;
220 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
221 zeroInitialGuess, modifier, gamma));
224 else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
226 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
227 zeroInitialGuess, modifier));
230 else if (stepperType ==
"SDIRK 2 Stage 3rd order") {
231 std::string gammaType =
"3rd Order A-stable";
232 double gamma = 0.7886751345948128;
234 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
235 zeroInitialGuess, modifier, gammaType, gamma));
238 else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
240 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
241 zeroInitialGuess, modifier));
244 else if (stepperType ==
"DIRK 1 Stage Theta Method") {
247 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
248 zeroInitialGuess, modifier, theta));
251 else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
254 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
255 zeroInitialGuess, modifier, theta));
261 else if (stepperType ==
"RK Trapezoidal Rule") {
263 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
264 zeroInitialGuess, modifier));
267 else if (stepperType ==
"RK Implicit Midpoint") {
269 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
270 zeroInitialGuess, modifier));
273 else if (stepperType ==
"SSPDIRK22") {
275 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
276 zeroInitialGuess, modifier));
279 else if (stepperType ==
"SSPDIRK32") {
281 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
282 zeroInitialGuess, modifier));
285 else if (stepperType ==
"SSPDIRK23") {
287 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
288 zeroInitialGuess, modifier));
291 else if (stepperType ==
"SSPDIRK33") {
293 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
294 zeroInitialGuess, modifier));
297 else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
299 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
300 zeroInitialGuess, modifier));
303 else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
305 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
306 zeroInitialGuess, modifier));
309 else if (stepperType ==
"SDIRK 5 Stage 4th order") {
311 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
312 zeroInitialGuess, modifier));
315 else if (stepperType ==
"SDIRK 3 Stage 4th order") {
317 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
318 zeroInitialGuess, modifier));
321 else if (stepperType ==
"SDIRK 5 Stage 5th order") {
323 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
324 zeroInitialGuess, modifier));
327 else if (stepperType ==
"SDIRK 2(1) Pair") {
329 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
330 zeroInitialGuess, modifier));
335 "Error - unknown stepperType = " + stepperType);
371 auto x = sh->getCurrentState()->getX();
373 testName = stepper->getStepperType() +
" - Modifier";
383 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
400 auto x = sh->getWorkingState()->getX();
406 "Error - unknown action location.\n");
456 auto x = sh->getCurrentState()->getX();
466 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
471 testName = stepper->getStepperType() +
" - Observer";
484 auto x = sh->getWorkingState()->getX();
490 "Error - unknown action location.\n");
534 const double dt,
const int stageNumber,
541 testX = get_ele(*(x), 0);
575 "Error - unknown action location.\n");
601 auto testNameOrig = stepper->getStepperType();
605 stepper->setModel(model);
607 stepper->setAppAction(modifier);
608 stepper->initialize();
610 auto testName = testNameOrig +
" - Modifier";
616 stepper->setInitialConditions(solutionHistory);
617 solutionHistory->initWorkingState();
619 solutionHistory->getWorkingState()->setTimeStep(dt);
620 stepper->takeStep(solutionHistory);
627 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
632 auto x = solutionHistory->getCurrentState()->getX();
635 x = solutionHistory->getWorkingState()->getX();
638 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
646 stepper->setModel(model);
648 stepper->setAppAction(observer);
649 stepper->setStepperName(testNameOrig);
650 stepper->initialize();
657 stepper->setInitialConditions(solutionHistory);
658 solutionHistory->initWorkingState();
660 solutionHistory->getWorkingState()->setTimeStep(dt);
661 stepper->takeStep(solutionHistory);
668 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
673 auto x = solutionHistory->getCurrentState()->getX();
676 x = solutionHistory->getWorkingState()->getX();
679 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
682 auto testName = testNameOrig +
" - Observer";
688 stepper->setModel(model);
690 stepper->setAppAction(modifierX);
691 stepper->setStepperName(testNameOrig);
692 stepper->initialize();
699 stepper->setInitialConditions(solutionHistory);
700 solutionHistory->initWorkingState();
702 solutionHistory->getWorkingState()->setTimeStep(dt);
703 stepper->takeStep(solutionHistory);
710 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
714 const double relTol = 1.0e-14;
716 auto x = solutionHistory->getCurrentState()->getX();
718 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
721 auto time = solutionHistory->getWorkingState()->getTime();
729 stepper->getNumberOfStages() - 1);
738 else if (stepper->isImplicit()) {
742 stepper) != Teuchos::null) {
749 stepper) != Teuchos::null) {
756 stepper) != Teuchos::null) {
763 stepper) != Teuchos::null) {
770 stepper) != Teuchos::null) {
777 stepper) != Teuchos::null) {
784 stepper) != Teuchos::null) {
791 stepper) != Teuchos::null) {
798 stepper) != Teuchos::null) {
805 stepper) != Teuchos::null) {
812 stepper) != Teuchos::null) {
819 stepper) != Teuchos::null) {
826 stepper) != Teuchos::null) {
832 else if (rcp_dynamic_cast<
834 stepper) != Teuchos::null) {
840 else if (rcp_dynamic_cast<
842 stepper) != Teuchos::null) {
849 stepper) != Teuchos::null) {
856 stepper) != Teuchos::null) {
863 stepper) != Teuchos::null) {
885 true, std::logic_error,
886 "Error - unknown stepperType = " + stepper->getStepperType());
900 stepper) != Teuchos::null) {
905 stepper) != Teuchos::null) {
912 stepper) != Teuchos::null) {
917 stepper) != Teuchos::null) {
922 stepper) != Teuchos::null) {
927 stepper) != Teuchos::null) {
934 stepper) != Teuchos::null) {
941 stepper) != Teuchos::null) {
963 stepper) != Teuchos::null) {
969 true, std::logic_error,
970 "Error - unknown stepperType = " + stepper->getStepperType());
977 stepper->setModel(model);
984 composite->addRKAppAction(modifier);
985 composite->addRKAppAction(observer);
986 composite->addRKAppAction(modifierX);
987 stepper->setAppAction(composite);
989 stepper->initialize();
996 stepper->setInitialConditions(solutionHistory);
997 solutionHistory->initWorkingState();
999 solutionHistory->getWorkingState()->setTimeStep(dt);
1000 stepper->takeStep(solutionHistory);
1002 auto xCS = solutionHistory->getCurrentState()->getX();
1003 auto xWS = solutionHistory->getWorkingState()->getX();
1004 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
1012 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
1016 const double relTol = 1.0e-14;
1024 auto testName = testNameOrig +
" - Modifier";
1033 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
1044 testName = testNameOrig +
" - Observer";
1053 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
1061 auto time = solutionHistory->getWorkingState()->getTime();
1069 stepper->getNumberOfStages() - 1);
1078 else if (stepper->isImplicit()) {
1082 stepper) != Teuchos::null) {
1089 stepper) != Teuchos::null) {
1096 stepper) != Teuchos::null) {
1103 stepper) != Teuchos::null) {
1110 stepper) != Teuchos::null) {
1117 stepper) != Teuchos::null) {
1124 stepper) != Teuchos::null) {
1131 stepper) != Teuchos::null) {
1138 stepper) != Teuchos::null) {
1145 stepper) != Teuchos::null) {
1152 stepper) != Teuchos::null) {
1159 stepper) != Teuchos::null) {
1166 stepper) != Teuchos::null) {
1172 else if (rcp_dynamic_cast<
1174 stepper) != Teuchos::null) {
1180 else if (rcp_dynamic_cast<
1182 stepper) != Teuchos::null) {
1189 stepper) != Teuchos::null) {
1196 stepper) != Teuchos::null) {
1203 stepper) != Teuchos::null) {
1225 true, std::logic_error,
1226 "Error - unknown stepperType = " + stepper->getStepperType());
1240 stepper) != Teuchos::null) {
1245 stepper) != Teuchos::null) {
1252 stepper) != Teuchos::null) {
1257 stepper) != Teuchos::null) {
1262 stepper) != Teuchos::null) {
1267 stepper) != Teuchos::null) {
1274 stepper) != Teuchos::null) {
1281 stepper) != Teuchos::null) {
1303 stepper) != Teuchos::null) {
1309 true, std::logic_error,
1310 "Error - unknown stepperType = " + stepper->getStepperType());
1317 #endif // Tempus_UnitTest_RK_Utils_hpp
At the beginning of the stage.
At the beginning of the step.
Unit test class for RK Stepper Observer AppAction.
void testDIRKAccessorsFullConstruction(const RCP< Tempus::StepperDIRK< double >> &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
General Implicit Runge-Kutta Butcher Tableau.
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 Implicit 2 Stage 2nd order Lobatto IIIB.
Default observer for StepperRK.
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.
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
#define TEST_COMPARE(v1, comp, v2)
RK Explicit 4 Stage 3rd order by Runge.
Unit test class for RK Stepper Modifier AppAction.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Before the implicit solve.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
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
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.
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.
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.
Diagonally Implicit Runge-Kutta (DIRK) time stepper.
Modify at the beginning of the step.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Explicit RK Bogacki-Shampine Butcher Tableau.
StepperRKModifierTest()
Constructor.
virtual ~StepperRKObserverTest()
Destructor.
EDIRK 2 Stage Theta Method.
StepperRKModifierXTest()
Constructor.
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.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
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.
After the implicit solve.
Before the explicit evaluation.
Default modifier for StepperRK.
Forward Euler Runge-Kutta Butcher Tableau.
void testExplicitRKAccessorsFullConstruction(const RCP< Tempus::StepperExplicitRK< double >> &stepper)
Unit test utility for ExplicitRK Stepper construction and accessors.
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.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
RK Explicit 3 Stage 3rd order by Heun.
StepperRKObserverTest()
Constructor.
Strong Stability Preserving Diagonally-Implicit RK Butcher Tableau.