12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_IntegratorBasic.hpp"
17 #include "Tempus_StepperFactory.hpp"
18 #include "Tempus_SolutionHistory.hpp"
20 #include "Tempus_TimeStepControl.hpp"
22 #include "Tempus_StepperNewmarkImplicitAForm.hpp"
28 #include "../TestModels/SinCosModel.hpp"
29 #include "../TestModels/VanDerPolModel.hpp"
30 #include "../TestModels/HarmonicOscillatorModel.hpp"
31 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
36 namespace Tempus_Unit_Test {
40 using Teuchos::rcp_const_cast;
41 using Teuchos::rcp_dynamic_cast;
43 using Teuchos::sublist;
44 using Teuchos::getParametersFromXmlFile;
57 stepper->setModel(model);
58 stepper->initialize();
68 bool useFSAL = stepper->getUseFSAL();
69 std::string ICConsistency = stepper->getICConsistency();
70 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
71 bool zeroInitialGuess = stepper->getZeroInitialGuess();
72 std::string schemeName =
"Average Acceleration";
82 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
93 model, solver, useFSAL,
94 ICConsistency, ICConsistencyCheck, zeroInitialGuess,
95 schemeName, beta, gamma, modifier));
113 class StepperNewmarkImplicitAFormModifierTest
119 StepperNewmarkImplicitAFormModifierTest()
120 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
121 testAFTER_SOLVE(false), testEND_STEP(false),
122 testCurrentValue(-0.99),
123 testDt(-1.5), testName(
"")
127 virtual ~StepperNewmarkImplicitAFormModifierTest(){}
138 testBEGIN_STEP =
true;
143 testBEFORE_SOLVE =
true;
144 testDt = sh->getWorkingState()->getTimeStep();
150 testAFTER_SOLVE =
true;
151 testName =
"Newmark Implicit A Form - Modifier";
152 stepper->setStepperName(testName);
158 auto x = sh->getWorkingState()->getX();
159 testCurrentValue = get_ele(*(x), 0);
164 "Error - unknown action location.\n");
169 bool testBEFORE_SOLVE;
170 bool testAFTER_SOLVE;
172 double testCurrentValue;
174 std::string testName;
180 class StepperNewmarkImplicitAFormModifierXTest
186 StepperNewmarkImplicitAFormModifierXTest()
187 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
188 testX_AFTER_SOLVE(false), testX_END_STEP(false),
189 testX(-0.99), testXDot(-0.99),
190 testDt(-1.5), testTime(-1.5)
194 virtual ~StepperNewmarkImplicitAFormModifierXTest(){}
199 const double time,
const double dt,
205 testX_BEGIN_STEP =
true;
206 testX = get_ele(*(x), 0);
211 testX_BEFORE_SOLVE =
true;
217 testX_AFTER_SOLVE =
true;
219 testX = get_ele(*(x), 0);
224 testX_END_STEP =
true;
225 testX = get_ele(*(x), 0);
230 "Error - unknown action location.\n");
234 bool testX_BEGIN_STEP;
235 bool testX_BEFORE_SOLVE;
236 bool testX_AFTER_SOLVE;
247 using Teuchos::getParametersFromXmlFile;
248 using Teuchos::sublist;
255 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
267 auto modifier =
rcp(
new StepperNewmarkImplicitAFormModifierTest());
268 stepper->setAppAction(modifier);
269 stepper->initialize();
276 timeStepControl->setInitIndex(tscPL.
get<
int> (
"Initial Time Index"));
277 timeStepControl->setInitTime (tscPL.
get<
double>(
"Initial Time"));
278 timeStepControl->setFinalTime(dt);
279 timeStepControl->setInitTimeStep(dt);
280 timeStepControl->initialize();
283 using Teuchos::rcp_const_cast;
284 auto inArgsIC = model->getNominalValues();
293 icState->setTime (timeStepControl->getInitTime());
294 icState->setIndex (timeStepControl->getInitIndex());
295 icState->setTimeStep(0.0);
296 icState->setOrder (stepper->getOrder());
302 solutionHistory->setName(
"Forward States");
304 solutionHistory->setStorageLimit(2);
305 solutionHistory->addState(icState);
309 Tempus::createIntegratorBasic<double>();
310 integrator->setStepper(stepper);
311 integrator->setTimeStepControl(timeStepControl);
312 integrator->setSolutionHistory(solutionHistory);
313 integrator->initialize();
316 bool integratorStatus = integrator->advanceTime();
327 auto x = integrator->getX();
328 auto Dt = integrator->getTime();
331 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
338 using Teuchos::getParametersFromXmlFile;
339 using Teuchos::sublist;
346 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
358 auto modifierX =
rcp(
new StepperNewmarkImplicitAFormModifierXTest());
359 stepper->setAppAction(modifierX);
360 stepper->initialize();
367 timeStepControl->setInitIndex(tscPL.
get<
int> (
"Initial Time Index"));
368 timeStepControl->setInitTime (tscPL.
get<
double>(
"Initial Time"));
369 timeStepControl->setFinalTime(dt);
370 timeStepControl->setInitTimeStep(dt);
371 timeStepControl->initialize();
374 using Teuchos::rcp_const_cast;
375 auto inArgsIC = model->getNominalValues();
384 icState->setTime (timeStepControl->getInitTime());
385 icState->setIndex (timeStepControl->getInitIndex());
386 icState->setTimeStep(0.0);
387 icState->setOrder (stepper->getOrder());
393 solutionHistory->setName(
"Forward States");
395 solutionHistory->setStorageLimit(2);
396 solutionHistory->addState(icState);
400 Tempus::createIntegratorBasic<double>();
401 integrator->setStepper(stepper);
402 integrator->setTimeStepControl(timeStepControl);
403 integrator->setSolutionHistory(solutionHistory);
404 integrator->initialize();
407 bool integratorStatus = integrator->advanceTime();
418 auto Dt = integrator->getTime();
421 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.
Teuchos::RCP< StepperNewmarkImplicitAForm< Scalar > > createStepperNewmarkImplicitAForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
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)