14#include "../TestModels/DahlquistTestModel.hpp"
15#include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
16#include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
20using Teuchos::ParameterList;
23using Teuchos::rcp_const_cast;
24using Teuchos::rcp_dynamic_cast;
25using Teuchos::sublist;
40 explicitModel, implicitModel));
44 stepper->setModel(model);
45 stepper->initialize();
46 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
55 bool useFSAL = stepper->getUseFSAL();
56 std::string ICConsistency = stepper->getICConsistency();
57 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
58 bool zeroInitialGuess = stepper->getZeroInitialGuess();
59 std::string stepperType =
"IMEX RK SSP2";
61 auto explicitTableau = stepperERK->getTableau();
64 auto implicitTableau = stepperSDIRK->getTableau();
68 stepper->setAppAction(modifier);
69 stepper->initialize();
70 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71 stepper->setAppAction(modifierX);
72 stepper->initialize();
73 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setAppAction(observer);
75 stepper->initialize();
76 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 stepper->setSolver(solver);
78 stepper->initialize();
79 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
80 stepper->setUseFSAL(useFSAL);
81 stepper->initialize();
82 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 stepper->setICConsistency(ICConsistency);
84 stepper->initialize();
85 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86 stepper->setICConsistencyCheck(ICConsistencyCheck);
87 stepper->initialize();
88 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 stepper->setZeroInitialGuess(zeroInitialGuess);
90 stepper->initialize();
91 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93 stepper->setStepperName(stepperType);
94 stepper->initialize();
95 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96 stepper->setExplicitTableau(explicitTableau);
97 stepper->initialize();
98 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
99 stepper->setImplicitTableau(implicitTableau);
100 stepper->initialize();
101 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
102 stepper->setOrder(order);
103 stepper->initialize();
104 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
106 TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
107 TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
108 TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
112 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
113 zeroInitialGuess, modifier, stepperType, explicitTableau, implicitTableau,
115 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
118 TEUCHOS_ASSERT(stepper->getOrder() == 2);
131 explicitModel, implicitModel));
146 explicitModel, implicitModel));
150 auto stepper = sf->createStepper(
"General IMEX RK", model);
151 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
157 StepperFactory_Construction_General_wo_Parameterlist_Model)
165 explicitModel, implicitModel));
169 auto stepper = sf->createStepper(
"General IMEX RK");
170 stepper->setModel(model);
171 stepper->initialize();
172 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
186 explicitModel, implicitModel));
191class StepperRKModifierIMEX_TrapezoidaTest
195 StepperRKModifierIMEX_TrapezoidaTest(Teuchos::FancyOStream &Out,
197 : out(Out), success(Success)
203 virtual ~StepperRKModifierIMEX_TrapezoidaTest() {}
211 const double relTol = 1.0e-14;
213 Teuchos::rcp_dynamic_cast<const Tempus::StepperIMEX_RK<double>>(stepper,
215 auto stageNumber = stepper->getStageNumber();
216 Teuchos::SerialDenseVector<int, double> c = stepper_imex->getTableau()->c();
217 Teuchos::SerialDenseVector<int, double> chat =
218 stepper_imex->getImplicitTableau()->c();
220 auto currentState = sh->getCurrentState();
221 auto workingState = sh->getWorkingState();
222 const double dt = workingState->getTimeStep();
223 double time = currentState->getTime();
224 double imp_time = time;
225 if (stageNumber >= 0) {
226 time += c(stageNumber) * dt;
227 imp_time += chat(stageNumber) * dt;
230 auto x = workingState->getX();
231 auto xDot = workingState->getXDot();
232 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
235 case StepperRKAppAction<double>::BEGIN_STEP: {
237 auto imex_me = Teuchos::rcp_dynamic_cast<
239 stepper->getModel(),
true);
240 auto explicitModel = Teuchos::rcp_dynamic_cast<
242 imex_me->getExplicitModel(),
true);
243 auto implicitModel = Teuchos::rcp_dynamic_cast<
245 imex_me->getImplicitModel(),
true);
247 TEST_FLOATING_EQUALITY(explicitModel->getLambda(), 1.0, relTol);
248 TEST_FLOATING_EQUALITY(implicitModel->getLambda(), 2.0, relTol);
250 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
252 const double x_0 = get_ele(*(x), 0);
253 TEST_FLOATING_EQUALITY(x_0, 1.0, relTol);
254 TEST_ASSERT(std::abs(time) < relTol);
255 TEST_ASSERT(std::abs(imp_time) < relTol);
256 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
257 TEST_COMPARE(stageNumber, ==, -1);
260 case StepperRKAppAction<double>::BEGIN_STAGE:
261 case StepperRKAppAction<double>::BEFORE_SOLVE: {
262 const double X_i = get_ele(*(x), 0);
263 const double f_i = get_ele(*(xDot), 0);
265 if (stageNumber == 0) {
266 TEST_FLOATING_EQUALITY(X_i, 1.0, relTol);
267 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
268 TEST_FLOATING_EQUALITY(imp_time, 0.78867513459481275, relTol);
269 TEST_ASSERT(std::abs(time) < relTol);
271 else if (stageNumber == 1) {
272 TEST_FLOATING_EQUALITY(X_i, -std::sqrt(3), relTol);
273 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
274 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
275 TEST_FLOATING_EQUALITY(imp_time, 0.21132486540518725, relTol);
278 TEUCHOS_TEST_FOR_EXCEPT(!(-1 < stageNumber && stageNumber < 2));
283 case StepperRKAppAction<double>::AFTER_SOLVE:
284 case StepperRKAppAction<double>::BEFORE_EXPLICIT_EVAL:
285 case StepperRKAppAction<double>::END_STAGE: {
286 const double X_i = get_ele(*(x), 0);
287 const double f_i = get_ele(*(xDot), 0);
289 if (stageNumber == 0) {
291 TEST_FLOATING_EQUALITY(X_i, -std::sqrt(3), relTol);
292 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
293 TEST_FLOATING_EQUALITY(imp_time, 0.78867513459481275, relTol);
294 TEST_ASSERT(std::abs(time) < relTol);
296 else if (stageNumber == 1) {
298 TEST_FLOATING_EQUALITY(X_i, 3.0 - 3.0 * std::sqrt(3.0),
300 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
301 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
304 TEUCHOS_TEST_FOR_EXCEPT(!(-1 < stageNumber && stageNumber < 2));
309 case StepperRKAppAction<double>::END_STEP: {
310 const double x_1 = get_ele(*(x), 0);
311 time = workingState->getTime();
312 TEST_FLOATING_EQUALITY(x_1, -(6.0 * std::sqrt(3) - 11.0 / 2.0),
314 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
315 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
316 TEST_COMPARE(stageNumber, ==, -1);
322 Teuchos::FancyOStream &out;
330 Teuchos::RCP<const Thyra::ModelEvaluator<double>> explicitModel =
332 Teuchos::RCP<const Thyra::ModelEvaluator<double>> implicitModel =
336 explicitModel, implicitModel));
338 auto modifier = rcp(
new StepperRKModifierIMEX_TrapezoidaTest(out, success));
342 stepper->setModel(model);
348 bool useFSAL = stepper->getUseFSAL();
349 std::string ICConsistency = stepper->getICConsistency();
350 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
351 bool zeroInitialGuess = stepper->getZeroInitialGuess();
352 std::string stepperType =
"IMEX RK SSP2";
354 auto explicitTableau = stepperERK->getTableau();
357 auto implicitTableau = stepperSDIRK->getTableau();
360 stepper->setStepperName(stepperType);
361 stepper->setExplicitTableau(explicitTableau);
362 stepper->setImplicitTableau(implicitTableau);
363 stepper->setOrder(order);
364 stepper->setSolver(solver);
365 stepper->setUseFSAL(useFSAL);
366 stepper->setICConsistency(ICConsistency);
367 stepper->setICConsistencyCheck(ICConsistencyCheck);
368 stepper->setZeroInitialGuess(zeroInitialGuess);
370 stepper->setModel(model);
371 stepper->setAppAction(modifier);
372 stepper->setUseFSAL(
false);
373 stepper->initialize();
379 stepper->setInitialConditions(solutionHistory);
380 solutionHistory->initWorkingState();
382 solutionHistory->getWorkingState()->setTimeStep(dt);
383 solutionHistory->getWorkingState()->setTime(dt);
384 stepper->takeStep(solutionHistory);
387 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.