16 #include "Tempus_StepperForwardEuler.hpp"
17 #include "Tempus_StepperBackwardEuler.hpp"
19 #include "Tempus_StepperOperatorSplit.hpp"
27 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
28 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
30 namespace Tempus_Unit_Test {
35 using Teuchos::rcp_const_cast;
36 using Teuchos::rcp_dynamic_cast;
37 using Teuchos::sublist;
56 stepper->addStepper(subStepper1);
57 stepper->addStepper(subStepper2);
58 stepper->initialize();
68 bool useFSAL = stepper->getUseFSAL();
69 std::string ICConsistency = stepper->getICConsistency();
70 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
74 stepper->setAppAction(modifier);
75 stepper->initialize();
77 stepper->setAppAction(modifierX);
78 stepper->initialize();
80 stepper->setAppAction(observer);
81 stepper->initialize();
83 stepper->setUseFSAL(useFSAL);
84 stepper->initialize();
86 stepper->setICConsistency(ICConsistency);
87 stepper->initialize();
89 stepper->setICConsistencyCheck(ICConsistencyCheck);
90 stepper->initialize();
92 stepper->setOrder(order);
93 stepper->initialize();
95 stepper->setOrderMin(order);
96 stepper->initialize();
98 stepper->setOrderMax(order);
99 stepper->initialize();
103 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
104 models.push_back(explicitModel);
105 models.push_back(implicitModel);
107 std::vector<Teuchos::RCP<Tempus::Stepper<double> > > subStepperList;
108 subStepperList.push_back(subStepper1);
109 subStepperList.push_back(subStepper2);
112 models, subStepperList, useFSAL, ICConsistency, ICConsistencyCheck, order,
113 order, order, modifier));
126 auto pList = Teuchos::getParametersFromXmlFile(
127 "../test/OperatorSplit/Tempus_OperatorSplit_VanDerPol.xml");
128 auto tempusPL = sublist(pList,
"Tempus",
true);
129 auto stepperPL = sublist(tempusPL,
"Demo Stepper",
true);
135 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
136 models.push_back(explicitModel);
137 models.push_back(implicitModel);
143 auto stepper = sf->createStepper(stepperPL, models);
149 class StepperOperatorSplitModifierTest
153 StepperOperatorSplitModifierTest()
154 : testBEGIN_STEP(false),
156 testCurrentValue(-0.99),
157 testWorkingValue(-0.99),
164 virtual ~StepperOperatorSplitModifierTest() {}
171 double>::ACTION_LOCATION actLoc)
175 testBEGIN_STEP =
true;
176 auto x = sh->getCurrentState()->getX();
177 testCurrentValue = get_ele(*(x), 0);
181 testBEFORE_STEPPER =
true;
182 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
183 sh->getWorkingState()->setTimeStep(testDt);
187 testAFTER_STEPPER =
true;
188 testName =
"OperatorSplit - Modifier";
189 stepper->setStepperName(testName);
194 auto x = sh->getWorkingState()->getX();
195 testWorkingValue = get_ele(*(x), 0);
200 "Error - unknown action location.\n");
205 bool testBEFORE_STEPPER;
206 bool testAFTER_STEPPER;
208 double testCurrentValue;
209 double testWorkingValue;
211 std::string testName;
226 auto modifier =
rcp(
new StepperOperatorSplitModifierTest());
227 stepper->setAppAction(modifier);
228 stepper->addStepper(subStepper1);
229 stepper->addStepper(subStepper2);
230 stepper->initialize();
233 auto inArgsIC = stepper->getModel()->getNominalValues();
238 icState->setTime(0.0);
239 icState->setIndex(1);
240 icState->setTimeStep(-15.0);
241 icState->setOrder(stepper->getOrder());
246 solutionHistory->setName(
"Forward States");
248 solutionHistory->setStorageLimit(2);
249 solutionHistory->addState(icState);
252 stepper->setInitialConditions(solutionHistory);
253 solutionHistory->initWorkingState();
254 solutionHistory->getWorkingState()->setTimeStep(-15.0);
255 stepper->takeStep(solutionHistory);
264 auto x = solutionHistory->getCurrentState()->getX();
266 x = solutionHistory->getWorkingState()->getX();
268 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
271 TEST_COMPARE(modifier->testName, ==,
"OperatorSplit - Modifier");
276 class StepperOperatorSplitObserverTest
280 StepperOperatorSplitObserverTest()
281 : testBEGIN_STEP(false),
282 testBEFORE_STEPPER(false),
283 testAFTER_STEPPER(false),
285 testCurrentValue(-0.99),
286 testWorkingValue(-0.99),
288 testName(
"Operator Split")
293 virtual ~StepperOperatorSplitObserverTest() {}
296 virtual void observe(
300 double>::ACTION_LOCATION actLoc)
304 testBEGIN_STEP =
true;
305 auto x = sh->getCurrentState()->getX();
306 testCurrentValue = get_ele(*(x), 0);
310 testBEFORE_STEPPER =
true;
311 testDt = sh->getWorkingState()->getTimeStep();
315 testAFTER_STEPPER =
true;
316 testName = stepper->getStepperType();
321 auto x = sh->getWorkingState()->getX();
322 testWorkingValue = get_ele(*(x), 0);
327 "Error - unknown action location.\n");
332 bool testBEFORE_STEPPER;
333 bool testAFTER_STEPPER;
335 double testCurrentValue;
336 double testWorkingValue;
338 std::string testName;
353 auto observer =
rcp(
new StepperOperatorSplitObserverTest());
354 stepper->setAppAction(observer);
355 stepper->addStepper(subStepper1);
356 stepper->addStepper(subStepper2);
357 stepper->initialize();
360 auto inArgsIC = stepper->getModel()->getNominalValues();
365 icState->setTime(0.0);
366 icState->setIndex(1);
367 icState->setTimeStep(-1.5);
368 icState->setOrder(stepper->getOrder());
373 solutionHistory->setName(
"Forward States");
375 solutionHistory->setStorageLimit(2);
376 solutionHistory->addState(icState);
379 stepper->setInitialConditions(solutionHistory);
380 solutionHistory->initWorkingState();
381 solutionHistory->getWorkingState()->setTimeStep(-1.5);
382 stepper->takeStep(solutionHistory);
391 auto x = solutionHistory->getCurrentState()->getX();
393 x = solutionHistory->getWorkingState()->getX();
402 class StepperOperatorSplitModifierXTest
406 StepperOperatorSplitModifierXTest()
407 : testX_BEGIN_STEP(false),
408 testX_BEFORE_STEPPER(false),
409 testX_AFTER_STEPPER(false),
410 testXDOT_END_STEP(false),
419 virtual ~StepperOperatorSplitModifierXTest() {}
423 const double time,
const double dt,
425 double>::MODIFIER_TYPE modType)
429 testX_BEGIN_STEP =
true;
430 testX = get_ele(*(x), 0);
434 testX_BEFORE_STEPPER =
true;
439 testX_AFTER_STEPPER =
true;
444 testXDOT_END_STEP =
true;
445 testXDot = get_ele(*(x), 0);
450 "Error - unknown action location.\n");
454 bool testX_BEGIN_STEP;
455 bool testX_BEFORE_STEPPER;
456 bool testX_AFTER_STEPPER;
457 bool testXDOT_END_STEP;
476 auto modifierX =
rcp(
new StepperOperatorSplitModifierXTest());
477 stepper->setAppAction(modifierX);
478 stepper->addStepper(subStepper1);
479 stepper->addStepper(subStepper2);
480 stepper->initialize();
483 auto inArgsIC = stepper->getModel()->getNominalValues();
488 icState->setTime(0.0);
489 icState->setIndex(1);
490 icState->setTimeStep(-1.5);
491 icState->setOrder(stepper->getOrder());
496 solutionHistory->setName(
"Forward States");
498 solutionHistory->setStorageLimit(2);
499 solutionHistory->addState(icState);
502 stepper->setInitialConditions(solutionHistory);
503 solutionHistory->initWorkingState();
504 solutionHistory->getWorkingState()->setTimeStep(-1.5);
505 stepper->takeStep(solutionHistory);
509 TEST_COMPARE(modifierX->testX_BEFORE_STEPPER, ==,
true);
514 auto x = solutionHistory->getCurrentState()->getX();
517 auto xDot = solutionHistory->getWorkingState()->getXDot();
518 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
521 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
524 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.
van der Pol model formulated for IMEX-RK.
Explicit Runge-Kutta time stepper.
After a stepper evaluation.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
Modify at the end of the step.
Base ModifierX for StepperOperatorSplit.
Base modifier for OperatorSplit.
At the beginning of the step.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
OperatorSplit stepper loops through the Stepper list.
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)
Before a stepper evaluation.
Base observer for StepperOperatorSplit.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Default modifier for StepperOperatorSplit.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
StepperOperatorSplitAppAction class for StepperOperatorSplit.
Teuchos::RCP< StepperBackwardEuler< Scalar > > createStepperBackwardEuler(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
van der Pol model formulated for IMEX.
#define TEUCHOS_ASSERT(assertion_test)
Default ModifierX for StepperOperatorSplit.
Modify before the implicit solve.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Default observer for StepperOperatorSplit.
Modify at the beginning of the step.