12 #include "Tempus_StepperBackwardEuler.hpp"
15 namespace Tempus_Unit_Test {
19 using Teuchos::rcp_const_cast;
20 using Teuchos::rcp_dynamic_cast;
22 using Teuchos::sublist;
33 TEST_ASSERT ( integrator->isInitialized() ==
false);
35 TEST_COMPARE ( integrator->getIntegratorName(), ==,
"Integrator Basic");
36 TEST_COMPARE ( integrator->getIntegratorType(), ==,
"Integrator Basic");
37 TEST_COMPARE ( integrator->getStepper()->getStepperName(), ==,
"Forward Euler");
38 TEST_ASSERT( integrator->getStepper()->getModel() == Teuchos::null);
39 TEST_ASSERT( integrator->getSolutionHistory() != Teuchos::null);
40 TEST_COMPARE ( integrator->getSolutionHistory()->getNumStates(), ==, 0);
41 TEST_ASSERT( integrator->getTimeStepControl() != Teuchos::null);
42 TEST_ASSERT( integrator->getTimeStepControl()->getStepType() ==
"Constant");
43 TEST_ASSERT( integrator->getObserver() != Teuchos::null);
47 integrator->setModel(model);
50 auto inArgsIC = model->getNominalValues();
54 solutionHistory->addState(icState);
56 integrator->setSolutionHistory(solutionHistory);
57 integrator->initialize();
69 stepper->setModel(model);
72 auto inArgsIC = model->getNominalValues();
76 solutionHistory->addState(icState);
84 std::vector<int> outputScreenIndices{ 10, 20, 30 };
85 int outputScreenInterval = 72;
94 outputScreenInterval ));
98 TEST_COMPARE ( integrator->getIntegratorName(), ==,
"Integrator Basic");
99 TEST_COMPARE ( integrator->getIntegratorType(), ==,
"Integrator Basic");
100 TEST_COMPARE ( integrator->getStepper()->getStepperName(), ==,
"Backward Euler");
101 TEST_ASSERT( integrator->getStepper()->getModel() != Teuchos::null);
102 TEST_ASSERT( integrator->getSolutionHistory() != Teuchos::null);
103 TEST_COMPARE ( integrator->getSolutionHistory()->getNumStates(), ==, 1);
104 TEST_ASSERT( integrator->getTimeStepControl() != Teuchos::null);
105 TEST_ASSERT( integrator->getTimeStepControl()->getStepType() ==
"Constant");
106 TEST_ASSERT( integrator->getObserver() != Teuchos::null);
107 TEST_ASSERT( integrator->getScreenOutputIndexList() == outputScreenIndices);
108 TEST_ASSERT( integrator->getScreenOutputIndexInterval() == outputScreenInterval);
118 RCP<ParameterList> pl = Teuchos::getParametersFromXmlFile(
"Tempus_IntegratorBasic_default.xml");
126 Tempus::createIntegratorBasic<double>(tempusPL, model);
128 std::ostringstream ss;
130 Teuchos::fancyOStream(Teuchos::rcpFromRef(ss));
134 auto testS = ss.str();
137 auto npos = std::string::npos;
138 TEST_ASSERT(npos != testS.find(
"--- Tempus::IntegratorBasic ---"));
139 TEST_ASSERT(npos != testS.find(
"--- Tempus::SolutionHistory"));
140 TEST_ASSERT(npos != testS.find(
"--- SolutionState (index = 0; time = 0; dt = 1e+99) ---"));
141 TEST_ASSERT(npos != testS.find(
"--- Tempus::SolutionStateMetaData ---"));
142 TEST_ASSERT(npos != testS.find(
"--- Tempus::StepperState"));
143 TEST_ASSERT(npos != testS.find(
"--- Tempus::PhysicsState"));
144 TEST_ASSERT(npos != testS.find(
"--- Tempus::TimeStepControl ---"));
145 TEST_ASSERT(npos != testS.find(
"--- Tempus::TimeStepControlStrategyConstant ---"));
146 TEST_ASSERT(npos != testS.find(
"--- Stepper ---"));
147 TEST_ASSERT(npos != testS.find(
"stepperType_ = Forward Euler"));
148 TEST_ASSERT(npos != testS.find(
"--- StepperExplicit ---"));
164 auto integrator = Tempus::createIntegratorBasic<double>(model, std::string(
"Backward Euler"));
167 integrator->getNonConstSolutionHistory()->initWorkingState();
170 auto tsc = integrator->getNonConstTimeStepControl();
171 auto ws = integrator->getSolutionHistory()->getWorkingState();
176 ws->setNFailures(11);
177 integrator->checkTimeStep();
184 ws->setNConsecutiveFailures(6);
185 integrator->checkTimeStep();
188 ws->setNConsecutiveFailures(0);
192 ws->setTimeStep(1.0);
194 tsc->setMinTimeStep(1.0);
195 integrator->checkTimeStep();
199 tsc->setMinTimeStep(0.1);
204 integrator->checkTimeStep();
211 ws->setNRunningFailures(0);
212 ws->setNConsecutiveFailures(0);
217 tsc->setTimeStepControlStrategy(tscs);
218 ws->setTimeStep(0.1);
219 tsc->setInitTimeStep(1.0);
220 integrator->checkTimeStep();
237 Tempus::createIntegratorBasic<double>();
243 integrator->getValidParameters());
245 tempusPL->
sublist(
"Default Integrator").
set(
"Stepper Name",
"Demo Stepper");
247 stepperPL->
set(
"Stepper Type",
"Forward Euler");
248 tempusPL->
set(
"Demo Stepper", *stepperPL);
252 integrator = Tempus::createIntegratorBasic<double>(tempusPL, model);
255 auto testPL = integrator->getValidParameters();
261 Teuchos::getParametersFromXmlFile(
"Tempus_IntegratorBasic_ref.xml");
263 bool pass = haveSameValuesSorted(*testPL, *referencePL,
true);
266 out <<
"testPL -------------- \n" << *testPL << std::endl;
267 out <<
"referencePL -------------- \n" << *referencePL << std::endl;
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.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEST_COMPARE(v1, comp, v2)
IntegratorObserverBasic class for time integrators. This basic class has simple no-op functions...
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
Backward Euler time stepper.
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepControlStrategy class for TimeStepControl.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")