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"
24 #include "../TestModels/SinCosModel.hpp"
25 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
30 namespace Tempus_Unit_Test {
34 using Teuchos::rcp_const_cast;
35 using Teuchos::rcp_dynamic_cast;
36 using Teuchos::ParameterList;
37 using Teuchos::sublist;
38 using Teuchos::getParametersFromXmlFile;
53 auto stepperBE = sf->createStepperBackwardEuler(model, Teuchos::null);
54 stepper->setSubcyclingStepper(stepperBE);
55 stepper->initialize();
56 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
59 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
65 auto solver = rcp(
new Thyra::NOXNonlinearSolver());
68 bool useFSAL = stepper->getUseFSALDefault();
69 std::string ICConsistency = stepper->getICConsistencyDefault();
70 bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
73 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
75 stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
80 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
81 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 auto stepperFE = sf->createStepperForwardEuler(model, Teuchos::null);
88 scIntegrator->setStepperWStepper(stepperFE);
89 scIntegrator->initialize();
91 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
93 model, obs, scIntegrator, useFSAL, ICConsistency, ICConsistencyCheck));
94 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
98 model,scIntegrator, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
99 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
102 TEUCHOS_ASSERT(stepper->getOrder() == 1);
114 auto stepperBE = sf->createStepperBackwardEuler(model, Teuchos::null);
115 stepper->setSubcyclingStepper(stepperBE);
116 stepper->initialize();
119 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
120 stepper->getModel()->getNominalValues();
121 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
124 solutionHistory->addState(icState);
125 solutionHistory->initWorkingState();
128 stepper->setSubcyclingMaxTimeStep(0.5);
129 double maxTimeStep_Set = stepper->getSubcyclingMaxTimeStep();
130 stepper->takeStep(solutionHistory);
131 double maxTimeStep_After = stepper->getSubcyclingMaxTimeStep();
133 TEST_FLOATING_EQUALITY(maxTimeStep_Set, maxTimeStep_After, 1.0e-14 );
163 auto x = sh->getCurrentState()->getX();
172 auto x = sh->getWorkingState()->getX();
174 testDt = sh->getWorkingState()->getTimeStep()/10.0;
175 sh->getWorkingState()->setTimeStep(
testDt);
179 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
180 "Error - unknown action location.\n");
200 auto stepperFE = sf->createStepperForwardEuler(model, Teuchos::null);
202 stepper->setAppAction(modifier);
203 stepper->setSubcyclingStepper(stepperFE);
205 stepper->setSubcyclingMinTimeStep (15);
206 stepper->setSubcyclingInitTimeStep (15.0);
207 stepper->setSubcyclingMaxTimeStep (15.0);
208 stepper->setSubcyclingStepType (
"Constant");
209 stepper->setSubcyclingMaxFailures (10);
210 stepper->setSubcyclingMaxConsecFailures(5);
211 stepper->setSubcyclingScreenOutputIndexInterval(1);
212 stepper->setSubcyclingPrintDtChanges(
true);
213 stepper->initialize();
217 timeStepControl->setStepType (
"Constant");
218 timeStepControl->setInitIndex(0);
219 timeStepControl->setInitTime (0.0);
220 timeStepControl->setFinalTime(1.0);
221 timeStepControl->setInitTimeStep(15.0);
222 timeStepControl->initialize();
225 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
226 stepper->getModel()->getNominalValues();
227 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
229 icState->setTime (timeStepControl->getInitTime());;
230 icState->setIndex (timeStepControl->getInitIndex());
231 icState->setTimeStep(0.0);
236 solutionHistory->setName(
"Forward States");
238 solutionHistory->setStorageLimit(2);
239 solutionHistory->addState(icState);
242 stepper->setInitialConditions(solutionHistory);
243 solutionHistory->initWorkingState();
244 solutionHistory->getWorkingState()->setTimeStep(15.0);
245 stepper->takeStep(solutionHistory);
248 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
249 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
252 auto x = solutionHistory->getCurrentState()->getX();
253 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
254 x = solutionHistory->getWorkingState()->getX();
255 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
256 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
257 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
259 TEST_COMPARE(modifier->testType, ==,
"Subcycling - Modifier");
289 auto x = sh->getCurrentState()->getX();
296 auto x = sh->getWorkingState()->getX();
301 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
302 "Error - unknown action location.\n");
322 auto stepperFE = sf->createStepperForwardEuler(model, Teuchos::null);
324 stepper->setAppAction(observer);
325 stepper->setSubcyclingStepper(stepperFE);
327 stepper->setSubcyclingMinTimeStep (15);
328 stepper->setSubcyclingInitTimeStep (15.0);
329 stepper->setSubcyclingMaxTimeStep (15.0);
330 stepper->setSubcyclingStepType (
"Constant");
331 stepper->setSubcyclingMaxFailures (10);
332 stepper->setSubcyclingMaxConsecFailures(5);
333 stepper->setSubcyclingScreenOutputIndexInterval(1);
334 stepper->setSubcyclingPrintDtChanges(
true);
335 stepper->initialize();
339 timeStepControl->setStepType (
"Constant");
340 timeStepControl->setInitIndex(0);
341 timeStepControl->setInitTime (0.0);
342 timeStepControl->setFinalTime(1.0);
343 timeStepControl->setInitTimeStep(15.0);
344 timeStepControl->initialize();
347 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
348 stepper->getModel()->getNominalValues();
349 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
351 icState->setTime (timeStepControl->getInitTime());;
352 icState->setIndex (timeStepControl->getInitIndex());
353 icState->setTimeStep(0.0);
358 solutionHistory->setName(
"Forward States");
360 solutionHistory->setStorageLimit(2);
361 solutionHistory->addState(icState);
364 stepper->setInitialConditions(solutionHistory);
365 solutionHistory->initWorkingState();
366 solutionHistory->getWorkingState()->setTimeStep(15.0);
367 stepper->takeStep(solutionHistory);
370 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
371 TEST_COMPARE(observer->testEND_STEP, ==,
true);
374 auto x = solutionHistory->getCurrentState()->getX();
375 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
376 x = solutionHistory->getWorkingState()->getX();
377 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
378 TEST_FLOATING_EQUALITY(observer->testDt, 15.0, 1.0e-15);
380 TEST_COMPARE(observer->testType, ==,
"Subcyling");
402 Teuchos::RCP<Thyra::VectorBase<double> > x,
403 const double time,
const double dt,
410 testX = get_ele(*(x), 0);
422 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
423 "Error - unknown action location.\n");
443 auto stepperFE = sf->createStepperForwardEuler(model, Teuchos::null);
445 stepper->setAppAction(modifierX);
446 stepper->setSubcyclingStepper(stepperFE);
448 stepper->setSubcyclingMinTimeStep (15);
449 stepper->setSubcyclingInitTimeStep (15.0);
450 stepper->setSubcyclingMaxTimeStep (15.0);
451 stepper->setSubcyclingStepType (
"Constant");
452 stepper->setSubcyclingMaxFailures (10);
453 stepper->setSubcyclingMaxConsecFailures(5);
454 stepper->setSubcyclingScreenOutputIndexInterval(1);
455 stepper->setSubcyclingPrintDtChanges(
true);
456 stepper->initialize();
460 timeStepControl->setStepType (
"Constant");
461 timeStepControl->setInitIndex(0);
462 timeStepControl->setInitTime (0.0);
463 timeStepControl->setFinalTime(1.0);
464 timeStepControl->setInitTimeStep(15.0);
465 timeStepControl->initialize();
468 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
469 stepper->getModel()->getNominalValues();
470 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
471 auto icSolutionDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
473 icState->setTime (timeStepControl->getInitTime());;
474 icState->setIndex (timeStepControl->getInitIndex());
475 icState->setTimeStep(0.0);
480 solutionHistory->setName(
"Forward States");
482 solutionHistory->setStorageLimit(2);
483 solutionHistory->addState(icState);
486 stepper->setInitialConditions(solutionHistory);
487 solutionHistory->initWorkingState();
488 solutionHistory->getWorkingState()->setTimeStep(15.0);
489 stepper->takeStep(solutionHistory);
492 stepper->setInitialConditions(solutionHistory);
493 solutionHistory->initWorkingState();
494 solutionHistory->getWorkingState()->setTimeStep(15.0);
495 stepper->takeStep(solutionHistory);
498 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
499 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
502 auto x = solutionHistory->getCurrentState()->getX();
503 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
505 auto xDot = stepper->getStepperXDot(solutionHistory->getWorkingState());
506 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-15);
507 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
508 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
510 auto time = solutionHistory->getWorkingState()->getTime();
511 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
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.
Explicit Runge-Kutta time stepper.
StepperSubcyclingModifierTest()
Constructor.
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperSubcycling< double > > stepper, const typename Tempus::StepperSubcyclingAppAction< double >::ACTION_LOCATION actLoc)
Observe Subcycling Stepper at action location.
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.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const typename Tempus::StepperSubcyclingModifierXBase< double >::MODIFIER_TYPE modType)
Modify Subcycling Stepper at action location.
virtual ~StepperSubcyclingModifierXTest()
Destructor.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Modify at the beginning of the step.
TimeStepControl manages the time step size. There several mechanicisms that effect the time step size...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepperSubcyclingObserverTest()
Constructor.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperSubcycling< double > > stepper, const typename Tempus::StepperSubcyclingAppAction< double >::ACTION_LOCATION actLoc)
Modify Subcycling Stepper at action location.
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.
StepperSubcyclingModifierXTest()
Constructor.
Base observer for StepperSubcycling.
virtual ~StepperSubcyclingModifierTest()
Destructor.
StepperSubcyclingObserver class for StepperSubcycling.
Base ModifierX for StepperSubcycling.
virtual ~StepperSubcyclingObserverTest()
Destructor.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).