12 #include "Tempus_StepperTrapezoidal.hpp"
20 namespace Tempus_Unit_Test {
25 using Teuchos::rcp_const_cast;
26 using Teuchos::rcp_dynamic_cast;
27 using Teuchos::sublist;
37 stepper->setModel(model);
38 stepper->initialize();
48 bool useFSAL = stepper->getUseFSAL();
49 std::string ICConsistency = stepper->getICConsistency();
50 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
51 bool zeroInitialGuess = stepper->getZeroInitialGuess();
54 stepper->setAppAction(modifier);
55 stepper->initialize();
57 stepper->setAppAction(modifierX);
58 stepper->initialize();
60 stepper->setSolver(solver);
61 stepper->initialize();
63 stepper->setUseFSAL(useFSAL);
64 stepper->initialize();
66 stepper->setICConsistency(ICConsistency);
67 stepper->initialize();
69 stepper->setICConsistencyCheck(ICConsistencyCheck);
70 stepper->initialize();
72 stepper->setZeroInitialGuess(zeroInitialGuess);
73 stepper->initialize();
78 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
79 zeroInitialGuess, modifier));
96 class StepperTrapezoidalModifierTest
100 StepperTrapezoidalModifierTest()
101 : testBEGIN_STEP(false),
102 testBEFORE_SOLVE(false),
103 testAFTER_SOLVE(false),
105 testCurrentValue(-0.99),
106 testWorkingValue(-0.99),
113 virtual ~StepperTrapezoidalModifierTest() {}
119 double>::ACTION_LOCATION actLoc)
123 testBEGIN_STEP =
true;
124 auto x = sh->getCurrentState()->getX();
125 testCurrentValue = get_ele(*(x), 0);
129 testBEFORE_SOLVE =
true;
130 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
131 sh->getWorkingState()->setTimeStep(testDt);
135 testAFTER_SOLVE =
true;
136 testName =
"Trapezoidal - Modifier";
137 stepper->setStepperName(testName);
142 auto x = sh->getWorkingState()->getX();
143 testWorkingValue = get_ele(*(x), 0);
148 "Error - unknown action location.\n");
153 bool testBEFORE_SOLVE;
154 bool testAFTER_SOLVE;
156 double testCurrentValue;
157 double testWorkingValue;
159 std::string testName;
169 stepper->setModel(model);
170 auto modifier =
rcp(
new StepperTrapezoidalModifierTest());
171 stepper->setAppAction(modifier);
172 stepper->initialize();
178 stepper->setInitialConditions(solutionHistory);
179 solutionHistory->initWorkingState();
181 solutionHistory->getWorkingState()->setTimeStep(dt);
182 stepper->takeStep(solutionHistory);
191 auto x = solutionHistory->getCurrentState()->getX();
193 x = solutionHistory->getWorkingState()->getX();
195 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
197 TEST_COMPARE(modifier->testName, ==,
"Trapezoidal - Modifier");
202 class StepperTrapezoidalObserverTest
206 StepperTrapezoidalObserverTest()
207 : testBEGIN_STEP(false),
208 testBEFORE_SOLVE(false),
209 testAFTER_SOLVE(false),
211 testCurrentValue(-0.99),
212 testWorkingValue(-0.99),
219 virtual ~StepperTrapezoidalObserverTest() {}
222 virtual void observe(
226 double>::ACTION_LOCATION actLoc)
230 testBEGIN_STEP =
true;
231 auto x = sh->getCurrentState()->getX();
232 testCurrentValue = get_ele(*(x), 0);
236 testBEFORE_SOLVE =
true;
237 testDt = sh->getWorkingState()->getTimeStep();
241 testAFTER_SOLVE =
true;
242 testName = stepper->getStepperType();
247 auto x = sh->getWorkingState()->getX();
248 testWorkingValue = get_ele(*(x), 0);
253 "Error - unknown action location.\n");
257 bool testBEFORE_SOLVE;
258 bool testAFTER_SOLVE;
260 double testCurrentValue;
261 double testWorkingValue;
263 std::string testName;
273 stepper->setModel(model);
274 auto observer =
rcp(
new StepperTrapezoidalObserverTest());
275 stepper->setAppAction(observer);
276 stepper->initialize();
282 stepper->setInitialConditions(solutionHistory);
283 solutionHistory->initWorkingState();
285 solutionHistory->getWorkingState()->setTimeStep(dt);
286 stepper->takeStep(solutionHistory);
295 auto x = solutionHistory->getCurrentState()->getX();
297 x = solutionHistory->getWorkingState()->getX();
300 TEST_COMPARE(observer->testName, ==,
"Trapezoidal Method");
305 class StepperTrapezoidalModifierXTest
309 StepperTrapezoidalModifierXTest()
310 : testX_BEGIN_STEP(false),
311 testX_BEFORE_SOLVE(false),
312 testX_AFTER_SOLVE(false),
313 testXDOT_END_STEP(false),
322 virtual ~StepperTrapezoidalModifierXTest() {}
325 const double time,
const double dt,
327 double>::MODIFIER_TYPE modType)
331 testX_BEGIN_STEP =
true;
332 testX = get_ele(*(x), 0);
336 testX_BEFORE_SOLVE =
true;
341 testX_AFTER_SOLVE =
true;
346 testXDOT_END_STEP =
true;
347 testXDot = get_ele(*(x), 0);
352 "Error - unknown action location.\n");
355 bool testX_BEGIN_STEP;
356 bool testX_BEFORE_SOLVE;
357 bool testX_AFTER_SOLVE;
358 bool testXDOT_END_STEP;
372 stepper->setModel(model);
373 auto modifierX =
rcp(
new StepperTrapezoidalModifierXTest());
374 stepper->setAppAction(modifierX);
375 stepper->initialize();
381 stepper->setInitialConditions(solutionHistory);
382 solutionHistory->initWorkingState();
384 solutionHistory->getWorkingState()->setTimeStep(dt);
385 stepper->takeStep(solutionHistory);
394 auto x = solutionHistory->getCurrentState()->getX();
397 auto xDot = solutionHistory->getWorkingState()->getXDot();
398 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
401 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
403 auto time = solutionHistory->getWorkingState()->getTime();
Trapezoidal method time stepper.
Default modifier for StepperTrapezoidal.
Modify at the end of the step.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Modify before the implicit solve.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
#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...
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
Base ModifierX for StepperTrapezoidal.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Modify at the beginning of the step.
Base modifier for StepperTrapezoidal.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Application Action for StepperTrapezoidal.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Base observer for StepperTrapezoidal.
#define TEUCHOS_ASSERT(assertion_test)
Default ModifierX for StepperTrapezoidal.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Modify after the implicit solve.
At the beginning of the step.