11#include "Tempus_StepperForwardEuler.hpp"
12#include "Tempus_StepperBackwardEuler.hpp"
14#include "Tempus_StepperSubcycling.hpp"
27using Teuchos::rcp_const_cast;
28using Teuchos::rcp_dynamic_cast;
29using Teuchos::ParameterList;
30using Teuchos::sublist;
39 auto model = rcp(
new Tempus_Test::SinCosModel<double>());
40 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double> > (model);
43 auto inArgsIC = model->getNominalValues();
44 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
47 solutionHistory->addState(icState);
48 solutionHistory->initWorkingState();
53 stepper->setSubcyclingStepper(stepperBE);
54 stepper->setInitialConditions(solutionHistory);
55 stepper->initialize();
56 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65 bool useFSAL = stepper->getUseFSAL();
66 std::string ICConsistency = stepper->getICConsistency();
67 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
70 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
75 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 scIntegrator->setStepper(stepperFE);
83 scIntegrator->setSolutionHistory(solutionHistory);
84 scIntegrator->initialize();
87 model,scIntegrator, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
88 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91 TEUCHOS_ASSERT(stepper->getOrder() == 1);
100 auto model = rcp(
new Tempus_Test::SinCosModel<double>());
101 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double> > (model);
104 stepper->setSubcyclingStepper(stepperBE);
107 auto inArgsIC = model->getNominalValues();
108 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
111 solutionHistory->addState(icState);
112 solutionHistory->initWorkingState();
115 stepper->setInitialConditions(solutionHistory);
116 stepper->initialize();
119 stepper->setSubcyclingInitTimeStep(0.25);
120 stepper->setSubcyclingMaxTimeStep(0.5);
121 double maxTimeStep_Set = stepper->getSubcyclingMaxTimeStep();
122 stepper->takeStep(solutionHistory);
123 double maxTimeStep_After = stepper->getSubcyclingMaxTimeStep();
125 TEST_FLOATING_EQUALITY(maxTimeStep_Set, maxTimeStep_After, 1.0e-14 );
131class StepperSubcyclingModifierTest
137 StepperSubcyclingModifierTest()
138 : testBEGIN_STEP(false), testEND_STEP(false),
139 testCurrentValue(-0.99), testWorkingValue(-0.99),
140 testDt(1.5), testName(
"")
143 virtual ~StepperSubcyclingModifierTest(){}
152 case StepperSubcyclingAppAction<double>::BEGIN_STEP:
154 testBEGIN_STEP =
true;
155 auto x = sh->getCurrentState()->getX();
156 testCurrentValue = get_ele(*(x), 0);
157 testName =
"Subcycling - Modifier";
158 stepper->setStepperName(testName);
161 case StepperSubcyclingAppAction<double>::END_STEP:
164 auto x = sh->getWorkingState()->getX();
165 testWorkingValue = get_ele(*(x), 0);
166 testDt = sh->getWorkingState()->getTimeStep()/10.0;
167 sh->getWorkingState()->setTimeStep(testDt);
171 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
172 "Error - unknown action location.\n");
178 double testCurrentValue;
179 double testWorkingValue;
181 std::string testName;
187 auto model = rcp(
new Tempus_Test::SinCosModel<double>());
188 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double> > (model);
193 auto modifier = rcp(
new StepperSubcyclingModifierTest());
194 stepper->setAppAction(modifier);
195 stepper->setSubcyclingStepper(stepperFE);
197 stepper->setSubcyclingMinTimeStep (15);
198 stepper->setSubcyclingInitTimeStep (15.0);
199 stepper->setSubcyclingMaxTimeStep (15.0);
200 stepper->setSubcyclingMaxFailures (10);
201 stepper->setSubcyclingMaxConsecFailures(5);
202 stepper->setSubcyclingScreenOutputIndexInterval(1);
203 stepper->setSubcyclingPrintDtChanges(
true);
207 timeStepControl->setInitIndex(0);
208 timeStepControl->setInitTime (0.0);
209 timeStepControl->setFinalTime(1.0);
210 timeStepControl->setInitTimeStep(15.0);
211 timeStepControl->initialize();
214 auto inArgsIC = model->getNominalValues();
215 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
217 icState->setTime (timeStepControl->getInitTime());;
218 icState->setIndex (timeStepControl->getInitIndex());
219 icState->setTimeStep(0.0);
224 solutionHistory->setName(
"Forward States");
226 solutionHistory->setStorageLimit(2);
227 solutionHistory->addState(icState);
230 stepper->setInitialConditions(solutionHistory);
231 stepper->initialize();
234 stepper->setInitialConditions(solutionHistory);
235 solutionHistory->initWorkingState();
236 solutionHistory->getWorkingState()->setTimeStep(15.0);
237 stepper->takeStep(solutionHistory);
240 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
241 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
244 auto x = solutionHistory->getCurrentState()->getX();
245 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
246 x = solutionHistory->getWorkingState()->getX();
247 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
248 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
249 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
251 TEST_COMPARE(modifier->testName, ==,
"Subcycling - Modifier");
256class StepperSubcyclingObserverTest
262 StepperSubcyclingObserverTest()
263 : testBEGIN_STEP(false), testEND_STEP(false),
264 testCurrentValue(-0.99), testWorkingValue(-0.99),
265 testDt(15.0), testName(
"Subcyling")
269 virtual ~StepperSubcyclingObserverTest(){}
272 virtual void observe(
278 case StepperSubcyclingAppAction<double>::BEGIN_STEP:
280 testBEGIN_STEP =
true;
281 auto x = sh->getCurrentState()->getX();
282 testCurrentValue = get_ele(*(x), 0);
285 case StepperSubcyclingAppAction<double>::END_STEP:
288 auto x = sh->getWorkingState()->getX();
289 testWorkingValue = get_ele(*(x), 0);
293 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
294 "Error - unknown action location.\n");
300 double testCurrentValue;
301 double testWorkingValue;
303 std::string testName;
309 auto model = rcp(
new Tempus_Test::SinCosModel<double>());
310 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double> > (model);
315 auto observer = rcp(
new StepperSubcyclingObserverTest());
316 stepper->setAppAction(observer);
317 stepper->setSubcyclingStepper(stepperFE);
319 stepper->setSubcyclingMinTimeStep (15);
320 stepper->setSubcyclingInitTimeStep (15.0);
321 stepper->setSubcyclingMaxTimeStep (15.0);
322 stepper->setSubcyclingMaxFailures (10);
323 stepper->setSubcyclingMaxConsecFailures(5);
324 stepper->setSubcyclingScreenOutputIndexInterval(1);
325 stepper->setSubcyclingPrintDtChanges(
true);
329 timeStepControl->setInitIndex(0);
330 timeStepControl->setInitTime (0.0);
331 timeStepControl->setFinalTime(1.0);
332 timeStepControl->setInitTimeStep(15.0);
333 timeStepControl->initialize();
336 auto inArgsIC = model->getNominalValues();
337 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
339 icState->setTime (timeStepControl->getInitTime());;
340 icState->setIndex (timeStepControl->getInitIndex());
341 icState->setTimeStep(0.0);
346 solutionHistory->setName(
"Forward States");
348 solutionHistory->setStorageLimit(2);
349 solutionHistory->addState(icState);
352 stepper->setInitialConditions(solutionHistory);
353 stepper->initialize();
356 stepper->setInitialConditions(solutionHistory);
357 solutionHistory->initWorkingState();
358 solutionHistory->getWorkingState()->setTimeStep(15.0);
359 stepper->takeStep(solutionHistory);
362 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
363 TEST_COMPARE(observer->testEND_STEP, ==,
true);
366 auto x = solutionHistory->getCurrentState()->getX();
367 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
368 x = solutionHistory->getWorkingState()->getX();
369 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
370 TEST_FLOATING_EQUALITY(observer->testDt, 15.0, 1.0e-14);
372 TEST_COMPARE(observer->testName, ==,
"Subcyling");
377class StepperSubcyclingModifierXTest
383 StepperSubcyclingModifierXTest()
384 : testX_BEGIN_STEP(false), testXDOT_END_STEP(false),
385 testX(-0.99), testXDot(-0.99),
386 testDt(1.5), testTime(1.5)
390 virtual ~StepperSubcyclingModifierXTest(){}
395 const double time,
const double dt,
399 case StepperSubcyclingModifierXBase<double>::X_BEGIN_STEP:
401 testX_BEGIN_STEP =
true;
402 testX = get_ele(*(x), 0);
406 case StepperSubcyclingModifierXBase<double>::XDOT_END_STEP:
408 testXDOT_END_STEP =
true;
409 testXDot = get_ele(*(x), 0);
414 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
415 "Error - unknown action location.\n");
419 bool testX_BEGIN_STEP;
420 bool testXDOT_END_STEP;
430 auto model = rcp(
new Tempus_Test::SinCosModel<double>());
431 auto modelME = rcp_dynamic_cast<const Thyra::ModelEvaluator<double> > (model);
436 auto modifierX = rcp(
new StepperSubcyclingModifierXTest());
437 stepper->setAppAction(modifierX);
438 stepper->setSubcyclingStepper(stepperFE);
440 stepper->setSubcyclingMinTimeStep (15);
441 stepper->setSubcyclingInitTimeStep (15.0);
442 stepper->setSubcyclingMaxTimeStep (15.0);
443 stepper->setSubcyclingMaxFailures (10);
444 stepper->setSubcyclingMaxConsecFailures(5);
445 stepper->setSubcyclingScreenOutputIndexInterval(1);
446 stepper->setSubcyclingPrintDtChanges(
true);
450 timeStepControl->setInitIndex(0);
451 timeStepControl->setInitTime (0.0);
452 timeStepControl->setFinalTime(1.0);
453 timeStepControl->setInitTimeStep(15.0);
454 timeStepControl->initialize();
457 auto inArgsIC = model->getNominalValues();
458 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
459 auto icSolutionDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
461 icState->setTime (timeStepControl->getInitTime());;
462 icState->setIndex (timeStepControl->getInitIndex());
463 icState->setTimeStep(0.0);
468 solutionHistory->setName(
"Forward States");
470 solutionHistory->setStorageLimit(2);
471 solutionHistory->addState(icState);
474 stepper->setInitialConditions(solutionHistory);
475 stepper->initialize();
478 stepper->setInitialConditions(solutionHistory);
479 solutionHistory->initWorkingState();
480 solutionHistory->getWorkingState()->setTimeStep(15.0);
481 stepper->takeStep(solutionHistory);
484 stepper->setInitialConditions(solutionHistory);
485 solutionHistory->initWorkingState();
486 solutionHistory->getWorkingState()->setTimeStep(15.0);
487 stepper->takeStep(solutionHistory);
490 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
491 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
494 auto x = solutionHistory->getCurrentState()->getX();
495 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
497 auto xDot = solutionHistory->getWorkingState()->getXDot();
498 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
500 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-14);
501 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
502 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
504 auto time = solutionHistory->getWorkingState()->getTime();
505 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-14);
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 StepperSubcycling.
Default modifier for StepperSubcycling.
Base ModifierX for StepperSubcycling.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Default ModifierX for StepperSubcycling.
Base observer for StepperSubcycling.
Default observer for StepperSubcycling.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
@ STORAGE_TYPE_STATIC
Keep a fix number of states.
Teuchos::RCP< StepperBackwardEuler< Scalar > > createStepperBackwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
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< StepperForwardEuler< Scalar > > createStepperForwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.