10#include "Teuchos_XMLParameterListHelpers.hpp"
12#include "Tempus_StepperBackwardEuler.hpp"
19using Teuchos::rcp_const_cast;
20using Teuchos::rcp_dynamic_cast;
21using Teuchos::ParameterList;
22using 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();
51 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
54 solutionHistory->addState(icState);
56 integrator->setSolutionHistory(solutionHistory);
57 integrator->initialize();
59 TEST_ASSERT ( integrator->isInitialized() ==
true);
69 stepper->setModel(model);
72 auto inArgsIC = model->getNominalValues();
73 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
76 solutionHistory->addState(icState);
84 std::vector<int> outputScreenIndices{ 10, 20, 30 };
85 int outputScreenInterval = 72;
88 auto integrator = Teuchos::rcp(
94 outputScreenInterval ));
96 TEST_ASSERT ( integrator->isInitialized() ==
true);
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");
124 RCP<ParameterList> tempusPL = sublist(pl,
"Tempus",
true);
125 RCP<Tempus::IntegratorBasic<double> > integrator =
126 Tempus::createIntegratorBasic<double>(tempusPL, model);
128 std::ostringstream ss;
129 Teuchos::RCP<Teuchos::FancyOStream> myOut =
130 Teuchos::fancyOStream(Teuchos::rcpFromRef(ss));
132 integrator->describe(*myOut, Teuchos::VERB_EXTREME);
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();
205 TEST_ASSERT(ws->getNFailures() == 1);
206 TEST_ASSERT(ws->getNRunningFailures() == 1);
207 TEST_ASSERT(ws->getNConsecutiveFailures() == 1);
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();
221 TEST_ASSERT(ws->getNFailures() == 1);
222 TEST_ASSERT(ws->getNRunningFailures() == 1);
223 TEST_ASSERT(ws->getNConsecutiveFailures() == 1);
236 RCP<Tempus::IntegratorBasic<double> > integrator =
237 Tempus::createIntegratorBasic<double>();
242 RCP<ParameterList> tempusPL = Teuchos::rcp_const_cast<ParameterList>(
243 integrator->getValidParameters());
245 tempusPL->sublist(
"Default Integrator").set(
"Stepper Name",
"Demo Stepper");
246 RCP<ParameterList> stepperPL = Teuchos::parameterList();
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();
260 RCP<ParameterList> referencePL =
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;
IntegratorObserverBasic class for time integrators. This basic class has simple no-op functions,...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
Backward Euler time stepper.
StepControlStrategy class for TimeStepControl.
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
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.