12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperFactory.hpp"
19 #include "Tempus_TimeStepControl.hpp"
21 #include "Tempus_StepperNewmarkImplicitDForm.hpp"
27 #include "../TestModels/SinCosModel.hpp"
28 #include "../TestModels/VanDerPolModel.hpp"
29 #include "../TestModels/HarmonicOscillatorModel.hpp"
30 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
35 namespace Tempus_Unit_Test {
39 using Teuchos::rcp_const_cast;
40 using Teuchos::rcp_dynamic_cast;
42 using Teuchos::sublist;
43 using Teuchos::getParametersFromXmlFile;
49 class StepperNewmarkImplicitDFormModifierTest
55 StepperNewmarkImplicitDFormModifierTest()
56 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
57 testAFTER_SOLVE(false), testEND_STEP(false),
58 testCurrentValue(-0.99),
59 testDt(-1.5), testName(
"")
63 virtual ~StepperNewmarkImplicitDFormModifierTest(){}
74 testBEGIN_STEP =
true;
79 testBEFORE_SOLVE =
true;
80 testDt = sh->getWorkingState()->getTimeStep();
86 testAFTER_SOLVE =
true;
87 testName =
"Newmark Implicit A Form - Modifier";
88 stepper->setStepperName(testName);
94 auto x = sh->getWorkingState()->getX();
95 testCurrentValue = get_ele(*(x), 0);
100 "Error - unknown action location.\n");
105 bool testBEFORE_SOLVE;
106 bool testAFTER_SOLVE;
108 double testCurrentValue;
110 std::string testName;
116 class StepperNewmarkImplicitDFormModifierXTest
122 StepperNewmarkImplicitDFormModifierXTest()
123 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
124 testX_AFTER_SOLVE(false), testX_END_STEP(false),
125 testX(-0.99), testXDot(-0.99),
126 testDt(-1.5), testTime(-1.5)
130 virtual ~StepperNewmarkImplicitDFormModifierXTest(){}
135 const double time,
const double dt,
141 testX_BEGIN_STEP =
true;
142 testX = get_ele(*(x), 0);
147 testX_BEFORE_SOLVE =
true;
153 testX_AFTER_SOLVE =
true;
155 testX = get_ele(*(x), 0);
160 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_SOLVE;
172 bool testX_AFTER_SOLVE;
188 stepper->setModel(model);
189 stepper->initialize();
200 bool useFSAL = stepper->getUseFSAL();
201 std::string ICConsistency = stepper->getICConsistency();
202 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
203 bool zeroInitialGuess = stepper->getZeroInitialGuess();
204 std::string schemeName =
"Average Acceleration";
214 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
215 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
216 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
225 model, solver, useFSAL,
226 ICConsistency, ICConsistencyCheck, zeroInitialGuess,
227 schemeName, beta, gamma, modifier));
246 using Teuchos::getParametersFromXmlFile;
247 using Teuchos::sublist;
254 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
266 auto modifier =
rcp(
new StepperNewmarkImplicitDFormModifierTest());
267 stepper->setAppAction(modifier);
268 stepper->initialize();
275 timeStepControl->setInitIndex(tscPL.
get<
int> (
"Initial Time Index"));
276 timeStepControl->setInitTime (tscPL.
get<
double>(
"Initial Time"));
277 timeStepControl->setFinalTime(dt);
278 timeStepControl->setInitTimeStep(dt);
279 timeStepControl->initialize();
282 using Teuchos::rcp_const_cast;
283 auto inArgsIC = model->getNominalValues();
292 icState->setTime (timeStepControl->getInitTime());
293 icState->setIndex (timeStepControl->getInitIndex());
294 icState->setTimeStep(0.0);
295 icState->setOrder (stepper->getOrder());
301 solutionHistory->setName(
"Forward States");
303 solutionHistory->setStorageLimit(2);
304 solutionHistory->addState(icState);
308 Tempus::createIntegratorBasic<double>();
309 integrator->setStepper(stepper);
310 integrator->setTimeStepControl(timeStepControl);
311 integrator->setSolutionHistory(solutionHistory);
312 integrator->initialize();
315 bool integratorStatus = integrator->advanceTime();
326 auto x = integrator->getX();
327 auto Dt = integrator->getTime();
330 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
336 using Teuchos::getParametersFromXmlFile;
337 using Teuchos::sublist;
344 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
356 auto modifierX =
rcp(
new StepperNewmarkImplicitDFormModifierXTest());
357 stepper->setAppAction(modifierX);
358 stepper->initialize();
365 timeStepControl->setInitIndex(tscPL.
get<
int> (
"Initial Time Index"));
366 timeStepControl->setInitTime (tscPL.
get<
double>(
"Initial Time"));
367 timeStepControl->setFinalTime(dt);
368 timeStepControl->setInitTimeStep(dt);
369 timeStepControl->initialize();
372 using Teuchos::rcp_const_cast;
373 auto inArgsIC = model->getNominalValues();
382 icState->setTime (timeStepControl->getInitTime());
383 icState->setIndex (timeStepControl->getInitIndex());
384 icState->setTimeStep(0.0);
385 icState->setOrder (stepper->getOrder());
391 solutionHistory->setName(
"Forward States");
393 solutionHistory->setStorageLimit(2);
394 solutionHistory->addState(icState);
398 Tempus::createIntegratorBasic<double>();
399 integrator->setStepper(stepper);
400 integrator->setTimeStepControl(timeStepControl);
401 integrator->setSolutionHistory(solutionHistory);
402 integrator->initialize();
405 bool integratorStatus = integrator->advanceTime();
416 auto Dt = integrator->getTime();
419 const auto x = integrator->getX();
Teuchos::RCP< SolutionState< Scalar > > createSolutionStateX(const Teuchos::RCP< Thyra::VectorBase< Scalar > > &x, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdot=Teuchos::null, const Teuchos::RCP< Thyra::VectorBase< Scalar > > &xdotdot=Teuchos::null)
Nonmember constructor from non-const solution vectors, x.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Teuchos::RCP< StepperNewmarkImplicitDForm< Scalar > > createStepperNewmarkImplicitDForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
T & get(const std::string &name, T def_value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
Consider the ODE: where is a constant, is a constant damping parameter, is a constant forcing par...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)