11 #include "../TestModels/DahlquistTestModel.hpp"
13 #include "Tempus_SolutionHistory.hpp"
20 namespace Tempus_Unit_Test {
24 using Teuchos::rcp_const_cast;
25 using Teuchos::rcp_dynamic_cast;
118 class StepperRKModifierBogackiShampineTest
125 : out(Out), success(Success)
129 virtual ~StepperRKModifierBogackiShampineTest(){}
137 const double relTol = 1.0e-14;
138 auto stageNumber = stepper->getStageNumber();
141 auto currentState = sh->getCurrentState();
142 auto workingState = sh->getWorkingState();
143 const double dt = workingState->getTimeStep();
144 double time = currentState->getTime();
145 if (stageNumber >= 0) time += c(stageNumber)*dt;
147 auto x = workingState->getX();
148 auto xDot = workingState->getXDot();
149 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
154 auto DME = Teuchos::rcp_dynamic_cast<
160 const double x_0 = get_ele(*(x), 0);
161 const double xDot_0 = get_ele(*(xDot), 0);
173 const double X_i = get_ele(*(x), 0);
174 const double f_i = get_ele(*(xDot), 0);
175 if (stageNumber == 0) {
179 !stepper->getUseFSAL()) {
185 }
else if (stageNumber == 1) {
194 }
else if (stageNumber == 2) {
203 }
else if (stageNumber == 3) {
208 }
else if (workingState->getNConsecutiveFailures() > 0) {
220 const double x_1 = get_ele(*(x), 0);
221 time = workingState->getTime();
227 if (stepper->getUseEmbedded() ==
true) {
229 TEST_ASSERT(std::abs(workingState->getTolAbs()) < relTol);
231 TEST_ASSERT(std::abs(workingState->getErrorRel()) < relTol);
236 "Error - unknown action location.\n");
254 auto modifier =
rcp(
new StepperRKModifierBogackiShampineTest(out, success));
256 stepper->setModel(model);
257 stepper->setAppAction(modifier);
258 stepper->setICConsistency(
"Consistent");
259 stepper->setUseFSAL(
false);
260 stepper->initialize();
266 stepper->setInitialConditions(solutionHistory);
267 solutionHistory->initWorkingState();
269 solutionHistory->getWorkingState()->setTimeStep(dt);
270 solutionHistory->getWorkingState()->setTime(dt);
271 stepper->takeStep(solutionHistory);
285 auto modifier =
rcp(
new StepperRKModifierBogackiShampineTest(out, success));
287 stepper->setModel(model);
288 stepper->setAppAction(modifier);
289 stepper->setICConsistency(
"Consistent");
290 stepper->setUseFSAL(
true);
291 stepper->initialize();
297 stepper->setInitialConditions(solutionHistory);
298 solutionHistory->initWorkingState();
300 solutionHistory->getWorkingState()->setTimeStep(dt);
301 solutionHistory->getWorkingState()->setTime(dt);
302 stepper->takeStep(solutionHistory);
316 auto modifier =
rcp(
new StepperRKModifierBogackiShampineTest(out, success));
318 stepper->setModel(model);
319 stepper->setAppAction(modifier);
320 stepper->setICConsistency(
"Consistent");
321 stepper->setUseFSAL(
true);
322 stepper->initialize();
328 stepper->setInitialConditions(solutionHistory);
329 solutionHistory->initWorkingState();
331 solutionHistory->getWorkingState()->setTimeStep(dt);
332 solutionHistory->getWorkingState()->setTime(dt);
333 solutionHistory->getWorkingState()->setNConsecutiveFailures(1);
334 stepper->takeStep(solutionHistory);
348 auto modifier =
rcp(
new StepperRKModifierBogackiShampineTest(out, success));
350 stepper->setModel(model);
351 stepper->setAppAction(modifier);
352 stepper->setICConsistency(
"Consistent");
353 stepper->setUseFSAL(
false);
354 stepper->setUseEmbedded(
true);
355 stepper->initialize();
361 stepper->setInitialConditions(solutionHistory);
362 solutionHistory->initWorkingState();
364 solutionHistory->getWorkingState()->setTimeStep(dt);
365 solutionHistory->getWorkingState()->setTime(dt);
366 solutionHistory->getWorkingState()->setTolRel(1.0);
367 solutionHistory->getWorkingState()->setTolAbs(0.0);
368 stepper->takeStep(solutionHistory);
381 class StepperRKModifierXBogackiShampineTest
388 : out(Out), success(Success)
392 virtual ~StepperRKModifierXBogackiShampineTest(){}
397 const double time,
const double dt,
const int stageNumber,
400 const double relTol = 1.0e-14;
402 const double x_0 = get_ele(*(x), 0);
413 const double X_i = get_ele(*(x), 0);
414 if (stageNumber == 0) {
417 }
else if (stageNumber == 1) {
420 }
else if (stageNumber == 2) {
423 }
else if (stageNumber == 3) {
432 const double x_1 = get_ele(*(x), 0);
440 "Error - unknown action location.\n");
458 auto modifierX =
rcp(
new StepperRKModifierXBogackiShampineTest(out, success));
460 stepper->setModel(model);
461 stepper->setAppAction(modifierX);
462 stepper->setICConsistency(
"Consistent");
463 stepper->setUseFSAL(
false);
464 stepper->initialize();
470 stepper->setInitialConditions(solutionHistory);
471 solutionHistory->initWorkingState();
473 solutionHistory->getWorkingState()->setTimeStep(dt);
474 solutionHistory->getWorkingState()->setTime(dt);
475 stepper->takeStep(solutionHistory);
489 auto modifierX =
rcp(
new StepperRKModifierXBogackiShampineTest(out, success));
491 stepper->setModel(model);
492 stepper->setAppAction(modifierX);
493 stepper->setICConsistency(
"Consistent");
494 stepper->setUseFSAL(
true);
495 stepper->initialize();
501 stepper->setInitialConditions(solutionHistory);
502 solutionHistory->initWorkingState();
504 solutionHistory->getWorkingState()->setTimeStep(dt);
505 solutionHistory->getWorkingState()->setTime(dt);
506 stepper->takeStep(solutionHistory);
520 auto modifierX =
rcp(
new StepperRKModifierXBogackiShampineTest(out, success));
522 stepper->setModel(model);
523 stepper->setAppAction(modifierX);
524 stepper->setICConsistency(
"Consistent");
525 stepper->setUseFSAL(
true);
526 stepper->initialize();
532 stepper->setInitialConditions(solutionHistory);
533 solutionHistory->initWorkingState();
535 solutionHistory->getWorkingState()->setTimeStep(dt);
536 solutionHistory->getWorkingState()->setTime(dt);
537 solutionHistory->getWorkingState()->setNConsecutiveFailures(1);
538 stepper->takeStep(solutionHistory);
At the beginning of the stage.
At the beginning of the step.
Modify at the end of the step.
Modify after the implicit solve.
Base ModifierX for StepperRK.
Modify at the beginning of the stage.
The classic Dahlquist Test Problem.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Before the implicit solve.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Modify before the implicit solve.
Base class for Runge-Kutta methods, ExplicitRK, DIRK and IMEX.
Modify at the beginning of the step.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Explicit RK Bogacki-Shampine Butcher Tableau.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Modify at the end of the stage.
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).
After the implicit solve.
Before the explicit evaluation.
#define TEUCHOS_ASSERT(assertion_test)
Base modifier for StepperRK.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const int, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.