11#include "Tempus_StepperTrapezoidal.hpp"
24using Teuchos::rcp_const_cast;
25using Teuchos::rcp_dynamic_cast;
26using Teuchos::ParameterList;
27using Teuchos::sublist;
38 stepper->setModel(model);
39 stepper->initialize();
40 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
49 bool useFSAL = stepper->getUseFSAL();
50 std::string ICConsistency = stepper->getICConsistency();
51 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
52 bool zeroInitialGuess = stepper->getZeroInitialGuess();
55 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
56 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
57 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
58 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
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());
65model, solver, useFSAL,
66 ICConsistency, ICConsistencyCheck, zeroInitialGuess, modifier));
67TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70 TEUCHOS_ASSERT(stepper->getOrder() == 2);
84class 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(){}
106 case StepperTrapezoidalAppAction<double>::BEGIN_STEP:
108 testBEGIN_STEP =
true;
109 auto x = sh->getCurrentState()->getX();
110 testCurrentValue = get_ele(*(x), 0);
113 case StepperTrapezoidalAppAction<double>::BEFORE_SOLVE:
115 testBEFORE_SOLVE =
true;
116 testDt = sh->getWorkingState()->getTimeStep()/10.0;
117 sh->getWorkingState()->setTimeStep(testDt);
120 case StepperTrapezoidalAppAction<double>::AFTER_SOLVE:
122 testAFTER_SOLVE =
true;
123 testName =
"Trapezoidal - Modifier";
124 stepper->setStepperName(testName);
127 case StepperTrapezoidalAppAction<double>::END_STEP:
130 auto x = sh->getWorkingState()->getX();
131 testWorkingValue = get_ele(*(x), 0);
135 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
136 "Error - unknown action location.\n");
141 bool testBEFORE_SOLVE;
142 bool testAFTER_SOLVE;
144 double testCurrentValue;
145 double testWorkingValue;
147 std::string testName;
152 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
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);
173 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
174 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
175 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
176 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
179 auto x = solutionHistory->getCurrentState()->getX();
180 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
181 x = solutionHistory->getWorkingState()->getX();
182 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
183 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
184 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
185 TEST_COMPARE(modifier->testName, ==,
"Trapezoidal - Modifier");
190class 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(
213 case StepperTrapezoidalAppAction<double>::BEGIN_STEP:
215 testBEGIN_STEP =
true;
216 auto x = sh->getCurrentState()->getX();
217 testCurrentValue = get_ele(*(x), 0);
220 case StepperTrapezoidalAppAction<double>::BEFORE_SOLVE:
222 testBEFORE_SOLVE =
true;
223 testDt = sh->getWorkingState()->getTimeStep();
226 case StepperTrapezoidalAppAction<double>::AFTER_SOLVE:
228 testAFTER_SOLVE =
true;
229 testName = stepper->getStepperType();
232 case StepperTrapezoidalAppAction<double>::END_STEP:
235 auto x = sh->getWorkingState()->getX();
236 testWorkingValue = get_ele(*(x), 0);
240 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
241 "Error - unknown action location.\n");
245 bool testBEFORE_SOLVE;
246 bool testAFTER_SOLVE;
248 double testCurrentValue;
249 double testWorkingValue;
251 std::string testName;
256 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
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);
277 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
278 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
279 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
280 TEST_COMPARE(observer->testEND_STEP, ==,
true);
283 auto x = solutionHistory->getCurrentState()->getX();
284 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
285 x = solutionHistory->getWorkingState()->getX();
286 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
287 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-14);
288 TEST_COMPARE(observer->testName, ==,
"Trapezoidal Method");
293class 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,
315 case StepperTrapezoidalModifierXBase<double>::X_BEGIN_STEP:
317 testX_BEGIN_STEP =
true;
318 testX = get_ele(*(x), 0);
321 case StepperTrapezoidalModifierXBase<double>::X_BEFORE_SOLVE:
323 testX_BEFORE_SOLVE =
true;
327 case StepperTrapezoidalModifierXBase<double>::X_AFTER_SOLVE:
329 testX_AFTER_SOLVE =
true;
333 case StepperTrapezoidalModifierXBase<double>::XDOT_END_STEP:
335 testXDOT_END_STEP =
true;
336 testXDot = get_ele(*(x), 0);
340 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
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;
356 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
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);
377 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
378 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
379 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
380 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
383 auto x = solutionHistory->getCurrentState()->getX();
384 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
386 auto xDot = solutionHistory->getWorkingState()->getXDot();
387 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
389 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-14);
390 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
391 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
392 auto time = solutionHistory->getWorkingState()->getTime();
393 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-14);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Base modifier for StepperTrapezoidal.
Default modifier for StepperTrapezoidal.
Base ModifierX for StepperTrapezoidal.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Default ModifierX for StepperTrapezoidal.
Base observer for StepperTrapezoidal.
Trapezoidal method time stepper.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.