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"
28 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
29 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
30 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
35 namespace Tempus_Unit_Test {
39 using Teuchos::rcp_const_cast;
40 using Teuchos::rcp_dynamic_cast;
41 using Teuchos::ParameterList;
42 using Teuchos::sublist;
43 using Teuchos::getParametersFromXmlFile;
60 sf->createStepperForwardEuler(explicitModel, Teuchos::null);
62 sf->createStepperBackwardEuler(implicitModel, Teuchos::null);
63 stepper->addStepper(subStepper1);
64 stepper->addStepper(subStepper2);
65 stepper->initialize();
66 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
69 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
75 bool useFSAL = stepper->getUseFSALDefault();
76 std::string ICConsistency = stepper->getICConsistencyDefault();
77 bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
81 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
82 stepper->setObserver(obs); 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());
90 stepper->setOrder(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91 stepper->setOrderMin(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92 stepper->setOrderMax(order); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
96 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
97 models.push_back(explicitModel);
98 models.push_back(implicitModel);
100 std::vector<Teuchos::RCP<Tempus::Stepper<double> > > subStepperList;
101 subStepperList.push_back(subStepper1);
102 subStepperList.push_back(subStepper2);
104 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
106 models, subStepperList, obs, useFSAL, ICConsistency, ICConsistencyCheck,
107 order, order, order));
110 models, subStepperList, useFSAL, ICConsistency, ICConsistencyCheck,order, order, order,modifier));
112 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
115 TEUCHOS_ASSERT(stepper->getOrder() == 1);
124 auto pList = getParametersFromXmlFile(
125 "../test/OperatorSplit/Tempus_OperatorSplit_VanDerPol.xml");
126 auto tempusPL = sublist(pList,
"Tempus",
true);
127 auto stepperPL = sublist(tempusPL,
"Demo Stepper",
true);
131 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
132 models.push_back(explicitModel);
133 models.push_back(implicitModel);
140 auto stepper = sf->createMultiSteppers(stepperPL, models);
141 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
172 auto x = sh->getCurrentState()->getX();
179 testDt = sh->getWorkingState()->getTimeStep()/10.0;
180 sh->getWorkingState()->setTimeStep(
testDt);
186 testType =
"OperatorSplit - Modifier";
193 auto x = sh->getWorkingState()->getX();
198 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
199 "Error - unknown action location.\n");
221 sf->createStepperForwardEuler(explicitModel, Teuchos::null);
223 sf->createStepperBackwardEuler(implicitModel, Teuchos::null);
225 stepper->setAppAction(modifier);
226 stepper->addStepper(subStepper1);
227 stepper->addStepper(subStepper2);
228 stepper->initialize();
231 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
232 stepper->getModel()->getNominalValues();
233 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
234 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
236 icState->setTime (0.0);
237 icState->setIndex (1);
238 icState->setTimeStep(-15.0);
239 icState->setOrder (stepper->getOrder());
244 solutionHistory->setName(
"Forward States");
246 solutionHistory->setStorageLimit(2);
247 solutionHistory->addState(icState);
250 stepper->setInitialConditions(solutionHistory);
251 solutionHistory->initWorkingState();
252 solutionHistory->getWorkingState()->setTimeStep(-15.0);
253 stepper->takeStep(solutionHistory);
256 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
257 TEST_COMPARE(modifier->testBEFORE_STEPPER, ==,
true);
258 TEST_COMPARE(modifier->testAFTER_STEPPER, ==,
true);
259 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
262 auto x = solutionHistory->getCurrentState()->getX();
263 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
264 x = solutionHistory->getWorkingState()->getX();
265 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
266 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
267 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
269 TEST_COMPARE(modifier->testType, ==,
"OperatorSplit - Modifier");
300 auto x = sh->getCurrentState()->getX();
307 testDt = sh->getWorkingState()->getTimeStep();
313 testType = stepper->getStepperType();
319 auto x = sh->getWorkingState()->getX();
324 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
325 "Error - unknown action location.\n");
347 sf->createStepperForwardEuler(explicitModel, Teuchos::null);
349 sf->createStepperBackwardEuler(implicitModel, Teuchos::null);
351 stepper->setAppAction(observer);
352 stepper->addStepper(subStepper1);
353 stepper->addStepper(subStepper2);
354 stepper->initialize();
357 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
358 stepper->getModel()->getNominalValues();
359 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
360 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
362 icState->setTime (0.0);
363 icState->setIndex (1);
364 icState->setTimeStep(-1.5);
365 icState->setOrder (stepper->getOrder());
370 solutionHistory->setName(
"Forward States");
372 solutionHistory->setStorageLimit(2);
373 solutionHistory->addState(icState);
376 stepper->setInitialConditions(solutionHistory);
377 solutionHistory->initWorkingState();
378 solutionHistory->getWorkingState()->setTimeStep(-1.5);
379 stepper->takeStep(solutionHistory);
382 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
383 TEST_COMPARE(observer->testBEFORE_STEPPER, ==,
true);
384 TEST_COMPARE(observer->testAFTER_STEPPER, ==,
true);
385 TEST_COMPARE(observer->testEND_STEP, ==,
true);
388 auto x = solutionHistory->getCurrentState()->getX();
389 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
390 x = solutionHistory->getWorkingState()->getX();
391 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
392 TEST_FLOATING_EQUALITY(observer->testDt, -1.5, 1.0e-15);
394 TEST_COMPARE(observer->testType, ==,
"Operator Split");
417 Teuchos::RCP<Thyra::VectorBase<double> > x,
418 const double time,
const double dt,
425 testX = get_ele(*(x), 0);
447 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
448 "Error - unknown action location.\n");
470 sf->createStepperForwardEuler(explicitModel, Teuchos::null);
472 sf->createStepperBackwardEuler(implicitModel, Teuchos::null);
474 stepper->setAppAction(modifierX);
475 stepper->addStepper(subStepper1);
476 stepper->addStepper(subStepper2);
477 stepper->initialize();
480 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
481 stepper->getModel()->getNominalValues();
482 auto icX = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
483 auto icXDot = rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x_dot());
485 icState->setTime (0.0);
486 icState->setIndex (1);
487 icState->setTimeStep(-1.5);
488 icState->setOrder (stepper->getOrder());
493 solutionHistory->setName(
"Forward States");
495 solutionHistory->setStorageLimit(2);
496 solutionHistory->addState(icState);
499 stepper->setInitialConditions(solutionHistory);
500 solutionHistory->initWorkingState();
501 solutionHistory->getWorkingState()->setTimeStep(-1.5);
502 stepper->takeStep(solutionHistory);
505 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
506 TEST_COMPARE(modifierX->testX_BEFORE_STEPPER, ==,
true);
507 TEST_COMPARE(modifierX->testX_AFTER_STEPPER, ==,
true);
508 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
511 auto x = solutionHistory->getCurrentState()->getX();
512 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
514 auto xDot = stepper->getStepperXDot(solutionHistory->getWorkingState());
515 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-15);
516 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
517 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
519 auto time = solutionHistory->getWorkingState()->getTime();
520 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.
van der Pol model formulated for IMEX-RK.
Explicit Runge-Kutta time stepper.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
After a stepper evaluation.
Modify at the end of the step.
Base ModifierX for StepperOperatorSplit.
Base modifier for OperatorSplit.
At the beginning of the step.
virtual ~StepperOperatorSplitObserverTest()
Destructor.
StepperOperatorSplitModifierTest()
Constructor.
OperatorSplit stepper loops through the Stepper list.
StepperOperatorSplitObserverTest()
Constructor.
Before a stepper evaluation.
Base observer for StepperOperatorSplit.
StepperOperatorSplitObserver class for StepperOperatorSplit.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperOperatorSplit< double > > stepper, const typename Tempus::StepperOperatorSplitAppAction< double >::ACTION_LOCATION actLoc)
Modify OperatorSplit Stepper at action location.
Default modifier for StepperOperatorSplit.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperOperatorSplit< double > > stepper, const typename Tempus::StepperOperatorSplitAppAction< double >::ACTION_LOCATION actLoc)
Observe OperatorSplit Stepper at action location.
Keep a fix number of states.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const typename Tempus::StepperOperatorSplitModifierXBase< double >::MODIFIER_TYPE modType)
Modify OperatorSplit Stepper at action location.
StepperOperatorSplitModifierXTest()
Constructor.
virtual ~StepperOperatorSplitModifierTest()
Destructor.
van der Pol model formulated for IMEX.
bool testX_BEFORE_STEPPER
Default ModifierX for StepperOperatorSplit.
virtual ~StepperOperatorSplitModifierXTest()
Destructor.
Modify before the implicit solve.
Default observer for StepperOperatorSplit.
Modify at the beginning of the step.