11 #include "Tempus_StepperLeapfrog.hpp"
17 #include "../TestModels/HarmonicOscillatorModel.hpp"
20 namespace Tempus_Unit_Test {
24 using Teuchos::rcp_const_cast;
25 using Teuchos::rcp_dynamic_cast;
27 using Teuchos::sublist;
38 stepper->setModel(model);
39 stepper->initialize();
45 stepper->setAppAction(modifier);
46 bool useFSAL = stepper->getUseFSAL();
47 std::string ICConsistency = stepper->getICConsistency();
48 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
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));
77 class 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(){}
103 testBEGIN_STEP =
true;
104 auto x = sh->getCurrentState()->getX();
105 testCurrentValue = get_ele(*(x), 0);
110 testBEFORE_EXPLICIT_EVAL =
true;
111 testDt = sh->getWorkingState()->getTimeStep()/10.0;
112 sh->getWorkingState()->setTimeStep(testDt);
117 testBEFORE_X_UPDATE =
true;
118 testName =
"Leapfrog - Modifier";
119 stepper->setStepperName(testName);
124 testBEFORE_XDOT_UPDATE =
true;
125 auto x = sh->getWorkingState()->getX();
126 testWorkingValue = get_ele(*(x), 0);
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();
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);
192 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
194 TEST_COMPARE(modifier->testBEFORE_XDOT_UPDATE, ==,
true);
197 auto x = solutionHistory->getCurrentState()->getX();
199 x = solutionHistory->getWorkingState()->getX();
201 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
204 TEST_COMPARE(modifier->testName, ==,
"Leapfrog - Modifier");
208 class 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,
233 testX_BEGIN_STEP =
true;
234 testX = get_ele(*(x), 0);
239 testX_BEFORE_EXPLICIT_EVAL =
true;
245 testX_BEFORE_X_UPDATE =
true;
251 testX_BEFORE_XDOT_UPDATE =
true;
252 testName =
"Leapfrog - ModifierX";
257 testX_END_STEP =
true;
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();
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);
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);
323 auto x = solutionHistory->getCurrentState()->getX();
325 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
327 auto time = solutionHistory->getWorkingState()->getTime();
329 TEST_COMPARE(modifierX->testName, ==,
"Leapfrog - ModifierX");
335 class 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(
359 testBEGIN_STEP =
true;
360 auto x = sh->getCurrentState()->getX();
361 testCurrentValue = get_ele(*(x), 0);
366 testBEFORE_EXPLICIT_EVAL =
true;
367 testDt = sh->getWorkingState()->getTimeStep();
372 testBEFORE_X_UPDATE =
true;
373 testName = stepper->getStepperType();
378 testBEFORE_XDOT_UPDATE =
true;
379 auto x = sh->getWorkingState()->getX();
380 testWorkingValue = get_ele(*(x), 0);
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();
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);
448 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
450 TEST_COMPARE(observer->testBEFORE_XDOT_UPDATE, ==,
true);
453 auto x = solutionHistory->getCurrentState()->getX();
455 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.
Modify before the explicit ME evaluation.
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)