12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_StepperFactory.hpp"
20 #include "Tempus_StepperForwardEuler.hpp"
21 #include "Tempus_StepperBackwardEuler.hpp"
23 #include "Tempus_StepperOperatorSplit.hpp"
31 #include "../TestModels/VanDerPol_IMEX_ExplicitModel.hpp"
32 #include "../TestModels/VanDerPol_IMEX_ImplicitModel.hpp"
33 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
38 namespace Tempus_Unit_Test {
42 using Teuchos::rcp_const_cast;
43 using Teuchos::rcp_dynamic_cast;
45 using Teuchos::sublist;
46 using Teuchos::getParametersFromXmlFile;
64 stepper->addStepper(subStepper1);
65 stepper->addStepper(subStepper2);
66 stepper->initialize();
73 bool useFSAL = stepper->getUseFSAL();
74 std::string ICConsistency = stepper->getICConsistency();
75 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
83 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
91 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
92 models.push_back(explicitModel);
93 models.push_back(implicitModel);
95 std::vector<Teuchos::RCP<Tempus::Stepper<double> > > subStepperList;
96 subStepperList.push_back(subStepper1);
97 subStepperList.push_back(subStepper2);
100 models, subStepperList, useFSAL, ICConsistency, ICConsistencyCheck,order, order, order,modifier));
114 auto pList = getParametersFromXmlFile(
115 "../test/OperatorSplit/Tempus_OperatorSplit_VanDerPol.xml");
116 auto tempusPL = sublist(pList,
"Tempus",
true);
117 auto stepperPL = sublist(tempusPL,
"Demo Stepper",
true);
121 std::vector<RCP<const Thyra::ModelEvaluator<double> > > models;
122 models.push_back(explicitModel);
123 models.push_back(implicitModel);
130 auto stepper = sf->createStepper(stepperPL, models);
137 class StepperOperatorSplitModifierTest
143 StepperOperatorSplitModifierTest()
144 : testBEGIN_STEP(false), testEND_STEP(false),
145 testCurrentValue(-0.99), testWorkingValue(-0.99),
146 testDt(-1.5), testName(
"")
150 virtual ~StepperOperatorSplitModifierTest(){}
161 testBEGIN_STEP =
true;
162 auto x = sh->getCurrentState()->getX();
163 testCurrentValue = get_ele(*(x), 0);
168 testBEFORE_STEPPER =
true;
169 testDt = sh->getWorkingState()->getTimeStep()/10.0;
170 sh->getWorkingState()->setTimeStep(testDt);
175 testAFTER_STEPPER =
true;
176 testName =
"OperatorSplit - Modifier";
177 stepper->setStepperName(testName);
183 auto x = sh->getWorkingState()->getX();
184 testWorkingValue = get_ele(*(x), 0);
189 "Error - unknown action location.\n");
194 bool testBEFORE_STEPPER;
195 bool testAFTER_STEPPER;
197 double testCurrentValue;
198 double testWorkingValue;
200 std::string testName;
213 auto modifier =
rcp(
new StepperOperatorSplitModifierTest());
214 stepper->setAppAction(modifier);
215 stepper->addStepper(subStepper1);
216 stepper->addStepper(subStepper2);
217 stepper->initialize();
220 auto inArgsIC = stepper->getModel()->getNominalValues();
224 icState->setTime (0.0);
225 icState->setIndex (1);
226 icState->setTimeStep(-15.0);
227 icState->setOrder (stepper->getOrder());
232 solutionHistory->setName(
"Forward States");
234 solutionHistory->setStorageLimit(2);
235 solutionHistory->addState(icState);
238 stepper->setInitialConditions(solutionHistory);
239 solutionHistory->initWorkingState();
240 solutionHistory->getWorkingState()->setTimeStep(-15.0);
241 stepper->takeStep(solutionHistory);
250 auto x = solutionHistory->getCurrentState()->getX();
252 x = solutionHistory->getWorkingState()->getX();
254 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
257 TEST_COMPARE(modifier->testName, ==,
"OperatorSplit - Modifier");
262 class StepperOperatorSplitObserverTest
268 StepperOperatorSplitObserverTest()
269 : testBEGIN_STEP(false), testBEFORE_STEPPER(false),
270 testAFTER_STEPPER(false), testEND_STEP(false),
271 testCurrentValue(-0.99), testWorkingValue(-0.99),
272 testDt(-1.5), testName(
"Operator Split")
276 virtual ~StepperOperatorSplitObserverTest(){}
279 virtual void observe(
287 testBEGIN_STEP =
true;
288 auto x = sh->getCurrentState()->getX();
289 testCurrentValue = get_ele(*(x), 0);
294 testBEFORE_STEPPER =
true;
295 testDt = sh->getWorkingState()->getTimeStep();
300 testAFTER_STEPPER =
true;
301 testName = stepper->getStepperType();
307 auto x = sh->getWorkingState()->getX();
308 testWorkingValue = get_ele(*(x), 0);
313 "Error - unknown action location.\n");
318 bool testBEFORE_STEPPER;
319 bool testAFTER_STEPPER;
321 double testCurrentValue;
322 double testWorkingValue;
324 std::string testName;
337 auto observer =
rcp(
new StepperOperatorSplitObserverTest());
338 stepper->setAppAction(observer);
339 stepper->addStepper(subStepper1);
340 stepper->addStepper(subStepper2);
341 stepper->initialize();
344 auto inArgsIC = stepper->getModel()->getNominalValues();
348 icState->setTime (0.0);
349 icState->setIndex (1);
350 icState->setTimeStep(-1.5);
351 icState->setOrder (stepper->getOrder());
356 solutionHistory->setName(
"Forward States");
358 solutionHistory->setStorageLimit(2);
359 solutionHistory->addState(icState);
362 stepper->setInitialConditions(solutionHistory);
363 solutionHistory->initWorkingState();
364 solutionHistory->getWorkingState()->setTimeStep(-1.5);
365 stepper->takeStep(solutionHistory);
374 auto x = solutionHistory->getCurrentState()->getX();
376 x = solutionHistory->getWorkingState()->getX();
385 class StepperOperatorSplitModifierXTest
391 StepperOperatorSplitModifierXTest()
392 : testX_BEGIN_STEP(false), testX_BEFORE_STEPPER(false),
393 testX_AFTER_STEPPER(false), testXDOT_END_STEP(false),
394 testX(-0.99), testXDot(-0.99),
395 testDt(-1.5), testTime(-1.5)
399 virtual ~StepperOperatorSplitModifierXTest(){}
404 const double time,
const double dt,
410 testX_BEGIN_STEP =
true;
411 testX = get_ele(*(x), 0);
416 testX_BEFORE_STEPPER =
true;
422 testX_AFTER_STEPPER =
true;
428 testXDOT_END_STEP =
true;
429 testXDot = get_ele(*(x), 0);
434 "Error - unknown action location.\n");
438 bool testX_BEGIN_STEP;
439 bool testX_BEFORE_STEPPER;
440 bool testX_AFTER_STEPPER;
441 bool testXDOT_END_STEP;
458 auto modifierX =
rcp(
new StepperOperatorSplitModifierXTest());
459 stepper->setAppAction(modifierX);
460 stepper->addStepper(subStepper1);
461 stepper->addStepper(subStepper2);
462 stepper->initialize();
465 auto inArgsIC = stepper->getModel()->getNominalValues();
469 icState->setTime (0.0);
470 icState->setIndex (1);
471 icState->setTimeStep(-1.5);
472 icState->setOrder (stepper->getOrder());
477 solutionHistory->setName(
"Forward States");
479 solutionHistory->setStorageLimit(2);
480 solutionHistory->addState(icState);
483 stepper->setInitialConditions(solutionHistory);
484 solutionHistory->initWorkingState();
485 solutionHistory->getWorkingState()->setTimeStep(-1.5);
486 stepper->takeStep(solutionHistory);
490 TEST_COMPARE(modifierX->testX_BEFORE_STEPPER, ==,
true);
495 auto x = solutionHistory->getCurrentState()->getX();
498 auto xDot = solutionHistory->getWorkingState()->getXDot();
499 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
502 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
505 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.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
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.
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.