9 #include "Teuchos_UnitTestHarness.hpp" 10 #include "Teuchos_XMLParameterListHelpers.hpp" 11 #include "Teuchos_TimeMonitor.hpp" 12 #include "Teuchos_DefaultComm.hpp" 14 #include "Thyra_VectorStdOps.hpp" 16 #include "Tempus_SolutionHistory.hpp" 17 #include "Tempus_StepperFactory.hpp" 22 #include "../TestModels/DahlquistTestModel.hpp" 23 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp" 24 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp" 25 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 34 using Teuchos::rcp_const_cast;
35 using Teuchos::rcp_dynamic_cast;
36 using Teuchos::ParameterList;
37 using Teuchos::sublist;
38 using Teuchos::getParametersFromXmlFile;
52 explicitModel, implicitModel));
56 stepper->setModel(model);
57 stepper->initialize();
58 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
67 bool useFSAL = stepper->getUseFSAL();
68 std::string ICConsistency = stepper->getICConsistency();
69 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
70 bool zeroInitialGuess = stepper->getZeroInitialGuess();
71 std::string stepperType =
"IMEX RK SSP2";
73 auto explicitTableau = stepperERK->getTableau();
75 auto implicitTableau = stepperSDIRK->getTableau();
80 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
81 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 stepper->setStepperName(stepperType); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90 stepper->setExplicitTableau(explicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91 stepper->setImplicitTableau(implicitTableau); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92 stepper->setOrder(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94 TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getTableau());
95 TEUCHOS_TEST_FOR_EXCEPT(explicitTableau != stepper->getExplicitTableau());
96 TEUCHOS_TEST_FOR_EXCEPT(implicitTableau != stepper->getImplicitTableau());
100 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
101 zeroInitialGuess, modifier, stepperType, explicitTableau,
102 implicitTableau, order));
103 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
106 TEUCHOS_ASSERT(stepper->getOrder() == 2);
118 explicitModel, implicitModel));
132 explicitModel, implicitModel));
136 auto stepper = sf->createStepper(
"General IMEX RK", model);
137 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
149 explicitModel, implicitModel));
153 auto stepper = sf->createStepper(
"General IMEX RK");
154 stepper->setModel(model);
155 stepper->initialize();
156 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
169 explicitModel, implicitModel));
176 class StepperRKModifierIMEX_TrapezoidaTest
182 StepperRKModifierIMEX_TrapezoidaTest(Teuchos::FancyOStream &Out,
bool &Success)
183 : out(Out), success(Success)
188 virtual ~StepperRKModifierIMEX_TrapezoidaTest(){}
196 const double relTol = 1.0e-14;
199 Teuchos::SerialDenseVector<int,double> c = stepper_imex->getTableau()->c();
200 Teuchos::SerialDenseVector<int,double> chat = stepper_imex->getImplicitTableau()->c();
202 auto currentState = sh->getCurrentState();
203 auto workingState = sh->getWorkingState();
204 const double dt = workingState->getTimeStep();
205 double time = currentState->getTime();
206 double imp_time = time;
207 if (stageNumber >= 0) {
208 time += c(stageNumber)*dt;
209 imp_time += chat(stageNumber)*dt;
212 auto x = workingState->getX();
213 auto xDot = workingState->getXDot();
214 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
225 TEST_FLOATING_EQUALITY(explicitModel->getLambda(), 1.0, relTol);
226 TEST_FLOATING_EQUALITY(implicitModel->getLambda(), 2.0, relTol);
228 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
230 const double x_0 = get_ele(*(x), 0);
231 TEST_FLOATING_EQUALITY(x_0, 1.0, relTol);
232 TEST_ASSERT(std::abs(time) < relTol);
233 TEST_ASSERT(std::abs(imp_time) < relTol);
234 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
235 TEST_COMPARE(stageNumber, ==, -1);
241 const double X_i = get_ele(*(x), 0);
242 const double f_i = get_ele(*(xDot), 0);
244 if (stageNumber == 0) {
245 TEST_FLOATING_EQUALITY(X_i , 1.0 , relTol);
246 TEST_FLOATING_EQUALITY(f_i , 1.0 , relTol);
247 TEST_FLOATING_EQUALITY(imp_time , 0.78867513459481275 , relTol);
248 TEST_ASSERT(std::abs(time) < relTol);
249 }
else if (stageNumber == 1) {
250 TEST_FLOATING_EQUALITY(X_i , -std::sqrt(3) , relTol);
251 TEST_FLOATING_EQUALITY(f_i , 1.0 , relTol);
252 TEST_FLOATING_EQUALITY(time , 1.0 , relTol);
253 TEST_FLOATING_EQUALITY(imp_time , 0.21132486540518725 , relTol);
255 TEUCHOS_TEST_FOR_EXCEPT( !(-1 < stageNumber && stageNumber < 2));
264 const double X_i = get_ele(*(x), 0);
265 const double f_i = get_ele(*(xDot), 0);
267 if (stageNumber == 0) {
269 TEST_FLOATING_EQUALITY(X_i, -std::sqrt(3), relTol);
270 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
271 TEST_FLOATING_EQUALITY(imp_time , 0.78867513459481275 , relTol);
272 TEST_ASSERT(std::abs(time) < relTol);
273 }
else if (stageNumber == 1) {
275 TEST_FLOATING_EQUALITY(X_i, 3.0 - 3.0*std::sqrt(3.0), relTol);
276 TEST_FLOATING_EQUALITY(f_i, 1.0, relTol);
277 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
279 TEUCHOS_TEST_FOR_EXCEPT( !(-1 < stageNumber && stageNumber < 2));
286 const double x_1 = get_ele(*(x), 0);
287 time = workingState->getTime();
288 TEST_FLOATING_EQUALITY(x_1, -(6.0*std::sqrt(3) - 11.0/2.0), relTol);
289 TEST_FLOATING_EQUALITY(time, 1.0, relTol);
290 TEST_FLOATING_EQUALITY(dt, 1.0, relTol);
291 TEST_COMPARE(stageNumber, ==, -1);
302 Teuchos::FancyOStream & out;
315 explicitModel, implicitModel));
317 auto modifier = rcp(
new StepperRKModifierIMEX_TrapezoidaTest(out, success));
322 stepper->setModel(model);
328 bool useFSAL = stepper->getUseFSAL();
329 std::string ICConsistency = stepper->getICConsistency();
330 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
331 bool zeroInitialGuess = stepper->getZeroInitialGuess();
332 std::string stepperType =
"IMEX RK SSP2";
334 auto explicitTableau = stepperERK->getTableau();
336 auto implicitTableau = stepperSDIRK->getTableau();
339 stepper->setStepperName(stepperType);
340 stepper->setExplicitTableau(explicitTableau);
341 stepper->setImplicitTableau(implicitTableau);
342 stepper->setOrder(order);
343 stepper->setSolver(solver);
344 stepper->setUseFSAL(useFSAL);
345 stepper->setICConsistency(ICConsistency);
346 stepper->setICConsistencyCheck(ICConsistencyCheck);
347 stepper->setZeroInitialGuess(zeroInitialGuess);
349 stepper->setModel(model);
350 stepper->setAppAction(modifier);
351 stepper->setUseFSAL(
false);
352 stepper->initialize();
358 stepper->setInitialConditions(solutionHistory);
359 solutionHistory->initWorkingState();
361 solutionHistory->getWorkingState()->setTimeStep(dt);
362 solutionHistory->getWorkingState()->setTime(dt);
363 stepper->takeStep(solutionHistory);
366 TEUCHOS_ASSERT(stepper->getOrder() == 2);
At the beginning of the stage.
At the beginning of the step.
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.
Default observer for StepperRK.
Explicit Runge-Kutta time stepper.
virtual int getStageNumber() const
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
The classic Dahlquist Test Problem.
ModelEvaluator pair for implicit and explicit (IMEX) evaulations.
Implicit-Explicit Runge-Kutta (IMEX-RK) time stepper.
Before the implicit solve.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Default ModifierX for StepperRK.
After the implicit solve.
Before the explicit evaluation.
Default modifier for StepperRK.
van der Pol model formulated for IMEX.
Base modifier for StepperRK.