12 #include "Tempus_StepperBackwardEuler.hpp"
15 namespace Tempus_Unit_Test {
20 using Teuchos::rcp_const_cast;
21 using Teuchos::rcp_dynamic_cast;
22 using Teuchos::sublist;
34 TEST_COMPARE(integrator->getIntegratorName(), ==,
"Integrator Basic");
35 TEST_COMPARE(integrator->getIntegratorType(), ==,
"Integrator Basic");
36 TEST_COMPARE(integrator->getStepper()->getStepperName(), ==,
"Forward Euler");
37 TEST_ASSERT(integrator->getStepper()->getModel() == Teuchos::null);
38 TEST_ASSERT(integrator->getSolutionHistory() != Teuchos::null);
39 TEST_COMPARE(integrator->getSolutionHistory()->getNumStates(), ==, 0);
40 TEST_ASSERT(integrator->getTimeStepControl() != Teuchos::null);
41 TEST_ASSERT(integrator->getTimeStepControl()->getStepType() ==
"Constant");
42 TEST_ASSERT(integrator->getObserver() != Teuchos::null);
46 integrator->setModel(model);
49 auto inArgsIC = model->getNominalValues();
54 solutionHistory->addState(icState);
56 integrator->setSolutionHistory(solutionHistory);
57 integrator->initialize();
68 stepper->setModel(model);
71 auto inArgsIC = model->getNominalValues();
76 solutionHistory->addState(icState);
84 std::vector<int> outputScreenIndices{10, 20, 30};
85 int outputScreenInterval = 72;
89 stepper, solutionHistory, timeStepControl, integratorObserver,
90 outputScreenIndices, outputScreenInterval));
94 TEST_COMPARE(integrator->getIntegratorName(), ==,
"Integrator Basic");
95 TEST_COMPARE(integrator->getIntegratorType(), ==,
"Integrator Basic");
96 TEST_COMPARE(integrator->getStepper()->getStepperName(), ==,
98 TEST_ASSERT(integrator->getStepper()->getModel() != Teuchos::null);
99 TEST_ASSERT(integrator->getSolutionHistory() != Teuchos::null);
100 TEST_COMPARE(integrator->getSolutionHistory()->getNumStates(), ==, 1);
101 TEST_ASSERT(integrator->getTimeStepControl() != Teuchos::null);
102 TEST_ASSERT(integrator->getTimeStepControl()->getStepType() ==
"Constant");
103 TEST_ASSERT(integrator->getObserver() != Teuchos::null);
104 TEST_ASSERT(integrator->getScreenOutputIndexList() == outputScreenIndices);
105 TEST_ASSERT(integrator->getScreenOutputIndexInterval() ==
106 outputScreenInterval);
115 Teuchos::getParametersFromXmlFile(
"Tempus_IntegratorBasic_default.xml");
123 Tempus::createIntegratorBasic<double>(tempusPL, model);
125 std::ostringstream ss;
127 Teuchos::fancyOStream(Teuchos::rcpFromRef(ss));
131 auto testS = ss.str();
134 auto npos = std::string::npos;
135 TEST_ASSERT(npos != testS.find(
"--- Tempus::IntegratorBasic ---"));
136 TEST_ASSERT(npos != testS.find(
"--- Tempus::SolutionHistory"));
137 TEST_ASSERT(npos != testS.find(
"--- SolutionState (index = 0; time = "
138 " 0; dt = 1e+99) ---"));
139 TEST_ASSERT(npos != testS.find(
"--- Tempus::SolutionStateMetaData ---"));
140 TEST_ASSERT(npos != testS.find(
"--- Tempus::StepperState"));
141 TEST_ASSERT(npos != testS.find(
"--- Tempus::PhysicsState"));
142 TEST_ASSERT(npos != testS.find(
"--- Tempus::TimeStepControl ---"));
144 testS.find(
"--- Tempus::TimeStepControlStrategyConstant ---"));
145 TEST_ASSERT(npos != testS.find(
"--- Stepper ---"));
146 TEST_ASSERT(npos != testS.find(
"stepperType_ = Forward Euler"));
147 TEST_ASSERT(npos != testS.find(
"--- StepperExplicit ---"));
162 auto integrator = Tempus::createIntegratorBasic<double>(
163 model, std::string(
"Backward Euler"));
166 integrator->getNonConstSolutionHistory()->initWorkingState();
169 auto tsc = integrator->getNonConstTimeStepControl();
170 auto ws = integrator->getSolutionHistory()->getWorkingState();
175 ws->setNFailures(11);
176 integrator->checkTimeStep();
183 ws->setNConsecutiveFailures(6);
184 integrator->checkTimeStep();
187 ws->setNConsecutiveFailures(0);
191 ws->setTimeStep(1.0);
193 tsc->setMinTimeStep(1.0);
194 integrator->checkTimeStep();
198 tsc->setMinTimeStep(0.1);
203 integrator->checkTimeStep();
210 ws->setNRunningFailures(0);
211 ws->setNConsecutiveFailures(0);
216 tsc->setTimeStepControlStrategy(tscs);
217 ws->setTimeStep(0.1);
218 tsc->setInitTimeStep(1.0);
219 integrator->checkTimeStep();
234 Tempus::createIntegratorBasic<double>();
240 Teuchos::rcp_const_cast<
ParameterList>(integrator->getValidParameters());
242 tempusPL->
sublist(
"Default Integrator").
set(
"Stepper Name",
"Demo Stepper");
244 stepperPL->
set(
"Stepper Type",
"Forward Euler");
245 tempusPL->
set(
"Demo Stepper", *stepperPL);
249 integrator = Tempus::createIntegratorBasic<double>(tempusPL, model);
252 auto testPL = integrator->getValidParameters();
258 Teuchos::getParametersFromXmlFile(
"Tempus_IntegratorBasic_ref.xml");
260 bool pass = haveSameValuesSorted(*testPL, *referencePL,
true);
263 out <<
"testPL -------------- \n"
264 << *testPL << std::endl;
265 out <<
"referencePL -------------- \n"
266 << *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="")