12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
19 #include "Tempus_StepperForwardEuler.hpp"
27 #include "../TestModels/SinCosModel.hpp"
28 #include "../TestModels/VanDerPolModel.hpp"
29 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
34 namespace Tempus_Unit_Test {
38 using Teuchos::rcp_const_cast;
39 using Teuchos::rcp_dynamic_cast;
41 using Teuchos::sublist;
42 using Teuchos::getParametersFromXmlFile;
60 stepper->setModel(model);
61 stepper->initialize();
64 bool useFSAL = stepper->getUseFSAL();
65 std::string ICConsistency = stepper->getICConsistency();
66 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
73 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 model, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
96 class StepperForwardEulerModifierTest
102 StepperForwardEulerModifierTest()
103 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
104 testEND_STEP(false), testCurrentValue(-0.99), testWorkingValue(-0.99),
105 testDt(-1.5), testName(
"")
109 virtual ~StepperForwardEulerModifierTest(){}
120 testBEGIN_STEP =
true;
121 auto x = sh->getCurrentState()->getX();
122 testCurrentValue = get_ele(*(x), 0);
127 testBEFORE_EXPLICIT_EVAL =
true;
128 testDt = sh->getWorkingState()->getTimeStep()/10.0;
129 sh->getWorkingState()->setTimeStep(testDt);
130 testName =
"Forward Euler - Modifier";
131 stepper->setStepperName(testName);
137 auto x = sh->getWorkingState()->getX();
138 testWorkingValue = get_ele(*(x), 0);
143 "Error - unknown action location.\n");
147 bool testBEFORE_EXPLICIT_EVAL;
149 double testCurrentValue;
150 double testWorkingValue;
152 std::string testName;
161 stepper->setModel(model);
162 auto modifier =
rcp(
new StepperForwardEulerModifierTest());
163 stepper->setAppAction(modifier);
164 stepper->initialize();
167 auto inArgsIC = model->getNominalValues();
171 icState->setTime (0.0);
172 icState->setIndex (0);
173 icState->setTimeStep(0.0);
174 icState->setOrder (stepper->getOrder());
179 solutionHistory->setName(
"Forward States");
181 solutionHistory->setStorageLimit(2);
182 solutionHistory->addState(icState);
185 stepper->setInitialConditions(solutionHistory);
186 solutionHistory->initWorkingState();
188 solutionHistory->getWorkingState()->setTimeStep(dt);
189 stepper->takeStep(solutionHistory);
192 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
195 auto x = solutionHistory->getCurrentState()->getX();
197 x = solutionHistory->getWorkingState()->getX();
199 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
202 TEST_COMPARE(modifier->testName, ==,
"Forward Euler - Modifier");
208 class StepperForwardEulerObserverTest
214 StepperForwardEulerObserverTest()
215 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
216 testEND_STEP(false), testCurrentValue(-0.99),
217 testWorkingValue(-0.99),testDt(-1.5), testName(
"")
221 virtual ~StepperForwardEulerObserverTest(){}
224 virtual void observe(
232 testBEGIN_STEP =
true;
233 auto x = sh->getCurrentState()->getX();
234 testCurrentValue = get_ele(*(x), 0);
239 testBEFORE_EXPLICIT_EVAL =
true;
240 testDt = sh->getWorkingState()->getTimeStep();
241 testName = stepper->getStepperName();
247 auto x = sh->getWorkingState()->getX();
248 testWorkingValue = get_ele(*(x), 0);
253 "Error - unknown action location.\n");
258 bool testBEFORE_EXPLICIT_EVAL;
260 double testCurrentValue;
261 double testWorkingValue;
263 std::string testName;
272 stepper->setModel(model);
273 auto observer =
rcp(
new StepperForwardEulerObserverTest());
274 stepper->setAppAction(observer);
275 stepper->initialize();
278 auto inArgsIC = model->getNominalValues();
282 icState->setTime (0.0);
283 icState->setIndex (0);
284 icState->setTimeStep(0.0);
285 icState->setOrder (stepper->getOrder());
290 solutionHistory->setName(
"Forward States");
292 solutionHistory->setStorageLimit(2);
293 solutionHistory->addState(icState);
296 stepper->setInitialConditions(solutionHistory);
297 solutionHistory->initWorkingState();
299 solutionHistory->getWorkingState()->setTimeStep(dt);
300 stepper->takeStep(solutionHistory);
303 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
306 auto x = solutionHistory->getCurrentState()->getX();
308 x = solutionHistory->getWorkingState()->getX();
318 class StepperForwardEulerModifierXTest
324 StepperForwardEulerModifierXTest()
325 : testX_BEGIN_STEP(false), testX_BEFORE_EXPLICIT_EVAL(false),
326 testXDOT_END_STEP(false), testX(-0.99),
327 testXDot(-0.99), testDt(-1.5), testTime(-1.5)
331 virtual ~StepperForwardEulerModifierXTest(){}
336 const double time,
const double dt,
342 testX_BEGIN_STEP =
true;
343 testX = get_ele(*(x), 0);
348 testX_BEFORE_EXPLICIT_EVAL =
true;
355 testXDOT_END_STEP =
true;
356 testXDot = get_ele(*(x), 0);
361 "Error - unknown action location.\n");
364 bool testX_BEGIN_STEP;
365 bool testX_BEFORE_EXPLICIT_EVAL;
366 bool testXDOT_END_STEP;
379 stepper->setModel(model);
380 auto modifierX =
rcp(
new StepperForwardEulerModifierXTest());
381 stepper->setAppAction(modifierX);
382 stepper->initialize();
385 auto inArgsIC = model->getNominalValues();
389 icState->setTime (0.0);
390 icState->setIndex (0);
391 icState->setTimeStep(0.0);
392 icState->setOrder (stepper->getOrder());
397 solutionHistory->setName(
"Forward States");
399 solutionHistory->setStorageLimit(2);
400 solutionHistory->addState(icState);
403 stepper->setInitialConditions(solutionHistory);
404 solutionHistory->initWorkingState();
406 solutionHistory->getWorkingState()->setTimeStep(dt);
407 stepper->takeStep(solutionHistory);
410 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
413 auto x = solutionHistory->getCurrentState()->getX();
416 auto xDot = solutionHistory->getWorkingState()->getXDot();
417 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
420 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
423 auto time = solutionHistory->getWorkingState()->getTime();
Default modifier for StepperForwardEuler.
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.
Base modifier for StepperBackwardEuler.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
At the beginning of the step.
Explicit Runge-Kutta time stepper.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Forward Euler time stepper.
Modify before the implicit solve.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Default ModifierX for StepperForwardEuler.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Base ModifierX for StepperForwardEuler.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Modify at the end of the step.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Default observer for StepperForwardEuler.
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.
Base observer for StepperForwardEuler.
#define TEUCHOS_ASSERT(assertion_test)
Modify at the beginning of the step.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Before the explicit evaluation.