12 #include "Tempus_StepperForwardEuler.hpp"
21 namespace Tempus_Unit_Test {
25 using Teuchos::rcp_const_cast;
26 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();
57 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
58 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61 model, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
80 class StepperForwardEulerModifierTest
86 StepperForwardEulerModifierTest()
87 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
88 testEND_STEP(false), testCurrentValue(-0.99), testWorkingValue(-0.99),
89 testDt(-1.5), testName(
"")
93 virtual ~StepperForwardEulerModifierTest(){}
104 testBEGIN_STEP =
true;
105 auto x = sh->getCurrentState()->getX();
106 testCurrentValue = get_ele(*(x), 0);
111 testBEFORE_EXPLICIT_EVAL =
true;
112 testDt = sh->getWorkingState()->getTimeStep()/10.0;
113 sh->getWorkingState()->setTimeStep(testDt);
114 testName =
"Forward Euler - Modifier";
115 stepper->setStepperName(testName);
121 auto x = sh->getWorkingState()->getX();
122 testWorkingValue = get_ele(*(x), 0);
127 "Error - unknown action location.\n");
131 bool testBEFORE_EXPLICIT_EVAL;
133 double testCurrentValue;
134 double testWorkingValue;
136 std::string testName;
145 stepper->setModel(model);
146 auto modifier =
rcp(
new StepperForwardEulerModifierTest());
147 stepper->setAppAction(modifier);
148 stepper->initialize();
151 auto inArgsIC = model->getNominalValues();
155 icState->setTime (0.0);
156 icState->setIndex (0);
157 icState->setTimeStep(0.0);
158 icState->setOrder (stepper->getOrder());
163 solutionHistory->setName(
"Forward States");
165 solutionHistory->setStorageLimit(2);
166 solutionHistory->addState(icState);
169 stepper->setInitialConditions(solutionHistory);
170 solutionHistory->initWorkingState();
172 solutionHistory->getWorkingState()->setTimeStep(dt);
173 stepper->takeStep(solutionHistory);
176 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
179 auto x = solutionHistory->getCurrentState()->getX();
181 x = solutionHistory->getWorkingState()->getX();
183 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
186 TEST_COMPARE(modifier->testName, ==,
"Forward Euler - Modifier");
192 class StepperForwardEulerObserverTest
198 StepperForwardEulerObserverTest()
199 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
200 testEND_STEP(false), testCurrentValue(-0.99),
201 testWorkingValue(-0.99),testDt(-1.5), testName(
"")
205 virtual ~StepperForwardEulerObserverTest(){}
208 virtual void observe(
216 testBEGIN_STEP =
true;
217 auto x = sh->getCurrentState()->getX();
218 testCurrentValue = get_ele(*(x), 0);
223 testBEFORE_EXPLICIT_EVAL =
true;
224 testDt = sh->getWorkingState()->getTimeStep();
225 testName = stepper->getStepperName();
231 auto x = sh->getWorkingState()->getX();
232 testWorkingValue = get_ele(*(x), 0);
237 "Error - unknown action location.\n");
242 bool testBEFORE_EXPLICIT_EVAL;
244 double testCurrentValue;
245 double testWorkingValue;
247 std::string testName;
256 stepper->setModel(model);
257 auto observer =
rcp(
new StepperForwardEulerObserverTest());
258 stepper->setAppAction(observer);
259 stepper->initialize();
262 auto inArgsIC = model->getNominalValues();
266 icState->setTime (0.0);
267 icState->setIndex (0);
268 icState->setTimeStep(0.0);
269 icState->setOrder (stepper->getOrder());
274 solutionHistory->setName(
"Forward States");
276 solutionHistory->setStorageLimit(2);
277 solutionHistory->addState(icState);
280 stepper->setInitialConditions(solutionHistory);
281 solutionHistory->initWorkingState();
283 solutionHistory->getWorkingState()->setTimeStep(dt);
284 stepper->takeStep(solutionHistory);
287 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
290 auto x = solutionHistory->getCurrentState()->getX();
292 x = solutionHistory->getWorkingState()->getX();
302 class StepperForwardEulerModifierXTest
308 StepperForwardEulerModifierXTest()
309 : testX_BEGIN_STEP(false), testX_BEFORE_EXPLICIT_EVAL(false),
310 testXDOT_END_STEP(false), testX(-0.99),
311 testXDot(-0.99), testDt(-1.5), testTime(-1.5)
315 virtual ~StepperForwardEulerModifierXTest(){}
320 const double time,
const double dt,
326 testX_BEGIN_STEP =
true;
327 testX = get_ele(*(x), 0);
332 testX_BEFORE_EXPLICIT_EVAL =
true;
339 testXDOT_END_STEP =
true;
340 testXDot = get_ele(*(x), 0);
345 "Error - unknown action location.\n");
348 bool testX_BEGIN_STEP;
349 bool testX_BEFORE_EXPLICIT_EVAL;
350 bool testXDOT_END_STEP;
363 stepper->setModel(model);
364 auto modifierX =
rcp(
new StepperForwardEulerModifierXTest());
365 stepper->setAppAction(modifierX);
366 stepper->initialize();
369 auto inArgsIC = model->getNominalValues();
373 icState->setTime (0.0);
374 icState->setIndex (0);
375 icState->setTimeStep(0.0);
376 icState->setOrder (stepper->getOrder());
381 solutionHistory->setName(
"Forward States");
383 solutionHistory->setStorageLimit(2);
384 solutionHistory->addState(icState);
387 stepper->setInitialConditions(solutionHistory);
388 solutionHistory->initWorkingState();
390 solutionHistory->getWorkingState()->setTimeStep(dt);
391 stepper->takeStep(solutionHistory);
394 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
397 auto x = solutionHistory->getCurrentState()->getX();
400 auto xDot = solutionHistory->getWorkingState()->getXDot();
401 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
404 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
407 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.