14 #include "Tempus_TimeStepControl.hpp"
16 #include "Tempus_StepperNewmarkImplicitAForm.hpp"
22 #include "../TestModels/HarmonicOscillatorModel.hpp"
24 namespace Tempus_Unit_Test {
29 using Teuchos::rcp_const_cast;
30 using Teuchos::rcp_dynamic_cast;
31 using Teuchos::sublist;
43 stepper->setModel(model);
44 stepper->initialize();
56 bool useFSAL = stepper->getUseFSAL();
57 std::string ICConsistency = stepper->getICConsistency();
58 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
59 bool zeroInitialGuess = stepper->getZeroInitialGuess();
60 std::string schemeName =
"Average Acceleration";
65 stepper->setAppAction(modifier);
66 stepper->initialize();
68 stepper->setAppAction(modifierX);
69 stepper->initialize();
71 stepper->setSolver(solver);
72 stepper->initialize();
74 stepper->setUseFSAL(useFSAL);
75 stepper->initialize();
77 stepper->setICConsistency(ICConsistency);
78 stepper->initialize();
80 stepper->setICConsistencyCheck(ICConsistencyCheck);
81 stepper->initialize();
83 stepper->setZeroInitialGuess(zeroInitialGuess);
84 stepper->initialize();
87 stepper->setSchemeName(schemeName);
88 stepper->initialize();
90 stepper->setBeta(beta);
91 stepper->initialize();
93 stepper->setGamma(gamma);
94 stepper->initialize();
99 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
100 zeroInitialGuess, schemeName, beta, gamma, modifier));
120 std::vector<std::string> options;
121 options.push_back(
"Default Parameters");
122 options.push_back(
"ICConsistency and Check");
124 for (
const auto& option : options) {
127 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder."
140 if (option ==
"ICConsistency and Check") {
141 stepper->setICConsistency(
"Consistent");
142 stepper->setICConsistencyCheck(
true);
144 stepper->initialize();
151 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
152 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
153 timeStepControl->setFinalTime(tscPL.
get<
double>(
"Final Time"));
154 timeStepControl->setInitTimeStep(dt);
155 timeStepControl->initialize();
158 using Teuchos::rcp_const_cast;
159 auto inArgsIC = model->getNominalValues();
168 icState->setTime(timeStepControl->getInitTime());
169 icState->setIndex(timeStepControl->getInitIndex());
170 icState->setTimeStep(0.0);
171 icState->setOrder(stepper->getOrder());
177 solutionHistory->setName(
"Forward States");
179 solutionHistory->setStorageLimit(2);
180 solutionHistory->addState(icState);
183 stepper->setInitialConditions(solutionHistory);
187 Tempus::createIntegratorBasic<double>();
188 integrator->setStepper(stepper);
189 integrator->setTimeStepControl(timeStepControl);
190 integrator->setSolutionHistory(solutionHistory);
192 integrator->initialize();
195 bool integratorStatus = integrator->advanceTime();
199 double time = integrator->getTime();
200 double timeFinal = pl->
sublist(
"Default Integrator")
202 .
get<
double>(
"Final Time");
208 model->getExactSolution(time).get_x();
212 Thyra::V_StVpStV(xdiff.
ptr(), 1.0, *x_exact, -1.0, *(x));
215 out <<
" Stepper = " << stepper->description() <<
"\n with "
216 << option << std::endl;
217 out <<
" =========================" << std::endl;
218 out <<
" Exact solution : " << get_ele(*(x_exact), 0) << std::endl;
219 out <<
" Computed solution: " << get_ele(*(x), 0) << std::endl;
220 out <<
" Difference : " << get_ele(*(xdiff), 0) << std::endl;
221 out <<
" =========================" << std::endl;
222 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), -0.222222, 1.0e-4);
228 class StepperNewmarkImplicitAFormModifierTest
232 StepperNewmarkImplicitAFormModifierTest()
233 : testBEGIN_STEP(false),
234 testBEFORE_SOLVE(false),
235 testAFTER_SOLVE(false),
237 testCurrentValue(-0.99),
244 virtual ~StepperNewmarkImplicitAFormModifierTest() {}
251 double>::ACTION_LOCATION actLoc)
255 testBEGIN_STEP =
true;
259 testBEFORE_SOLVE =
true;
260 testDt = sh->getWorkingState()->getTimeStep();
265 testAFTER_SOLVE =
true;
266 testName =
"Newmark Implicit A Form - Modifier";
267 stepper->setStepperName(testName);
272 auto x = sh->getWorkingState()->getX();
273 testCurrentValue = get_ele(*(x), 0);
278 "Error - unknown action location.\n");
283 bool testBEFORE_SOLVE;
284 bool testAFTER_SOLVE;
286 double testCurrentValue;
288 std::string testName;
293 class StepperNewmarkImplicitAFormModifierXTest
297 StepperNewmarkImplicitAFormModifierXTest()
298 : testX_BEGIN_STEP(false),
299 testX_BEFORE_SOLVE(false),
300 testX_AFTER_SOLVE(false),
301 testX_END_STEP(false),
310 virtual ~StepperNewmarkImplicitAFormModifierXTest() {}
317 double>::MODIFIER_TYPE modType)
321 testX_BEGIN_STEP =
true;
322 testX = get_ele(*(x), 0);
326 testX_BEFORE_SOLVE =
true;
331 testX_AFTER_SOLVE =
true;
333 testX = get_ele(*(x), 0);
337 testX_END_STEP =
true;
338 testX = get_ele(*(x), 0);
343 "Error - unknown action location.\n");
347 bool testX_BEGIN_STEP;
348 bool testX_BEFORE_SOLVE;
349 bool testX_AFTER_SOLVE;
361 using Teuchos::sublist;
367 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
379 auto modifier =
rcp(
new StepperNewmarkImplicitAFormModifierTest());
380 stepper->setAppAction(modifier);
381 stepper->initialize();
388 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
389 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
390 timeStepControl->setFinalTime(dt);
391 timeStepControl->setInitTimeStep(dt);
392 timeStepControl->initialize();
395 using Teuchos::rcp_const_cast;
396 auto inArgsIC = model->getNominalValues();
405 icState->setTime(timeStepControl->getInitTime());
406 icState->setIndex(timeStepControl->getInitIndex());
407 icState->setTimeStep(0.0);
408 icState->setOrder(stepper->getOrder());
414 solutionHistory->setName(
"Forward States");
416 solutionHistory->setStorageLimit(2);
417 solutionHistory->addState(icState);
421 Tempus::createIntegratorBasic<double>();
422 integrator->setStepper(stepper);
423 integrator->setTimeStepControl(timeStepControl);
424 integrator->setSolutionHistory(solutionHistory);
425 integrator->initialize();
428 bool integratorStatus = integrator->advanceTime();
438 auto x = integrator->getX();
439 auto Dt = integrator->getTime();
442 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
449 using Teuchos::sublist;
455 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
467 auto modifierX =
rcp(
new StepperNewmarkImplicitAFormModifierXTest());
468 stepper->setAppAction(modifierX);
469 stepper->initialize();
476 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
477 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
478 timeStepControl->setFinalTime(dt);
479 timeStepControl->setInitTimeStep(dt);
480 timeStepControl->initialize();
483 using Teuchos::rcp_const_cast;
484 auto inArgsIC = model->getNominalValues();
493 icState->setTime(timeStepControl->getInitTime());
494 icState->setIndex(timeStepControl->getInitIndex());
495 icState->setTimeStep(0.0);
496 icState->setOrder(stepper->getOrder());
502 solutionHistory->setName(
"Forward States");
504 solutionHistory->setStorageLimit(2);
505 solutionHistory->addState(icState);
509 Tempus::createIntegratorBasic<double>();
510 integrator->setStepper(stepper);
511 integrator->setTimeStepControl(timeStepControl);
512 integrator->setSolutionHistory(solutionHistory);
513 integrator->initialize();
516 bool integratorStatus = integrator->advanceTime();
526 auto Dt = integrator->getTime();
529 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)