11 #include "Tempus_StepperForwardEuler.hpp"
12 #include "Tempus_StepperBackwardEuler.hpp"
14 #include "Tempus_StepperSubcycling.hpp"
23 namespace Tempus_Unit_Test {
27 using Teuchos::rcp_const_cast;
28 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();
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));
104 stepper->setSubcyclingStepper(stepperBE);
107 auto inArgsIC = model->getNominalValues();
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();
131 class 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(){}
154 testBEGIN_STEP =
true;
155 auto x = sh->getCurrentState()->getX();
156 testCurrentValue = get_ele(*(x), 0);
157 testName =
"Subcycling - Modifier";
158 stepper->setStepperName(testName);
164 auto x = sh->getWorkingState()->getX();
165 testWorkingValue = get_ele(*(x), 0);
166 testDt = sh->getWorkingState()->getTimeStep()/10.0;
167 sh->getWorkingState()->setTimeStep(testDt);
172 "Error - unknown action location.\n");
178 double testCurrentValue;
179 double testWorkingValue;
181 std::string testName;
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();
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);
244 auto x = solutionHistory->getCurrentState()->getX();
246 x = solutionHistory->getWorkingState()->getX();
248 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
251 TEST_COMPARE(modifier->testName, ==,
"Subcycling - Modifier");
256 class 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(
280 testBEGIN_STEP =
true;
281 auto x = sh->getCurrentState()->getX();
282 testCurrentValue = get_ele(*(x), 0);
288 auto x = sh->getWorkingState()->getX();
289 testWorkingValue = get_ele(*(x), 0);
294 "Error - unknown action location.\n");
300 double testCurrentValue;
301 double testWorkingValue;
303 std::string testName;
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();
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);
366 auto x = solutionHistory->getCurrentState()->getX();
368 x = solutionHistory->getWorkingState()->getX();
377 class 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,
401 testX_BEGIN_STEP =
true;
402 testX = get_ele(*(x), 0);
408 testXDOT_END_STEP =
true;
409 testXDot = get_ele(*(x), 0);
415 "Error - unknown action location.\n");
419 bool testX_BEGIN_STEP;
420 bool testXDOT_END_STEP;
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();
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);
494 auto x = solutionHistory->getCurrentState()->getX();
497 auto xDot = solutionHistory->getWorkingState()->getXDot();
498 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
501 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
504 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)
MODIFIER_TYPE
Indicates the location of application action (see algorithm).