9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
14 #include "Thyra_VectorStdOps.hpp"
17 #include "Tempus_SolutionHistory.hpp"
26 #include "../TestModels/SinCosModel.hpp"
27 #include "../TestModels/VanDerPolModel.hpp"
28 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
33 namespace Tempus_Unit_Test {
37 using Teuchos::rcp_const_cast;
38 using Teuchos::rcp_dynamic_cast;
39 using Teuchos::ParameterList;
40 using Teuchos::sublist;
41 using Teuchos::getParametersFromXmlFile;
54 stepper->setModel(model);
55 stepper->initialize();
56 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
63 auto solver = rcp(
new Thyra::NOXNonlinearSolver());
67 predictorStepper->setModel(model);
68 predictorStepper->initialize();
71 bool useFSAL = defaultStepper->getUseFSALDefault();
72 std::string ICConsistency = defaultStepper->getICConsistencyDefault();
73 bool ICConsistencyCheck = defaultStepper->getICConsistencyCheckDefault();
74 bool zeroInitialGuess = defaultStepper->getZeroInitialGuess();
77 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
79 stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
81 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
82 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
83 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
84 stepper->setSolver(solver); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
85 stepper->setPredictor(predictorStepper); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
86 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
87 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
89 stepper->setZeroInitialGuess(zeroInitialGuess); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
95 model, obs, solver, predictorStepper, useFSAL,
96 ICConsistency, ICConsistencyCheck, zeroInitialGuess));
97 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
102 model, solver, predictorStepper, useFSAL,
103 ICConsistency, ICConsistencyCheck, zeroInitialGuess, modifier));
104 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
107 TEUCHOS_ASSERT(stepper->getOrder() == 1);
148 auto x = sh->getCurrentState()->getX();
155 testDt = sh->getWorkingState()->getTimeStep()/10.0;
156 sh->getWorkingState()->setTimeStep(
testDt);
162 testType =
"Backward Euler - Modifier";
169 auto x = sh->getWorkingState()->getX();
174 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
175 "Error - unknown action location.\n");
191 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
196 stepper->setModel(model);
198 stepper->setAppAction(modifier);
199 stepper->initialize();
205 stepper->setInitialConditions(solutionHistory);
206 solutionHistory->initWorkingState();
208 solutionHistory->getWorkingState()->setTimeStep(dt);
209 stepper->takeStep(solutionHistory);
212 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
213 TEST_COMPARE(modifier->testBEFORE_SOLVE, ==,
true);
214 TEST_COMPARE(modifier->testAFTER_SOLVE, ==,
true);
215 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
218 auto x = solutionHistory->getCurrentState()->getX();
219 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
220 x = solutionHistory->getWorkingState()->getX();
221 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
222 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
223 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
225 TEST_COMPARE(modifier->testType, ==,
"Backward Euler - Modifier");
258 auto x = sh->getCurrentState()->getX();
265 testDt = sh->getWorkingState()->getTimeStep();
271 testType = stepper->getStepperType();
277 auto x = sh->getWorkingState()->getX();
282 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
283 "Error - unknown action location.\n");
299 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
304 stepper->setModel(model);
306 stepper->setAppAction(observer);
307 stepper->initialize();
313 stepper->setInitialConditions(solutionHistory);
314 solutionHistory->initWorkingState();
316 solutionHistory->getWorkingState()->setTimeStep(dt);
317 stepper->takeStep(solutionHistory);
320 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
321 TEST_COMPARE(observer->testBEFORE_SOLVE, ==,
true);
322 TEST_COMPARE(observer->testAFTER_SOLVE, ==,
true);
323 TEST_COMPARE(observer->testEND_STEP, ==,
true);
326 auto x = solutionHistory->getCurrentState()->getX();
327 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
328 x = solutionHistory->getWorkingState()->getX();
329 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
330 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-15);
332 TEST_COMPARE(observer->testType, ==,
"Backward Euler");
356 Teuchos::RCP<Thyra::VectorBase<double> > x,
357 const double time,
const double dt,
364 testX = get_ele(*(x), 0);
386 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
387 "Error - unknown action location.\n");
403 Teuchos::RCP<const Thyra::ModelEvaluator<double> >
408 stepper->setModel(model);
410 stepper->setAppAction(modifierX);
411 stepper->initialize();
417 stepper->setInitialConditions(solutionHistory);
418 solutionHistory->initWorkingState();
420 solutionHistory->getWorkingState()->setTimeStep(dt);
421 stepper->takeStep(solutionHistory);
424 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
425 TEST_COMPARE(modifierX->testX_BEFORE_SOLVE, ==,
true);
426 TEST_COMPARE(modifierX->testX_AFTER_SOLVE, ==,
true);
427 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
430 auto x = solutionHistory->getCurrentState()->getX();
431 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
433 auto xDot = stepper->getStepperXDot(solutionHistory->getWorkingState());
434 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-15);
435 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
436 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
438 auto time = solutionHistory->getWorkingState()->getTime();
439 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
StepperBackwardEulerObserver class for StepperBackwardEuler.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
StepperBackwardEulerObserverTest()
Constructor.
StepperBackwardEulerModifierTest()
Constructor.
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.
After the implicit solve.
At the beginning of the step.
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.
Base ModifierX for StepperBackwardEuler.
Teuchos::RCP< SolutionHistory< Scalar > > createSolutionHistoryME(const Teuchos::RCP< const Thyra::ModelEvaluator< Scalar > > &model)
Nonmember contructor from a Thyra ModelEvaluator.
virtual ~StepperBackwardEulerObserverTest()
Destructor.
virtual ~StepperBackwardEulerModifierXTest()
Destructor.
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperBackwardEuler< double > > stepper, const typename Tempus::StepperBackwardEulerAppAction< double >::ACTION_LOCATION actLoc)
Observe BackwardEuler Stepper at action location.
Modify at the beginning of the step.
Base observer for StepperBackwardEuler.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const typename Tempus::StepperBackwardEulerModifierXBase< double >::MODIFIER_TYPE modType)
Modify BackwardEuler Stepper at action location.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
StepperBackwardEulerModifierXTest()
Constructor.
Backward Euler time stepper.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
virtual ~StepperBackwardEulerModifierTest()
Destructor.
Modify at the end of the step.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperBackwardEuler< double > > stepper, const typename Tempus::StepperBackwardEulerAppAction< double >::ACTION_LOCATION actLoc)
Modify BackwardEuler Stepper at action location.
Before the implicit solve.
Base modifier for StepperBackwardEuler.
Default ModifierX for StepperBackwardEuler.