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"
27 #include "../TestModels/SinCosModel.hpp"
28 #include "../TestModels/VanDerPolModel.hpp"
29 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
34 namespace Tempus_Unit_Test {
38 using Teuchos::rcp_const_cast;
39 using Teuchos::rcp_dynamic_cast;
40 using Teuchos::ParameterList;
41 using Teuchos::sublist;
42 using Teuchos::getParametersFromXmlFile;
61 stepper->setModel(model);
62 stepper->initialize();
63 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
65 bool useFSAL = stepper->getUseFSALDefault();
66 std::string ICConsistency = stepper->getICConsistencyDefault();
67 bool ICConsistencyCheck = stepper->getICConsistencyCheckDefault();
70 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
72 stepper->setObserver(obs); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
74 stepper->setAppAction(modifier); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
75 stepper->setAppAction(modifierX); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
76 stepper->setAppAction(observer); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
77 stepper->setUseFSAL(useFSAL); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
78 stepper->setICConsistency(ICConsistency); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
79 stepper->setICConsistencyCheck(ICConsistencyCheck); stepper->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
81 #ifndef TEMPUS_HIDE_DEPRECATED_CODE
84 model, obs, useFSAL, ICConsistency, ICConsistencyCheck));
85 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
88 model, useFSAL, ICConsistency, ICConsistencyCheck,modifier));
89 TEUCHOS_TEST_FOR_EXCEPT(!stepper->isInitialized());
92 TEUCHOS_ASSERT(stepper->getOrder() == 1);
132 auto x = sh->getCurrentState()->getX();
139 testDt = sh->getWorkingState()->getTimeStep()/10.0;
140 sh->getWorkingState()->setTimeStep(
testDt);
141 testType =
"Forward Euler - Modifier";
148 auto x = sh->getWorkingState()->getX();
153 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
154 "Error - unknown action location.\n");
172 stepper->setModel(model);
174 stepper->setAppAction(modifier);
175 stepper->initialize();
178 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
179 stepper->getModel()->getNominalValues();
181 rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
183 icState->setTime (0.0);
184 icState->setIndex (0);
185 icState->setTimeStep(0.0);
186 icState->setOrder (stepper->getOrder());
191 solutionHistory->setName(
"Forward States");
193 solutionHistory->setStorageLimit(2);
194 solutionHistory->addState(icState);
197 stepper->setInitialConditions(solutionHistory);
198 solutionHistory->initWorkingState();
200 solutionHistory->getWorkingState()->setTimeStep(dt);
201 stepper->takeStep(solutionHistory);
203 TEST_COMPARE(modifier->testBEGIN_STEP, ==,
true);
204 TEST_COMPARE(modifier->testBEFORE_EXPLICIT_EVAL, ==,
true);
205 TEST_COMPARE(modifier->testEND_STEP, ==,
true);
207 auto x = solutionHistory->getCurrentState()->getX();
208 TEST_FLOATING_EQUALITY(modifier->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
209 x = solutionHistory->getWorkingState()->getX();
210 TEST_FLOATING_EQUALITY(modifier->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
211 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
212 TEST_FLOATING_EQUALITY(modifier->testDt, Dt, 1.0e-15);
214 TEST_COMPARE(modifier->testType, ==,
"Forward Euler - Modifier");
244 auto x = sh->getCurrentState()->getX();
251 testDt = sh->getWorkingState()->getTimeStep();
252 testType = stepper->getStepperType();
258 auto x = sh->getWorkingState()->getX();
263 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
264 "Error - unknown action location.\n");
283 stepper->setModel(model);
285 stepper->setAppAction(observer);
286 stepper->initialize();
289 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
290 stepper->getModel()->getNominalValues();
292 rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
294 icState->setTime (0.0);
295 icState->setIndex (0);
296 icState->setTimeStep(0.0);
297 icState->setOrder (stepper->getOrder());
302 solutionHistory->setName(
"Forward States");
304 solutionHistory->setStorageLimit(2);
305 solutionHistory->addState(icState);
308 stepper->setInitialConditions(solutionHistory);
309 solutionHistory->initWorkingState();
311 solutionHistory->getWorkingState()->setTimeStep(dt);
312 stepper->takeStep(solutionHistory);
314 TEST_COMPARE(observer->testBEGIN_STEP, ==,
true);
315 TEST_COMPARE(observer->testBEFORE_EXPLICIT_EVAL, ==,
true);
316 TEST_COMPARE(observer->testEND_STEP, ==,
true);
318 auto x = solutionHistory->getCurrentState()->getX();
319 TEST_FLOATING_EQUALITY(observer->testCurrentValue, get_ele(*(x), 0), 1.0e-15);
320 x = solutionHistory->getWorkingState()->getX();
321 TEST_FLOATING_EQUALITY(observer->testWorkingValue, get_ele(*(x), 0), 1.0e-15);
322 TEST_FLOATING_EQUALITY(observer->testDt, dt, 1.0e-15);
324 TEST_COMPARE(observer->testType, ==,
"Forward Euler");
346 Teuchos::RCP<Thyra::VectorBase<double> > x,
347 const double time,
const double dt,
354 testX = get_ele(*(x), 0);
371 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::logic_error,
372 "Error - unknown action location.\n");
390 stepper->setModel(model);
392 stepper->setAppAction(modifierX);
393 stepper->initialize();
396 Thyra::ModelEvaluatorBase::InArgs<double> inArgsIC =
397 stepper->getModel()->getNominalValues();
399 rcp_const_cast<Thyra::VectorBase<double> > (inArgsIC.get_x());
401 icState->setTime (0.0);
402 icState->setIndex (0);
403 icState->setTimeStep(0.0);
404 icState->setOrder (stepper->getOrder());
409 solutionHistory->setName(
"Forward States");
411 solutionHistory->setStorageLimit(2);
412 solutionHistory->addState(icState);
415 stepper->setInitialConditions(solutionHistory);
416 solutionHistory->initWorkingState();
418 solutionHistory->getWorkingState()->setTimeStep(dt);
419 stepper->takeStep(solutionHistory);
421 TEST_COMPARE(modifierX->testX_BEGIN_STEP, ==,
true);
422 TEST_COMPARE(modifierX->testX_BEFORE_EXPLICIT_EVAL, ==,
true);
423 TEST_COMPARE(modifierX->testXDOT_END_STEP, ==,
true);
425 auto x = solutionHistory->getCurrentState()->getX();
426 TEST_FLOATING_EQUALITY(modifierX->testX, get_ele(*(x), 0), 1.0e-15);
428 auto xDot = stepper->getStepperXDot(solutionHistory->getWorkingState());
429 TEST_FLOATING_EQUALITY(modifierX->testXDot, get_ele(*(xDot), 0),1.0e-15);
430 auto Dt = solutionHistory->getWorkingState()->getTimeStep();
431 TEST_FLOATING_EQUALITY(modifierX->testDt, Dt, 1.0e-15);
433 auto time = solutionHistory->getWorkingState()->getTime();
434 TEST_FLOATING_EQUALITY(modifierX->testTime, time, 1.0e-15);
Default modifier for StepperForwardEuler.
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.
Base modifier for StepperBackwardEuler.
StepperForwardEulerModifierTest()
Constructor.
MODIFIER_TYPE
Indicates the location of application action (see algorithm).
At the beginning of the step.
virtual ~StepperForwardEulerModifierXTest()
Destructor.
virtual ~StepperForwardEulerObserverTest()
Destructor.
Explicit Runge-Kutta time stepper.
void testFactoryConstruction(std::string stepperType, const Teuchos::RCP< const Thyra::ModelEvaluator< double > > &model)
Unit test utility for Stepper construction through StepperFactory.
Forward Euler time stepper.
Modify before the implicit solve.
bool testBEFORE_EXPLICIT_EVAL
bool testX_BEFORE_EXPLICIT_EVAL
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
ACTION_LOCATION
Indicates the location of application action (see algorithm).
Default ModifierX for StepperForwardEuler.
StepperForwardEulerObserver class for StepperForwardEuler.
virtual void observe(Teuchos::RCP< const Tempus::SolutionHistory< double > > sh, Teuchos::RCP< const Tempus::StepperForwardEuler< double > > stepper, const typename Tempus::StepperForwardEulerAppAction< double >::ACTION_LOCATION actLoc)
Observe ForwardEuler Stepper at end of takeStep.
StepperForwardEulerObserverTest()
Constructor.
Base ModifierX for StepperForwardEuler.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Modify at the end of the step.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Default observer for StepperForwardEuler.
Keep a fix number of states.
bool testBEFORE_EXPLICIT_EVAL
Base observer for StepperForwardEuler.
virtual ~StepperForwardEulerModifierTest()
Destructor.
virtual void modify(Teuchos::RCP< Thyra::VectorBase< double > > x, const double time, const double dt, const typename Tempus::StepperForwardEulerModifierXBase< double >::MODIFIER_TYPE modType)
Observe BackwardEuler Stepper at end of takeStep.
virtual void modify(Teuchos::RCP< Tempus::SolutionHistory< double > > sh, Teuchos::RCP< Tempus::StepperForwardEuler< double > > stepper, const typename Tempus::StepperForwardEulerAppAction< double >::ACTION_LOCATION actLoc)
Observe ForwardEuler Stepper at end of takeStep.
StepperForwardEulerModifierXTest()
Constructor.
Modify at the beginning of the step.
Before the explicit evaluation.