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"
29 namespace Tempus_Unit_Test {
33 using Teuchos::rcp_const_cast;
34 using Teuchos::rcp_dynamic_cast;
45 stepper->setModel(model);
46 stepper->initialize();
53 bool useFSAL = stepper->getUseFSAL();
54 std::string ICConsistency = stepper->getICConsistency();
55 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
56 bool useEmbedded = stepper->getUseEmbedded();
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));
74 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
76 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
78 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
80 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
82 }
else if (stepperType ==
"RK Explicit 3/8 Rule") {
84 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
86 }
else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
88 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
90 }
else if (stepperType ==
"RK Explicit 4 Stage") {
92 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
94 }
else if (stepperType ==
"RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
96 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
98 }
else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
100 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
102 }
else if (stepperType ==
"RK Forward Euler") {
104 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
106 }
else if (stepperType ==
"Merson 4(5) Pair") {
108 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
110 }
else if (stepperType ==
"RK Explicit Midpoint") {
112 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
114 }
else if (stepperType ==
"RK Explicit Trapezoidal") {
116 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
129 stepper->setModel(model);
130 stepper->initialize();
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();
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));
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));
170 }
else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
172 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
173 useEmbedded, zeroInitialGuess, modifier));
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));
182 }
else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
184 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
185 useEmbedded, zeroInitialGuess, modifier));
187 }
else if (stepperType ==
"DIRK 1 Stage Theta Method") {
190 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
191 useEmbedded, zeroInitialGuess, modifier, theta));
193 }
else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
196 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
197 useEmbedded, zeroInitialGuess, modifier, theta));
202 }
else if (stepperType ==
"RK Trapezoidal Rule") {
204 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
205 useEmbedded, zeroInitialGuess, modifier));
207 }
else if (stepperType ==
"RK Implicit Midpoint") {
209 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
210 useEmbedded, zeroInitialGuess, modifier));
212 }
else if (stepperType ==
"SSPDIRK22") {
214 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
215 useEmbedded, zeroInitialGuess, modifier));
217 }
else if (stepperType ==
"SSPDIRK32") {
219 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
220 useEmbedded, zeroInitialGuess, modifier));
222 }
else if (stepperType ==
"SSPDIRK23") {
224 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
225 useEmbedded, zeroInitialGuess, modifier));
227 }
else if (stepperType ==
"SSPDIRK33") {
229 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
230 useEmbedded, zeroInitialGuess, modifier));
232 }
else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
234 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
235 useEmbedded, zeroInitialGuess, modifier));
237 }
else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
239 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
240 useEmbedded, zeroInitialGuess, modifier));
242 }
else if (stepperType ==
"SDIRK 5 Stage 4th order") {
244 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
245 useEmbedded, zeroInitialGuess, modifier));
247 }
else if (stepperType ==
"SDIRK 3 Stage 4th order") {
249 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
250 useEmbedded, zeroInitialGuess, modifier));
252 }
else if (stepperType ==
"SDIRK 5 Stage 5th order") {
254 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
255 useEmbedded, zeroInitialGuess, modifier));
257 }
else if (stepperType ==
"SDIRK 2(1) Pair") {
259 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
260 useEmbedded, zeroInitialGuess, modifier));
302 auto x = sh->getCurrentState()->getX();
304 testName = stepper->getStepperType() +
" - Modifier";
316 testDt = sh->getWorkingState()->getTimeStep()/10.0;
337 auto x = sh->getWorkingState()->getX();
343 "Error - unknown action location.\n");
396 auto x = sh->getCurrentState()->getX();
408 testDt = sh->getWorkingState()->getTimeStep()/10.0;
414 testName = stepper->getStepperType() +
" - Observer";
430 auto x = sh->getWorkingState()->getX();
436 "Error - unknown action location.\n");
482 const double time,
const double dt,
483 const int stageNumber,
490 testX = get_ele(*(x), 0);
530 "Error - unknown action location.\n");
557 auto testNameOrig = stepper->getStepperType();
561 stepper->setModel(model);
563 stepper->setAppAction(modifier);
564 stepper->initialize();
566 auto testName = testNameOrig +
" - Modifier";
572 stepper->setInitialConditions(solutionHistory);
573 solutionHistory->initWorkingState();
575 solutionHistory->getWorkingState()->setTimeStep(dt);
576 stepper->takeStep(solutionHistory);
583 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
588 auto x = solutionHistory->getCurrentState()->getX();
590 x = solutionHistory->getWorkingState()->getX();
592 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
600 stepper->setModel(model);
602 stepper->setAppAction(observer);
603 stepper->setStepperName(testNameOrig);
604 stepper->initialize();
611 stepper->setInitialConditions(solutionHistory);
612 solutionHistory->initWorkingState();
614 solutionHistory->getWorkingState()->setTimeStep(dt);
615 stepper->takeStep(solutionHistory);
622 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
627 auto x = solutionHistory->getCurrentState()->getX();
629 x = solutionHistory->getWorkingState()->getX();
631 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
634 auto testName = testNameOrig +
" - Observer";
640 stepper->setModel(model);
642 stepper->setAppAction(modifierX);
643 stepper->setStepperName(testNameOrig);
644 stepper->initialize();
651 stepper->setInitialConditions(solutionHistory);
652 solutionHistory->initWorkingState();
654 solutionHistory->getWorkingState()->setTimeStep(dt);
655 stepper->takeStep(solutionHistory);
662 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
666 const double relTol = 1.0e-14;
668 auto x = solutionHistory->getCurrentState()->getX();
670 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
673 auto time = solutionHistory->getWorkingState()->getTime();
680 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
686 }
else if (stepper->isImplicit()) {
751 "Error - unknown stepperType = "+stepper->getStepperType());
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();
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();
840 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
844 const double relTol = 1.0e-14;
850 auto testName = testNameOrig +
" - Modifier";
860 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
869 testName = testNameOrig +
" - Observer";
879 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
887 auto time = solutionHistory->getWorkingState()->getTime();
894 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
900 }
else if (stepper->isImplicit()) {
965 "Error - unknown stepperType = "+stepper->getStepperType());
1011 "Error - unknown stepperType = "+stepper->getStepperType());
1019 #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.
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.
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...
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.
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.
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.
#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.