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"
33 namespace Tempus_Unit_Test {
37 using Teuchos::rcp_const_cast;
38 using Teuchos::rcp_dynamic_cast;
52 auto stepper = sf->createStepper(stepperType, model);
55 stepper = sf->createStepper(stepperType);
56 stepper->setModel(model);
57 stepper->initialize();
62 auto stepperPL = rcp_const_cast<
ParameterList>(stepper->getValidParameters());
63 stepper = sf->createStepper(stepperPL, model);
66 stepper = sf->createStepper(stepperPL);
67 stepper->setModel(model);
68 stepper->initialize();
79 stepper->setModel(model);
80 stepper->initialize();
87 bool useFSAL = stepper->getUseFSAL();
88 std::string ICConsistency = stepper->getICConsistency();
89 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
90 bool useEmbedded = stepper->getUseEmbedded();
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));
108 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order by Heun") {
110 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
112 }
else if (stepperType ==
"RK Explicit 3 Stage 3rd order TVD") {
114 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
116 }
else if (stepperType ==
"RK Explicit 3/8 Rule") {
118 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
120 }
else if (stepperType ==
"RK Explicit 4 Stage 3rd order by Runge") {
122 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
124 }
else if (stepperType ==
"RK Explicit 4 Stage") {
126 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
128 }
else if (stepperType ==
"RK Explicit 5 Stage 3rd order by Kinnmark and Gray") {
130 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
132 }
else if (stepperType ==
"Bogacki-Shampine 3(2) Pair") {
134 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
136 }
else if (stepperType ==
"RK Forward Euler") {
138 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
140 }
else if (stepperType ==
"Merson 4(5) Pair") {
142 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
144 }
else if (stepperType ==
"RK Explicit Midpoint") {
146 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
148 }
else if (stepperType ==
"RK Explicit Trapezoidal") {
150 model, useFSAL, ICConsistency, ICConsistencyCheck, useEmbedded, modifier));
163 stepper->setModel(model);
164 stepper->initialize();
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();
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));
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));
204 }
else if (stepperType ==
"SDIRK 3 Stage 2nd order") {
206 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
207 useEmbedded, zeroInitialGuess, modifier));
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));
216 }
else if (stepperType ==
"EDIRK 2 Stage 3rd order") {
218 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
219 useEmbedded, zeroInitialGuess, modifier));
221 }
else if (stepperType ==
"DIRK 1 Stage Theta Method") {
224 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
225 useEmbedded, zeroInitialGuess, modifier, theta));
227 }
else if (stepperType ==
"EDIRK 2 Stage Theta Method") {
230 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
231 useEmbedded, zeroInitialGuess, modifier, theta));
236 }
else if (stepperType ==
"RK Trapezoidal Rule") {
238 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
239 useEmbedded, zeroInitialGuess, modifier));
241 }
else if (stepperType ==
"RK Implicit Midpoint") {
243 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
244 useEmbedded, zeroInitialGuess, modifier));
246 }
else if (stepperType ==
"SSPDIRK22") {
248 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
249 useEmbedded, zeroInitialGuess, modifier));
251 }
else if (stepperType ==
"SSPDIRK32") {
253 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
254 useEmbedded, zeroInitialGuess, modifier));
256 }
else if (stepperType ==
"SSPDIRK23") {
258 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
259 useEmbedded, zeroInitialGuess, modifier));
261 }
else if (stepperType ==
"SSPDIRK33") {
263 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
264 useEmbedded, zeroInitialGuess, modifier));
266 }
else if (stepperType ==
"RK Implicit 1 Stage 1st order Radau IA") {
268 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
269 useEmbedded, zeroInitialGuess, modifier));
271 }
else if (stepperType ==
"RK Implicit 2 Stage 2nd order Lobatto IIIB") {
273 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
274 useEmbedded, zeroInitialGuess, modifier));
276 }
else if (stepperType ==
"SDIRK 5 Stage 4th order") {
278 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
279 useEmbedded, zeroInitialGuess, modifier));
281 }
else if (stepperType ==
"SDIRK 3 Stage 4th order") {
283 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
284 useEmbedded, zeroInitialGuess, modifier));
286 }
else if (stepperType ==
"SDIRK 5 Stage 5th order") {
288 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
289 useEmbedded, zeroInitialGuess, modifier));
291 }
else if (stepperType ==
"SDIRK 2(1) Pair") {
293 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
294 useEmbedded, zeroInitialGuess, modifier));
336 auto x = sh->getCurrentState()->getX();
338 testName = stepper->getStepperType() +
" - Modifier";
350 testDt = sh->getWorkingState()->getTimeStep()/10.0;
371 auto x = sh->getWorkingState()->getX();
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();
470 "Error - unknown action location.\n");
516 const double time,
const double dt,
517 const int stageNumber,
524 testX = get_ele(*(x), 0);
564 "Error - unknown action location.\n");
591 auto testNameOrig = stepper->getStepperType();
595 stepper->setModel(model);
597 stepper->setAppAction(modifier);
598 stepper->initialize();
600 auto testName = testNameOrig +
" - Modifier";
606 stepper->setInitialConditions(solutionHistory);
607 solutionHistory->initWorkingState();
609 solutionHistory->getWorkingState()->setTimeStep(dt);
610 stepper->takeStep(solutionHistory);
617 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
622 auto x = solutionHistory->getCurrentState()->getX();
624 x = solutionHistory->getWorkingState()->getX();
626 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
634 stepper->setModel(model);
636 stepper->setAppAction(observer);
637 stepper->setStepperName(testNameOrig);
638 stepper->initialize();
645 stepper->setInitialConditions(solutionHistory);
646 solutionHistory->initWorkingState();
648 solutionHistory->getWorkingState()->setTimeStep(dt);
649 stepper->takeStep(solutionHistory);
656 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
661 auto x = solutionHistory->getCurrentState()->getX();
663 x = solutionHistory->getWorkingState()->getX();
665 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
668 auto testName = testNameOrig +
" - Observer";
674 stepper->setModel(model);
676 stepper->setAppAction(modifierX);
677 stepper->setStepperName(testNameOrig);
678 stepper->initialize();
685 stepper->setInitialConditions(solutionHistory);
686 solutionHistory->initWorkingState();
688 solutionHistory->getWorkingState()->setTimeStep(dt);
689 stepper->takeStep(solutionHistory);
696 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
700 const double relTol = 1.0e-14;
702 auto x = solutionHistory->getCurrentState()->getX();
704 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
707 auto time = solutionHistory->getWorkingState()->getTime();
714 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
720 }
else if (stepper->isImplicit()) {
785 "Error - unknown stepperType = "+stepper->getStepperType());
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();
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();
874 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
878 const double relTol = 1.0e-14;
884 auto testName = testNameOrig +
" - Modifier";
894 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
903 testName = testNameOrig +
" - Observer";
913 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
921 auto time = solutionHistory->getWorkingState()->getTime();
928 TEST_COMPARE(modifierX->testStageNumber,==,stepper->getNumberOfStages()-1);
934 }
else if (stepper->isImplicit()) {
999 "Error - unknown stepperType = "+stepper->getStepperType());
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.
#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.