14 #include "Tempus_TimeStepControl.hpp"
16 #include "Tempus_StepperNewmarkImplicitDForm.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 "Tempus_NewmarkImplicitDForm_HarmonicOscillator_Damped_SecondOrder.xml");
61 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
62 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
63 timeStepControl->setFinalTime(tscPL.
get<
double>(
"Final Time"));
64 timeStepControl->setInitTimeStep(dt);
65 timeStepControl->initialize();
68 using Teuchos::rcp_const_cast;
69 auto inArgsIC = model->getNominalValues();
78 icState->setTime(timeStepControl->getInitTime());
79 icState->setIndex(timeStepControl->getInitIndex());
80 icState->setTimeStep(0.0);
81 icState->setOrder(stepper->getOrder());
87 solutionHistory->setName(
"Forward States");
89 solutionHistory->setStorageLimit(2);
90 solutionHistory->addState(icState);
94 Tempus::createIntegratorBasic<double>();
95 integrator->setStepper(stepper);
96 integrator->setTimeStepControl(timeStepControl);
97 integrator->setSolutionHistory(solutionHistory);
99 integrator->initialize();
102 bool integratorStatus = integrator->advanceTime();
106 double time = integrator->getTime();
107 double timeFinal = pl->
sublist(
"Default Integrator")
109 .
get<
double>(
"Final Time");
115 model->getExactSolution(time).get_x();
119 Thyra::V_StVpStV(xdiff.
ptr(), 1.0, *x_exact, -1.0, *(x));
122 out <<
" Stepper = " << stepper->description() << std::endl;
123 out <<
" =========================" << std::endl;
124 out <<
" Exact solution : " << get_ele(*(x_exact), 0) << std::endl;
125 out <<
" Computed solution: " << get_ele(*(x), 0) << std::endl;
126 out <<
" Difference : " << get_ele(*(xdiff), 0) << std::endl;
127 out <<
" =========================" << std::endl;
128 TEST_FLOATING_EQUALITY(get_ele(*(x), 0), -0.222222, 1.0e-4);
132 class StepperNewmarkImplicitDFormModifierTest
136 StepperNewmarkImplicitDFormModifierTest()
137 : testBEGIN_STEP(false),
138 testBEFORE_SOLVE(false),
139 testAFTER_SOLVE(false),
141 testCurrentValue(-0.99),
148 virtual ~StepperNewmarkImplicitDFormModifierTest() {}
155 double>::ACTION_LOCATION actLoc)
159 testBEGIN_STEP =
true;
163 testBEFORE_SOLVE =
true;
164 testDt = sh->getWorkingState()->getTimeStep();
169 testAFTER_SOLVE =
true;
170 testName =
"Newmark Implicit A Form - Modifier";
171 stepper->setStepperName(testName);
176 auto x = sh->getWorkingState()->getX();
177 testCurrentValue = get_ele(*(x), 0);
182 "Error - unknown action location.\n");
187 bool testBEFORE_SOLVE;
188 bool testAFTER_SOLVE;
190 double testCurrentValue;
192 std::string testName;
197 class StepperNewmarkImplicitDFormModifierXTest
201 StepperNewmarkImplicitDFormModifierXTest()
202 : testX_BEGIN_STEP(false),
203 testX_BEFORE_SOLVE(false),
204 testX_AFTER_SOLVE(false),
205 testX_END_STEP(false),
214 virtual ~StepperNewmarkImplicitDFormModifierXTest() {}
221 double>::MODIFIER_TYPE modType)
225 testX_BEGIN_STEP =
true;
226 testX = get_ele(*(x), 0);
230 testX_BEFORE_SOLVE =
true;
235 testX_AFTER_SOLVE =
true;
237 testX = get_ele(*(x), 0);
241 testX_END_STEP =
true;
242 testX = get_ele(*(x), 0);
247 "Error - unknown action location.\n");
251 bool testX_BEGIN_STEP;
252 bool testX_BEFORE_SOLVE;
253 bool testX_AFTER_SOLVE;
269 stepper->setModel(model);
270 stepper->initialize();
282 bool useFSAL = stepper->getUseFSAL();
283 std::string ICConsistency = stepper->getICConsistency();
284 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
285 bool zeroInitialGuess = stepper->getZeroInitialGuess();
286 std::string schemeName =
"Average Acceleration";
291 stepper->setAppAction(modifier);
292 stepper->initialize();
294 stepper->setAppAction(modifierX);
295 stepper->initialize();
297 stepper->setSolver(solver);
298 stepper->initialize();
300 stepper->setUseFSAL(useFSAL);
301 stepper->initialize();
303 stepper->setICConsistency(ICConsistency);
304 stepper->initialize();
306 stepper->setICConsistencyCheck(ICConsistencyCheck);
307 stepper->initialize();
309 stepper->setZeroInitialGuess(zeroInitialGuess);
310 stepper->initialize();
313 stepper->setSchemeName(schemeName);
314 stepper->initialize();
316 stepper->setBeta(beta);
317 stepper->initialize();
319 stepper->setGamma(gamma);
320 stepper->initialize();
325 model, solver, useFSAL, ICConsistency, ICConsistencyCheck,
326 zeroInitialGuess, schemeName, beta, gamma, modifier));
345 using Teuchos::sublist;
351 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
363 auto modifier =
rcp(
new StepperNewmarkImplicitDFormModifierTest());
364 stepper->setAppAction(modifier);
365 stepper->initialize();
372 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
373 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
374 timeStepControl->setFinalTime(dt);
375 timeStepControl->setInitTimeStep(dt);
376 timeStepControl->initialize();
379 using Teuchos::rcp_const_cast;
380 auto inArgsIC = model->getNominalValues();
389 icState->setTime(timeStepControl->getInitTime());
390 icState->setIndex(timeStepControl->getInitIndex());
391 icState->setTimeStep(0.0);
392 icState->setOrder(stepper->getOrder());
398 solutionHistory->setName(
"Forward States");
400 solutionHistory->setStorageLimit(2);
401 solutionHistory->addState(icState);
405 Tempus::createIntegratorBasic<double>();
406 integrator->setStepper(stepper);
407 integrator->setTimeStepControl(timeStepControl);
408 integrator->setSolutionHistory(solutionHistory);
409 integrator->initialize();
412 bool integratorStatus = integrator->advanceTime();
422 auto x = integrator->getX();
423 auto Dt = integrator->getTime();
426 TEST_COMPARE(modifier->testName, ==, stepper->getStepperName());
433 using Teuchos::sublist;
439 "Tempus_NewmarkImplicitAForm_HarmonicOscillator_Damped_SecondOrder.xml");
451 auto modifierX =
rcp(
new StepperNewmarkImplicitDFormModifierXTest());
452 stepper->setAppAction(modifierX);
453 stepper->initialize();
460 timeStepControl->setInitIndex(tscPL.
get<
int>(
"Initial Time Index"));
461 timeStepControl->setInitTime(tscPL.
get<
double>(
"Initial Time"));
462 timeStepControl->setFinalTime(dt);
463 timeStepControl->setInitTimeStep(dt);
464 timeStepControl->initialize();
467 using Teuchos::rcp_const_cast;
468 auto inArgsIC = model->getNominalValues();
477 icState->setTime(timeStepControl->getInitTime());
478 icState->setIndex(timeStepControl->getInitIndex());
479 icState->setTimeStep(0.0);
480 icState->setOrder(stepper->getOrder());
486 solutionHistory->setName(
"Forward States");
488 solutionHistory->setStorageLimit(2);
489 solutionHistory->addState(icState);
493 Tempus::createIntegratorBasic<double>();
494 integrator->setStepper(stepper);
495 integrator->setTimeStepControl(timeStepControl);
496 integrator->setSolutionHistory(solutionHistory);
497 integrator->initialize();
500 bool integratorStatus = integrator->advanceTime();
510 auto Dt = integrator->getTime();
513 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.
T & get(const std::string &name, T def_value)
Teuchos::RCP< StepperNewmarkImplicitDForm< Scalar > > createStepperNewmarkImplicitDForm(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar >> &model, Teuchos::RCP< Teuchos::ParameterList > pl)
Nonmember constructor - ModelEvaluator and ParameterList.
#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)