12 #include "Tempus_StepperLeapfrog.hpp"
18 #include "../TestModels/HarmonicOscillatorModel.hpp"
20 namespace Tempus_Unit_Test {
25 using Teuchos::rcp_const_cast;
26 using Teuchos::rcp_dynamic_cast;
27 using Teuchos::sublist;
37 stepper->setModel(model);
38 stepper->initialize();
43 stepper->setAppAction(modifier);
44 bool useFSAL = stepper->getUseFSAL();
45 std::string ICConsistency = stepper->getICConsistency();
46 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
49 stepper->setAppAction(modifier);
50 stepper->initialize();
52 stepper->setUseFSAL(useFSAL);
53 stepper->initialize();
55 stepper->setICConsistency(ICConsistency);
56 stepper->initialize();
58 stepper->setICConsistencyCheck(ICConsistencyCheck);
59 stepper->initialize();
64 model, useFSAL, ICConsistency, ICConsistencyCheck, modifier));
81 class StepperLeapfrogModifierTest
85 StepperLeapfrogModifierTest()
86 : testBEGIN_STEP(false),
87 testBEFORE_X_UPDATE(false),
88 testBEFORE_EXPLICIT_EVAL(false),
89 testBEFORE_XDOT_UPDATE(false),
91 testCurrentValue(-0.99),
92 testWorkingValue(-0.99),
99 virtual ~StepperLeapfrogModifierTest() {}
110 testBEGIN_STEP =
true;
111 auto x = sh->getCurrentState()->getX();
112 testCurrentValue = get_ele(*(x), 0);
116 testBEFORE_EXPLICIT_EVAL =
true;
117 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
118 sh->getWorkingState()->setTimeStep(testDt);
122 testBEFORE_X_UPDATE =
true;
123 testName =
"Leapfrog - Modifier";
124 stepper->setStepperName(testName);
128 testBEFORE_XDOT_UPDATE =
true;
129 auto x = sh->getWorkingState()->getX();
130 testWorkingValue = get_ele(*(x), 0);
139 "Error - unknown action location.\n");
143 bool testBEFORE_X_UPDATE;
144 bool testBEFORE_EXPLICIT_EVAL;
145 bool testBEFORE_XDOT_UPDATE;
147 double testCurrentValue;
148 double testWorkingValue;
150 std::string testName;
159 stepper->setModel(model);
160 auto modifier =
rcp(
new StepperLeapfrogModifierTest());
161 stepper->setAppAction(modifier);
162 stepper->initialize();
166 timeStepControl->setInitTimeStep(15.0);
167 timeStepControl->initialize();
170 auto inArgsIC = model->getNominalValues();
176 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
177 icState->setTime(timeStepControl->getInitTime());
178 icState->setIndex(timeStepControl->getInitIndex());
179 icState->setTimeStep(15.0);
180 icState->setOrder(stepper->getOrder());
185 solutionHistory->setName(
"Forward States");
187 solutionHistory->setStorageLimit(2);
188 solutionHistory->addState(icState);
191 stepper->setInitialConditions(solutionHistory);
192 solutionHistory->initWorkingState();
193 solutionHistory->getWorkingState()->setTimeStep(15.0);
194 stepper->takeStep(solutionHistory);
197 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
199 TEST_COMPARE(modifier->testBEFORE_XDOT_UPDATE, ==,
true);
202 auto x = solutionHistory->getCurrentState()->getX();
204 x = solutionHistory->getWorkingState()->getX();
206 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
209 TEST_COMPARE(modifier->testName, ==,
"Leapfrog - Modifier");
213 class StepperLeapfrogModifierXTest
217 StepperLeapfrogModifierXTest()
218 : testX_BEGIN_STEP(false),
219 testX_BEFORE_EXPLICIT_EVAL(false),
220 testX_BEFORE_X_UPDATE(false),
221 testX_BEFORE_XDOT_UPDATE(false),
222 testX_END_STEP(false),
231 virtual ~StepperLeapfrogModifierXTest() {}
242 testX_BEGIN_STEP =
true;
243 testX = get_ele(*(x), 0);
247 testX_BEFORE_EXPLICIT_EVAL =
true;
252 testX_BEFORE_X_UPDATE =
true;
257 testX_BEFORE_XDOT_UPDATE =
true;
258 testName =
"Leapfrog - ModifierX";
262 testX_END_STEP =
true;
267 "Error - unknown action location.\n");
270 bool testX_BEGIN_STEP;
271 bool testX_BEFORE_EXPLICIT_EVAL;
272 bool testX_BEFORE_X_UPDATE;
273 bool testX_BEFORE_XDOT_UPDATE;
278 std::string testName;
287 stepper->setModel(model);
288 auto modifierX =
rcp(
new StepperLeapfrogModifierXTest());
289 stepper->setAppAction(modifierX);
290 stepper->initialize();
294 timeStepControl->setInitTimeStep(15.0);
295 timeStepControl->initialize();
298 auto inArgsIC = model->getNominalValues();
304 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
305 icState->setTime(timeStepControl->getInitTime());
306 icState->setIndex(timeStepControl->getInitIndex());
307 icState->setTimeStep(15.0);
308 icState->setOrder(stepper->getOrder());
313 solutionHistory->setName(
"Forward States");
315 solutionHistory->setStorageLimit(2);
316 solutionHistory->addState(icState);
319 stepper->setInitialConditions(solutionHistory);
320 solutionHistory->initWorkingState();
321 solutionHistory->getWorkingState()->setTimeStep(15.0);
322 stepper->takeStep(solutionHistory);
325 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
326 TEST_COMPARE(modifierX->testX_BEFORE_XDOT_UPDATE, ==,
true);
327 TEST_COMPARE(modifierX->testX_BEFORE_X_UPDATE, ==,
true);
330 auto x = solutionHistory->getCurrentState()->getX();
332 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
334 auto time = solutionHistory->getWorkingState()->getTime();
336 TEST_COMPARE(modifierX->testName, ==,
"Leapfrog - ModifierX");
341 class StepperLeapfrogObserverTest
345 StepperLeapfrogObserverTest()
346 : testBEGIN_STEP(false),
347 testBEFORE_EXPLICIT_EVAL(false),
348 testBEFORE_X_UPDATE(false),
349 testBEFORE_XDOT_UPDATE(false),
351 testCurrentValue(-0.99),
352 testWorkingValue(-0.99),
358 virtual ~StepperLeapfrogObserverTest() {}
361 virtual void observe(
369 testBEGIN_STEP =
true;
370 auto x = sh->getCurrentState()->getX();
371 testCurrentValue = get_ele(*(x), 0);
375 testBEFORE_EXPLICIT_EVAL =
true;
376 testDt = sh->getWorkingState()->getTimeStep();
380 testBEFORE_X_UPDATE =
true;
381 testName = stepper->getStepperType();
385 testBEFORE_XDOT_UPDATE =
true;
386 auto x = sh->getWorkingState()->getX();
387 testWorkingValue = get_ele(*(x), 0);
396 "Error - unknown action location.\n");
400 bool testBEFORE_EXPLICIT_EVAL;
401 bool testBEFORE_X_UPDATE;
402 bool testBEFORE_XDOT_UPDATE;
404 double testCurrentValue;
405 double testWorkingValue;
407 std::string testName;
416 stepper->setModel(model);
417 auto observer =
rcp(
new StepperLeapfrogObserverTest());
418 stepper->setAppAction(observer);
419 stepper->initialize();
424 timeStepControl->setInitTimeStep(dt);
425 timeStepControl->initialize();
428 auto inArgsIC = model->getNominalValues();
434 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
435 icState->setTime(timeStepControl->getInitTime());
436 icState->setIndex(timeStepControl->getInitIndex());
437 icState->setTimeStep(dt);
438 icState->setOrder(stepper->getOrder());
443 solutionHistory->setName(
"Forward States");
445 solutionHistory->setStorageLimit(2);
446 solutionHistory->addState(icState);
449 stepper->setInitialConditions(solutionHistory);
450 solutionHistory->initWorkingState();
451 solutionHistory->getWorkingState()->setTimeStep(dt);
452 stepper->takeStep(solutionHistory);
456 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
458 TEST_COMPARE(observer->testBEFORE_XDOT_UPDATE, ==,
true);
461 auto x = solutionHistory->getCurrentState()->getX();
463 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)