13#include "Tempus_StepperBDF2.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());
49 startUpStepper->setModel(model);
50 startUpStepper->initialize();
53 bool useFSAL = defaultStepper->getUseFSAL();
54 std::string ICConsistency = defaultStepper->getICConsistency();
55 bool ICConsistencyCheck = defaultStepper->getICConsistencyCheck();
56 bool zeroInitialGuess = defaultStepper->getZeroInitialGuess();
59 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
60 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61 stepper->setStartUpStepper(startUpStepper); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
62 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
64 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
68 ICConsistency, ICConsistencyCheck, zeroInitialGuess,modifier));
69 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71 TEUCHOS_ASSERT(stepper->getOrder() == 2);
86class StepperBDF2ModifierTest
92 StepperBDF2ModifierTest()
93 : testBEGIN_STEP(false),testBEFORE_SOLVE(false),
94 testAFTER_SOLVE(false),testEND_STEP(false),
95 testCurrentValue(-0.99), testWorkingValue(-0.99),
96 testDt(.99), testType(
"")
100 virtual ~StepperBDF2ModifierTest(){}
108 case StepperBDF2AppAction<double>::BEGIN_STEP:
110 testBEGIN_STEP =
true;
111 auto x = sh->getWorkingState()->getX();
112 testCurrentValue = get_ele(*(x), 0);
115 case StepperBDF2AppAction<double>::BEFORE_SOLVE:
117 testBEFORE_SOLVE =
true;
118 testType =
"BDF2 - Modifier";
121 case StepperBDF2AppAction<double>::AFTER_SOLVE:
123 testAFTER_SOLVE =
true;
124 testDt = sh->getCurrentState()->getTimeStep()/10.0;
125 sh->getCurrentState()->setTimeStep(testDt);
128 case StepperBDF2AppAction<double>::END_STEP:
131 auto x = sh->getWorkingState()->getX();
132 testWorkingValue = get_ele(*(x), 0);
136 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
137 "Error - unknown action location.\n");
141 bool testBEFORE_SOLVE;
142 bool testAFTER_SOLVE;
144 double testCurrentValue;
145 double testWorkingValue;
147 std::string testType;
156 stepper->setModel(model);
157 auto modifier = rcp(
new StepperBDF2ModifierTest());
158 stepper->setAppAction(modifier);
159 stepper->initialize();
162 auto inArgsIC = model->getNominalValues();
164 rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
166 icState->setTime (0.0);
167 icState->setIndex (0);
168 icState->setTimeStep(1.0);
169 icState->setOrder (stepper->getOrder());
174 timeStepControl->setInitIndex(0);
175 timeStepControl->setInitTime (0.0);
176 timeStepControl->setFinalTime(2.0);
177 timeStepControl->setInitTimeStep(1.0);
178 timeStepControl->initialize();
182 solutionHistory->setName(
"Forward States");
184 solutionHistory->setStorageLimit(3);
185 solutionHistory->addState(icState);
188 stepper->setInitialConditions(solutionHistory);
189 solutionHistory->initWorkingState();
191 solutionHistory->getWorkingState()->setTimeStep(dt);
192 stepper->takeStep(solutionHistory);
193 solutionHistory->promoteWorkingState();
194 solutionHistory->initWorkingState();
195 stepper->takeStep(solutionHistory);
197 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
198 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
199 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
200 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
202 auto Dt = solutionHistory->getCurrentState()->getTimeStep();
203 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
204 auto x = solutionHistory->getCurrentState()->getX();
205 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
206 x = solutionHistory->getWorkingState()->getX();
207 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
208 TEST_COMPARE(modifier->testType, ==,
"BDF2 - Modifier");
214class StepperBDF2ObserverTest
220 StepperBDF2ObserverTest()
221 : testBEGIN_STEP(false),testBEFORE_SOLVE(false),
222 testAFTER_SOLVE(false),testEND_STEP(false),
223 testCurrentValue(0.99), testWorkingValue(0.99),
224 testDt(.99), testType(
"")
228 virtual ~StepperBDF2ObserverTest(){}
236 case StepperBDF2AppAction<double>::BEGIN_STEP:
238 testBEGIN_STEP =
true;
239 auto x = sh->getCurrentState()->getX();
240 testCurrentValue = get_ele(*(x), 0);
243 case StepperBDF2AppAction<double>::BEFORE_SOLVE:
245 testBEFORE_SOLVE =
true;
246 testType = stepper->getStepperType();
249 case StepperBDF2AppAction<double>::AFTER_SOLVE:
251 testAFTER_SOLVE =
true;
252 testDt = sh->getCurrentState()->getTimeStep();
255 case StepperBDF2AppAction<double>::END_STEP:
258 auto x = sh->getWorkingState()->getX();
259 testWorkingValue = get_ele(*(x), 0);
264 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
265 "Error - unknown action location.\n");
269 bool testBEFORE_SOLVE;
270 bool testAFTER_SOLVE;
272 double testCurrentValue;
273 double testWorkingValue;
275 std::string testType;
287 stepper->setModel(model);
288 auto observer = rcp(
new StepperBDF2ModifierTest());
289 stepper->setAppAction(observer);
290 stepper->initialize();
293 auto inArgsIC = model->getNominalValues();
295 rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
297 icState->setTime (0.0);
298 icState->setIndex (0);
299 icState->setTimeStep(1.0);
300 icState->setOrder (stepper->getOrder());
305 timeStepControl->setInitIndex(0);
306 timeStepControl->setInitTime (0.0);
307 timeStepControl->setFinalTime(2.0);
308 timeStepControl->setInitTimeStep(1.0);
309 timeStepControl->initialize();
313 solutionHistory->setName(
"Forward States");
315 solutionHistory->setStorageLimit(3);
316 solutionHistory->addState(icState);
319 stepper->setInitialConditions(solutionHistory);
320 solutionHistory->initWorkingState();
322 solutionHistory->getWorkingState()->setTimeStep(dt);
323 stepper->takeStep(solutionHistory);
324 solutionHistory->promoteWorkingState();
325 solutionHistory->initWorkingState();
326 stepper->takeStep(solutionHistory);
328 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
329 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
330 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
331 TEST_COMPARE(observer->testEND_STEP, ==,
true);
333 auto Dt = solutionHistory->getCurrentState()->getTimeStep();
334 TEST_FLOATING_EQUALITY(observer->testDt, Dt, 1.0e-15);
336 auto x = solutionHistory->getCurrentState()->getX();
337 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
338 x = solutionHistory->getWorkingState()->getX();
339 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
340 TEST_COMPARE(observer->testType, ==,
"BDF2 - Modifier");
346class StepperBDF2ModifierXTest
352 StepperBDF2ModifierXTest()
353 : testX_BEGIN_STEP(false),testX_BEFORE_SOLVE(false),
354 testX_AFTER_SOLVE(false),testX_END_STEP(false),
355 testXbegin(-.99),testXend(-.99),testTime(0.0),testDt(0.0)
359 virtual ~StepperBDF2ModifierXTest(){}
364 const double time,
const double dt,
368 case StepperBDF2ModifierXBase<double>::X_BEGIN_STEP:
370 testX_BEGIN_STEP =
true;
371 testXbegin = get_ele(*(x), 0);
374 case StepperBDF2ModifierXBase<double>::X_BEFORE_SOLVE:
376 testX_BEFORE_SOLVE =
true;
380 case StepperBDF2ModifierXBase<double>::X_AFTER_SOLVE:
382 testX_AFTER_SOLVE =
true;
386 case StepperBDF2ModifierXBase<double>::X_END_STEP:
388 testX_END_STEP =
true;
389 testXend = get_ele(*(x), 0);
393 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
394 "Error - unknown action location.\n");
397 bool testX_BEGIN_STEP;
398 bool testX_BEFORE_SOLVE;
399 bool testX_AFTER_SOLVE;
415 stepper->setModel(model);
416 auto modifierX = rcp(
new StepperBDF2ModifierXTest());
417 stepper->setAppAction(modifierX);
418 stepper->initialize();
421 auto inArgsIC = model->getNominalValues();
423 rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
425 icState->setTime (0.0);
426 icState->setIndex (0);
427 icState->setTimeStep(1.0);
428 icState->setOrder (stepper->getOrder());
433 timeStepControl->setInitIndex(0);
434 timeStepControl->setInitTime (0.0);
435 timeStepControl->setFinalTime(2.0);
436 timeStepControl->setInitTimeStep(1.0);
437 timeStepControl->initialize();
441 solutionHistory->setName(
"Forward States");
443 solutionHistory->setStorageLimit(3);
444 solutionHistory->addState(icState);
448 stepper->setInitialConditions(solutionHistory);
449 solutionHistory->initWorkingState();
451 solutionHistory->getWorkingState()->setTimeStep(dt);
452 stepper->takeStep(solutionHistory);
453 solutionHistory->promoteWorkingState();
454 solutionHistory->initWorkingState();
455 stepper->takeStep(solutionHistory);
457 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
458 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
459 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
460 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
463 auto x = solutionHistory->getCurrentState()->getX();
464 TEST_FLOATING_EQUALITY(modifierX->testXbegin, get_ele(*(x), 0), 1.0e-15);
465 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
466 x = solutionHistory->getWorkingState()->getX();
467 TEST_FLOATING_EQUALITY(modifierX->testXend, get_ele(*(x), 0), 1.0e-15);
468 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
469 auto time = solutionHistory->getWorkingState()->getTime();
470 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
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 StepperBDF2.
Default modifier for StepperBDF2.
Base ModifierX for StepperBDF2.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
Base observer for StepperBDF2.
BDF2 (Backward-Difference-Formula-2) time stepper.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation.
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.
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.