11#include "Tempus_StepperLeapfrog.hpp"
17#include "../TestModels/HarmonicOscillatorModel.hpp"
24using Teuchos::rcp_const_cast;
25using Teuchos::rcp_dynamic_cast;
26using Teuchos::ParameterList;
27using Teuchos::sublist;
38 stepper->setModel(model);
39 stepper->initialize();
40 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
45 stepper->setAppAction(modifier);
46 bool useFSAL = stepper->getUseFSAL();
47 std::string ICConsistency = stepper->getICConsistency();
48 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
52 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
53 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
54 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
55 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
59 model, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
60 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 TEUCHOS_ASSERT(stepper->getOrder() == 2);
77class StepperLeapfrogModifierTest
83 StepperLeapfrogModifierTest()
84 : testBEGIN_STEP(false), testBEFORE_X_UPDATE(false),
85 testBEFORE_EXPLICIT_EVAL(false), testBEFORE_XDOT_UPDATE(false),
87 testCurrentValue(-0.99), testWorkingValue(-0.99),
88 testDt(-1.5), testName(
"")
92 virtual ~StepperLeapfrogModifierTest(){}
101 case StepperLeapfrogAppAction<double>::BEGIN_STEP:
103 testBEGIN_STEP =
true;
104 auto x = sh->getCurrentState()->getX();
105 testCurrentValue = get_ele(*(x), 0);
108 case StepperLeapfrogAppAction<double>::BEFORE_EXPLICIT_EVAL:
110 testBEFORE_EXPLICIT_EVAL =
true;
111 testDt = sh->getWorkingState()->getTimeStep()/10.0;
112 sh->getWorkingState()->setTimeStep(testDt);
115 case StepperLeapfrogAppAction<double>::BEFORE_X_UPDATE:
117 testBEFORE_X_UPDATE =
true;
118 testName =
"Leapfrog - Modifier";
119 stepper->setStepperName(testName);
122 case StepperLeapfrogAppAction<double>::BEFORE_XDOT_UPDATE:
124 testBEFORE_XDOT_UPDATE =
true;
125 auto x = sh->getWorkingState()->getX();
126 testWorkingValue = get_ele(*(x), 0);
129 case StepperLeapfrogAppAction<double>::END_STEP:
135 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
136 "Error - unknown action location.\n");
140 bool testBEFORE_X_UPDATE;
141 bool testBEFORE_EXPLICIT_EVAL;
142 bool testBEFORE_XDOT_UPDATE;
144 double testCurrentValue;
145 double testWorkingValue;
147 std::string testName;
156 stepper->setModel(model);
157 auto modifier = rcp(
new StepperLeapfrogModifierTest());
158 stepper->setAppAction(modifier);
159 stepper->initialize();
163 timeStepControl->setInitTimeStep(15.0);
164 timeStepControl->initialize();
167 auto inArgsIC = model->getNominalValues();
168 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
169 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
170 auto icXDotDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot_dot());
171 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
172 icState->setTime (timeStepControl->getInitTime());
173 icState->setIndex (timeStepControl->getInitIndex());
174 icState->setTimeStep(15.0);
175 icState->setOrder (stepper->getOrder());
180 solutionHistory->setName(
"Forward States");
182 solutionHistory->setStorageLimit(2);
183 solutionHistory->addState(icState);
186 stepper->setInitialConditions(solutionHistory);
187 solutionHistory->initWorkingState();
188 solutionHistory->getWorkingState()->setTimeStep(15.0);
189 stepper->takeStep(solutionHistory);
191 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
192 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
193 TEST_COMPARE(modifier->testBEFORE_X_UPDATE, ==,
true);
194 TEST_COMPARE(modifier->testBEFORE_XDOT_UPDATE, ==,
true);
195 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
197 auto x = solutionHistory->getCurrentState()->getX();
198 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
199 x = solutionHistory->getWorkingState()->getX();
200 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
201 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
202 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
204 TEST_COMPARE(modifier->testName, ==,
"Leapfrog - Modifier");
208class StepperLeapfrogModifierXTest
214 StepperLeapfrogModifierXTest()
215 : testX_BEGIN_STEP(false), testX_BEFORE_EXPLICIT_EVAL(false),
216 testX_BEFORE_X_UPDATE(false), testX_BEFORE_XDOT_UPDATE(false),
217 testX_END_STEP(false),
218 testX(0.0), testDt(-1.25), testTime(-1.25),testName(
"")
222 virtual ~StepperLeapfrogModifierXTest(){}
227 const double time,
const double dt,
231 case StepperLeapfrogModifierXBase<double>::X_BEGIN_STEP:
233 testX_BEGIN_STEP =
true;
234 testX = get_ele(*(x), 0);
237 case StepperLeapfrogModifierXBase<double>::X_BEFORE_EXPLICIT_EVAL:
239 testX_BEFORE_EXPLICIT_EVAL =
true;
243 case StepperLeapfrogModifierXBase<double>::X_BEFORE_X_UPDATE:
245 testX_BEFORE_X_UPDATE =
true;
249 case StepperLeapfrogModifierXBase<double>::X_BEFORE_XDOT_UPDATE:
251 testX_BEFORE_XDOT_UPDATE =
true;
252 testName =
"Leapfrog - ModifierX";
255 case StepperLeapfrogModifierXBase<double>::X_END_STEP:
257 testX_END_STEP =
true;
261 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
262 "Error - unknown action location.\n");
265 bool testX_BEGIN_STEP;
266 bool testX_BEFORE_EXPLICIT_EVAL;
267 bool testX_BEFORE_X_UPDATE;
268 bool testX_BEFORE_XDOT_UPDATE;
273 std::string testName;
282 stepper->setModel(model);
283 auto modifierX = rcp(
new StepperLeapfrogModifierXTest());
284 stepper->setAppAction(modifierX);
285 stepper->initialize();
289 timeStepControl->setInitTimeStep(15.0);
290 timeStepControl->initialize();
293 auto inArgsIC = model->getNominalValues();
294 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
295 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
296 auto icXDotDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot_dot());
297 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
298 icState->setTime (timeStepControl->getInitTime());
299 icState->setIndex (timeStepControl->getInitIndex());
300 icState->setTimeStep(15.0);
301 icState->setOrder (stepper->getOrder());
306 solutionHistory->setName(
"Forward States");
308 solutionHistory->setStorageLimit(2);
309 solutionHistory->addState(icState);
312 stepper->setInitialConditions(solutionHistory);
313 solutionHistory->initWorkingState();
314 solutionHistory->getWorkingState()->setTimeStep(15.0);
315 stepper->takeStep(solutionHistory);
317 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
318 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
319 TEST_COMPARE(modifierX->testX_BEFORE_XDOT_UPDATE, ==,
true);
320 TEST_COMPARE(modifierX->testX_BEFORE_X_UPDATE, ==,
true);
321 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
323 auto x = solutionHistory->getCurrentState()->getX();
324 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
325 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
326 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
327 auto time = solutionHistory->getWorkingState()->getTime();
328 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
329 TEST_COMPARE(modifierX->testName, ==,
"Leapfrog - ModifierX");
335class StepperLeapfrogObserverTest
340 StepperLeapfrogObserverTest()
341 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
342 testBEFORE_X_UPDATE(false), testBEFORE_XDOT_UPDATE(false),
344 testCurrentValue(-0.99), testWorkingValue(-0.99),
345 testDt(-1.5), testName(
"")
348 virtual ~StepperLeapfrogObserverTest(){}
351 virtual void observe(
357 case StepperLeapfrogAppAction<double>::BEGIN_STEP:
359 testBEGIN_STEP =
true;
360 auto x = sh->getCurrentState()->getX();
361 testCurrentValue = get_ele(*(x), 0);
364 case StepperLeapfrogAppAction<double>::BEFORE_EXPLICIT_EVAL:
366 testBEFORE_EXPLICIT_EVAL =
true;
367 testDt = sh->getWorkingState()->getTimeStep();
370 case StepperLeapfrogAppAction<double>::BEFORE_X_UPDATE:
372 testBEFORE_X_UPDATE =
true;
373 testName = stepper->getStepperType();
376 case StepperLeapfrogAppAction<double>::BEFORE_XDOT_UPDATE:
378 testBEFORE_XDOT_UPDATE =
true;
379 auto x = sh->getWorkingState()->getX();
380 testWorkingValue = get_ele(*(x), 0);
383 case StepperLeapfrogAppAction<double>::END_STEP:
389 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
390 "Error - unknown action location.\n");
394 bool testBEFORE_EXPLICIT_EVAL;
395 bool testBEFORE_X_UPDATE;
396 bool testBEFORE_XDOT_UPDATE;
398 double testCurrentValue;
399 double testWorkingValue;
401 std::string testName;
410 stepper->setModel(model);
411 auto observer = rcp(
new StepperLeapfrogObserverTest());
412 stepper->setAppAction(observer);
413 stepper->initialize();
418 timeStepControl->setInitTimeStep(dt);
419 timeStepControl->initialize();
422 auto inArgsIC = model->getNominalValues();
423 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
424 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
425 auto icXDotDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot_dot());
426 auto icState = Tempus::createSolutionStateX<double>(icX, icXDot, icXDotDot);
427 icState->setTime (timeStepControl->getInitTime());
428 icState->setIndex (timeStepControl->getInitIndex());
429 icState->setTimeStep(dt);
430 icState->setOrder (stepper->getOrder());
435 solutionHistory->setName(
"Forward States");
437 solutionHistory->setStorageLimit(2);
438 solutionHistory->addState(icState);
441 stepper->setInitialConditions(solutionHistory);
442 solutionHistory->initWorkingState();
443 solutionHistory->getWorkingState()->setTimeStep(dt);
444 stepper->takeStep(solutionHistory);
447 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
448 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
449 TEST_COMPARE(observer->testBEFORE_X_UPDATE, ==,
true);
450 TEST_COMPARE(observer->testBEFORE_XDOT_UPDATE, ==,
true);
451 TEST_COMPARE(observer->testEND_STEP, ==,
true);
453 auto x = solutionHistory->getCurrentState()->getX();
454 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
455 x = solutionHistory->getWorkingState()->getX();
456 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
457 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-15);
459 TEST_COMPARE(observer->testName, ==,
"Leapfrog");
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Base modifier for StepperLeapfrog.
Default modifier for StepperLeapfrog.
Base ModifierX for StepperLeapfrog.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Base observer for StepperLeapfrog.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
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.
@ STORAGE_TYPE_STATIC
Keep a fix number of states.