13 #include "Tempus_StepperForwardEuler.hpp"
21 namespace Tempus_Unit_Test {
26 using Teuchos::rcp_const_cast;
27 using Teuchos::rcp_dynamic_cast;
28 using Teuchos::sublist;
44 stepper->setModel(model);
45 stepper->initialize();
48 bool useFSAL = stepper->getUseFSAL();
49 std::string ICConsistency = stepper->getICConsistency();
50 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
53 stepper->setAppAction(modifier);
54 stepper->initialize();
56 stepper->setAppAction(modifierX);
57 stepper->initialize();
59 stepper->setAppAction(observer);
60 stepper->initialize();
62 stepper->setUseFSAL(useFSAL);
63 stepper->initialize();
65 stepper->setICConsistency(ICConsistency);
66 stepper->initialize();
68 stepper->setICConsistencyCheck(ICConsistencyCheck);
69 stepper->initialize();
73 model, useFSAL, ICConsistency, ICConsistencyCheck, modifier));
90 class StepperForwardEulerModifierTest
94 StepperForwardEulerModifierTest()
95 : testBEGIN_STEP(false),
96 testBEFORE_EXPLICIT_EVAL(false),
98 testCurrentValue(-0.99),
99 testWorkingValue(-0.99),
106 virtual ~StepperForwardEulerModifierTest() {}
113 double>::ACTION_LOCATION actLoc)
117 testBEGIN_STEP =
true;
118 auto x = sh->getCurrentState()->getX();
119 testCurrentValue = get_ele(*(x), 0);
123 testBEFORE_EXPLICIT_EVAL =
true;
124 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
125 sh->getWorkingState()->setTimeStep(testDt);
126 testName =
"Forward Euler - Modifier";
127 stepper->setStepperName(testName);
132 auto x = sh->getWorkingState()->getX();
133 testWorkingValue = get_ele(*(x), 0);
138 "Error - unknown action location.\n");
142 bool testBEFORE_EXPLICIT_EVAL;
144 double testCurrentValue;
145 double testWorkingValue;
147 std::string testName;
156 stepper->setModel(model);
157 auto modifier =
rcp(
new StepperForwardEulerModifierTest());
158 stepper->setAppAction(modifier);
159 stepper->initialize();
162 auto inArgsIC = model->getNominalValues();
166 icState->setTime(0.0);
167 icState->setIndex(0);
168 icState->setTimeStep(0.0);
169 icState->setOrder(stepper->getOrder());
174 solutionHistory->setName(
"Forward States");
176 solutionHistory->setStorageLimit(2);
177 solutionHistory->addState(icState);
180 stepper->setInitialConditions(solutionHistory);
181 solutionHistory->initWorkingState();
183 solutionHistory->getWorkingState()->setTimeStep(dt);
184 stepper->takeStep(solutionHistory);
187 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
190 auto x = solutionHistory->getCurrentState()->getX();
192 x = solutionHistory->getWorkingState()->getX();
194 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
197 TEST_COMPARE(modifier->testName, ==,
"Forward Euler - Modifier");
202 class StepperForwardEulerObserverTest
206 StepperForwardEulerObserverTest()
207 : testBEGIN_STEP(false),
208 testBEFORE_EXPLICIT_EVAL(false),
210 testCurrentValue(-0.99),
211 testWorkingValue(-0.99),
218 virtual ~StepperForwardEulerObserverTest() {}
221 virtual void observe(
225 double>::ACTION_LOCATION actLoc)
229 testBEGIN_STEP =
true;
230 auto x = sh->getCurrentState()->getX();
231 testCurrentValue = get_ele(*(x), 0);
235 testBEFORE_EXPLICIT_EVAL =
true;
236 testDt = sh->getWorkingState()->getTimeStep();
237 testName = stepper->getStepperName();
242 auto x = sh->getWorkingState()->getX();
243 testWorkingValue = get_ele(*(x), 0);
248 "Error - unknown action location.\n");
253 bool testBEFORE_EXPLICIT_EVAL;
255 double testCurrentValue;
256 double testWorkingValue;
258 std::string testName;
267 stepper->setModel(model);
268 auto observer =
rcp(
new StepperForwardEulerObserverTest());
269 stepper->setAppAction(observer);
270 stepper->initialize();
273 auto inArgsIC = model->getNominalValues();
277 icState->setTime(0.0);
278 icState->setIndex(0);
279 icState->setTimeStep(0.0);
280 icState->setOrder(stepper->getOrder());
285 solutionHistory->setName(
"Forward States");
287 solutionHistory->setStorageLimit(2);
288 solutionHistory->addState(icState);
291 stepper->setInitialConditions(solutionHistory);
292 solutionHistory->initWorkingState();
294 solutionHistory->getWorkingState()->setTimeStep(dt);
295 stepper->takeStep(solutionHistory);
298 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
301 auto x = solutionHistory->getCurrentState()->getX();
303 x = solutionHistory->getWorkingState()->getX();
312 class StepperForwardEulerModifierXTest
316 StepperForwardEulerModifierXTest()
317 : testX_BEGIN_STEP(false),
318 testX_BEFORE_EXPLICIT_EVAL(false),
319 testXDOT_END_STEP(false),
328 virtual ~StepperForwardEulerModifierXTest() {}
332 const double time,
const double dt,
334 double>::MODIFIER_TYPE modType)
338 testX_BEGIN_STEP =
true;
339 testX = get_ele(*(x), 0);
343 testX_BEFORE_EXPLICIT_EVAL =
true;
349 testXDOT_END_STEP =
true;
350 testXDot = get_ele(*(x), 0);
355 "Error - unknown action location.\n");
358 bool testX_BEGIN_STEP;
359 bool testX_BEFORE_EXPLICIT_EVAL;
360 bool testXDOT_END_STEP;
373 stepper->setModel(model);
374 auto modifierX =
rcp(
new StepperForwardEulerModifierXTest());
375 stepper->setAppAction(modifierX);
376 stepper->initialize();
379 auto inArgsIC = model->getNominalValues();
383 icState->setTime(0.0);
384 icState->setIndex(0);
385 icState->setTimeStep(0.0);
386 icState->setOrder(stepper->getOrder());
391 solutionHistory->setName(
"Forward States");
393 solutionHistory->setStorageLimit(2);
394 solutionHistory->addState(icState);
397 stepper->setInitialConditions(solutionHistory);
398 solutionHistory->initWorkingState();
400 solutionHistory->getWorkingState()->setTimeStep(dt);
401 stepper->takeStep(solutionHistory);
404 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
407 auto x = solutionHistory->getCurrentState()->getX();
410 auto xDot = solutionHistory->getWorkingState()->getXDot();
411 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
414 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
417 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.
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...
Default ModifierX for StepperForwardEuler.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Application Action for StepperForwardEuler.
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.