11#include "Teuchos_XMLParameterListHelpers.hpp"
13#include "Tempus_StepperNewmarkExplicitAForm.hpp"
19#include "../TestModels/HarmonicOscillatorModel.hpp"
26using Teuchos::rcp_const_cast;
27using Teuchos::rcp_dynamic_cast;
28using Teuchos::ParameterList;
29using Teuchos::sublist;
34class StepperNewmarkExplicitAFormModifierTest
40 StepperNewmarkExplicitAFormModifierTest()
41 : testBEGIN_STEP(false), testBEFORE_EXPLICIT_EVAL(false),
42 testAFTER_EXPLICIT_EVAL(false), testEND_STEP(false),
43 testCurrentValue(-0.99),
44 testDt(-1.5), testName(
"")
48 virtual ~StepperNewmarkExplicitAFormModifierTest(){}
57 case StepperNewmarkExplicitAFormAppAction<double>::BEGIN_STEP:
59 testBEGIN_STEP =
true;
62 case StepperNewmarkExplicitAFormAppAction<double>::BEFORE_EXPLICIT_EVAL:
64 testBEFORE_EXPLICIT_EVAL =
true;
65 testName =
"Newmark Explicit A Form - Modifier";
66 stepper->setStepperName(testName);
69 case StepperNewmarkExplicitAFormAppAction<double>::AFTER_EXPLICIT_EVAL:
71 testAFTER_EXPLICIT_EVAL =
true;
72 testDt = sh->getWorkingState()->getTimeStep();
76 case StepperNewmarkExplicitAFormAppAction<double>::END_STEP:
79 auto x = sh->getWorkingState()->getX();
80 testCurrentValue = get_ele(*(x), 0);
84 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
85 "Error - unknown action location.\n");
90 bool testBEFORE_EXPLICIT_EVAL;
91 bool testAFTER_EXPLICIT_EVAL;
93 double testCurrentValue;
101class StepperNewmarkExplicitAFormModifierXTest
107 StepperNewmarkExplicitAFormModifierXTest()
108 : testX_BEGIN_STEP(false), testX_BEFORE_EXPLICIT_EVAL(false),
109 testX_AFTER_EXPLICIT_EVAL(false), testX_END_STEP(false),
110 testX(-0.99), testXDot(-0.99),
111 testDt(-1.5), testTime(-1.5)
115 virtual ~StepperNewmarkExplicitAFormModifierXTest(){}
120 const double time,
const double dt,
124 case StepperNewmarkExplicitAFormModifierXBase<double>::X_BEGIN_STEP:
126 testX_BEGIN_STEP =
true;
128 testX = get_ele(*(x), 0);
131 case StepperNewmarkExplicitAFormModifierXBase<double>::X_BEFORE_EXPLICIT_EVAL:
133 testX_BEFORE_EXPLICIT_EVAL =
true;
135 testX = get_ele(*(x), 0);
138 case StepperNewmarkExplicitAFormModifierXBase<double>::X_AFTER_EXPLICIT_EVAL:
140 testX_AFTER_EXPLICIT_EVAL =
true;
141 testX = get_ele(*(x), 0);
144 case StepperNewmarkExplicitAFormModifierXBase<double>::X_END_STEP:
146 testX_END_STEP =
true;
148 testX = get_ele(*(x), 0);
152 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
153 "Error - unknown action location.\n");
157 bool testX_BEGIN_STEP;
158 bool testX_BEFORE_EXPLICIT_EVAL;
159 bool testX_AFTER_EXPLICIT_EVAL;
171 using Teuchos::sublist;
172 using Teuchos::ParameterList;
174 RCP<Tempus::IntegratorBasic<double> > integrator;
175 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
176 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
179 RCP<ParameterList> pList =
180 Teuchos::getParametersFromXmlFile(
"Tempus_NewmarkExplicitAForm_HarmonicOscillator_Damped.xml");
183 RCP<ParameterList> hom_pl = sublist(pList,
"HarmonicOscillatorModel",
true);
184 RCP<Tempus_Test::HarmonicOscillatorModel<double> > model =
185 Teuchos::rcp(
new Tempus_Test::HarmonicOscillatorModel<double>(hom_pl));
188 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
189 RCP<ParameterList> stepperPL = sublist(pl,
"Default Stepper",
true);
190 stepperPL->remove(
"Zero Initial Guess");
192 double dt =pl->sublist(
"Default Integrator")
193 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
196 pl->sublist(
"Default Integrator")
197 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
198 integrator = Tempus::createIntegratorBasic<double>(pl, model);
200 RCP<Tempus::StepperNewmarkExplicitAForm<double> > stepper =
201 Teuchos::rcp_dynamic_cast<Tempus::StepperNewmarkExplicitAForm<double> >(integrator->getStepper(),
true);
203 auto modifier = rcp(
new StepperNewmarkExplicitAFormModifierTest());
204 stepper->setAppAction(modifier);
205 stepper->initialize();
206 integrator->initialize();
209 bool integratorStatus = integrator->advanceTime();
210 TEST_ASSERT(integratorStatus)
213 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
214 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
215 TEST_COMPARE(modifier->testAFTER_EXPLICIT_EVAL, ==,
true);
216 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
219 auto x = integrator->getX();
220 auto Dt = integrator->getTime();
221 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-14);
222 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-14);
223 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
230 using Teuchos::sublist;
231 using Teuchos::ParameterList;
233 RCP<Tempus::IntegratorBasic<double> > integrator;
234 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
235 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
238 RCP<ParameterList> pList =
239 Teuchos::getParametersFromXmlFile(
"Tempus_NewmarkExplicitAForm_HarmonicOscillator_Damped.xml");
242 RCP<ParameterList> hom_pl = sublist(pList,
"HarmonicOscillatorModel",
true);
243 RCP<Tempus_Test::HarmonicOscillatorModel<double> > model =
244 Teuchos::rcp(
new Tempus_Test::HarmonicOscillatorModel<double>(hom_pl));
247 RCP<ParameterList> pl = sublist(pList,
"Tempus",
true);
248 RCP<ParameterList> stepperPL = sublist(pl,
"Default Stepper",
true);
249 stepperPL->remove(
"Zero Initial Guess");
251 double dt =pl->sublist(
"Default Integrator")
252 .sublist(
"Time Step Control").get<
double>(
"Initial Time Step");
255 pl->sublist(
"Default Integrator")
256 .sublist(
"Time Step Control").set(
"Initial Time Step", dt);
257 integrator = Tempus::createIntegratorBasic<double>(pl, model);
259 RCP<Tempus::StepperNewmarkExplicitAForm<double> > stepper =
260 Teuchos::rcp_dynamic_cast<Tempus::StepperNewmarkExplicitAForm<double> >(integrator->getStepper(),
true);
262 auto modifierX = rcp(
new StepperNewmarkExplicitAFormModifierXTest());
263 stepper->setAppAction(modifierX);
264 stepper->initialize();
265 integrator->initialize();
268 bool integratorStatus = integrator->advanceTime();
269 TEST_ASSERT(integratorStatus)
272 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
273 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
274 TEST_COMPARE(modifierX->testX_AFTER_EXPLICIT_EVAL, ==,
true);
275 TEST_COMPARE(modifierX->testX_END_STEP, ==,
true);
279 auto Dt = integrator->getTime();
280 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-14);
282 const auto x = integrator->getX();
283 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-14);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)