13#include "../TestModels/DahlquistTestModel.hpp"
14#include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
15#include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
22using Teuchos::rcp_const_cast;
23using Teuchos::rcp_dynamic_cast;
24using Teuchos::ParameterList;
25using Teuchos::sublist;
39 explicitModel, implicitModel));
43 stepper->setModel(model);
44 stepper->initialize();
45 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
54 bool useFSAL = stepper->getUseFSAL();
55 std::string ICConsistency = stepper->getICConsistency();
56 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
57 bool zeroInitialGuess = stepper->getZeroInitialGuess();
58 std::string stepperType =
"IMEX RK SSP2";
60 auto explicitTableau = stepperERK->getTableau();
62 auto implicitTableau = stepperSDIRK->getTableau();
67 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
68 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
69 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76 stepper->setStepperName(stepperType); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 stepper->setExplicitTableau(explicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 stepper->setImplicitTableau(implicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 stepper->setOrder(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
81 TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
82 TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
83 TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
87 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
88 zeroInitialGuess, modifier, stepperType, explicitTableau,
89 implicitTableau, order));
90 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93 TEUCHOS_ASSERT(stepper->getOrder() == 2);
105 explicitModel, implicitModel));
119 explicitModel, implicitModel));
123 auto stepper = sf->createStepper(
"General IMEX RK", model);
124 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
136 explicitModel, implicitModel));
140 auto stepper = sf->createStepper(
"General IMEX RK");
141 stepper->setModel(model);
142 stepper->initialize();
143 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
156 explicitModel, implicitModel));
163class StepperRKModifierIMEX_TrapezoidaTest
169 StepperRKModifierIMEX_TrapezoidaTest(Teuchos::FancyOStream &Out,
bool &Success)
170 : out(Out), success(Success)
175 virtual ~StepperRKModifierIMEX_TrapezoidaTest(){}
183 const double relTol = 1.0e-14;
184 auto stepper_imex = Teuchos::rcp_dynamic_cast<const Tempus::StepperIMEX_RK<double>>(stepper,
true);
185 auto stageNumber = stepper->getStageNumber();
186 Teuchos::SerialDenseVector<int,double> c = stepper_imex->getTableau()->c();
187 Teuchos::SerialDenseVector<int,double> chat = stepper_imex->getImplicitTableau()->c();
189 auto currentState = sh->getCurrentState();
190 auto workingState = sh->getWorkingState();
191 const double dt = workingState->getTimeStep();
192 double time = currentState->getTime();
193 double imp_time = time;
194 if (stageNumber >= 0) {
195 time += c(stageNumber)*dt;
196 imp_time += chat(stageNumber)*dt;
199 auto x = workingState->getX();
200 auto xDot = workingState->getXDot();
201 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
204 case StepperRKAppAction<double>::BEGIN_STEP:
208 auto imex_me = Teuchos::rcp_dynamic_cast<const Tempus::WrapperModelEvaluatorPairIMEX_Basic<double>>(stepper->getModel(),
true);
209 auto explicitModel = Teuchos::rcp_dynamic_cast<const Tempus_Test::DahlquistTestModel<double> > (imex_me->getExplicitModel(),
true);
210 auto implicitModel = Teuchos::rcp_dynamic_cast<const Tempus_Test::DahlquistTestModel<double> > (imex_me->getImplicitModel(),
true);
212 TEST_FLOATING_EQUALITY(explicitModel->getLambda(), 1.0, relTol);
213 TEST_FLOATING_EQUALITY(implicitModel->getLambda(), 2.0, relTol);
215 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
217 const double x_0 = get_ele(*(x), 0);
218 TEST_FLOATING_EQUALITY(x_0, 1.0, relTol);
219 TEST_ASSERT(std::abs(time) < relTol);
220 TEST_ASSERT(std::abs(imp_time) < relTol);
221 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
222 TEST_COMPARE(stageNumber, ==, -1);
225 case StepperRKAppAction<double>::BEGIN_STAGE:
226 case StepperRKAppAction<double>::BEFORE_SOLVE:
228 const double X_i = get_ele(*(x), 0);
229 const double f_i = get_ele(*(xDot), 0);
231 if (stageNumber == 0) {
232 TEST_FLOATING_EQUALITY(X_i , 1.0 , relTol);
233 TEST_FLOATING_EQUALITY(f_i , 1.0 , relTol);
234 TEST_FLOATING_EQUALITY(imp_time , 0.78867513459481275 , relTol);
235 TEST_ASSERT(std::abs(time) < relTol);
236 }
else if (stageNumber == 1) {
237 TEST_FLOATING_EQUALITY(X_i , -std::sqrt(3) , relTol);
238 TEST_FLOATING_EQUALITY(f_i , 1.0 , relTol);
239 TEST_FLOATING_EQUALITY(time , 1.0 , relTol);
240 TEST_FLOATING_EQUALITY(imp_time , 0.21132486540518725 , relTol);
242 TEUCHOS_TEST_FOR_EXCEPT( !(-1 < stageNumber && stageNumber < 2));
247 case StepperRKAppAction<double>::AFTER_SOLVE:
248 case StepperRKAppAction<double>::BEFORE_EXPLICIT_EVAL:
249 case StepperRKAppAction<double>::END_STAGE:
251 const double X_i = get_ele(*(x), 0);
252 const double f_i = get_ele(*(xDot), 0);
254 if (stageNumber == 0) {
256 TEST_FLOATING_EQUALITY(X_i, -std::sqrt(3), relTol);
257 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
258 TEST_FLOATING_EQUALITY(imp_time , 0.78867513459481275 , relTol);
259 TEST_ASSERT(std::abs(time) < relTol);
260 }
else if (stageNumber == 1) {
262 TEST_FLOATING_EQUALITY(X_i, 3.0 - 3.0*std::sqrt(3.0), relTol);
263 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
264 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
266 TEUCHOS_TEST_FOR_EXCEPT( !(-1 < stageNumber && stageNumber < 2));
271 case StepperRKAppAction<double>::END_STEP:
273 const double x_1 = get_ele(*(x), 0);
274 time = workingState->getTime();
275 TEST_FLOATING_EQUALITY(x_1, -(6.0*std::sqrt(3) - 11.0/2.0), relTol);
276 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
277 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
278 TEST_COMPARE(stageNumber, ==, -1);
289 Teuchos::FancyOStream & out;
302 explicitModel, implicitModel));
304 auto modifier = rcp(
new StepperRKModifierIMEX_TrapezoidaTest(out, success));
309 stepper->setModel(model);
315 bool useFSAL = stepper->getUseFSAL();
316 std::string ICConsistency = stepper->getICConsistency();
317 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
318 bool zeroInitialGuess = stepper->getZeroInitialGuess();
319 std::string stepperType =
"IMEX RK SSP2";
321 auto explicitTableau = stepperERK->getTableau();
323 auto implicitTableau = stepperSDIRK->getTableau();
326 stepper->setStepperName(stepperType);
327 stepper->setExplicitTableau(explicitTableau);
328 stepper->setImplicitTableau(implicitTableau);
329 stepper->setOrder(order);
330 stepper->setSolver(solver);
331 stepper->setUseFSAL(useFSAL);
332 stepper->setICConsistency(ICConsistency);
333 stepper->setICConsistencyCheck(ICConsistencyCheck);
334 stepper->setZeroInitialGuess(zeroInitialGuess);
336 stepper->setModel(model);
337 stepper->setAppAction(modifier);
338 stepper->setUseFSAL(
false);
339 stepper->initialize();
345 stepper->setInitialConditions(solutionHistory);
346 solutionHistory->initWorkingState();
348 solutionHistory->getWorkingState()->setTimeStep(dt);
349 solutionHistory->getWorkingState()->setTime(dt);
350 stepper->takeStep(solutionHistory);
353 TEUCHOS_ASSERT(stepper->getOrder() == 2);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Explicit Runge-Kutta time stepper.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
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.
Default ModifierX for StepperRK.
Default observer for StepperRK.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
The classic Dahlquist Test Problem.
van der Pol model formulated for IMEX.
van der Pol model formulated for IMEX-RK.
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_UNIT_TEST(BackwardEuler, Default_Construction)
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
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.