11 #include "Tempus_StepperLeapfrog.hpp"
17 #include "../TestModels/HarmonicOscillatorModel.hpp"
19 namespace Tempus_Unit_Test {
24 using Teuchos::rcp_const_cast;
25 using Teuchos::rcp_dynamic_cast;
26 using Teuchos::sublist;
36 stepper->setModel(model);
37 stepper->initialize();
42 stepper->setAppAction(modifier);
43 bool useFSAL = stepper->getUseFSAL();
44 std::string ICConsistency = stepper->getICConsistency();
45 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
48 stepper->setAppAction(modifier);
49 stepper->initialize();
51 stepper->setUseFSAL(useFSAL);
52 stepper->initialize();
54 stepper->setICConsistency(ICConsistency);
55 stepper->initialize();
57 stepper->setICConsistencyCheck(ICConsistencyCheck);
58 stepper->initialize();
63 model, useFSAL, ICConsistency, ICConsistencyCheck, modifier));
80 class StepperLeapfrogModifierTest
84 StepperLeapfrogModifierTest()
85 : testBEGIN_STEP(false),
86 testBEFORE_X_UPDATE(false),
87 testBEFORE_EXPLICIT_EVAL(false),
88 testBEFORE_XDOT_UPDATE(false),
90 testCurrentValue(-0.99),
91 testWorkingValue(-0.99),
98 virtual ~StepperLeapfrogModifierTest() {}
109 testBEGIN_STEP =
true;
110 auto x = sh->getCurrentState()->getX();
111 testCurrentValue = get_ele(*(x), 0);
115 testBEFORE_EXPLICIT_EVAL =
true;
116 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
117 sh->getWorkingState()->setTimeStep(testDt);
121 testBEFORE_X_UPDATE =
true;
122 testName =
"Leapfrog - Modifier";
123 stepper->setStepperName(testName);
127 testBEFORE_XDOT_UPDATE =
true;
128 auto x = sh->getWorkingState()->getX();
129 testWorkingValue = get_ele(*(x), 0);
138 "Error - unknown action location.\n");
142 bool testBEFORE_X_UPDATE;
143 bool testBEFORE_EXPLICIT_EVAL;
144 bool testBEFORE_XDOT_UPDATE;
146 double testCurrentValue;
147 double testWorkingValue;
149 std::string testName;
158 stepper->setModel(model);
159 auto modifier =
rcp(
new StepperLeapfrogModifierTest());
160 stepper->setAppAction(modifier);
161 stepper->initialize();
165 timeStepControl->setInitTimeStep(15.0);
166 timeStepControl->initialize();
169 auto inArgsIC = model->getNominalValues();
175 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
176 icState->setTime(timeStepControl->getInitTime());
177 icState->setIndex(timeStepControl->getInitIndex());
178 icState->setTimeStep(15.0);
179 icState->setOrder(stepper->getOrder());
184 solutionHistory->setName(
"Forward States");
186 solutionHistory->setStorageLimit(2);
187 solutionHistory->addState(icState);
190 stepper->setInitialConditions(solutionHistory);
191 solutionHistory->initWorkingState();
192 solutionHistory->getWorkingState()->setTimeStep(15.0);
193 stepper->takeStep(solutionHistory);
196 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
198 TEST_COMPARE(modifier->testBEFORE_XDOT_UPDATE, ==,
true);
201 auto x = solutionHistory->getCurrentState()->getX();
203 x = solutionHistory->getWorkingState()->getX();
205 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
208 TEST_COMPARE(modifier->testName, ==,
"Leapfrog - Modifier");
212 class StepperLeapfrogModifierXTest
216 StepperLeapfrogModifierXTest()
217 : testX_BEGIN_STEP(false),
218 testX_BEFORE_EXPLICIT_EVAL(false),
219 testX_BEFORE_X_UPDATE(false),
220 testX_BEFORE_XDOT_UPDATE(false),
221 testX_END_STEP(false),
230 virtual ~StepperLeapfrogModifierXTest() {}
241 testX_BEGIN_STEP =
true;
242 testX = get_ele(*(x), 0);
246 testX_BEFORE_EXPLICIT_EVAL =
true;
251 testX_BEFORE_X_UPDATE =
true;
256 testX_BEFORE_XDOT_UPDATE =
true;
257 testName =
"Leapfrog - ModifierX";
261 testX_END_STEP =
true;
266 "Error - unknown action location.\n");
269 bool testX_BEGIN_STEP;
270 bool testX_BEFORE_EXPLICIT_EVAL;
271 bool testX_BEFORE_X_UPDATE;
272 bool testX_BEFORE_XDOT_UPDATE;
277 std::string testName;
286 stepper->setModel(model);
287 auto modifierX =
rcp(
new StepperLeapfrogModifierXTest());
288 stepper->setAppAction(modifierX);
289 stepper->initialize();
293 timeStepControl->setInitTimeStep(15.0);
294 timeStepControl->initialize();
297 auto inArgsIC = model->getNominalValues();
303 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
304 icState->setTime(timeStepControl->getInitTime());
305 icState->setIndex(timeStepControl->getInitIndex());
306 icState->setTimeStep(15.0);
307 icState->setOrder(stepper->getOrder());
312 solutionHistory->setName(
"Forward States");
314 solutionHistory->setStorageLimit(2);
315 solutionHistory->addState(icState);
318 stepper->setInitialConditions(solutionHistory);
319 solutionHistory->initWorkingState();
320 solutionHistory->getWorkingState()->setTimeStep(15.0);
321 stepper->takeStep(solutionHistory);
324 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
325 TEST_COMPARE(modifierX->testX_BEFORE_XDOT_UPDATE, ==,
true);
326 TEST_COMPARE(modifierX->testX_BEFORE_X_UPDATE, ==,
true);
329 auto x = solutionHistory->getCurrentState()->getX();
331 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
333 auto time = solutionHistory->getWorkingState()->getTime();
335 TEST_COMPARE(modifierX->testName, ==,
"Leapfrog - ModifierX");
340 class StepperLeapfrogObserverTest
344 StepperLeapfrogObserverTest()
345 : testBEGIN_STEP(false),
346 testBEFORE_EXPLICIT_EVAL(false),
347 testBEFORE_X_UPDATE(false),
348 testBEFORE_XDOT_UPDATE(false),
350 testCurrentValue(-0.99),
351 testWorkingValue(-0.99),
357 virtual ~StepperLeapfrogObserverTest() {}
360 virtual void observe(
368 testBEGIN_STEP =
true;
369 auto x = sh->getCurrentState()->getX();
370 testCurrentValue = get_ele(*(x), 0);
374 testBEFORE_EXPLICIT_EVAL =
true;
375 testDt = sh->getWorkingState()->getTimeStep();
379 testBEFORE_X_UPDATE =
true;
380 testName = stepper->getStepperType();
384 testBEFORE_XDOT_UPDATE =
true;
385 auto x = sh->getWorkingState()->getX();
386 testWorkingValue = get_ele(*(x), 0);
395 "Error - unknown action location.\n");
399 bool testBEFORE_EXPLICIT_EVAL;
400 bool testBEFORE_X_UPDATE;
401 bool testBEFORE_XDOT_UPDATE;
403 double testCurrentValue;
404 double testWorkingValue;
406 std::string testName;
415 stepper->setModel(model);
416 auto observer =
rcp(
new StepperLeapfrogObserverTest());
417 stepper->setAppAction(observer);
418 stepper->initialize();
423 timeStepControl->setInitTimeStep(dt);
424 timeStepControl->initialize();
427 auto inArgsIC = model->getNominalValues();
433 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
434 icState->setTime(timeStepControl->getInitTime());
435 icState->setIndex(timeStepControl->getInitIndex());
436 icState->setTimeStep(dt);
437 icState->setOrder(stepper->getOrder());
442 solutionHistory->setName(
"Forward States");
444 solutionHistory->setStorageLimit(2);
445 solutionHistory->addState(icState);
448 stepper->setInitialConditions(solutionHistory);
449 solutionHistory->initWorkingState();
450 solutionHistory->getWorkingState()->setTimeStep(dt);
451 stepper->takeStep(solutionHistory);
455 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
457 TEST_COMPARE(observer->testBEFORE_XDOT_UPDATE, ==,
true);
460 auto x = solutionHistory->getCurrentState()->getX();
462 x = solutionHistory->getWorkingState()->getX();
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Before the explicit ME evaluation.
Default modifier for StepperLeapfrog.
Modify Before updating xDot.
Modify at the beginning of the step.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
Base ModifierX for StepperLeapfrog.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Base observer for StepperLeapfrog.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Base modifier for StepperLeapfrog.
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
Modify before updating x.
Modify at the end of the step.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
At the beginning of the step.
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)