9 #ifndef Tempus_UnitTest_RK_Utils_hpp
10 #define Tempus_UnitTest_RK_Utils_hpp
16 #include "Tempus_StepperIMEX_RK.hpp"
17 #include "Tempus_StepperIMEX_RK_Partition.hpp"
27 namespace Tempus_Unit_Test {
32 using Teuchos::rcp_const_cast;
33 using Teuchos::rcp_dynamic_cast;
43 stepper->setModel(model);
44 stepper->initialize();
51 bool useFSAL = stepper->getUseFSAL();
52 std::string ICConsistency = stepper->getICConsistency();
53 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
54 bool useEmbedded = stepper->getUseEmbedded();
57 stepper->setAppAction(modifier);
58 stepper->initialize();
60 stepper->setAppAction(modifierX);
61 stepper->initialize();
63 stepper->setAppAction(observer);
64 stepper->initialize();
66 stepper->setUseFSAL(useFSAL);
67 stepper->initialize();
69 stepper->setICConsistency(ICConsistency);
70 stepper->initialize();
72 stepper->setICConsistencyCheck(ICConsistencyCheck);
73 stepper->initialize();
75 stepper->setUseEmbedded(useEmbedded);
76 stepper->initialize();
79 std::string stepperType = stepper->getStepperType();
81 if (stepperType ==
"RK Explicit 3 Stage 3rd order") {
83 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
87 else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
89 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
93 else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
95 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
99 else if (stepperType ==
"RK Explicit 3/8 Rule") {
101 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
105 else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
107 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
111 else if (stepperType ==
"RK Explicit 4 Stage") {
113 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
117 else if (stepperType ==
118 "RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
120 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
124 else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
126 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
130 else if (stepperType ==
"RK Forward Euler") {
132 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
136 else if (stepperType ==
"Merson 4(5) Pair") {
138 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
142 else if (stepperType ==
"RK Explicit Midpoint") {
144 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
148 else if (stepperType ==
"RK Explicit Trapezoidal") {
150 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
156 "Error - unknown stepperType = " + stepperType);
165 stepper->setModel(model);
166 stepper->initialize();
176 bool useFSAL = stepper->getUseFSAL();
177 std::string ICConsistency = stepper->getICConsistency();
178 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
179 bool useEmbedded = stepper->getUseEmbedded();
180 bool zeroInitialGuess = stepper->getZeroInitialGuess();
183 stepper->setAppAction(modifierX);
184 stepper->initialize();
186 stepper->setAppAction(observer);
187 stepper->initialize();
189 stepper->setSolver(solver);
190 stepper->initialize();
192 stepper->setUseFSAL(useFSAL);
193 stepper->initialize();
195 stepper->setICConsistency(ICConsistency);
196 stepper->initialize();
198 stepper->setICConsistencyCheck(ICConsistencyCheck);
199 stepper->initialize();
201 stepper->setUseEmbedded(useEmbedded);
202 stepper->initialize();
204 stepper->setZeroInitialGuess(zeroInitialGuess);
205 stepper->initialize();
208 std::string stepperType = stepper->getStepperType();
210 if (stepperType ==
"RK Backward Euler") {
212 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
213 zeroInitialGuess, modifier));
216 else if (stepperType ==
"SDIRK 2 Stage 2nd order") {
217 double gamma = 0.2928932188134524;
219 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
220 zeroInitialGuess, modifier, gamma));
223 else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
225 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
226 zeroInitialGuess, modifier));
229 else if (stepperType ==
"SDIRK 2 Stage 3rd order") {
230 std::string gammaType =
"3rd Order A-stable";
231 double gamma = 0.7886751345948128;
233 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
234 zeroInitialGuess, modifier, gammaType, gamma));
237 else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
239 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
240 zeroInitialGuess, modifier));
243 else if (stepperType ==
"DIRK 1 Stage Theta Method") {
246 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
247 zeroInitialGuess, modifier, theta));
250 else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
253 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
254 zeroInitialGuess, modifier, theta));
260 else if (stepperType ==
"RK Trapezoidal Rule") {
262 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
263 zeroInitialGuess, modifier));
266 else if (stepperType ==
"RK Implicit Midpoint") {
268 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
269 zeroInitialGuess, modifier));
272 else if (stepperType ==
"SSPDIRK22") {
274 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
275 zeroInitialGuess, modifier));
278 else if (stepperType ==
"SSPDIRK32") {
280 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
281 zeroInitialGuess, modifier));
284 else if (stepperType ==
"SSPDIRK23") {
286 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
287 zeroInitialGuess, modifier));
290 else if (stepperType ==
"SSPDIRK33") {
292 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
293 zeroInitialGuess, modifier));
296 else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
298 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
299 zeroInitialGuess, modifier));
302 else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
304 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
305 zeroInitialGuess, modifier));
308 else if (stepperType ==
"SDIRK 5 Stage 4th order") {
310 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
311 zeroInitialGuess, modifier));
314 else if (stepperType ==
"SDIRK 3 Stage 4th order") {
316 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
317 zeroInitialGuess, modifier));
320 else if (stepperType ==
"SDIRK 5 Stage 5th order") {
322 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
323 zeroInitialGuess, modifier));
326 else if (stepperType ==
"SDIRK 2(1) Pair") {
328 model, solver, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded,
329 zeroInitialGuess, modifier));
334 "Error - unknown stepperType = " + stepperType);
370 auto x = sh->getCurrentState()->getX();
372 testName = stepper->getStepperType() +
" - Modifier";
382 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
399 auto x = sh->getWorkingState()->getX();
405 "Error - unknown action location.\n");
455 auto x = sh->getCurrentState()->getX();
465 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
470 testName = stepper->getStepperType() +
" - Observer";
483 auto x = sh->getWorkingState()->getX();
489 "Error - unknown action location.\n");
533 const double dt,
const int stageNumber,
540 testX = get_ele(*(x), 0);
574 "Error - unknown action location.\n");
600 auto testNameOrig = stepper->getStepperType();
604 stepper->setModel(model);
606 stepper->setAppAction(modifier);
607 stepper->initialize();
609 auto testName = testNameOrig +
" - Modifier";
615 stepper->setInitialConditions(solutionHistory);
616 solutionHistory->initWorkingState();
618 solutionHistory->getWorkingState()->setTimeStep(dt);
619 stepper->takeStep(solutionHistory);
626 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
631 auto x = solutionHistory->getCurrentState()->getX();
634 x = solutionHistory->getWorkingState()->getX();
637 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
645 stepper->setModel(model);
647 stepper->setAppAction(observer);
648 stepper->setStepperName(testNameOrig);
649 stepper->initialize();
656 stepper->setInitialConditions(solutionHistory);
657 solutionHistory->initWorkingState();
659 solutionHistory->getWorkingState()->setTimeStep(dt);
660 stepper->takeStep(solutionHistory);
667 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
672 auto x = solutionHistory->getCurrentState()->getX();
675 x = solutionHistory->getWorkingState()->getX();
678 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
681 auto testName = testNameOrig +
" - Observer";
687 stepper->setModel(model);
689 stepper->setAppAction(modifierX);
690 stepper->setStepperName(testNameOrig);
691 stepper->initialize();
698 stepper->setInitialConditions(solutionHistory);
699 solutionHistory->initWorkingState();
701 solutionHistory->getWorkingState()->setTimeStep(dt);
702 stepper->takeStep(solutionHistory);
709 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
713 const double relTol = 1.0e-14;
715 auto x = solutionHistory->getCurrentState()->getX();
717 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
720 auto time = solutionHistory->getWorkingState()->getTime();
728 stepper->getNumberOfStages() - 1);
737 else if (stepper->isImplicit()) {
741 stepper) != Teuchos::null) {
748 stepper) != Teuchos::null) {
755 stepper) != Teuchos::null) {
762 stepper) != Teuchos::null) {
769 stepper) != Teuchos::null) {
776 stepper) != Teuchos::null) {
783 stepper) != Teuchos::null) {
790 stepper) != Teuchos::null) {
797 stepper) != Teuchos::null) {
804 stepper) != Teuchos::null) {
811 stepper) != Teuchos::null) {
818 stepper) != Teuchos::null) {
825 stepper) != Teuchos::null) {
831 else if (rcp_dynamic_cast<
833 stepper) != Teuchos::null) {
839 else if (rcp_dynamic_cast<
841 stepper) != Teuchos::null) {
848 stepper) != Teuchos::null) {
855 stepper) != Teuchos::null) {
862 stepper) != Teuchos::null) {
884 true, std::logic_error,
885 "Error - unknown stepperType = " + stepper->getStepperType());
899 stepper) != Teuchos::null) {
904 stepper) != Teuchos::null) {
911 stepper) != Teuchos::null) {
916 stepper) != Teuchos::null) {
921 stepper) != Teuchos::null) {
926 stepper) != Teuchos::null) {
933 stepper) != Teuchos::null) {
940 stepper) != Teuchos::null) {
962 stepper) != Teuchos::null) {
968 true, std::logic_error,
969 "Error - unknown stepperType = " + stepper->getStepperType());
976 stepper->setModel(model);
983 composite->addRKAppAction(modifier);
984 composite->addRKAppAction(observer);
985 composite->addRKAppAction(modifierX);
986 stepper->setAppAction(composite);
988 stepper->initialize();
995 stepper->setInitialConditions(solutionHistory);
996 solutionHistory->initWorkingState();
998 solutionHistory->getWorkingState()->setTimeStep(dt);
999 stepper->takeStep(solutionHistory);
1001 auto xCS = solutionHistory->getCurrentState()->getX();
1002 auto xWS = solutionHistory->getWorkingState()->getX();
1003 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
1011 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
1015 const double relTol = 1.0e-14;
1023 auto testName = testNameOrig +
" - Modifier";
1032 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
1043 testName = testNameOrig +
" - Observer";
1052 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
1060 auto time = solutionHistory->getWorkingState()->getTime();
1068 stepper->getNumberOfStages() - 1);
1077 else if (stepper->isImplicit()) {
1081 stepper) != Teuchos::null) {
1088 stepper) != Teuchos::null) {
1095 stepper) != Teuchos::null) {
1102 stepper) != Teuchos::null) {
1109 stepper) != Teuchos::null) {
1116 stepper) != Teuchos::null) {
1123 stepper) != Teuchos::null) {
1130 stepper) != Teuchos::null) {
1137 stepper) != Teuchos::null) {
1144 stepper) != Teuchos::null) {
1151 stepper) != Teuchos::null) {
1158 stepper) != Teuchos::null) {
1165 stepper) != Teuchos::null) {
1171 else if (rcp_dynamic_cast<
1173 stepper) != Teuchos::null) {
1179 else if (rcp_dynamic_cast<
1181 stepper) != Teuchos::null) {
1188 stepper) != Teuchos::null) {
1195 stepper) != Teuchos::null) {
1202 stepper) != Teuchos::null) {
1224 true, std::logic_error,
1225 "Error - unknown stepperType = " + stepper->getStepperType());
1239 stepper) != Teuchos::null) {
1244 stepper) != Teuchos::null) {
1251 stepper) != Teuchos::null) {
1256 stepper) != Teuchos::null) {
1261 stepper) != Teuchos::null) {
1266 stepper) != Teuchos::null) {
1273 stepper) != Teuchos::null) {
1280 stepper) != Teuchos::null) {
1302 stepper) != Teuchos::null) {
1308 true, std::logic_error,
1309 "Error - unknown stepperType = " + stepper->getStepperType());
1316 #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.