12#include "Tempus_StepperTrapezoidal.hpp"
22using Teuchos::ParameterList;
25using Teuchos::rcp_const_cast;
26using Teuchos::rcp_dynamic_cast;
27using Teuchos::sublist;
37 stepper->setModel(model);
38 stepper->initialize();
39 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
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();
56 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
57 stepper->setAppAction(modifierX);
58 stepper->initialize();
59 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
60 stepper->setSolver(solver);
61 stepper->initialize();
62 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 stepper->setUseFSAL(useFSAL);
64 stepper->initialize();
65 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
66 stepper->setICConsistency(ICConsistency);
67 stepper->initialize();
68 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
69 stepper->setICConsistencyCheck(ICConsistencyCheck);
70 stepper->initialize();
71 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72 stepper->setZeroInitialGuess(zeroInitialGuess);
73 stepper->initialize();
74 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
79 zeroInitialGuess, modifier));
80 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 TEUCHOS_ASSERT(stepper->getOrder() == 2);
96class 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() {}
122 case StepperTrapezoidalAppAction<double>::BEGIN_STEP: {
123 testBEGIN_STEP =
true;
124 auto x = sh->getCurrentState()->getX();
125 testCurrentValue = get_ele(*(x), 0);
128 case StepperTrapezoidalAppAction<double>::BEFORE_SOLVE: {
129 testBEFORE_SOLVE =
true;
130 testDt = sh->getWorkingState()->getTimeStep() / 10.0;
131 sh->getWorkingState()->setTimeStep(testDt);
134 case StepperTrapezoidalAppAction<double>::AFTER_SOLVE: {
135 testAFTER_SOLVE =
true;
136 testName =
"Trapezoidal - Modifier";
137 stepper->setStepperName(testName);
140 case StepperTrapezoidalAppAction<double>::END_STEP: {
142 auto x = sh->getWorkingState()->getX();
143 testWorkingValue = get_ele(*(x), 0);
147 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
148 "Error - unknown action location.\n");
153 bool testBEFORE_SOLVE;
154 bool testAFTER_SOLVE;
156 double testCurrentValue;
157 double testWorkingValue;
159 std::string testName;
164 Teuchos::RCP<const Thyra::ModelEvaluator<double> > model =
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);
185 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
186 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
187 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
188 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
191 auto x = solutionHistory->getCurrentState()->getX();
192 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
193 x = solutionHistory->getWorkingState()->getX();
194 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
195 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
196 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
197 TEST_COMPARE(modifier->testName, ==,
"Trapezoidal - Modifier");
202class 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(
229 case StepperTrapezoidalAppAction<double>::BEGIN_STEP: {
230 testBEGIN_STEP =
true;
231 auto x = sh->getCurrentState()->getX();
232 testCurrentValue = get_ele(*(x), 0);
235 case StepperTrapezoidalAppAction<double>::BEFORE_SOLVE: {
236 testBEFORE_SOLVE =
true;
237 testDt = sh->getWorkingState()->getTimeStep();
240 case StepperTrapezoidalAppAction<double>::AFTER_SOLVE: {
241 testAFTER_SOLVE =
true;
242 testName = stepper->getStepperType();
245 case StepperTrapezoidalAppAction<double>::END_STEP: {
247 auto x = sh->getWorkingState()->getX();
248 testWorkingValue = get_ele(*(x), 0);
252 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
253 "Error - unknown action location.\n");
257 bool testBEFORE_SOLVE;
258 bool testAFTER_SOLVE;
260 double testCurrentValue;
261 double testWorkingValue;
263 std::string testName;
268 Teuchos::RCP<const Thyra::ModelEvaluator<double> > model =
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);
289 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
290 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
291 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
292 TEST_COMPARE(observer->testEND_STEP, ==,
true);
295 auto x = solutionHistory->getCurrentState()->getX();
296 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
297 x = solutionHistory->getWorkingState()->getX();
298 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
299 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-14);
300 TEST_COMPARE(observer->testName, ==,
"Trapezoidal Method");
305class 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,
330 case StepperTrapezoidalModifierXBase<double>::X_BEGIN_STEP: {
331 testX_BEGIN_STEP =
true;
332 testX = get_ele(*(x), 0);
335 case StepperTrapezoidalModifierXBase<double>::X_BEFORE_SOLVE: {
336 testX_BEFORE_SOLVE =
true;
340 case StepperTrapezoidalModifierXBase<double>::X_AFTER_SOLVE: {
341 testX_AFTER_SOLVE =
true;
345 case StepperTrapezoidalModifierXBase<double>::XDOT_END_STEP: {
346 testXDOT_END_STEP =
true;
347 testXDot = get_ele(*(x), 0);
351 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
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;
367 Teuchos::RCP<const Thyra::ModelEvaluator<double> > model =
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);
388 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
389 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
390 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
391 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
394 auto x = solutionHistory->getCurrentState()->getX();
395 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
397 auto xDot = solutionHistory->getWorkingState()->getXDot();
398 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
400 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0), 1.0e-14);
401 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
402 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
403 auto time = solutionHistory->getWorkingState()->getTime();
404 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-14);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Application Action for StepperTrapezoidal.
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.