9 #include "Teuchos_UnitTestHarness.hpp" 10 #include "Teuchos_XMLParameterListHelpers.hpp" 11 #include "Teuchos_TimeMonitor.hpp" 12 #include "Teuchos_DefaultComm.hpp" 14 #include "Thyra_VectorStdOps.hpp" 16 #include "Tempus_TimeStepControl.hpp" 22 #include "../TestModels/SinCosModel.hpp" 23 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp" 32 using Teuchos::rcp_const_cast;
33 using Teuchos::rcp_dynamic_cast;
34 using Teuchos::ParameterList;
35 using Teuchos::sublist;
36 using Teuchos::getParametersFromXmlFile;
44 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
47 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
48 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 0.0 , 1.0e-14);
49 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 1.0e+99, 1.0e-14);
50 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.0 , 1.0e-14);
51 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 1.0 , 1.0e-14);
52 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 1.0e+99, 1.0e-14);
53 TEST_COMPARE ( tsc->getInitIndex() , ==, 0 );
54 TEST_COMPARE ( tsc->getFinalIndex() , ==, 1000000 );
55 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-08, 1.0e-14);
56 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-08, 1.0e-14);
57 TEST_COMPARE ( tsc->getMaxFailures() , ==, 10 );
58 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 5 );
59 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
60 TEST_COMPARE ( tsc->getPrintDtChanges() , ==, true );
61 TEST_COMPARE ( tsc->getOutputExactly() , ==, true );
62 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 1000000 );
63 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 1.0e+99, 1.0e-14);
66 tsc->setInitTime(1.0); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
67 tsc->setFinalTime(100.0); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
68 tsc->setMinTimeStep(0.01); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
69 tsc->setInitTimeStep(0.02); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
70 tsc->setMaxTimeStep(0.05); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
71 tsc->setInitIndex(-100); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
72 tsc->setFinalIndex(100); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
73 tsc->setMaxAbsError(1.0e-06); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
74 tsc->setMaxRelError(1.0e-06); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
75 tsc->setMaxFailures(8); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
76 tsc->setMaxConsecFailures(4); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
77 tsc->setNumTimeSteps(-1); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
78 tsc->setPrintDtChanges(
false); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
79 tsc->setOutputExactly(
false); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
80 tsc->setOutputIndexInterval(9); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
81 tsc->setOutputTimeInterval(0.1);tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
83 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
84 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 1.0 , 1.0e-14);
85 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0 , 1.0e-14);
86 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
87 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 0.02 , 1.0e-14);
88 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
89 TEST_COMPARE ( tsc->getInitIndex() , ==, -100 );
90 TEST_COMPARE ( tsc->getFinalIndex() , ==, 100 );
91 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-06, 1.0e-14);
92 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-06, 1.0e-14);
93 TEST_COMPARE ( tsc->getMaxFailures() , ==, 8 );
94 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 4 );
95 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
96 TEST_COMPARE ( tsc->getPrintDtChanges() , ==, false );
97 TEST_COMPARE ( tsc->getOutputExactly() , ==, false );
98 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 9 );
99 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 0.1 , 1.0e-14);
107 std::vector<int> outputIndices;
108 outputIndices.push_back(7);
109 outputIndices.push_back(11);
110 outputIndices.push_back(13);
112 std::vector<double> outputTimes;
113 outputTimes.push_back(0.3);
114 outputTimes.push_back(0.7);
115 outputTimes.push_back(1.3);
116 outputTimes.push_back(1.7);
122 1.0, 100.0, 0.01, 0.02, 0.05, -100,
123 100, 1.0e-06, 1.0e-06, 8, 4, -1,
false,
false,
124 outputIndices, outputTimes, 9, 0.011, tscsc));
126 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
128 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
129 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 1.0 , 1.0e-14);
130 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0 , 1.0e-14);
131 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
132 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 0.02 , 1.0e-14);
133 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
134 TEST_COMPARE ( tsc->getInitIndex() , ==, -100 );
135 TEST_COMPARE ( tsc->getFinalIndex() , ==, 100 );
136 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-06, 1.0e-14);
137 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-06, 1.0e-14);
138 TEST_COMPARE ( tsc->getMaxFailures() , ==, 8 );
139 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 4 );
140 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
141 TEST_COMPARE ( tsc->getPrintDtChanges() , ==, false );
142 TEST_COMPARE ( tsc->getOutputExactly() , ==, false );
143 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 9 );
144 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 0.011 , 1.0e-14);
153 Teuchos::RCP<Teuchos::ParameterList> pl =
154 Tempus::getTimeStepControlPL<double>();
156 pl->set<
double> (
"Initial Time" , 1.0);
157 pl->set<
double> (
"Final Time" , 100.0);
158 pl->set<
double> (
"Minimum Time Step" , 0.01);
159 pl->set<
double> (
"Initial Time Step" , 0.02);
160 pl->set<
double> (
"Maximum Time Step" , 0.05);
161 pl->set<
int> (
"Initial Time Index" , -100);
162 pl->set<
int> (
"Final Time Index" , 100);
163 pl->set<
double> (
"Maximum Absolute Error", 1.0e-06);
164 pl->set<
double> (
"Maximum Relative Error", 1.0e-06);
165 pl->set<
int> (
"Maximum Number of Stepper Failures", 8);
166 pl->set<
int> (
"Maximum Number of Consecutive Stepper Failures", 4);
167 pl->set<
int> (
"Number of Time Steps" , -1);
168 pl->set<
bool> (
"Print Time Step Changes",
false);
169 pl->set<
bool> (
"Output Exactly On Output Times",
false);
170 pl->set<std::string>(
"Output Index List" ,
"7, 11, 13" );
171 pl->set<std::string>(
"Output Time List" ,
"0.3, 0.7, 1.3, 1.7");
172 pl->set<
int> (
"Output Index Interval" , 9);
173 pl->set<
double> (
"Output Time Interval" , 0.011);
176 auto tscsPL = tscs->getValidParameters();
177 pl->set(
"Time Step Control Strategy", *tscsPL);
180 auto tsc = Tempus::createTimeStepControl<double>(pl);
181 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
187 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
188 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 1.0 , 1.0e-14);
189 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0 , 1.0e-14);
190 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
191 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 0.02 , 1.0e-14);
192 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
193 TEST_COMPARE ( tsc->getInitIndex() , ==, -100 );
194 TEST_COMPARE ( tsc->getFinalIndex() , ==, 100 );
195 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-06, 1.0e-14);
196 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-06, 1.0e-14);
197 TEST_COMPARE ( tsc->getMaxFailures() , ==, 8 );
198 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 4 );
199 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
200 TEST_COMPARE ( tsc->getPrintDtChanges() , ==, false );
201 TEST_COMPARE ( tsc->getOutputExactly() , ==, false );
202 TEST_COMPARE ( tsc->getOutputIndices()[0] , ==, 7 );
203 TEST_COMPARE ( tsc->getOutputIndices()[1] , ==, 11 );
204 TEST_COMPARE ( tsc->getOutputIndices()[2] , ==, 13 );
205 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[0] , 0.3 , 1.0e-14);
206 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[1] , 0.7 , 1.0e-14);
207 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[2] , 1.3 , 1.0e-14);
208 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[3] , 1.7 , 1.0e-14);
209 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 9 );
210 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 0.011 , 1.0e-14);
223 tsc->setInitTime(dSet); TEST_COMPARE( tsc->getInitTime(), ==, dSet);
224 tsc->setFinalTime(dSet); TEST_COMPARE( tsc->getFinalTime(), ==, dSet);
225 tsc->setMinTimeStep(dSet); TEST_COMPARE( tsc->getMinTimeStep(), ==, dSet);
226 tsc->setInitTimeStep(dSet); TEST_COMPARE( tsc->getInitTimeStep(), ==, dSet);
227 tsc->setMaxTimeStep(dSet); TEST_COMPARE( tsc->getMaxTimeStep(), ==, dSet);
228 tsc->setInitIndex(iSet); TEST_COMPARE( tsc->getInitIndex(), ==, iSet);
229 tsc->setFinalIndex(iSet); TEST_COMPARE( tsc->getFinalIndex(), ==, iSet);
230 tsc->setMaxAbsError(dSet); TEST_COMPARE( tsc->getMaxAbsError(), ==, dSet);
231 tsc->setMaxRelError(dSet); TEST_COMPARE( tsc->getMaxRelError(), ==, dSet);
232 tsc->setOutputExactly(
false); TEST_COMPARE( tsc->getOutputExactly(), ==,
false);
233 tsc->setOutputExactly(
true); TEST_COMPARE( tsc->getOutputExactly(), ==,
true);
235 std::vector<int> iVSet{ 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 };
236 tsc->setOutputIndices(iVSet); TEUCHOS_TEST_FOR_EXCEPT(tsc->getOutputIndices() != iVSet);
239 tsc->setOutputIndexInterval(iSet); TEST_COMPARE( tsc->getOutputIndexInterval(), ==, iSet);
240 tsc->setOutputTimeInterval(dSet); TEST_COMPARE( tsc->getOutputTimeInterval(), ==, dSet);
250 std::vector<double> times_in;
251 times_in.push_back(0.0000000000000000e-11);
252 times_in.push_back(0.1001384570000000e-11);
253 times_in.push_back(0.2002769140000000e-11);
254 times_in.push_back(0.3004153710000000e-11);
255 times_in.push_back(0.4005538280000000e-11);
256 times_in.push_back(0.5006922850000000e-11);
257 times_in.push_back(0.6008307420000000e-11);
258 times_in.push_back(0.7009691990000000e-11);
259 times_in.push_back(0.8011076560000000e-11);
260 times_in.push_back(0.9012461130000000e-11);
261 times_in.push_back(1.0013845700000000e-11);
263 tsc->setOutputTimes(times_in);
265 auto times_out = tsc->getOutputTimes();
266 double maxDiff = 0.0;
269 for (
size_t i=0; i < times_in.size(); ++i) {
273 maxDiff = std::max(std::fabs(times_in[i] - times_out[i]), maxDiff);
277 TEST_COMPARE(maxDiff, <, 1.0e-25);
281 times_in.push_back(0.00000000000000000000000000000000);
282 times_in.push_back(0.00000000000100138457000000009381);
283 times_in.push_back(0.00000000000200276914000000018762);
284 times_in.push_back(0.00000000000300415371000000007949);
285 times_in.push_back(0.00000000000400553828000000037525);
286 times_in.push_back(0.00000000000500692284999999986321);
287 times_in.push_back(0.00000000000600830742000000015898);
288 times_in.push_back(0.00000000000700969198999999964694);
289 times_in.push_back(0.00000000000801107656000000075050);
290 times_in.push_back(0.00000000000901246112999999943067);
291 times_in.push_back(0.00000000001001384569999999972643);
293 tsc->setOutputTimes(times_in);
295 times_out = tsc->getOutputTimes();
299 for (
size_t i=0; i < times_in.size(); ++i) {
303 maxDiff = std::max(std::fabs(times_in[i] - times_out[i]), maxDiff);
307 TEST_COMPARE(maxDiff, <, 1.0e-25);
316 int setOutputTimeIndex = 17;
317 double setOutputTimeInterval = 1.101001000100001e-7;
319 tsc->setOutputIndexInterval(setOutputTimeIndex);
320 tsc->setOutputTimeInterval(setOutputTimeInterval);
322 int getOutputTimeIndex = tsc->getOutputIndexInterval();
323 double getOutputTimeInterval = tsc->getOutputTimeInterval();
324 TEST_COMPARE(getOutputTimeInterval, ==, setOutputTimeInterval);
325 TEST_COMPARE(getOutputTimeIndex, ==, setOutputTimeIndex);
334 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
337 auto testTimeInRange = [=] (
double initTime,
double finalTime)
339 tsc->setInitTime (initTime);
340 tsc->setFinalTime(finalTime);
342 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
344 const int i = (initTime == 0) ? 0 : 1 + (
int)std::floor(std::log10(std::fabs(initTime) ) );
345 const double absTolInit10 = std::pow(10, i-10);
346 const double absTolInit15 = std::pow(10, i-15);
347 const int j = (finalTime == 0) ? 0 : 1 + (
int)std::floor(std::log10(std::fabs(finalTime) ) );
348 const double absTolFinal10 = std::pow(10, j-10);
349 const double absTolFinal15 = std::pow(10, j-15);
353 if ( initTime == 0.0 ) {
354 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange( initTime - 0.1));
356 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange( initTime - 0.1*std::fabs(initTime)));
358 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange( initTime - absTolInit10));
359 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime - absTolInit15));
360 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime ));
361 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime + absTolInit15));
362 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime + absTolInit10));
363 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime + 0.3*(std::fabs(finalTime-initTime))));
364 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange(finalTime - absTolFinal10));
365 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime - absTolFinal15));
366 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime ));
367 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + absTolFinal15));
368 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + absTolFinal10));
369 if ( finalTime == 0.0 ) {
370 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + 0.1));
372 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + 0.1*std::fabs(finalTime)));
377 testTimeInRange (0.0, 1.0);
380 testTimeInRange (-1.0, 0.0);
383 testTimeInRange ( 9.9e-20, 3.3e+20);
384 testTimeInRange (-1.9e+20, 2.3e-20);
393 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
396 auto testIndexInRange = [=] (
double initIndex,
double finalIndex)
398 tsc->setInitIndex (initIndex);
399 tsc->setFinalIndex(finalIndex);
401 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
404 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange( initIndex - 7));
405 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange( initIndex - 1));
406 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange( initIndex ));
407 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange( initIndex + 1));
408 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange( initIndex + (
int)0.3*(std::fabs(finalIndex-initIndex))));
409 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange(finalIndex - 1));
410 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange(finalIndex ));
411 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange(finalIndex + 1));
412 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange(finalIndex + 7));
416 testIndexInRange (0, 10);
419 testIndexInRange (-10, 0);
422 testIndexInRange (-190000, 20);
423 testIndexInRange (-19, 200000);
431 std::vector<int> outputIndices;
432 outputIndices.push_back(7);
433 outputIndices.push_back(11);
434 outputIndices.push_back(13);
436 std::vector<double> outputTimes;
437 outputTimes.push_back(0.3);
438 outputTimes.push_back(0.7);
439 outputTimes.push_back(1.3);
440 outputTimes.push_back(1.7);
446 1.0, 100.0, 0.01, 0.02, 0.05, -100,
447 100, 1.0e-06, 1.0e-06, 8, 4, -1,
false,
false,
448 outputIndices, outputTimes, 9, 0.011, tscsc));
449 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
451 auto pl = tsc->getValidParameters();
453 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Initial Time") , 1.0 , 1.0e-14);
454 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Final Time") , 100.0 , 1.0e-14);
455 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Minimum Time Step") , 0.01 , 1.0e-14);
456 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Initial Time Step") , 0.02 , 1.0e-14);
457 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Maximum Time Step") , 0.05 , 1.0e-14);
458 TEST_COMPARE ( pl->get<
int> (
"Initial Time Index") , ==, -100 );
459 TEST_COMPARE ( pl->get<
int> (
"Final Time Index") , ==, 100 );
460 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Maximum Absolute Error") , 1.0e-06, 1.0e-14);
461 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Maximum Relative Error") , 1.0e-06, 1.0e-14);
462 TEST_COMPARE ( pl->get<
int> (
"Maximum Number of Stepper Failures") , ==, 8);
463 TEST_COMPARE ( pl->get<
int> (
"Maximum Number of Consecutive Stepper Failures"), ==, 4);
464 TEST_COMPARE ( pl->get<
int> (
"Number of Time Steps") , ==, -1 );
465 TEST_COMPARE ( pl->get<
bool> (
"Print Time Step Changes") , ==,
false );
466 TEST_COMPARE ( pl->get<
bool> (
"Output Exactly On Output Times"), ==,
false );
467 TEST_COMPARE ( pl->get<std::string>(
"Output Index List") , ==,
"7, 11, 13" );
468 TEST_COMPARE ( pl->get<std::string>(
"Output Time List") , ==,
"0.3, 0.7, 1.3, 1.7");
469 TEST_COMPARE ( pl->get<
int> (
"Output Index Interval") , ==, 9 );
470 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Output Time Interval") , 0.011 , 1.0e-14);
473 std::ostringstream unusedParameters;
474 pl->unused(unusedParameters);
475 TEST_COMPARE ( unusedParameters.str(), ==,
476 "WARNING: Parameter \"Time Step Control Strategy\" [unused] is unused\n");
479 auto tscs_PL = pl->sublist(
"Time Step Control Strategy");
480 TEST_COMPARE ( tscs_PL.get<std::string>(
"Strategy Type") , ==,
"Constant");
481 TEST_FLOATING_EQUALITY( tscs_PL.get<
double>(
"Time Step"), 0.0, 1.0e-14);
484 std::ostringstream unusedParameters;
485 tscs_PL.unused(unusedParameters);
486 TEST_COMPARE ( unusedParameters.str(), ==,
"");
497 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
499 tsc->setInitTime(0.0);
500 tsc->setFinalTime(100.0);
501 tsc->setMinTimeStep(0.01);
502 tsc->setInitTimeStep(0.02);
503 tsc->setMaxTimeStep(0.05);
504 tsc->setNumTimeSteps(-1);
506 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
508 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 0.0 , 1.0e-14);
509 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0, 1.0e-14);
510 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
511 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep(), 0.02 , 1.0e-14);
512 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
513 TEST_COMPARE ( tsc->getNumTimeSteps(), ==, -1 );
515 tsc->setNumTimeSteps(100);
518 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 0.0 , 1.0e-14);
519 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0, 1.0e-14);
520 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 1.0 , 1.0e-14);
521 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep(), 1.0 , 1.0e-14);
522 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 1.0 , 1.0e-14);
523 TEST_COMPARE ( tsc->getNumTimeSteps(), ==, 100 );
534 auto inArgsIC = model->getNominalValues();
536 auto icState = Tempus::createSolutionStateX<double>(icSolution);
538 solutionHistory->addState(icState);
540 solutionHistory->getCurrentState()->setTimeStep(dt);
544 std::vector<double> outputTimes;
545 double outputTime = 0.8;
546 outputTimes.push_back(outputTime);
547 tsc->setOutputTimes(outputTimes);
548 tsc->setOutputExactly(
true);
550 tsc->setTimeStepControlStrategy(tscs);
551 tsc->setMinTimeStep (dt/2.0);
552 tsc->setInitTimeStep(dt);
553 tsc->setMaxTimeStep (2.0*dt);
554 tsc->setPrintDtChanges(
true);
556 TEST_COMPARE(tsc->getOutputExactly(), ==,
true);
561 solutionHistory->initWorkingState();
562 auto currentState = solutionHistory->getCurrentState();
563 auto workingState = solutionHistory->getWorkingState();
565 tsc->setNextTimeStep(solutionHistory, status);
567 TEST_FLOATING_EQUALITY( workingState->getTimeStep(), outputTime, 1.0e-14);
568 TEST_FLOATING_EQUALITY( workingState->getTime(), outputTime, 1.0e-14);
569 TEST_COMPARE(workingState->getOutput(), ==,
true);
574 solutionHistory->promoteWorkingState();
578 solutionHistory->initWorkingState();
579 currentState = solutionHistory->getCurrentState();
580 workingState = solutionHistory->getWorkingState();
582 tsc->setNextTimeStep(solutionHistory, status);
584 TEST_FLOATING_EQUALITY( workingState->getTimeStep(), dt, 1.0e-14);
585 TEST_FLOATING_EQUALITY(
586 currentState->getTime() + workingState->getTimeStep(),
587 workingState->getTime(), 1.0e-14);
589 TEST_COMPARE(workingState->getOutput(), ==,
false);
599 auto inArgsIC = model->getNominalValues();
601 auto icState = Tempus::createSolutionStateX<double>(icSolution);
603 solutionHistory->addState(icState);
605 solutionHistory->getCurrentState()->setTimeStep(dt);
609 std::vector<double> outputTimes;
610 double outputTime = 0.8;
611 outputTimes.push_back(outputTime);
612 tsc->setOutputTimes(outputTimes);
613 tsc->setOutputExactly(
true);
614 tsc->setMinTimeStep (dt/2.0);
615 tsc->setInitTimeStep(dt);
616 tsc->setMaxTimeStep (2.0*dt);
617 tsc->setOutputExactly(
false);
619 TEST_COMPARE(tsc->getOutputExactly(), ==,
false);
623 solutionHistory->initWorkingState();
624 auto currentState = solutionHistory->getCurrentState();
625 auto workingState = solutionHistory->getWorkingState();
627 tsc->setNextTimeStep(solutionHistory, status);
628 double timeN = workingState->getTime();
629 TEST_COMPARE(timeN, ==, dt);
631 TEST_COMPARE(workingState->getOutput(), ==,
true);
636 solutionHistory->promoteWorkingState();
639 solutionHistory->initWorkingState();
641 currentState = solutionHistory->getCurrentState();
642 workingState = solutionHistory->getWorkingState();
644 tsc->setNextTimeStep(solutionHistory, status);
645 timeN = workingState->getTime();
646 TEST_COMPARE( (timeN), ==, 2*dt);
648 double dtN = workingState->getTimeStep();
649 TEST_COMPARE( dt, ==, dtN);
651 TEST_COMPARE(workingState->getOutput(), ==,
false);
661 auto inArgsIC = model->getNominalValues();
663 auto icState = Tempus::createSolutionStateX<double>(icSolution);
665 solutionHistory->addState(icState);
667 solutionHistory->getCurrentState()->setTimeStep(dt);
671 std::vector<double> outputTimes;
672 double outputTime = 0.8;
673 outputTimes.push_back(outputTime);
674 tsc->setOutputTimes(outputTimes);
675 tsc->setOutputExactly(
true);
676 tsc->setTimeStepControlStrategy();
677 tsc->setInitTimeStep(dt);
683 for (
int i=0; i < 10000; ++i) {
684 solutionHistory->initWorkingState();
685 tsc->setNextTimeStep(solutionHistory, status);
690 solutionHistory->promoteWorkingState();
693 auto currentState = solutionHistory->getCurrentState();
694 double time = currentState->getTime();
695 TEST_COMPARE( std::fabs(time-1.0), <, 1.0e-15);
705 auto pl = Tempus::getTimeStepControlPL<double>();
706 pl->remove(
"Time Step Control Strategy");
708 auto tsc = Tempus::createTimeStepControl<double>(pl,
false);
709 TEUCHOS_TEST_FOR_EXCEPT(tsc->isInitialized());
711 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
714 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Constant"));
715 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Constant"));
719 auto pl = Tempus::getTimeStepControlPL<double>();
720 pl->remove(
"Time Step Control Strategy");
721 pl->set(
"Time Step Control Strategy",
722 *(Tempus::getTimeStepControlStrategyBasicVS_PL<double>()));
724 auto tsc = Tempus::createTimeStepControl<double>(pl);
725 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
728 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Variable"));
729 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Basic VS"));
733 auto pl = Tempus::getTimeStepControlPL<double>();
734 pl->remove(
"Time Step Control Strategy");
735 pl->set(
"Time Step Control Strategy",
736 *(Tempus::getTimeStepControlStrategyIntegralControllerPL<double>()));
738 auto tsc = Tempus::createTimeStepControl<double>(pl);
739 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
742 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Variable"));
743 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Integral Controller"));
747 auto pl = Tempus::getTimeStepControlPL<double>();
748 pl->remove(
"Time Step Control Strategy");
749 pl->set(
"Time Step Control Strategy",
750 *(Tempus::getTimeStepControlStrategyCompositePL<double>()));
752 auto tsc = Tempus::createTimeStepControl<double>(pl);
753 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
756 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Constant"));
757 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Composite"));
761 auto pl = Tempus::getTimeStepControlPL<double>();
762 pl->remove(
"Time Step Control Strategy");
764 auto nonTempusStrategyPL =
765 Teuchos::parameterList(
"Time Step Control Strategy");
766 nonTempusStrategyPL->set<std::string>(
"Strategy Type",
"Application Strategy");
767 nonTempusStrategyPL->set<
double>(
"Secret Sauce", 1.2345);
769 pl->set(
"Time Step Control Strategy", *nonTempusStrategyPL);
771 auto tsc = Tempus::createTimeStepControl<double>(pl);
772 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
775 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Constant"));
776 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Constant"));
789 temp->addStrategy(tscsBasicVS);
791 temp->addStrategy(tscsIntCtrl);
793 TEUCHOS_TEST_FOR_EXCEPT(!temp->isInitialized());
796 tsc->setTimeStepControlStrategy(temp);
798 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
800 Teuchos::RCP<Tempus::TimeStepControlStrategy<double>> strategy =
801 tsc->getTimeStepControlStrategy();
806 TEST_COMPARE(tscsc->size(), ==, 2);
808 std::vector<Teuchos::RCP<Tempus::TimeStepControlStrategy<double>>>
813 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getStepType() !=
"Variable");
814 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getAmplFactor() != 1.75);
815 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getReductFactor() != 0.5);
816 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getMinEta() != 0.0);
817 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getMaxEta() != 1.0e+16);
821 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getStepType() !=
"Variable");
822 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getController() !=
"PID");
823 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getKI() != 0.58);
824 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getKP() != 0.21);
825 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getKD() != 0.10);
826 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getSafetyFactor() != 0.90);
827 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getSafetyFactorAfterReject() != 0.90);
828 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getFacMax() != 5.0);
829 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getFacMin() != 0.5);
virtual std::vector< Teuchos::RCP< TimeStepControlStrategy< Scalar > > > getStrategies() const
Return composite list.
StepControlStrategy class for TimeStepControl.
Sine-Cosine model problem from Rythmos. This is a canonical Sine-Cosine differential equation with a...
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.
TimeStepControlStrategyComposite loops over a vector of TimeStepControlStrategies.
StepControlStrategy class for TimeStepControl.