11 #include "Tempus_StepperTrapezoidal.hpp"
20 namespace Tempus_Unit_Test {
24 using Teuchos::rcp_const_cast;
25 using Teuchos::rcp_dynamic_cast;
27 using Teuchos::sublist;
38 stepper->setModel(model);
39 stepper->initialize();
49 bool useFSAL = stepper->getUseFSAL();
50 std::string ICConsistency = stepper->getICConsistency();
51 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
52 bool zeroInitialGuess = stepper->getZeroInitialGuess();
59 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
60 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65 model, solver, useFSAL,
66 ICConsistency, ICConsistencyCheck, zeroInitialGuess, modifier));
84 class StepperTrapezoidalModifierTest
89 StepperTrapezoidalModifierTest()
90 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
91 testAFTER_SOLVE(false), testEND_STEP(false),
92 testCurrentValue(-0.99), testWorkingValue(-0.99),
93 testDt(-1.5), testName(
"")
97 virtual ~StepperTrapezoidalModifierTest(){}
108 testBEGIN_STEP =
true;
109 auto x = sh->getCurrentState()->getX();
110 testCurrentValue = get_ele(*(x), 0);
115 testBEFORE_SOLVE =
true;
116 testDt = sh->getWorkingState()->getTimeStep()/10.0;
117 sh->getWorkingState()->setTimeStep(testDt);
122 testAFTER_SOLVE =
true;
123 testName =
"Trapezoidal - Modifier";
124 stepper->setStepperName(testName);
130 auto x = sh->getWorkingState()->getX();
131 testWorkingValue = get_ele(*(x), 0);
136 "Error - unknown action location.\n");
141 bool testBEFORE_SOLVE;
142 bool testAFTER_SOLVE;
144 double testCurrentValue;
145 double testWorkingValue;
147 std::string testName;
157 stepper->setModel(model);
158 auto modifier =
rcp(
new StepperTrapezoidalModifierTest());
159 stepper->setAppAction(modifier);
160 stepper->initialize();
166 stepper->setInitialConditions(solutionHistory);
167 solutionHistory->initWorkingState();
169 solutionHistory->getWorkingState()->setTimeStep(dt);
170 stepper->takeStep(solutionHistory);
179 auto x = solutionHistory->getCurrentState()->getX();
181 x = solutionHistory->getWorkingState()->getX();
183 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
185 TEST_COMPARE(modifier->testName, ==,
"Trapezoidal - Modifier");
190 class StepperTrapezoidalObserverTest
196 StepperTrapezoidalObserverTest()
197 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
198 testAFTER_SOLVE(false), testEND_STEP(false),
199 testCurrentValue(-0.99), testWorkingValue(-0.99),
200 testDt(-1.5), testName(
"")
204 virtual ~StepperTrapezoidalObserverTest(){}
207 virtual void observe(
215 testBEGIN_STEP =
true;
216 auto x = sh->getCurrentState()->getX();
217 testCurrentValue = get_ele(*(x), 0);
222 testBEFORE_SOLVE =
true;
223 testDt = sh->getWorkingState()->getTimeStep();
228 testAFTER_SOLVE =
true;
229 testName = stepper->getStepperType();
235 auto x = sh->getWorkingState()->getX();
236 testWorkingValue = get_ele(*(x), 0);
241 "Error - unknown action location.\n");
245 bool testBEFORE_SOLVE;
246 bool testAFTER_SOLVE;
248 double testCurrentValue;
249 double testWorkingValue;
251 std::string testName;
261 stepper->setModel(model);
262 auto observer =
rcp(
new StepperTrapezoidalObserverTest());
263 stepper->setAppAction(observer);
264 stepper->initialize();
270 stepper->setInitialConditions(solutionHistory);
271 solutionHistory->initWorkingState();
273 solutionHistory->getWorkingState()->setTimeStep(dt);
274 stepper->takeStep(solutionHistory);
283 auto x = solutionHistory->getCurrentState()->getX();
285 x = solutionHistory->getWorkingState()->getX();
288 TEST_COMPARE(observer->testName, ==,
"Trapezoidal Method");
293 class StepperTrapezoidalModifierXTest
299 StepperTrapezoidalModifierXTest()
300 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
301 testX_AFTER_SOLVE(false), testXDOT_END_STEP(false),
302 testX(-0.99), testXDot(-0.99),
303 testDt(-1.5), testTime(-1.5)
307 virtual ~StepperTrapezoidalModifierXTest(){}
311 const double time,
const double dt,
317 testX_BEGIN_STEP =
true;
318 testX = get_ele(*(x), 0);
323 testX_BEFORE_SOLVE =
true;
329 testX_AFTER_SOLVE =
true;
335 testXDOT_END_STEP =
true;
336 testXDot = get_ele(*(x), 0);
341 "Error - unknown action location.\n");
344 bool testX_BEGIN_STEP;
345 bool testX_BEFORE_SOLVE;
346 bool testX_AFTER_SOLVE;
347 bool testXDOT_END_STEP;
361 stepper->setModel(model);
362 auto modifierX =
rcp(
new StepperTrapezoidalModifierXTest());
363 stepper->setAppAction(modifierX);
364 stepper->initialize();
370 stepper->setInitialConditions(solutionHistory);
371 solutionHistory->initWorkingState();
373 solutionHistory->getWorkingState()->setTimeStep(dt);
374 stepper->takeStep(solutionHistory);
383 auto x = solutionHistory->getCurrentState()->getX();
386 auto xDot = solutionHistory->getWorkingState()->getXDot();
387 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
390 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
392 auto time = solutionHistory->getWorkingState()->getTime();
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
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)
ACTION_LOCATION
Indicates the location of application action (see algorithm).
#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)
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.