9 #include "Teuchos_UnitTestHarness.hpp" 10 #include "Teuchos_XMLParameterListHelpers.hpp" 11 #include "Teuchos_TimeMonitor.hpp" 12 #include "Teuchos_DefaultComm.hpp" 14 #include "Thyra_VectorStdOps.hpp" 15 #include "NOX_Thyra.H" 17 #include "Tempus_StepperFactory.hpp" 18 #include "Tempus_StepperForwardEuler.hpp" 19 #include "Tempus_StepperBackwardEuler.hpp" 21 #include "Tempus_StepperSubcycling.hpp" 29 #include "../TestModels/SinCosModel.hpp" 30 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 39 using Teuchos::rcp_const_cast;
40 using Teuchos::rcp_dynamic_cast;
41 using Teuchos::ParameterList;
42 using Teuchos::sublist;
43 using Teuchos::getParametersFromXmlFile;
56 auto inArgsIC = model->getNominalValues();
60 solutionHistory->addState(icState);
61 solutionHistory->initWorkingState();
66 stepper->setSubcyclingStepper(stepperBE);
67 stepper->setInitialConditions(solutionHistory);
68 stepper->initialize();
69 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 bool useFSAL = stepper->getUseFSAL();
79 std::string ICConsistency = stepper->getICConsistency();
80 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
83 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
95 scIntegrator->setStepper(stepperFE);
96 scIntegrator->setSolutionHistory(solutionHistory);
97 scIntegrator->initialize();
100 model,scIntegrator, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
101 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
104 TEUCHOS_ASSERT(stepper->getOrder() == 1);
117 stepper->setSubcyclingStepper(stepperBE);
120 auto inArgsIC = model->getNominalValues();
124 solutionHistory->addState(icState);
125 solutionHistory->initWorkingState();
128 stepper->setInitialConditions(solutionHistory);
129 stepper->initialize();
132 stepper->setSubcyclingInitTimeStep(0.25);
133 stepper->setSubcyclingMaxTimeStep(0.5);
134 double maxTimeStep_Set = stepper->getSubcyclingMaxTimeStep();
135 stepper->takeStep(solutionHistory);
136 double maxTimeStep_After = stepper->getSubcyclingMaxTimeStep();
138 TEST_FLOATING_EQUALITY(maxTimeStep_Set, maxTimeStep_After, 1.0e-14 );
144 class StepperSubcyclingModifierTest
150 StepperSubcyclingModifierTest()
151 : testBEGIN_STEP(false), testEND_STEP(false),
152 testCurrentValue(-0.99), testWorkingValue(-0.99),
153 testDt(1.5), testName(
"")
156 virtual ~StepperSubcyclingModifierTest(){}
167 testBEGIN_STEP =
true;
168 auto x = sh->getCurrentState()->getX();
169 testCurrentValue = get_ele(*(x), 0);
170 testName =
"Subcycling - Modifier";
171 stepper->setStepperName(testName);
177 auto x = sh->getWorkingState()->getX();
178 testWorkingValue = get_ele(*(x), 0);
179 testDt = sh->getWorkingState()->getTimeStep()/10.0;
180 sh->getWorkingState()->setTimeStep(testDt);
184 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
185 "Error - unknown action location.\n");
191 double testCurrentValue;
192 double testWorkingValue;
194 std::string testName;
206 auto modifier = rcp(
new StepperSubcyclingModifierTest());
207 stepper->setAppAction(modifier);
208 stepper->setSubcyclingStepper(stepperFE);
210 stepper->setSubcyclingMinTimeStep (15);
211 stepper->setSubcyclingInitTimeStep (15.0);
212 stepper->setSubcyclingMaxTimeStep (15.0);
213 stepper->setSubcyclingMaxFailures (10);
214 stepper->setSubcyclingMaxConsecFailures(5);
215 stepper->setSubcyclingScreenOutputIndexInterval(1);
216 stepper->setSubcyclingPrintDtChanges(
true);
220 timeStepControl->setInitIndex(0);
221 timeStepControl->setInitTime (0.0);
222 timeStepControl->setFinalTime(1.0);
223 timeStepControl->setInitTimeStep(15.0);
224 timeStepControl->initialize();
227 auto inArgsIC = model->getNominalValues();
230 icState->setTime (timeStepControl->getInitTime());;
231 icState->setIndex (timeStepControl->getInitIndex());
232 icState->setTimeStep(0.0);
237 solutionHistory->setName(
"Forward States");
239 solutionHistory->setStorageLimit(2);
240 solutionHistory->addState(icState);
243 stepper->setInitialConditions(solutionHistory);
244 stepper->initialize();
247 stepper->setInitialConditions(solutionHistory);
248 solutionHistory->initWorkingState();
249 solutionHistory->getWorkingState()->setTimeStep(15.0);
250 stepper->takeStep(solutionHistory);
253 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
254 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
257 auto x = solutionHistory->getCurrentState()->getX();
258 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
259 x = solutionHistory->getWorkingState()->getX();
260 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
261 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
262 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
264 TEST_COMPARE(modifier->testName, ==,
"Subcycling - Modifier");
269 class StepperSubcyclingObserverTest
275 StepperSubcyclingObserverTest()
276 : testBEGIN_STEP(false), testEND_STEP(false),
277 testCurrentValue(-0.99), testWorkingValue(-0.99),
278 testDt(15.0), testName(
"Subcyling")
282 virtual ~StepperSubcyclingObserverTest(){}
285 virtual void observe(
293 testBEGIN_STEP =
true;
294 auto x = sh->getCurrentState()->getX();
295 testCurrentValue = get_ele(*(x), 0);
301 auto x = sh->getWorkingState()->getX();
302 testWorkingValue = get_ele(*(x), 0);
306 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
307 "Error - unknown action location.\n");
313 double testCurrentValue;
314 double testWorkingValue;
316 std::string testName;
328 auto observer = rcp(
new StepperSubcyclingObserverTest());
329 stepper->setAppAction(observer);
330 stepper->setSubcyclingStepper(stepperFE);
332 stepper->setSubcyclingMinTimeStep (15);
333 stepper->setSubcyclingInitTimeStep (15.0);
334 stepper->setSubcyclingMaxTimeStep (15.0);
335 stepper->setSubcyclingMaxFailures (10);
336 stepper->setSubcyclingMaxConsecFailures(5);
337 stepper->setSubcyclingScreenOutputIndexInterval(1);
338 stepper->setSubcyclingPrintDtChanges(
true);
342 timeStepControl->setInitIndex(0);
343 timeStepControl->setInitTime (0.0);
344 timeStepControl->setFinalTime(1.0);
345 timeStepControl->setInitTimeStep(15.0);
346 timeStepControl->initialize();
349 auto inArgsIC = model->getNominalValues();
352 icState->setTime (timeStepControl->getInitTime());;
353 icState->setIndex (timeStepControl->getInitIndex());
354 icState->setTimeStep(0.0);
359 solutionHistory->setName(
"Forward States");
361 solutionHistory->setStorageLimit(2);
362 solutionHistory->addState(icState);
365 stepper->setInitialConditions(solutionHistory);
366 stepper->initialize();
369 stepper->setInitialConditions(solutionHistory);
370 solutionHistory->initWorkingState();
371 solutionHistory->getWorkingState()->setTimeStep(15.0);
372 stepper->takeStep(solutionHistory);
375 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
376 TEST_COMPARE(observer->testEND_STEP, ==,
true);
379 auto x = solutionHistory->getCurrentState()->getX();
380 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
381 x = solutionHistory->getWorkingState()->getX();
382 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
383 TEST_FLOATING_EQUALITY(observer->testDt, 15.0, 1.0e-14);
385 TEST_COMPARE(observer->testName, ==,
"Subcyling");
390 class StepperSubcyclingModifierXTest
396 StepperSubcyclingModifierXTest()
397 : testX_BEGIN_STEP(false), testXDOT_END_STEP(false),
398 testX(-0.99), testXDot(-0.99),
399 testDt(1.5), testTime(1.5)
403 virtual ~StepperSubcyclingModifierXTest(){}
408 const double time,
const double dt,
414 testX_BEGIN_STEP =
true;
415 testX = get_ele(*(x), 0);
421 testXDOT_END_STEP =
true;
422 testXDot = get_ele(*(x), 0);
427 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
428 "Error - unknown action location.\n");
432 bool testX_BEGIN_STEP;
433 bool testXDOT_END_STEP;
449 auto modifierX = rcp(
new StepperSubcyclingModifierXTest());
450 stepper->setAppAction(modifierX);
451 stepper->setSubcyclingStepper(stepperFE);
453 stepper->setSubcyclingMinTimeStep (15);
454 stepper->setSubcyclingInitTimeStep (15.0);
455 stepper->setSubcyclingMaxTimeStep (15.0);
456 stepper->setSubcyclingMaxFailures (10);
457 stepper->setSubcyclingMaxConsecFailures(5);
458 stepper->setSubcyclingScreenOutputIndexInterval(1);
459 stepper->setSubcyclingPrintDtChanges(
true);
463 timeStepControl->setInitIndex(0);
464 timeStepControl->setInitTime (0.0);
465 timeStepControl->setFinalTime(1.0);
466 timeStepControl->setInitTimeStep(15.0);
467 timeStepControl->initialize();
470 auto inArgsIC = model->getNominalValues();
474 icState->setTime (timeStepControl->getInitTime());;
475 icState->setIndex (timeStepControl->getInitIndex());
476 icState->setTimeStep(0.0);
481 solutionHistory->setName(
"Forward States");
483 solutionHistory->setStorageLimit(2);
484 solutionHistory->addState(icState);
487 stepper->setInitialConditions(solutionHistory);
488 stepper->initialize();
491 stepper->setInitialConditions(solutionHistory);
492 solutionHistory->initWorkingState();
493 solutionHistory->getWorkingState()->setTimeStep(15.0);
494 stepper->takeStep(solutionHistory);
497 stepper->setInitialConditions(solutionHistory);
498 solutionHistory->initWorkingState();
499 solutionHistory->getWorkingState()->setTimeStep(15.0);
500 stepper->takeStep(solutionHistory);
503 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
504 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
507 auto x = solutionHistory->getCurrentState()->getX();
508 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
510 auto xDot = solutionHistory->getWorkingState()->getXDot();
511 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
513 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-14);
514 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
515 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
517 auto time = solutionHistory->getWorkingState()->getTime();
518 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-14);
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.
Modify at the end of the step.
At the beginning of the step.
Default modifier for StepperSubcycling.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
Teuchos::RCP< StepperForwardEuler< Scalar > > createStepperForwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Modify at the beginning of the step.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Keep a fix number of states.
Base modifier for StepperSubcycling.
Default ModifierX for StepperSubcycling.
Default observer for StepperSubcycling.
Teuchos::RCP< StepperBackwardEuler< Scalar > > createStepperBackwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
Base observer for StepperSubcycling.
Base ModifierX for StepperSubcycling.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).