13 #include "Tempus_StepperBackwardEuler.hpp"
16 namespace Tempus_Unit_Test {
21 using Teuchos::rcp_const_cast;
22 using Teuchos::rcp_dynamic_cast;
23 using Teuchos::sublist;
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();
55 solutionHistory->addState(icState);
57 integrator->setSolutionHistory(solutionHistory);
58 integrator->initialize();
69 stepper->setModel(model);
72 auto inArgsIC = model->getNominalValues();
77 solutionHistory->addState(icState);
85 std::vector<int> outputScreenIndices{10, 20, 30};
86 int outputScreenInterval = 72;
90 stepper, solutionHistory, timeStepControl, integratorObserver,
91 outputScreenIndices, outputScreenInterval));
95 TEST_COMPARE(integrator->getIntegratorName(), ==,
"Integrator Basic");
96 TEST_COMPARE(integrator->getIntegratorType(), ==,
"Integrator Basic");
97 TEST_COMPARE(integrator->getStepper()->getStepperName(), ==,
99 TEST_ASSERT(integrator->getStepper()->getModel() != Teuchos::null);
100 TEST_ASSERT(integrator->getSolutionHistory() != Teuchos::null);
101 TEST_COMPARE(integrator->getSolutionHistory()->getNumStates(), ==, 1);
102 TEST_ASSERT(integrator->getTimeStepControl() != Teuchos::null);
103 TEST_ASSERT(integrator->getTimeStepControl()->getStepType() ==
"Constant");
104 TEST_ASSERT(integrator->getObserver() != Teuchos::null);
105 TEST_ASSERT(integrator->getScreenOutputIndexList() == outputScreenIndices);
106 TEST_ASSERT(integrator->getScreenOutputIndexInterval() ==
107 outputScreenInterval);
116 Teuchos::getParametersFromXmlFile(
"Tempus_IntegratorBasic_default.xml");
124 Tempus::createIntegratorBasic<double>(tempusPL, model);
126 std::ostringstream ss;
128 Teuchos::fancyOStream(Teuchos::rcpFromRef(ss));
132 auto testS = ss.str();
135 auto npos = std::string::npos;
136 TEST_ASSERT(npos != testS.find(
"--- Tempus::IntegratorBasic ---"));
137 TEST_ASSERT(npos != testS.find(
"--- Tempus::SolutionHistory"));
138 TEST_ASSERT(npos != testS.find(
"--- SolutionState (index = 0; time = "
139 " 0; dt = 1e+99) ---"));
140 TEST_ASSERT(npos != testS.find(
"--- Tempus::SolutionStateMetaData ---"));
141 TEST_ASSERT(npos != testS.find(
"--- Tempus::StepperState"));
142 TEST_ASSERT(npos != testS.find(
"--- Tempus::PhysicsState"));
143 TEST_ASSERT(npos != testS.find(
"--- Tempus::TimeStepControl ---"));
145 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 ---"));
163 auto integrator = Tempus::createIntegratorBasic<double>(
164 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();
235 Tempus::createIntegratorBasic<double>();
241 Teuchos::rcp_const_cast<
ParameterList>(integrator->getValidParameters());
243 tempusPL->
sublist(
"Default Integrator").
set(
"Stepper Name",
"Demo Stepper");
245 stepperPL->
set(
"Stepper Type",
"Forward Euler");
246 tempusPL->
set(
"Demo Stepper", *stepperPL);
250 integrator = Tempus::createIntegratorBasic<double>(tempusPL, model);
253 auto testPL = integrator->getValidParameters();
259 Teuchos::getParametersFromXmlFile(
"Tempus_IntegratorBasic_ref.xml");
261 bool pass = haveSameValuesSorted(*testPL, *referencePL,
true);
264 out <<
"testPL -------------- \n"
265 << *testPL << std::endl;
266 out <<
"referencePL -------------- \n"
267 << *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.
#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...
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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="")