12 #include "Tempus_StepperForwardEuler.hpp"
13 #include "Tempus_StepperBackwardEuler.hpp"
15 #include "Tempus_StepperSubcycling.hpp"
23 namespace Tempus_Unit_Test {
28 using Teuchos::rcp_const_cast;
29 using Teuchos::rcp_dynamic_cast;
30 using Teuchos::sublist;
47 solutionHistory->addState(icState);
48 solutionHistory->initWorkingState();
53 stepper->setSubcyclingStepper(stepperBE);
54 stepper->setInitialConditions(solutionHistory);
55 stepper->initialize();
65 bool useFSAL = stepper->getUseFSAL();
66 std::string ICConsistency = stepper->getICConsistency();
67 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
70 stepper->setSolver(solver);
71 stepper->initialize();
73 stepper->setAppAction(modifier);
74 stepper->initialize();
76 stepper->setAppAction(modifierX);
77 stepper->initialize();
79 stepper->setAppAction(observer);
80 stepper->initialize();
82 stepper->setUseFSAL(useFSAL);
83 stepper->initialize();
85 stepper->setICConsistency(ICConsistency);
86 stepper->initialize();
88 stepper->setICConsistencyCheck(ICConsistencyCheck);
89 stepper->initialize();
95 scIntegrator->setStepper(stepperFE);
96 scIntegrator->setSolutionHistory(solutionHistory);
97 scIntegrator->initialize();
100 model, scIntegrator, useFSAL, ICConsistency, ICConsistencyCheck,
117 stepper->setSubcyclingStepper(stepperBE);
120 auto inArgsIC = model->getNominalValues();
125 solutionHistory->addState(icState);
126 solutionHistory->initWorkingState();
129 stepper->setInitialConditions(solutionHistory);
130 stepper->initialize();
133 stepper->setSubcyclingInitTimeStep(0.25);
134 stepper->setSubcyclingMaxTimeStep(0.5);
135 double maxTimeStep_Set = stepper->getSubcyclingMaxTimeStep();
136 stepper->takeStep(solutionHistory);
137 double maxTimeStep_After = stepper->getSubcyclingMaxTimeStep();
144 class StepperSubcyclingModifierTest
148 StepperSubcyclingModifierTest()
149 : testBEGIN_STEP(false),
151 testCurrentValue(-0.99),
152 testWorkingValue(-0.99),
158 virtual ~StepperSubcyclingModifierTest() {}
169 testBEGIN_STEP =
true;
170 auto x = sh->getCurrentState()->getX();
171 testCurrentValue = get_ele(*(x), 0);
172 testName =
"Subcycling - Modifier";
173 stepper->setStepperName(testName);
178 auto x = sh->getWorkingState()->getX();
179 testWorkingValue = get_ele(*(x), 0);
180 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
181 sh->getWorkingState()->setTimeStep(testDt);
186 "Error - unknown action location.\n");
192 double testCurrentValue;
193 double testWorkingValue;
195 std::string testName;
207 auto modifier =
rcp(
new StepperSubcyclingModifierTest());
208 stepper->setAppAction(modifier);
209 stepper->setSubcyclingStepper(stepperFE);
211 stepper->setSubcyclingMinTimeStep(15);
212 stepper->setSubcyclingInitTimeStep(15.0);
213 stepper->setSubcyclingMaxTimeStep(15.0);
214 stepper->setSubcyclingMaxFailures(10);
215 stepper->setSubcyclingMaxConsecFailures(5);
216 stepper->setSubcyclingScreenOutputIndexInterval(1);
217 stepper->setSubcyclingPrintDtChanges(
true);
221 timeStepControl->setInitIndex(0);
222 timeStepControl->setInitTime(0.0);
223 timeStepControl->setFinalTime(1.0);
224 timeStepControl->setInitTimeStep(15.0);
225 timeStepControl->initialize();
228 auto inArgsIC = model->getNominalValues();
232 icState->setTime(timeStepControl->getInitTime());
233 icState->setIndex(timeStepControl->getInitIndex());
234 icState->setTimeStep(0.0);
239 solutionHistory->setName(
"Forward States");
241 solutionHistory->setStorageLimit(2);
242 solutionHistory->addState(icState);
245 stepper->setInitialConditions(solutionHistory);
246 stepper->initialize();
249 stepper->setInitialConditions(solutionHistory);
250 solutionHistory->initWorkingState();
251 solutionHistory->getWorkingState()->setTimeStep(15.0);
252 stepper->takeStep(solutionHistory);
259 auto x = solutionHistory->getCurrentState()->getX();
261 x = solutionHistory->getWorkingState()->getX();
263 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
266 TEST_COMPARE(modifier->testName, ==,
"Subcycling - Modifier");
271 class StepperSubcyclingObserverTest
275 StepperSubcyclingObserverTest()
276 : testBEGIN_STEP(false),
278 testCurrentValue(-0.99),
279 testWorkingValue(-0.99),
281 testName(
"Subcyling")
286 virtual ~StepperSubcyclingObserverTest() {}
289 virtual void observe(
297 testBEGIN_STEP =
true;
298 auto x = sh->getCurrentState()->getX();
299 testCurrentValue = get_ele(*(x), 0);
304 auto x = sh->getWorkingState()->getX();
305 testWorkingValue = get_ele(*(x), 0);
310 "Error - unknown action location.\n");
316 double testCurrentValue;
317 double testWorkingValue;
319 std::string testName;
331 auto observer =
rcp(
new StepperSubcyclingObserverTest());
332 stepper->setAppAction(observer);
333 stepper->setSubcyclingStepper(stepperFE);
335 stepper->setSubcyclingMinTimeStep(15);
336 stepper->setSubcyclingInitTimeStep(15.0);
337 stepper->setSubcyclingMaxTimeStep(15.0);
338 stepper->setSubcyclingMaxFailures(10);
339 stepper->setSubcyclingMaxConsecFailures(5);
340 stepper->setSubcyclingScreenOutputIndexInterval(1);
341 stepper->setSubcyclingPrintDtChanges(
true);
345 timeStepControl->setInitIndex(0);
346 timeStepControl->setInitTime(0.0);
347 timeStepControl->setFinalTime(1.0);
348 timeStepControl->setInitTimeStep(15.0);
349 timeStepControl->initialize();
352 auto inArgsIC = model->getNominalValues();
356 icState->setTime(timeStepControl->getInitTime());
357 icState->setIndex(timeStepControl->getInitIndex());
358 icState->setTimeStep(0.0);
363 solutionHistory->setName(
"Forward States");
365 solutionHistory->setStorageLimit(2);
366 solutionHistory->addState(icState);
369 stepper->setInitialConditions(solutionHistory);
370 stepper->initialize();
373 stepper->setInitialConditions(solutionHistory);
374 solutionHistory->initWorkingState();
375 solutionHistory->getWorkingState()->setTimeStep(15.0);
376 stepper->takeStep(solutionHistory);
383 auto x = solutionHistory->getCurrentState()->getX();
385 x = solutionHistory->getWorkingState()->getX();
394 class StepperSubcyclingModifierXTest
398 StepperSubcyclingModifierXTest()
399 : testX_BEGIN_STEP(false),
400 testXDOT_END_STEP(false),
409 virtual ~StepperSubcyclingModifierXTest() {}
413 const double time,
const double dt,
415 double>::MODIFIER_TYPE modType)
419 testX_BEGIN_STEP =
true;
420 testX = get_ele(*(x), 0);
425 testXDOT_END_STEP =
true;
426 testXDot = get_ele(*(x), 0);
432 "Error - unknown action location.\n");
436 bool testX_BEGIN_STEP;
437 bool testXDOT_END_STEP;
453 auto modifierX =
rcp(
new StepperSubcyclingModifierXTest());
454 stepper->setAppAction(modifierX);
455 stepper->setSubcyclingStepper(stepperFE);
457 stepper->setSubcyclingMinTimeStep(15);
458 stepper->setSubcyclingInitTimeStep(15.0);
459 stepper->setSubcyclingMaxTimeStep(15.0);
460 stepper->setSubcyclingMaxFailures(10);
461 stepper->setSubcyclingMaxConsecFailures(5);
462 stepper->setSubcyclingScreenOutputIndexInterval(1);
463 stepper->setSubcyclingPrintDtChanges(
true);
467 timeStepControl->setInitIndex(0);
468 timeStepControl->setInitTime(0.0);
469 timeStepControl->setFinalTime(1.0);
470 timeStepControl->setInitTimeStep(15.0);
471 timeStepControl->initialize();
474 auto inArgsIC = model->getNominalValues();
480 icState->setTime(timeStepControl->getInitTime());
481 icState->setIndex(timeStepControl->getInitIndex());
482 icState->setTimeStep(0.0);
487 solutionHistory->setName(
"Forward States");
489 solutionHistory->setStorageLimit(2);
490 solutionHistory->addState(icState);
493 stepper->setInitialConditions(solutionHistory);
494 stepper->initialize();
497 stepper->setInitialConditions(solutionHistory);
498 solutionHistory->initWorkingState();
499 solutionHistory->getWorkingState()->setTimeStep(15.0);
500 stepper->takeStep(solutionHistory);
503 stepper->setInitialConditions(solutionHistory);
504 solutionHistory->initWorkingState();
505 solutionHistory->getWorkingState()->setTimeStep(15.0);
506 stepper->takeStep(solutionHistory);
513 auto x = solutionHistory->getCurrentState()->getX();
516 auto xDot = solutionHistory->getWorkingState()->getXDot();
517 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
520 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
523 auto time = solutionHistory->getWorkingState()->getTime();
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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
Default modifier for StepperSubcycling.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
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_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
virtual ModelEvaluatorBase::InArgs< Scalar > getNominalValues() const =0
#define TEUCHOS_ASSERT(assertion_test)
Base ModifierX for StepperSubcycling.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)