15 #include "Teuchos_DefaultComm.hpp"
17 #include "Thyra_VectorStdOps.hpp"
19 #include "Tempus_IntegratorBasic.hpp"
22 #include "Tempus_StepperBDF2.hpp"
28 #include "../TestModels/SinCosModel.hpp"
29 #include "../TestModels/VanDerPolModel.hpp"
30 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
33 namespace Tempus_Unit_Test {
37 using Teuchos::rcp_const_cast;
38 using Teuchos::rcp_dynamic_cast;
40 using Teuchos::sublist;
41 using Teuchos::getParametersFromXmlFile;
55 stepper->setModel(model);
56 stepper->initialize();
66 startUpStepper->setModel(model);
67 startUpStepper->initialize();
70 bool useFSAL = defaultStepper->getUseFSAL();
71 std::string ICConsistency = defaultStepper->getICConsistency();
72 bool ICConsistencyCheck = defaultStepper->getICConsistencyCheck();
73 bool zeroInitialGuess = defaultStepper->getZeroInitialGuess();
78 stepper->setStartUpStepper(startUpStepper); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
80 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
81 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85 ICConsistency, ICConsistencyCheck, zeroInitialGuess,modifier));
103 class StepperBDF2ModifierTest
109 StepperBDF2ModifierTest()
110 : testBEGIN_STEP(false),testBEFORE_SOLVE(false),
111 testAFTER_SOLVE(false),testEND_STEP(false),
112 testCurrentValue(-0.99), testWorkingValue(-0.99),
113 testDt(.99), testType(
"")
117 virtual ~StepperBDF2ModifierTest(){}
127 testBEGIN_STEP =
true;
128 auto x = sh->getWorkingState()->getX();
129 testCurrentValue = get_ele(*(x), 0);
134 testBEFORE_SOLVE =
true;
135 testType =
"BDF2 - Modifier";
140 testAFTER_SOLVE =
true;
141 testDt = sh->getCurrentState()->getTimeStep()/10.0;
142 sh->getCurrentState()->setTimeStep(testDt);
148 auto x = sh->getWorkingState()->getX();
149 testWorkingValue = get_ele(*(x), 0);
154 "Error - unknown action location.\n");
158 bool testBEFORE_SOLVE;
159 bool testAFTER_SOLVE;
161 double testCurrentValue;
162 double testWorkingValue;
164 std::string testType;
173 stepper->setModel(model);
174 auto modifier =
rcp(
new StepperBDF2ModifierTest());
175 stepper->setAppAction(modifier);
176 stepper->initialize();
179 auto inArgsIC = model->getNominalValues();
183 icState->setTime (0.0);
184 icState->setIndex (0);
185 icState->setTimeStep(1.0);
186 icState->setOrder (stepper->getOrder());
191 timeStepControl->setInitIndex(0);
192 timeStepControl->setInitTime (0.0);
193 timeStepControl->setFinalTime(2.0);
194 timeStepControl->setInitTimeStep(1.0);
195 timeStepControl->initialize();
199 solutionHistory->setName(
"Forward States");
201 solutionHistory->setStorageLimit(3);
202 solutionHistory->addState(icState);
205 stepper->setInitialConditions(solutionHistory);
206 solutionHistory->initWorkingState();
208 solutionHistory->getWorkingState()->setTimeStep(dt);
209 stepper->takeStep(solutionHistory);
210 solutionHistory->promoteWorkingState();
211 solutionHistory->initWorkingState();
212 stepper->takeStep(solutionHistory);
219 auto Dt = solutionHistory->getCurrentState()->getTimeStep();
221 auto x = solutionHistory->getCurrentState()->getX();
223 x = solutionHistory->getWorkingState()->getX();
225 TEST_COMPARE(modifier->testType, ==,
"BDF2 - Modifier");
230 class StepperBDF2ObserverTest
236 StepperBDF2ObserverTest()
237 : testBEGIN_STEP(false),testBEFORE_SOLVE(false),
238 testAFTER_SOLVE(false),testEND_STEP(false),
239 testCurrentValue(0.99), testWorkingValue(0.99),
240 testDt(.99), testType(
"")
244 virtual ~StepperBDF2ObserverTest(){}
254 testBEGIN_STEP =
true;
255 auto x = sh->getCurrentState()->getX();
256 testCurrentValue = get_ele(*(x), 0);
261 testBEFORE_SOLVE =
true;
262 testType = stepper->getStepperType();
267 testAFTER_SOLVE =
true;
268 testDt = sh->getCurrentState()->getTimeStep();
274 auto x = sh->getWorkingState()->getX();
275 testWorkingValue = get_ele(*(x), 0);
281 "Error - unknown action location.\n");
285 bool testBEFORE_SOLVE;
286 bool testAFTER_SOLVE;
288 double testCurrentValue;
289 double testWorkingValue;
291 std::string testType;
300 stepper->setModel(model);
301 auto observer =
rcp(
new StepperBDF2ModifierTest());
302 stepper->setAppAction(observer);
303 stepper->initialize();
306 auto inArgsIC = model->getNominalValues();
310 icState->setTime (0.0);
311 icState->setIndex (0);
312 icState->setTimeStep(1.0);
313 icState->setOrder (stepper->getOrder());
318 timeStepControl->setInitIndex(0);
319 timeStepControl->setInitTime (0.0);
320 timeStepControl->setFinalTime(2.0);
321 timeStepControl->setInitTimeStep(1.0);
322 timeStepControl->initialize();
326 solutionHistory->setName(
"Forward States");
328 solutionHistory->setStorageLimit(3);
329 solutionHistory->addState(icState);
332 stepper->setInitialConditions(solutionHistory);
333 solutionHistory->initWorkingState();
335 solutionHistory->getWorkingState()->setTimeStep(dt);
336 stepper->takeStep(solutionHistory);
337 solutionHistory->promoteWorkingState();
338 solutionHistory->initWorkingState();
339 stepper->takeStep(solutionHistory);
346 auto Dt = solutionHistory->getCurrentState()->getTimeStep();
349 auto x = solutionHistory->getCurrentState()->getX();
351 x = solutionHistory->getWorkingState()->getX();
353 TEST_COMPARE(observer->testType, ==,
"BDF2 - Modifier");
357 class StepperBDF2ModifierXTest
363 StepperBDF2ModifierXTest()
364 : testX_BEGIN_STEP(false),testX_BEFORE_SOLVE(false),
365 testX_AFTER_SOLVE(false),testX_END_STEP(false),
366 testXbegin(-.99),testXend(-.99),testTime(0.0),testDt(0.0)
370 virtual ~StepperBDF2ModifierXTest(){}
375 const double time,
const double dt,
381 testX_BEGIN_STEP =
true;
382 testXbegin = get_ele(*(x), 0);
387 testX_BEFORE_SOLVE =
true;
393 testX_AFTER_SOLVE =
true;
399 testX_END_STEP =
true;
400 testXend = get_ele(*(x), 0);
405 "Error - unknown action location.\n");
408 bool testX_BEGIN_STEP;
409 bool testX_BEFORE_SOLVE;
410 bool testX_AFTER_SOLVE;
423 stepper->setModel(model);
424 auto modifierX =
rcp(
new StepperBDF2ModifierXTest());
425 stepper->setAppAction(modifierX);
426 stepper->initialize();
429 auto inArgsIC = model->getNominalValues();
433 icState->setTime (0.0);
434 icState->setIndex (0);
435 icState->setTimeStep(1.0);
436 icState->setOrder (stepper->getOrder());
441 timeStepControl->setInitIndex(0);
442 timeStepControl->setInitTime (0.0);
443 timeStepControl->setFinalTime(2.0);
444 timeStepControl->setInitTimeStep(1.0);
445 timeStepControl->initialize();
449 solutionHistory->setName(
"Forward States");
451 solutionHistory->setStorageLimit(3);
452 solutionHistory->addState(icState);
456 stepper->setInitialConditions(solutionHistory);
457 solutionHistory->initWorkingState();
459 solutionHistory->getWorkingState()->setTimeStep(dt);
460 stepper->takeStep(solutionHistory);
461 solutionHistory->promoteWorkingState();
462 solutionHistory->initWorkingState();
463 stepper->takeStep(solutionHistory);
471 auto x = solutionHistory->getCurrentState()->getX();
473 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
474 x = solutionHistory->getWorkingState()->getX();
477 auto time = solutionHistory->getWorkingState()->getTime();
BDF2 (Backward-Difference-Formula-2) time stepper.
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.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Modify after the implicit solve.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Modify at the beginning of the step.
Base ModifierX for StepperBDF2.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
Modify before the implicit solve.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
Teuchos::RCP< Teuchos::ParameterList > defaultSolverParameters()
Returns the default solver ParameterList for implicit Steppers.
Modify at the end of the step.
Default modifier for StepperBDF2.
Base observer for StepperBDF2.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
At the beginning of the step.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Keep a fix number of states.
Base modifier for StepperBDF2.
#define TEUCHOS_ASSERT(assertion_test)
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)