12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_SolutionHistory.hpp"
17 #include "Tempus_StepperForwardEuler.hpp"
18 #include "Tempus_StepperBackwardEuler.hpp"
28 #include "../TestModels/SinCosModel.hpp"
29 #include "../TestModels/VanDerPolModel.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;
55 stepper->setModel(model);
56 stepper->initialize();
68 predictorStepper->setModel(model);
69 predictorStepper->initialize();
72 bool useFSAL = defaultStepper->getUseFSAL();
73 std::string ICConsistency = defaultStepper->getICConsistency();
74 bool ICConsistencyCheck = defaultStepper->getICConsistencyCheck();
75 bool zeroInitialGuess = defaultStepper->getZeroInitialGuess();
82 stepper->setPredictor(predictorStepper); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
90 model, solver, predictorStepper, useFSAL,
91 ICConsistency, ICConsistencyCheck, zeroInitialGuess, modifier));
110 class StepperBackwardEulerModifierTest
116 StepperBackwardEulerModifierTest()
117 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
118 testAFTER_SOLVE(false), testEND_STEP(false),
119 testCurrentValue(-0.99), testWorkingValue(-0.99),
120 testDt(-1.5), testName(
"")
124 virtual ~StepperBackwardEulerModifierTest(){}
135 testBEGIN_STEP =
true;
136 auto x = sh->getCurrentState()->getX();
137 testCurrentValue = get_ele(*(x), 0);
142 testBEFORE_SOLVE =
true;
143 testDt = sh->getWorkingState()->getTimeStep()/10.0;
144 sh->getWorkingState()->setTimeStep(testDt);
149 testAFTER_SOLVE =
true;
150 testName =
"Backward Euler - Modifier";
151 stepper->setStepperName(testName);
157 auto x = sh->getWorkingState()->getX();
158 testWorkingValue = get_ele(*(x), 0);
163 "Error - unknown action location.\n");
168 bool testBEFORE_SOLVE;
169 bool testAFTER_SOLVE;
171 double testCurrentValue;
172 double testWorkingValue;
174 std::string testName;
184 stepper->setModel(model);
185 auto modifier =
rcp(
new StepperBackwardEulerModifierTest());
186 stepper->setAppAction(modifier);
187 stepper->initialize();
193 stepper->setInitialConditions(solutionHistory);
194 solutionHistory->initWorkingState();
196 solutionHistory->getWorkingState()->setTimeStep(dt);
197 stepper->takeStep(solutionHistory);
206 auto x = solutionHistory->getCurrentState()->getX();
208 x = solutionHistory->getWorkingState()->getX();
210 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
213 TEST_COMPARE(modifier->testName, ==,
"Backward Euler - Modifier");
220 class StepperBackwardEulerObserverTest
226 StepperBackwardEulerObserverTest()
227 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
228 testAFTER_SOLVE(false), testEND_STEP(false),
229 testCurrentValue(-0.99), testWorkingValue(-0.99),
230 testDt(-1.5), testName(
"")
234 virtual ~StepperBackwardEulerObserverTest(){}
237 virtual void observe(
245 testBEGIN_STEP =
true;
246 auto x = sh->getCurrentState()->getX();
247 testCurrentValue = get_ele(*(x), 0);
252 testBEFORE_SOLVE =
true;
253 testDt = sh->getWorkingState()->getTimeStep();
258 testAFTER_SOLVE =
true;
259 testName = stepper->getStepperType();
265 auto x = sh->getWorkingState()->getX();
266 testWorkingValue = get_ele(*(x), 0);
271 "Error - unknown action location.\n");
276 bool testBEFORE_SOLVE;
277 bool testAFTER_SOLVE;
279 double testCurrentValue;
280 double testWorkingValue;
282 std::string testName;
292 stepper->setModel(model);
293 auto observer =
rcp(
new StepperBackwardEulerObserverTest());
294 stepper->setAppAction(observer);
295 stepper->initialize();
301 stepper->setInitialConditions(solutionHistory);
302 solutionHistory->initWorkingState();
304 solutionHistory->getWorkingState()->setTimeStep(dt);
305 stepper->takeStep(solutionHistory);
314 auto x = solutionHistory->getCurrentState()->getX();
316 x = solutionHistory->getWorkingState()->getX();
326 class StepperBackwardEulerModifierXTest
332 StepperBackwardEulerModifierXTest()
333 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
334 testX_AFTER_SOLVE(false), testXDOT_END_STEP(false),
335 testX(-0.99), testXDot(-0.99),
336 testDt(-1.5), testTime(-1.5)
340 virtual ~StepperBackwardEulerModifierXTest(){}
345 const double time,
const double dt,
351 testX_BEGIN_STEP =
true;
352 testX = get_ele(*(x), 0);
357 testX_BEFORE_SOLVE =
true;
363 testX_AFTER_SOLVE =
true;
369 testXDOT_END_STEP =
true;
370 testXDot = get_ele(*(x), 0);
375 "Error - unknown action location.\n");
379 bool testX_BEGIN_STEP;
380 bool testX_BEFORE_SOLVE;
381 bool testX_AFTER_SOLVE;
382 bool testXDOT_END_STEP;
396 stepper->setModel(model);
397 auto modifierX =
rcp(
new StepperBackwardEulerModifierXTest());
398 stepper->setAppAction(modifierX);
399 stepper->initialize();
405 stepper->setInitialConditions(solutionHistory);
406 solutionHistory->initWorkingState();
408 solutionHistory->getWorkingState()->setTimeStep(dt);
409 stepper->takeStep(solutionHistory);
418 auto x = solutionHistory->getCurrentState()->getX();
421 auto xDot = solutionHistory->getWorkingState()->getXDot();
422 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
425 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
428 auto time = solutionHistory->getWorkingState()->getTime();
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Default observer for StepperBackwardEuler.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Forward Euler time stepper.
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Modify before the implicit solve.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
After the implicit solve.
At the beginning of the step.
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Default modifier for StepperBackwardEuler.
Modify after the implicit solve.
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.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
Base ModifierX for StepperBackwardEuler.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Modify at the beginning of the step.
Base observer for StepperBackwardEuler.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Backward Euler time stepper.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Modify at the end of the step.
Before the implicit solve.
Base modifier for StepperBackwardEuler.
#define TEUCHOS_ASSERT(assertion_test)
Default ModifierX for StepperBackwardEuler.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)