12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
16 #include "Tempus_StepperTrapezoidal.hpp"
25 #include "../TestModels/SinCosModel.hpp"
26 #include "../TestModels/VanDerPolModel.hpp"
27 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
32 namespace Tempus_Unit_Test {
36 using Teuchos::rcp_const_cast;
37 using Teuchos::rcp_dynamic_cast;
39 using Teuchos::sublist;
40 using Teuchos::getParametersFromXmlFile;
51 stepper->setModel(model);
52 stepper->initialize();
62 bool useFSAL = stepper->getUseFSAL();
63 std::string ICConsistency = stepper->getICConsistency();
64 bool ICConsistencyCheck = stepper->getICConsistencyCheck();
65 bool zeroInitialGuess = stepper->getZeroInitialGuess();
72 stepper->setICConsistency(ICConsistency); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
73 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize();
TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 model, solver, useFSAL,
79 ICConsistency, ICConsistencyCheck, zeroInitialGuess, modifier));
97 class StepperTrapezoidalModifierTest
102 StepperTrapezoidalModifierTest()
103 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
104 testAFTER_SOLVE(false), testEND_STEP(false),
105 testCurrentValue(-0.99), testWorkingValue(-0.99),
106 testDt(-1.5), testName(
"")
110 virtual ~StepperTrapezoidalModifierTest(){}
121 testBEGIN_STEP =
true;
122 auto x = sh->getCurrentState()->getX();
123 testCurrentValue = get_ele(*(x), 0);
128 testBEFORE_SOLVE =
true;
129 testDt = sh->getWorkingState()->getTimeStep()/10.0;
130 sh->getWorkingState()->setTimeStep(testDt);
135 testAFTER_SOLVE =
true;
136 testName =
"Trapezoidal - Modifier";
137 stepper->setStepperName(testName);
143 auto x = sh->getWorkingState()->getX();
144 testWorkingValue = get_ele(*(x), 0);
149 "Error - unknown action location.\n");
154 bool testBEFORE_SOLVE;
155 bool testAFTER_SOLVE;
157 double testCurrentValue;
158 double testWorkingValue;
160 std::string testName;
170 stepper->setModel(model);
171 auto modifier =
rcp(
new StepperTrapezoidalModifierTest());
172 stepper->setAppAction(modifier);
173 stepper->initialize();
179 stepper->setInitialConditions(solutionHistory);
180 solutionHistory->initWorkingState();
182 solutionHistory->getWorkingState()->setTimeStep(dt);
183 stepper->takeStep(solutionHistory);
192 auto x = solutionHistory->getCurrentState()->getX();
194 x = solutionHistory->getWorkingState()->getX();
196 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
198 TEST_COMPARE(modifier->testName, ==,
"Trapezoidal - Modifier");
203 class StepperTrapezoidalObserverTest
209 StepperTrapezoidalObserverTest()
210 : testBEGIN_STEP(false), testBEFORE_SOLVE(false),
211 testAFTER_SOLVE(false), testEND_STEP(false),
212 testCurrentValue(-0.99), testWorkingValue(-0.99),
213 testDt(-1.5), testName(
"")
217 virtual ~StepperTrapezoidalObserverTest(){}
220 virtual void observe(
228 testBEGIN_STEP =
true;
229 auto x = sh->getCurrentState()->getX();
230 testCurrentValue = get_ele(*(x), 0);
235 testBEFORE_SOLVE =
true;
236 testDt = sh->getWorkingState()->getTimeStep();
241 testAFTER_SOLVE =
true;
242 testName = stepper->getStepperType();
248 auto x = sh->getWorkingState()->getX();
249 testWorkingValue = get_ele(*(x), 0);
254 "Error - unknown action location.\n");
258 bool testBEFORE_SOLVE;
259 bool testAFTER_SOLVE;
261 double testCurrentValue;
262 double testWorkingValue;
264 std::string testName;
274 stepper->setModel(model);
275 auto observer =
rcp(
new StepperTrapezoidalObserverTest());
276 stepper->setAppAction(observer);
277 stepper->initialize();
283 stepper->setInitialConditions(solutionHistory);
284 solutionHistory->initWorkingState();
286 solutionHistory->getWorkingState()->setTimeStep(dt);
287 stepper->takeStep(solutionHistory);
296 auto x = solutionHistory->getCurrentState()->getX();
298 x = solutionHistory->getWorkingState()->getX();
301 TEST_COMPARE(observer->testName, ==,
"Trapezoidal Method");
306 class StepperTrapezoidalModifierXTest
312 StepperTrapezoidalModifierXTest()
313 : testX_BEGIN_STEP(false), testX_BEFORE_SOLVE(false),
314 testX_AFTER_SOLVE(false), testXDOT_END_STEP(false),
315 testX(-0.99), testXDot(-0.99),
316 testDt(-1.5), testTime(-1.5)
320 virtual ~StepperTrapezoidalModifierXTest(){}
324 const double time,
const double dt,
330 testX_BEGIN_STEP =
true;
331 testX = get_ele(*(x), 0);
336 testX_BEFORE_SOLVE =
true;
342 testX_AFTER_SOLVE =
true;
348 testXDOT_END_STEP =
true;
349 testXDot = get_ele(*(x), 0);
354 "Error - unknown action location.\n");
357 bool testX_BEGIN_STEP;
358 bool testX_BEFORE_SOLVE;
359 bool testX_AFTER_SOLVE;
360 bool testXDOT_END_STEP;
374 stepper->setModel(model);
375 auto modifierX =
rcp(
new StepperTrapezoidalModifierXTest());
376 stepper->setAppAction(modifierX);
377 stepper->initialize();
383 stepper->setInitialConditions(solutionHistory);
384 solutionHistory->initWorkingState();
386 solutionHistory->getWorkingState()->setTimeStep(dt);
387 stepper->takeStep(solutionHistory);
396 auto x = solutionHistory->getCurrentState()->getX();
399 auto xDot = solutionHistory->getWorkingState()->getXDot();
400 if (xDot == Teuchos::null) xDot = stepper->getStepperXDot();
403 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
405 auto time = solutionHistory->getWorkingState()->getTime();
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
Trapezoidal method time stepper.
Default modifier for StepperTrapezoidal.
Modify at the end of the step.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Modify before the implicit solve.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > >, const double, const double, const MODIFIER_TYPE modType)=0
Modify solution based on the MODIFIER_TYPE.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
#define TEST_COMPARE(v1, comp, v2)
ACTION_LOCATION
Indicates the location of application action (see algorithm).
#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.
Base ModifierX for StepperTrapezoidal.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
Modify at the beginning of the step.
Base modifier for StepperTrapezoidal.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Base observer for StepperTrapezoidal.
#define TEUCHOS_ASSERT(assertion_test)
Default ModifierX for StepperTrapezoidal.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Modify after the implicit solve.
At the beginning of the step.