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_IntegratorBasic.hpp" 17 #include "Tempus_SolutionHistory.hpp" 20 #include "Tempus_StepperNewmarkExplicitAForm.hpp" 26 #include "../TestModels/SinCosModel.hpp" 27 #include "../TestModels/VanDerPolModel.hpp" 28 #include "../TestModels/HarmonicOscillatorModel.hpp" 29 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 38 using Teuchos::rcp_const_cast;
39 using Teuchos::rcp_dynamic_cast;
40 using Teuchos::ParameterList;
41 using Teuchos::sublist;
42 using Teuchos::getParametersFromXmlFile;
47 class StepperNewmarkExplicitAFormModifierTest
53 StepperNewmarkExplicitAFormModifierTest()
54 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
55 testAFTER_EXPLICIT_EVAL(false), testEND_STEP(false),
56 testCurrentValue(-0.99),
57 testDt(-1.5), testName(
"")
61 virtual ~StepperNewmarkExplicitAFormModifierTest(){}
72 testBEGIN_STEP =
true;
77 testBEFORE_EXPLICIT_EVAL =
true;
78 testName =
"Newmark Explicit A Form - Modifier";
79 stepper->setStepperName(testName);
84 testAFTER_EXPLICIT_EVAL =
true;
85 testDt = sh->getWorkingState()->getTimeStep();
92 auto x = sh->getWorkingState()->getX();
93 testCurrentValue = get_ele(*(x), 0);
97 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
98 "Error - unknown action location.\n");
103 bool testBEFORE_EXPLICIT_EVAL;
104 bool testAFTER_EXPLICIT_EVAL;
106 double testCurrentValue;
108 std::string testName;
114 class StepperNewmarkExplicitAFormModifierXTest
120 StepperNewmarkExplicitAFormModifierXTest()
121 : testX_BEGIN_STEP(false), testX_BEFORE_EXPLICIT_EVAL(false),
122 testX_AFTER_EXPLICIT_EVAL(false), testX_END_STEP(false),
123 testX(-0.99), testXDot(-0.99),
124 testDt(-1.5), testTime(-1.5)
128 virtual ~StepperNewmarkExplicitAFormModifierXTest(){}
133 const double time,
const double dt,
139 testX_BEGIN_STEP =
true;
141 testX = get_ele(*(x), 0);
146 testX_BEFORE_EXPLICIT_EVAL =
true;
148 testX = get_ele(*(x), 0);
153 testX_AFTER_EXPLICIT_EVAL =
true;
154 testX = get_ele(*(x), 0);
159 testX_END_STEP =
true;
161 testX = get_ele(*(x), 0);
165 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
166 "Error - unknown action location.\n");
170 bool testX_BEGIN_STEP;
171 bool testX_BEFORE_EXPLICIT_EVAL;
172 bool testX_AFTER_EXPLICIT_EVAL;
184 using Teuchos::getParametersFromXmlFile;
185 using Teuchos::sublist;
186 using Teuchos::ParameterList;
188 RCP<Tempus::IntegratorBasic<double> > integrator;
189 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
190 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
193 RCP<ParameterList> pList =
194 getParametersFromXmlFile(
"Tempus_NewmarkExplicitAForm_HarmonicOscillator_Damped.xml");
197 RCP<ParameterList> hom_pl = sublist(pList,
"HarmonicOscillatorModel",
true);
198 RCP<Tempus_Test::HarmonicOscillatorModel<double> > model =
202 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
203 RCP<ParameterList> stepperPL = sublist(pl,
"Default Stepper",
true);
204 stepperPL->remove(
"Zero Initial Guess");
206 double dt =pl->sublist(
"Default Integrator")
207 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
210 pl->sublist(
"Default Integrator")
211 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
212 integrator = Tempus::createIntegratorBasic<double>(pl, model);
214 RCP<Tempus::StepperNewmarkExplicitAForm<double> > stepper =
217 auto modifier = rcp(
new StepperNewmarkExplicitAFormModifierTest());
218 stepper->setAppAction(modifier);
219 stepper->initialize();
220 integrator->initialize();
223 bool integratorStatus = integrator->advanceTime();
224 TEST_ASSERT(integratorStatus)
227 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
228 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
229 TEST_COMPARE(modifier->testAFTER_EXPLICIT_EVAL, ==,
true);
230 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
233 auto x = integrator->getX();
234 auto Dt = integrator->getTime();
235 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
236 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
237 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
244 using Teuchos::getParametersFromXmlFile;
245 using Teuchos::sublist;
246 using Teuchos::ParameterList;
248 RCP<Tempus::IntegratorBasic<double> > integrator;
249 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
250 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
253 RCP<ParameterList> pList =
254 getParametersFromXmlFile(
"Tempus_NewmarkExplicitAForm_HarmonicOscillator_Damped.xml");
257 RCP<ParameterList> hom_pl = sublist(pList,
"HarmonicOscillatorModel",
true);
258 RCP<Tempus_Test::HarmonicOscillatorModel<double> > model =
262 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
263 RCP<ParameterList> stepperPL = sublist(pl,
"Default Stepper",
true);
264 stepperPL->remove(
"Zero Initial Guess");
266 double dt =pl->sublist(
"Default Integrator")
267 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
270 pl->sublist(
"Default Integrator")
271 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
272 integrator = Tempus::createIntegratorBasic<double>(pl, model);
274 RCP<Tempus::StepperNewmarkExplicitAForm<double> > stepper =
277 auto modifierX = rcp(
new StepperNewmarkExplicitAFormModifierXTest());
278 stepper->setAppAction(modifierX);
279 stepper->initialize();
280 integrator->initialize();
283 bool integratorStatus = integrator->advanceTime();
284 TEST_ASSERT(integratorStatus)
287 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
288 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
289 TEST_COMPARE(modifierX->testX_AFTER_EXPLICIT_EVAL, ==,
true);
290 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
294 auto Dt = integrator->getTime();
295 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
297 const auto x = integrator->getX();
298 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...