9 #include "Teuchos_UnitTestHarness.hpp" 10 #include "Teuchos_XMLParameterListHelpers.hpp" 11 #include "Teuchos_TimeMonitor.hpp" 12 #include "Teuchos_DefaultComm.hpp" 14 #include "Thyra_VectorStdOps.hpp" 16 #include "Tempus_StepperTrapezoidal.hpp" 25 #include "../TestModels/SinCosModel.hpp" 26 #include "../TestModels/VanDerPolModel.hpp" 27 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 36 using Teuchos::rcp_const_cast;
37 using Teuchos::rcp_dynamic_cast;
38 using Teuchos::ParameterList;
39 using Teuchos::sublist;
40 using Teuchos::getParametersFromXmlFile;
51 stepper->setModel(model);
52 stepper->initialize();
53 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
62 bool useFSAL = stepper->getUseFSAL();
63 std::string ICConsistency = stepper->getICConsistency();
64 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
65 bool zeroInitialGuess = stepper->getZeroInitialGuess();
68 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
69 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
70 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
71 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
72 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 model, solver, useFSAL,
79 ICConsistency, ICConsistencyCheck, zeroInitialGuess, modifier));
80 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 TEUCHOS_ASSERT(stepper->getOrder() == 2);
97 class StepperTrapezoidalModifierTest
102 StepperTrapezoidalModifierTest()
103 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
104 testAFTER_SOLVE(false), testEND_STEP(false),
105 testCurrentValue(-0.99), testWorkingValue(-0.99),
106 testDt(-1.5), testName(
"")
110 virtual ~StepperTrapezoidalModifierTest(){}
121 testBEGIN_STEP =
true;
122 auto x = sh->getCurrentState()->getX();
123 testCurrentValue = get_ele(*(x), 0);
128 testBEFORE_SOLVE =
true;
129 testDt = sh->getWorkingState()->getTimeStep()/10.0;
130 sh->getWorkingState()->setTimeStep(testDt);
135 testAFTER_SOLVE =
true;
136 testName =
"Trapezoidal - Modifier";
137 stepper->setStepperName(testName);
143 auto x = sh->getWorkingState()->getX();
144 testWorkingValue = get_ele(*(x), 0);
148 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
149 "Error - unknown action location.\n");
154 bool testBEFORE_SOLVE;
155 bool testAFTER_SOLVE;
157 double testCurrentValue;
158 double testWorkingValue;
160 std::string testName;
165 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
170 stepper->setModel(model);
171 auto modifier = rcp(
new StepperTrapezoidalModifierTest());
172 stepper->setAppAction(modifier);
173 stepper->initialize();
179 stepper->setInitialConditions(solutionHistory);
180 solutionHistory->initWorkingState();
182 solutionHistory->getWorkingState()->setTimeStep(dt);
183 stepper->takeStep(solutionHistory);
186 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
187 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
188 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
189 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
192 auto x = solutionHistory->getCurrentState()->getX();
193 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
194 x = solutionHistory->getWorkingState()->getX();
195 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
196 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
197 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
198 TEST_COMPARE(modifier->testName, ==,
"Trapezoidal - Modifier");
203 class StepperTrapezoidalObserverTest
209 StepperTrapezoidalObserverTest()
210 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
211 testAFTER_SOLVE(false), testEND_STEP(false),
212 testCurrentValue(-0.99), testWorkingValue(-0.99),
213 testDt(-1.5), testName(
"")
217 virtual ~StepperTrapezoidalObserverTest(){}
220 virtual void observe(
228 testBEGIN_STEP =
true;
229 auto x = sh->getCurrentState()->getX();
230 testCurrentValue = get_ele(*(x), 0);
235 testBEFORE_SOLVE =
true;
236 testDt = sh->getWorkingState()->getTimeStep();
241 testAFTER_SOLVE =
true;
242 testName = stepper->getStepperType();
248 auto x = sh->getWorkingState()->getX();
249 testWorkingValue = get_ele(*(x), 0);
253 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
254 "Error - unknown action location.\n");
258 bool testBEFORE_SOLVE;
259 bool testAFTER_SOLVE;
261 double testCurrentValue;
262 double testWorkingValue;
264 std::string testName;
269 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
274 stepper->setModel(model);
275 auto observer = rcp(
new StepperTrapezoidalObserverTest());
276 stepper->setAppAction(observer);
277 stepper->initialize();
283 stepper->setInitialConditions(solutionHistory);
284 solutionHistory->initWorkingState();
286 solutionHistory->getWorkingState()->setTimeStep(dt);
287 stepper->takeStep(solutionHistory);
290 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
291 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
292 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
293 TEST_COMPARE(observer->testEND_STEP, ==,
true);
296 auto x = solutionHistory->getCurrentState()->getX();
297 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
298 x = solutionHistory->getWorkingState()->getX();
299 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
300 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-14);
301 TEST_COMPARE(observer->testName, ==,
"Trapezoidal Method");
306 class StepperTrapezoidalModifierXTest
312 StepperTrapezoidalModifierXTest()
313 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
314 testX_AFTER_SOLVE(false), testXDOT_END_STEP(false),
315 testX(-0.99), testXDot(-0.99),
316 testDt(-1.5), testTime(-1.5)
320 virtual ~StepperTrapezoidalModifierXTest(){}
324 const double time,
const double dt,
330 testX_BEGIN_STEP =
true;
331 testX = get_ele(*(x), 0);
336 testX_BEFORE_SOLVE =
true;
342 testX_AFTER_SOLVE =
true;
348 testXDOT_END_STEP =
true;
349 testXDot = get_ele(*(x), 0);
353 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
354 "Error - unknown action location.\n");
357 bool testX_BEGIN_STEP;
358 bool testX_BEFORE_SOLVE;
359 bool testX_AFTER_SOLVE;
360 bool testXDOT_END_STEP;
369 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
374 stepper->setModel(model);
375 auto modifierX = rcp(
new StepperTrapezoidalModifierXTest());
376 stepper->setAppAction(modifierX);
377 stepper->initialize();
383 stepper->setInitialConditions(solutionHistory);
384 solutionHistory->initWorkingState();
386 solutionHistory->getWorkingState()->setTimeStep(dt);
387 stepper->takeStep(solutionHistory);
390 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
391 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
392 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
393 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
396 auto x = solutionHistory->getCurrentState()->getX();
397 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
399 auto xDot = solutionHistory->getWorkingState()->getXDot();
400 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
402 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-14);
403 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
404 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
405 auto time = solutionHistory->getWorkingState()->getTime();
406 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-14);
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.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
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_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Base observer for StepperTrapezoidal.
Default ModifierX for StepperTrapezoidal.
Modify after the implicit solve.
At the beginning of the step.