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"
34 namespace Tempus_Unit_Test {
38 using Teuchos::rcp_const_cast;
39 using Teuchos::rcp_dynamic_cast;
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);
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);
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;
189 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
190 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
194 getParametersFromXmlFile(
"Tempus_NewmarkExplicitAForm_HarmonicOscillator_Damped.xml");
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);
217 auto modifier =
rcp(
new StepperNewmarkExplicitAFormModifierTest());
218 stepper->setAppAction(modifier);
219 stepper->initialize();
220 integrator->initialize();
223 bool integratorStatus = integrator->advanceTime();
228 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
229 TEST_COMPARE(modifier->testAFTER_EXPLICIT_EVAL, ==,
true);
233 auto x = integrator->getX();
234 auto Dt = integrator->getTime();
237 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
244 using Teuchos::getParametersFromXmlFile;
245 using Teuchos::sublist;
249 std::vector<RCP<Thyra::VectorBase<double>>> solutions;
250 std::vector<RCP<Thyra::VectorBase<double>>> solutionsDot;
254 getParametersFromXmlFile(
"Tempus_NewmarkExplicitAForm_HarmonicOscillator_Damped.xml");
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);
277 auto modifierX =
rcp(
new StepperNewmarkExplicitAFormModifierXTest());
278 stepper->setAppAction(modifierX);
279 stepper->initialize();
280 integrator->initialize();
283 bool integratorStatus = integrator->advanceTime();
288 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
289 TEST_COMPARE(modifierX->testX_AFTER_EXPLICIT_EVAL, ==,
true);
294 auto Dt = integrator->getTime();
297 const auto x = integrator->getX();
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
bool remove(std::string const &name, bool throwIfNotExists=true)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")