12 #include "Tempus_TimeStepControl.hpp"
15 #include "../TestModels/DahlquistTestModel.hpp"
17 namespace Tempus_Unit_Test {
22 using Teuchos::rcp_const_cast;
23 using Teuchos::rcp_dynamic_cast;
24 using Teuchos::sublist;
39 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKP() != 0.21);
40 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKD() != 0.10);
41 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactor() != 0.90);
42 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactorAfterReject() != 0.90);
43 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMax() != 5.0);
44 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMin() != 0.5);
47 tscs->setController(
"I");
49 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
52 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
55 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
58 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
59 tscs->setSafetyFactor(0.8);
61 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
62 tscs->setSafetyFactorAfterReject(0.8);
64 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
67 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
70 TEUCHOS_TEST_FOR_EXCEPT(!tscs->isInitialized());
72 TEUCHOS_TEST_FOR_EXCEPT(tscs->getStepType() !=
"Variable");
73 TEUCHOS_TEST_FOR_EXCEPT(tscs->getController() !=
"I");
74 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKI() != 0.6);
75 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKP() != 0.0);
76 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKD() != 0.0);
77 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactor() != 0.8);
78 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactorAfterReject() != 0.8);
79 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMax() != 4.0);
80 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMin() != 0.4);
88 "I", 0.6, 0.0, 0.0, 0.8, 0.8, 4.0, 0.4));
94 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKP() != 0.0);
95 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKD() != 0.0);
96 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactor() != 0.8);
97 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactorAfterReject() != 0.8);
98 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMax() != 4.0);
99 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMin() != 0.4);
107 auto pl = Tempus::getTimeStepControlStrategyIntegralControllerPL<double>();
109 pl->set<std::string>(
"Controller Type",
"I");
110 pl->set<
double>(
"KI", 0.6);
111 pl->set<
double>(
"KP", 0.0);
112 pl->set<
double>(
"KD", 0.0);
113 pl->set<
double>(
"Safety Factor", 0.8);
114 pl->set<
double>(
"Safety Factor After Step Rejection", 0.8);
115 pl->set<
double>(
"Maximum Safety Factor", 4.0);
116 pl->set<
double>(
"Minimum Safety Factor", 0.4);
119 Tempus::createTimeStepControlStrategyIntegralController<double>(pl);
124 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKP() != 0.0);
125 TEUCHOS_TEST_FOR_EXCEPT(tscs->getKD() != 0.0);
126 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactor() != 0.8);
127 TEUCHOS_TEST_FOR_EXCEPT(tscs->getSafetyFactorAfterReject() != 0.8);
128 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMax() != 4.0);
129 TEUCHOS_TEST_FOR_EXCEPT(tscs->getFacMin() != 0.4);
139 double safetyFactor = 0.9;
140 double safetyFactorAfterReject = 0.9;
145 "PID", KI, KP, KD, safetyFactor, safetyFactorAfterReject, facMax,
150 tsc->setTimeStepControlStrategy(tscs);
151 tsc->setInitTime(0.0);
152 tsc->setFinalTime(10.0);
153 tsc->setMinTimeStep(0.01);
154 tsc->setInitTimeStep(1.0);
155 tsc->setMaxTimeStep(10.0);
156 tsc->setFinalIndex(100);
163 auto inArgsIC = model->getNominalValues();
166 auto icState = Tempus::createSolutionStateX<double>(icSolution);
170 solutionHistory->addState(icState);
171 solutionHistory->getCurrentState()->setTimeStep(1.0);
172 solutionHistory->getCurrentState()->setTime(0.0);
173 solutionHistory->getCurrentState()->setIndex(0);
174 solutionHistory->getCurrentState()->setOrder(order);
179 solutionHistory->initWorkingState();
180 auto currentState = solutionHistory->getCurrentState();
181 auto workingState = solutionHistory->getWorkingState();
187 tsc->setNextTimeStep(solutionHistory, status);
195 workingState->setErrorRel(errN);
199 solutionHistory->initWorkingState();
200 currentState = solutionHistory->getCurrentState();
201 workingState = solutionHistory->getWorkingState();
202 double dt = workingState->getTimeStep();
208 tsc->setNextTimeStep(solutionHistory, status);
210 double p = order - 1.0;
211 double dtNew = dt * safetyFactor * std::pow(errN, -KI / p);
217 workingState->setErrorRel(errN);
221 solutionHistory->initWorkingState();
222 currentState = solutionHistory->getCurrentState();
223 workingState = solutionHistory->getWorkingState();
224 dt = workingState->getTimeStep();
230 tsc->setNextTimeStep(solutionHistory, status);
233 dt * safetyFactor * std::pow(errN, -KI / p) * std::pow(errNm1, KP / p);
240 workingState->setErrorRel(errN);
244 solutionHistory->initWorkingState();
245 currentState = solutionHistory->getCurrentState();
246 workingState = solutionHistory->getWorkingState();
247 dt = workingState->getTimeStep();
253 tsc->setNextTimeStep(solutionHistory, status);
255 dtNew = dt * safetyFactor * std::pow(errN, -KI / p) *
256 std::pow(errNm1, KP / p) * std::pow(errNm2, -KD / p);
267 auto pl = tscs->getValidParameters();
270 "Integral Controller");
271 TEST_COMPARE(pl->get<std::string>(
"Controller Type"), ==,
"PID");
284 std::ostringstream unusedParameters;
285 pl->unused(unusedParameters);
The classic Dahlquist Test Problem.
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Status
Status for the Integrator, the Stepper and the SolutionState.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeStepControl manages the time step size. There several mechanisms that effect the time step size a...
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
StepControlStrategy class for TimeStepControl.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)