12 #include "Tempus_StepperForwardEuler.hpp"
20 namespace Tempus_Unit_Test {
25 using Teuchos::rcp_const_cast;
26 using Teuchos::rcp_dynamic_cast;
27 using Teuchos::sublist;
43 stepper->setModel(model);
44 stepper->initialize();
47 bool useFSAL = stepper->getUseFSAL();
48 std::string ICConsistency = stepper->getICConsistency();
49 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
52 stepper->setAppAction(modifier);
53 stepper->initialize();
55 stepper->setAppAction(modifierX);
56 stepper->initialize();
58 stepper->setAppAction(observer);
59 stepper->initialize();
61 stepper->setUseFSAL(useFSAL);
62 stepper->initialize();
64 stepper->setICConsistency(ICConsistency);
65 stepper->initialize();
67 stepper->setICConsistencyCheck(ICConsistencyCheck);
68 stepper->initialize();
72 model, useFSAL, ICConsistency, ICConsistencyCheck, modifier));
89 class StepperForwardEulerModifierTest
93 StepperForwardEulerModifierTest()
94 : testBEGIN_STEP(false),
95 testBEFORE_EXPLICIT_EVAL(false),
97 testCurrentValue(-0.99),
98 testWorkingValue(-0.99),
105 virtual ~StepperForwardEulerModifierTest() {}
112 double>::ACTION_LOCATION actLoc)
116 testBEGIN_STEP =
true;
117 auto x = sh->getCurrentState()->getX();
118 testCurrentValue = get_ele(*(x), 0);
122 testBEFORE_EXPLICIT_EVAL =
true;
123 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
124 sh->getWorkingState()->setTimeStep(testDt);
125 testName =
"Forward Euler - Modifier";
126 stepper->setStepperName(testName);
131 auto x = sh->getWorkingState()->getX();
132 testWorkingValue = get_ele(*(x), 0);
137 "Error - unknown action location.\n");
141 bool testBEFORE_EXPLICIT_EVAL;
143 double testCurrentValue;
144 double testWorkingValue;
146 std::string testName;
155 stepper->setModel(model);
156 auto modifier =
rcp(
new StepperForwardEulerModifierTest());
157 stepper->setAppAction(modifier);
158 stepper->initialize();
161 auto inArgsIC = model->getNominalValues();
165 icState->setTime(0.0);
166 icState->setIndex(0);
167 icState->setTimeStep(0.0);
168 icState->setOrder(stepper->getOrder());
173 solutionHistory->setName(
"Forward States");
175 solutionHistory->setStorageLimit(2);
176 solutionHistory->addState(icState);
179 stepper->setInitialConditions(solutionHistory);
180 solutionHistory->initWorkingState();
182 solutionHistory->getWorkingState()->setTimeStep(dt);
183 stepper->takeStep(solutionHistory);
186 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
189 auto x = solutionHistory->getCurrentState()->getX();
191 x = solutionHistory->getWorkingState()->getX();
193 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
196 TEST_COMPARE(modifier->testName, ==,
"Forward Euler - Modifier");
201 class StepperForwardEulerObserverTest
205 StepperForwardEulerObserverTest()
206 : testBEGIN_STEP(false),
207 testBEFORE_EXPLICIT_EVAL(false),
209 testCurrentValue(-0.99),
210 testWorkingValue(-0.99),
217 virtual ~StepperForwardEulerObserverTest() {}
220 virtual void observe(
224 double>::ACTION_LOCATION actLoc)
228 testBEGIN_STEP =
true;
229 auto x = sh->getCurrentState()->getX();
230 testCurrentValue = get_ele(*(x), 0);
234 testBEFORE_EXPLICIT_EVAL =
true;
235 testDt = sh->getWorkingState()->getTimeStep();
236 testName = stepper->getStepperName();
241 auto x = sh->getWorkingState()->getX();
242 testWorkingValue = get_ele(*(x), 0);
247 "Error - unknown action location.\n");
252 bool testBEFORE_EXPLICIT_EVAL;
254 double testCurrentValue;
255 double testWorkingValue;
257 std::string testName;
266 stepper->setModel(model);
267 auto observer =
rcp(
new StepperForwardEulerObserverTest());
268 stepper->setAppAction(observer);
269 stepper->initialize();
272 auto inArgsIC = model->getNominalValues();
276 icState->setTime(0.0);
277 icState->setIndex(0);
278 icState->setTimeStep(0.0);
279 icState->setOrder(stepper->getOrder());
284 solutionHistory->setName(
"Forward States");
286 solutionHistory->setStorageLimit(2);
287 solutionHistory->addState(icState);
290 stepper->setInitialConditions(solutionHistory);
291 solutionHistory->initWorkingState();
293 solutionHistory->getWorkingState()->setTimeStep(dt);
294 stepper->takeStep(solutionHistory);
297 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
300 auto x = solutionHistory->getCurrentState()->getX();
302 x = solutionHistory->getWorkingState()->getX();
311 class StepperForwardEulerModifierXTest
315 StepperForwardEulerModifierXTest()
316 : testX_BEGIN_STEP(false),
317 testX_BEFORE_EXPLICIT_EVAL(false),
318 testXDOT_END_STEP(false),
327 virtual ~StepperForwardEulerModifierXTest() {}
331 const double time,
const double dt,
333 double>::MODIFIER_TYPE modType)
337 testX_BEGIN_STEP =
true;
338 testX = get_ele(*(x), 0);
342 testX_BEFORE_EXPLICIT_EVAL =
true;
348 testXDOT_END_STEP =
true;
349 testXDot = get_ele(*(x), 0);
354 "Error - unknown action location.\n");
357 bool testX_BEGIN_STEP;
358 bool testX_BEFORE_EXPLICIT_EVAL;
359 bool testXDOT_END_STEP;
372 stepper->setModel(model);
373 auto modifierX =
rcp(
new StepperForwardEulerModifierXTest());
374 stepper->setAppAction(modifierX);
375 stepper->initialize();
378 auto inArgsIC = model->getNominalValues();
382 icState->setTime(0.0);
383 icState->setIndex(0);
384 icState->setTimeStep(0.0);
385 icState->setOrder(stepper->getOrder());
390 solutionHistory->setName(
"Forward States");
392 solutionHistory->setStorageLimit(2);
393 solutionHistory->addState(icState);
396 stepper->setInitialConditions(solutionHistory);
397 solutionHistory->initWorkingState();
399 solutionHistory->getWorkingState()->setTimeStep(dt);
400 stepper->takeStep(solutionHistory);
403 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
406 auto x = solutionHistory->getCurrentState()->getX();
409 auto xDot = solutionHistory->getWorkingState()->getXDot();
410 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
413 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
416 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.