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"
35 namespace Tempus_Unit_Test {
39 using Teuchos::rcp_const_cast;
40 using Teuchos::rcp_dynamic_cast;
42 using Teuchos::sublist;
43 using Teuchos::getParametersFromXmlFile;
60 solutionHistory->addState(icState);
61 solutionHistory->initWorkingState();
66 stepper->setSubcyclingStepper(stepperBE);
67 stepper->setInitialConditions(solutionHistory);
68 stepper->initialize();
78 bool useFSAL = stepper->getUseFSAL();
79 std::string ICConsistency = stepper->getICConsistency();
80 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
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));
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();
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);
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);
257 auto x = solutionHistory->getCurrentState()->getX();
259 x = solutionHistory->getWorkingState()->getX();
261 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
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);
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);
379 auto x = solutionHistory->getCurrentState()->getX();
381 x = solutionHistory->getWorkingState()->getX();
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);
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);
507 auto x = solutionHistory->getCurrentState()->getX();
510 auto xDot = solutionHistory->getWorkingState()->getXDot();
511 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
514 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
517 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).