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_StepperHHTAlpha.hpp" 25 #include "../TestModels/SinCosModel.hpp" 26 #include "../TestModels/VanDerPolModel.hpp" 27 #include "../TestModels/HarmonicOscillatorModel.hpp" 28 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 37 using Teuchos::rcp_const_cast;
38 using Teuchos::rcp_dynamic_cast;
39 using Teuchos::ParameterList;
40 using Teuchos::sublist;
41 using Teuchos::getParametersFromXmlFile;
52 stepper->setModel(model);
53 stepper->initialize();
54 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
61 bool useFSAL = stepper->getUseFSAL();
62 std::string ICConsistency = stepper->getICConsistency();
63 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
64 bool zeroInitialGuess = stepper->getZeroInitialGuess();
65 std::string schemeName =
"Newmark Beta User Defined";
76 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
80 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86 stepper->setSchemeName(schemeName); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 stepper->setBeta(beta); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88 stepper->setGamma(gamma); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 stepper->setAlphaF(alpha_f); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90 stepper->setAlphaM(alpha_m); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
94 model, solver, useFSAL,
95 ICConsistency, ICConsistencyCheck, zeroInitialGuess,
96 schemeName, beta, gamma, alpha_f, alpha_m,modifier));
97 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
100 TEUCHOS_ASSERT(stepper->getOrder() == 2);
114 class StepperHHTAlphaModifierTest
120 StepperHHTAlphaModifierTest()
121 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
122 testAFTER_SOLVE(false), testEND_STEP(false),
123 testCurrentValue(-0.99), testWorkingValue(-0.99),
124 testDt(-1.5), testName(
"")
128 virtual ~StepperHHTAlphaModifierTest(){}
139 testBEGIN_STEP =
true;
140 auto x = sh->getCurrentState()->getX();
141 testCurrentValue = get_ele(*(x), 0);
146 testBEFORE_SOLVE =
true;
147 testDt = sh->getWorkingState()->getTimeStep()/10.0;
148 sh->getWorkingState()->setTimeStep(testDt);
153 testAFTER_SOLVE =
true;
154 testName =
"HHT Alpha - Modifier";
155 stepper->setStepperName(testName);
161 auto x = sh->getWorkingState()->getX();
162 testWorkingValue = get_ele(*(x), 0);
166 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
167 "Error - unknown action location.\n");
171 bool testBEFORE_SOLVE;
172 bool testAFTER_SOLVE;
174 double testCurrentValue;
175 double testWorkingValue;
177 std::string testName;
182 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
187 stepper->setModel(model);
188 auto modifier = rcp(
new StepperHHTAlphaModifierTest());
189 stepper->setAppAction(modifier);
190 stepper->initialize();
196 stepper->setInitialConditions(solutionHistory);
197 solutionHistory->initWorkingState();
199 solutionHistory->getWorkingState()->setTimeStep(dt);
200 stepper->takeStep(solutionHistory);
203 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
204 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
205 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
206 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
209 auto x = solutionHistory->getCurrentState()->getX();
210 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
211 x = solutionHistory->getWorkingState()->getX();
212 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
213 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
214 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
215 TEST_COMPARE(modifier->testName, ==,
"HHT Alpha - Modifier");
220 class StepperHHTAlphaObserverTest
225 StepperHHTAlphaObserverTest()
226 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
227 testAFTER_SOLVE(false), testEND_STEP(false),
228 testCurrentValue(-0.99), testWorkingValue(-0.99),
229 testDt(-1.5), testName(
"")
233 virtual ~StepperHHTAlphaObserverTest(){}
236 virtual void observe(
244 testBEGIN_STEP =
true;
245 auto x = sh->getCurrentState()->getX();
246 testCurrentValue = get_ele(*(x), 0);
251 testBEFORE_SOLVE =
true;
252 testDt = sh->getWorkingState()->getTimeStep();
257 testAFTER_SOLVE =
true;
258 testName = stepper->getStepperType();
264 auto x = sh->getWorkingState()->getX();
265 testWorkingValue = get_ele(*(x), 0);
269 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
270 "Error - unknown action location.\n");
275 bool testBEFORE_SOLVE;
276 bool testAFTER_SOLVE;
278 double testCurrentValue;
279 double testWorkingValue;
281 std::string testName;
286 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
291 stepper->setModel(model);
292 auto observer = rcp(
new StepperHHTAlphaObserverTest());
293 stepper->setAppAction(observer);
294 stepper->initialize();
300 stepper->setInitialConditions(solutionHistory);
301 solutionHistory->initWorkingState();
303 solutionHistory->getWorkingState()->setTimeStep(dt);
304 stepper->takeStep(solutionHistory);
307 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
308 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
309 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
310 TEST_COMPARE(observer->testEND_STEP, ==,
true);
312 auto x = solutionHistory->getCurrentState()->getX();
313 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
314 x = solutionHistory->getWorkingState()->getX();
315 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-14);
316 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-14);
318 TEST_COMPARE(observer->testName, ==,
"HHT-Alpha");
323 class StepperHHTAlphaModifierXTest
329 StepperHHTAlphaModifierXTest()
330 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
331 testX_AFTER_SOLVE(false), testX_END_STEP(false),
332 testXbegin(-0.99), testXend(-0.99),
333 testDt(-1.5), testTime(-1.5)
337 virtual ~StepperHHTAlphaModifierXTest(){}
342 const double time,
const double dt,
348 testX_BEGIN_STEP =
true;
349 testXbegin = get_ele(*(x), 0);
354 testX_BEFORE_SOLVE =
true;
360 testX_AFTER_SOLVE =
true;
366 testX_END_STEP =
true;
367 testXend = get_ele(*(x), 0);
371 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
372 "Error - unknown action location.\n");
376 bool testX_BEGIN_STEP;
377 bool testX_BEFORE_SOLVE;
378 bool testX_AFTER_SOLVE;
388 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
393 stepper->setModel(model);
394 auto modifierX = rcp(
new StepperHHTAlphaModifierXTest());
395 stepper->setAppAction(modifierX);
396 stepper->initialize();
401 stepper->setInitialConditions(solutionHistory);
402 solutionHistory->initWorkingState();
404 solutionHistory->getWorkingState()->setTimeStep(dt);
405 stepper->takeStep(solutionHistory);
408 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
409 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
410 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
411 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
414 auto xbegin = solutionHistory->getCurrentState()->getX();
415 TEST_FLOATING_EQUALITY(modifierX->testXbegin, get_ele(*(xbegin), 0), 1.0e-14);
416 auto xend = solutionHistory->getWorkingState()->getX();
417 TEST_FLOATING_EQUALITY(modifierX->testXend, get_ele(*(xend), 0),1.0e-14);
418 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
419 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
420 auto time = solutionHistory->getWorkingState()->getTime();
421 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-14);
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Base observer for StepperHHTAlpha.
Base ModifierX for StepperHHTAlpha.
Modify at the beginning of the step.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
After the implicit solve.
Modify after the implicit solve.
Modify at the end of the step.
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
At the beginning of the step.
Base modifier for StepperHHTAlpha.
Default ModifierX for StepperHHTAlpha.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
Before the implicit solve.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Default modifier for StepperHHTAlpha.
Default observer for StepperHHTAlpha.
Modify before the implicit solve.
ACTION_LOCATION
Indicates the location of application action (see algorithm).