11#include "Tempus_TimeStepControl.hpp"
22using Teuchos::rcp_const_cast;
23using Teuchos::rcp_dynamic_cast;
24using Teuchos::ParameterList;
25using Teuchos::sublist;
33 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
36 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
37 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 0.0 , 1.0e-14);
38 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 1.0e+99, 1.0e-14);
39 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.0 , 1.0e-14);
40 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 1.0e+99, 1.0e-14);
41 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 1.0e+99, 1.0e-14);
42 TEST_COMPARE ( tsc->getInitIndex() , ==, 0 );
43 TEST_COMPARE ( tsc->getFinalIndex() , ==, 1000000 );
44 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-08, 1.0e-14);
45 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-08, 1.0e-14);
46 TEST_COMPARE ( tsc->getMaxFailures() , ==, 10 );
47 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 5 );
48 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
49 TEST_COMPARE ( tsc->getPrintDtChanges() , ==,
true );
50 TEST_COMPARE ( tsc->getOutputExactly() , ==,
true );
51 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 1000000 );
52 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 1.0e+99, 1.0e-14);
53 auto tec = tsc->getTimeEvents();
54 TEST_COMPARE ( tec->getSize() , ==, 2 );
55 TEST_COMPARE ( tec->getTimeEventNames() , ==,
"Output Index Interval, Output Time Interval");
58 tsc->setInitTime(1.0); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
59 tsc->setFinalTime(100.0); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
60 tsc->setMinTimeStep(0.01); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
61 tsc->setInitTimeStep(0.02); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
62 tsc->setMaxTimeStep(0.05); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
63 tsc->setInitIndex(-100); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
64 tsc->setFinalIndex(100); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
65 tsc->setMaxAbsError(1.0e-06); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
66 tsc->setMaxRelError(1.0e-06); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
67 tsc->setMaxFailures(8); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
68 tsc->setMaxConsecFailures(4); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
69 tsc->setNumTimeSteps(-1); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
70 tsc->setPrintDtChanges(
false); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
71 tsc->setOutputExactly(
false); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
72 tsc->setOutputIndexInterval(9); tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
73 tsc->setOutputTimeInterval(0.1);tsc->initialize(); TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
75 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
76 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 1.0 , 1.0e-14);
77 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0 , 1.0e-14);
78 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
79 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 0.02 , 1.0e-14);
80 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
81 TEST_COMPARE ( tsc->getInitIndex() , ==, -100 );
82 TEST_COMPARE ( tsc->getFinalIndex() , ==, 100 );
83 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-06, 1.0e-14);
84 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-06, 1.0e-14);
85 TEST_COMPARE ( tsc->getMaxFailures() , ==, 8 );
86 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 4 );
87 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
88 TEST_COMPARE ( tsc->getPrintDtChanges() , ==,
false );
89 TEST_COMPARE ( tsc->getOutputExactly() , ==,
false );
90 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 9 );
91 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 0.1 , 1.0e-14);
96 ter->setName(
"Test Range");
97 tel->setName(
"Test List");
100 tsc->setTimeEvents(tecTmp);
101 tec = tsc->getTimeEvents();
102 TEST_COMPARE ( tec->getSize() , ==, 2 );
103 TEST_COMPARE ( tec->getTimeEventNames() , ==,
"Test Range, Test List");
111 std::vector<int> outputIndices;
112 outputIndices.push_back(7);
113 outputIndices.push_back(11);
114 outputIndices.push_back(13);
116 std::vector<double> outputTimes;
117 outputTimes.push_back(0.3);
118 outputTimes.push_back(0.7);
119 outputTimes.push_back(1.3);
120 outputTimes.push_back(1.7);
127 ter-> setName(
"Test Range");
128 teri->setName(
"Test Range Index");
129 tel-> setName(
"Test List");
130 teli->setName(
"Test List Index");
162 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
164 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
165 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 1.0 , 1.0e-14);
166 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0 , 1.0e-14);
167 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
168 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 0.02 , 1.0e-14);
169 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
170 TEST_COMPARE ( tsc->getInitIndex() , ==, -100 );
171 TEST_COMPARE ( tsc->getFinalIndex() , ==, 100 );
172 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-06, 1.0e-14);
173 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-06, 1.0e-14);
174 TEST_COMPARE ( tsc->getMaxFailures() , ==, 8 );
175 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 4 );
176 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
177 TEST_COMPARE ( tsc->getPrintDtChanges() , ==,
false );
178 TEST_COMPARE ( tsc->getOutputExactly() , ==,
false );
179 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 9 );
180 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 0.011 , 1.0e-14);
181 auto tec = tsc->getTimeEvents();
182 TEST_COMPARE ( tec->getSize() , ==, 8 );
183 TEST_COMPARE ( tec->getTimeEventNames() , ==,
"Test Range, Test Range Index, Test List, Test List Index, Output Time Interval, Output Time List, Output Index Interval, Output Index List");
191 Teuchos::RCP<Teuchos::ParameterList> pl =
192 Tempus::getTimeStepControlPL<double>();
194 pl->set<
double> (
"Initial Time" , 1.0);
195 pl->set<
double> (
"Final Time" , 100.0);
196 pl->set<
double> (
"Minimum Time Step" , 0.01);
197 pl->set<
double> (
"Initial Time Step" , 0.02);
198 pl->set<
double> (
"Maximum Time Step" , 0.05);
199 pl->set<
int> (
"Initial Time Index" , -100);
200 pl->set<
int> (
"Final Time Index" , 100);
201 pl->set<
double> (
"Maximum Absolute Error", 1.0e-06);
202 pl->set<
double> (
"Maximum Relative Error", 1.0e-06);
203 pl->set<
int> (
"Maximum Number of Stepper Failures", 8);
204 pl->set<
int> (
"Maximum Number of Consecutive Stepper Failures", 4);
205 pl->set<
int> (
"Number of Time Steps" , -1);
206 pl->set<
bool> (
"Print Time Step Changes",
false);
207 pl->set<
bool> (
"Output Exactly On Output Times",
false);
208 pl->set<std::string>(
"Output Index List" ,
"7, 11, 13" );
209 pl->set<std::string>(
"Output Time List" ,
"0.3, 0.7, 1.3, 1.7");
210 pl->set<
int> (
"Output Index Interval" , 9);
211 pl->set<
double> (
"Output Time Interval" , 0.011);
214 auto tscsPL = tscs->getValidParameters();
215 pl->set(
"Time Step Control Strategy", *tscsPL);
222 ter-> setName(
"Test Range");
223 teri->setName(
"Test Range Index");
224 tel-> setName(
"Test List");
225 teli->setName(
"Test List Index");
230 auto tecPL = rcp_const_cast<ParameterList>(tec->getValidParameters());
231 pl->set(
"Time Step Control Events", *tecPL);
233 auto tsc = Tempus::createTimeStepControl<double>(pl);
234 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
236 tsc->describe(out, Teuchos::VERB_EXTREME);
238 TEST_COMPARE ( tsc->getStepType() , ==,
"Constant" );
239 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 1.0 , 1.0e-14);
240 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0 , 1.0e-14);
241 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
242 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep() , 0.02 , 1.0e-14);
243 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
244 TEST_COMPARE ( tsc->getInitIndex() , ==, -100 );
245 TEST_COMPARE ( tsc->getFinalIndex() , ==, 100 );
246 TEST_FLOATING_EQUALITY( tsc->getMaxAbsError() , 1.0e-06, 1.0e-14);
247 TEST_FLOATING_EQUALITY( tsc->getMaxRelError() , 1.0e-06, 1.0e-14);
248 TEST_COMPARE ( tsc->getMaxFailures() , ==, 8 );
249 TEST_COMPARE ( tsc->getMaxConsecFailures() , ==, 4 );
250 TEST_COMPARE ( tsc->getNumTimeSteps() , ==, -1 );
251 TEST_COMPARE ( tsc->getPrintDtChanges() , ==,
false );
252 TEST_COMPARE ( tsc->getOutputExactly() , ==,
false );
253 TEST_COMPARE ( tsc->getOutputIndices()[0] , ==, 7 );
254 TEST_COMPARE ( tsc->getOutputIndices()[1] , ==, 11 );
255 TEST_COMPARE ( tsc->getOutputIndices()[2] , ==, 13 );
256 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[0] , 0.3 , 1.0e-14);
257 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[1] , 0.7 , 1.0e-14);
258 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[2] , 1.3 , 1.0e-14);
259 TEST_FLOATING_EQUALITY( tsc->getOutputTimes()[3] , 1.7 , 1.0e-14);
260 TEST_COMPARE ( tsc->getOutputIndexInterval(), ==, 9 );
261 TEST_FLOATING_EQUALITY( tsc->getOutputTimeInterval() , 0.011 , 1.0e-14);
263 tec = tsc->getTimeEvents();
264 TEST_COMPARE ( tec->getSize() , ==, 8 );
265 TEST_COMPARE ( tec->getTimeEventNames() , ==,
"Output Index List, Output Index Interval, Output Time List, Output Time Interval, Test Range, Test Range Index, Test List, Test List Index");
278 double dLast = 0.989;
281 tsc->setInitTime(dFirst); TEST_COMPARE( tsc->getInitTime(), ==, dFirst);
282 tsc->setFinalTime(dLast); TEST_COMPARE( tsc->getFinalTime(), ==, dLast);
283 tsc->setMinTimeStep(dStep); TEST_COMPARE( tsc->getMinTimeStep(), ==, dStep);
284 tsc->setInitTimeStep(dStep); TEST_COMPARE( tsc->getInitTimeStep(), ==, dStep);
285 tsc->setMaxTimeStep(dLast); TEST_COMPARE( tsc->getMaxTimeStep(), ==, dLast);
286 tsc->setInitIndex(iFirst); TEST_COMPARE( tsc->getInitIndex(), ==, iFirst);
287 tsc->setFinalIndex(iLast); TEST_COMPARE( tsc->getFinalIndex(), ==, iLast);
288 tsc->setMaxAbsError(dStep); TEST_COMPARE( tsc->getMaxAbsError(), ==, dStep);
289 tsc->setMaxRelError(dStep); TEST_COMPARE( tsc->getMaxRelError(), ==, dStep);
290 tsc->setOutputExactly(
false); TEST_COMPARE( tsc->getOutputExactly(), ==,
false);
291 tsc->setOutputExactly(
true); TEST_COMPARE( tsc->getOutputExactly(), ==,
true);
293 std::vector<int> iVSet{ 0, 1, 2, 3, 5, 8, 13, 21, 34 };
294 tsc->setOutputIndices(iVSet); TEUCHOS_TEST_FOR_EXCEPT(tsc->getOutputIndices() != iVSet);
296 tsc->setOutputIndexInterval(iStep); TEST_COMPARE( tsc->getOutputIndexInterval(), ==, iStep);
297 tsc->setOutputTimeInterval(dStep); TEST_COMPARE( tsc->getOutputTimeInterval(), ==, dStep);
307 std::vector<double> times_in;
308 times_in.push_back(0.0000000000000000e-11);
309 times_in.push_back(0.1001384570000000e-11);
310 times_in.push_back(0.2002769140000000e-11);
311 times_in.push_back(0.3004153710000000e-11);
312 times_in.push_back(0.4005538280000000e-11);
313 times_in.push_back(0.5006922850000000e-11);
314 times_in.push_back(0.6008307420000000e-11);
315 times_in.push_back(0.7009691990000000e-11);
316 times_in.push_back(0.8011076560000000e-11);
317 times_in.push_back(0.9012461130000000e-11);
318 times_in.push_back(1.0013845700000000e-11);
320 tsc->setOutputTimes(times_in);
322 auto times_out = tsc->getOutputTimes();
323 double maxDiff = 0.0;
326 for (
size_t i=0; i < times_in.size(); ++i) {
330 maxDiff = std::max(std::fabs(times_in[i] - times_out[i]), maxDiff);
334 TEST_COMPARE(maxDiff, <, 1.0e-25);
338 times_in.push_back(0.00000000000000000000000000000000);
339 times_in.push_back(0.00000000000100138457000000009381);
340 times_in.push_back(0.00000000000200276914000000018762);
341 times_in.push_back(0.00000000000300415371000000007949);
342 times_in.push_back(0.00000000000400553828000000037525);
343 times_in.push_back(0.00000000000500692284999999986321);
344 times_in.push_back(0.00000000000600830742000000015898);
345 times_in.push_back(0.00000000000700969198999999964694);
346 times_in.push_back(0.00000000000801107656000000075050);
347 times_in.push_back(0.00000000000901246112999999943067);
348 times_in.push_back(0.00000000001001384569999999972643);
350 tsc->setOutputTimes(times_in);
352 times_out = tsc->getOutputTimes();
356 for (
size_t i=0; i < times_in.size(); ++i) {
360 maxDiff = std::max(std::fabs(times_in[i] - times_out[i]), maxDiff);
364 TEST_COMPARE(maxDiff, <, 1.0e-25);
373 int setOutputTimeIndex = 17;
374 double setOutputTimeInterval = 1.101001000100001e-7;
376 tsc->setFinalTime(1.0);
377 tsc->setOutputIndexInterval(setOutputTimeIndex);
378 tsc->setOutputTimeInterval(setOutputTimeInterval);
380 int getOutputTimeIndex = tsc->getOutputIndexInterval();
381 double getOutputTimeInterval = tsc->getOutputTimeInterval();
382 TEST_COMPARE(getOutputTimeInterval, ==, setOutputTimeInterval);
383 TEST_COMPARE(getOutputTimeIndex, ==, setOutputTimeIndex);
392 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
395 auto testTimeInRange = [=] (
double initTime,
double finalTime)
397 tsc->setInitTime (initTime);
398 tsc->setFinalTime(finalTime);
400 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
402 const int i = (initTime == 0) ? 0 : 1 + (
int)std::floor(std::log10(std::fabs(initTime) ) );
403 const double absTolInit10 = std::pow(10, i-10);
404 const double absTolInit15 = std::pow(10, i-15);
405 const int j = (finalTime == 0) ? 0 : 1 + (
int)std::floor(std::log10(std::fabs(finalTime) ) );
406 const double absTolFinal10 = std::pow(10, j-10);
407 const double absTolFinal15 = std::pow(10, j-15);
411 if ( initTime == 0.0 ) {
412 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange( initTime - 0.1));
414 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange( initTime - 0.1*std::fabs(initTime)));
416 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange( initTime - absTolInit10));
417 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime - absTolInit15));
418 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime ));
419 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime + absTolInit15));
420 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime + absTolInit10));
421 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange( initTime + 0.3*(std::fabs(finalTime-initTime))));
422 TEUCHOS_TEST_FOR_EXCEPT(!tsc->timeInRange(finalTime - absTolFinal10));
423 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime - absTolFinal15));
424 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime ));
425 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + absTolFinal15));
426 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + absTolFinal10));
427 if ( finalTime == 0.0 ) {
428 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + 0.1));
430 TEUCHOS_TEST_FOR_EXCEPT( tsc->timeInRange(finalTime + 0.1*std::fabs(finalTime)));
435 testTimeInRange (0.0, 1.0);
438 testTimeInRange (-1.0, 0.0);
441 testTimeInRange ( 9.9e-20, 3.3e+20);
442 testTimeInRange (-1.9e+20, 2.3e-20);
451 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
454 auto testIndexInRange = [=] (
double initIndex,
double finalIndex)
456 tsc->setInitIndex (initIndex);
457 tsc->setFinalIndex(finalIndex);
459 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
462 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange( initIndex - 7));
463 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange( initIndex - 1));
464 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange( initIndex ));
465 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange( initIndex + 1));
466 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange( initIndex + (
int)0.3*(std::fabs(finalIndex-initIndex))));
467 TEUCHOS_TEST_FOR_EXCEPT(!tsc->indexInRange(finalIndex - 1));
468 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange(finalIndex ));
469 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange(finalIndex + 1));
470 TEUCHOS_TEST_FOR_EXCEPT( tsc->indexInRange(finalIndex + 7));
474 testIndexInRange (0, 10);
477 testIndexInRange (-10, 0);
480 testIndexInRange (-190000, 20);
481 testIndexInRange (-19, 200000);
489 std::vector<int> outputIndices;
490 outputIndices.push_back(7);
491 outputIndices.push_back(11);
492 outputIndices.push_back(13);
494 std::vector<double> outputTimes;
495 outputTimes.push_back(0.3);
496 outputTimes.push_back(0.7);
497 outputTimes.push_back(1.3);
498 outputTimes.push_back(1.7);
506 1.0, 100.0, 0.01, 0.02, 0.05, -100,
507 100, 1.0e-06, 1.0e-06, 8, 4, -1,
false,
false,
508 outputIndices, outputTimes, 9, 0.011, tec, tscsc));
509 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
511 auto pl = tsc->getValidParameters();
513 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Initial Time") , 1.0 , 1.0e-14);
514 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Final Time") , 100.0 , 1.0e-14);
515 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Minimum Time Step") , 0.01 , 1.0e-14);
516 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Initial Time Step") , 0.02 , 1.0e-14);
517 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Maximum Time Step") , 0.05 , 1.0e-14);
518 TEST_COMPARE ( pl->get<
int> (
"Initial Time Index") , ==, -100 );
519 TEST_COMPARE ( pl->get<
int> (
"Final Time Index") , ==, 100 );
520 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Maximum Absolute Error") , 1.0e-06, 1.0e-14);
521 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Maximum Relative Error") , 1.0e-06, 1.0e-14);
522 TEST_COMPARE ( pl->get<
int> (
"Maximum Number of Stepper Failures") , ==, 8);
523 TEST_COMPARE ( pl->get<
int> (
"Maximum Number of Consecutive Stepper Failures"), ==, 4);
524 TEST_COMPARE ( pl->get<
int> (
"Number of Time Steps") , ==, -1 );
525 TEST_COMPARE ( pl->get<
bool> (
"Print Time Step Changes") , ==,
false );
526 TEST_COMPARE ( pl->get<
bool> (
"Output Exactly On Output Times"), ==,
false );
527 TEST_COMPARE ( pl->get<std::string>(
"Output Index List") , ==,
"7, 11, 13" );
528 TEST_COMPARE ( pl->get<std::string>(
"Output Time List") , ==,
"0.3, 0.7, 1.3, 1.7");
529 TEST_COMPARE ( pl->get<
int> (
"Output Index Interval") , ==, 9 );
530 TEST_FLOATING_EQUALITY( pl->get<
double>(
"Output Time Interval") , 0.011 , 1.0e-14);
533 std::ostringstream unusedParameters;
534 pl->unused(unusedParameters);
535 TEST_COMPARE ( unusedParameters.str(), ==,
536 "WARNING: Parameter \"Time Step Control Strategy\" [unused] is unused\n");
539 auto tscs_PL = pl->sublist(
"Time Step Control Strategy");
540 TEST_COMPARE ( tscs_PL.get<std::string>(
"Strategy Type") , ==,
"Constant");
541 TEST_FLOATING_EQUALITY( tscs_PL.get<
double>(
"Time Step"), 0.0, 1.0e-14);
544 std::ostringstream unusedParameters;
545 tscs_PL.unused(unusedParameters);
546 TEST_COMPARE ( unusedParameters.str(), ==,
"");
557 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
559 tsc->setInitTime(0.0);
560 tsc->setFinalTime(100.0);
561 tsc->setMinTimeStep(0.01);
562 tsc->setInitTimeStep(0.02);
563 tsc->setMaxTimeStep(0.05);
564 tsc->setNumTimeSteps(-1);
566 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
568 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 0.0 , 1.0e-14);
569 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0, 1.0e-14);
570 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 0.01 , 1.0e-14);
571 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep(), 0.02 , 1.0e-14);
572 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 0.05 , 1.0e-14);
573 TEST_COMPARE ( tsc->getNumTimeSteps(), ==, -1 );
575 tsc->setNumTimeSteps(100);
578 TEST_FLOATING_EQUALITY( tsc->getInitTime() , 0.0 , 1.0e-14);
579 TEST_FLOATING_EQUALITY( tsc->getFinalTime() , 100.0, 1.0e-14);
580 TEST_FLOATING_EQUALITY( tsc->getMinTimeStep() , 1.0 , 1.0e-14);
581 TEST_FLOATING_EQUALITY( tsc->getInitTimeStep(), 1.0 , 1.0e-14);
582 TEST_FLOATING_EQUALITY( tsc->getMaxTimeStep() , 1.0 , 1.0e-14);
583 TEST_COMPARE ( tsc->getNumTimeSteps(), ==, 100 );
594 auto inArgsIC = model->getNominalValues();
595 auto icSolution = rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
596 auto icState = Tempus::createSolutionStateX<double>(icSolution);
598 solutionHistory->addState(icState);
600 solutionHistory->getCurrentState()->setTimeStep(dt);
604 std::vector<double> outputTimes;
605 double outputTime = 0.8;
606 outputTimes.push_back(outputTime);
607 tsc->setOutputTimes(outputTimes);
608 tsc->setOutputExactly(
true);
610 tsc->setTimeStepControlStrategy(tscs);
611 tsc->setMinTimeStep (dt/2.0);
612 tsc->setInitTimeStep(dt);
613 tsc->setMaxTimeStep (2.0*dt);
614 tsc->setPrintDtChanges(
true);
616 TEST_COMPARE(tsc->getOutputExactly(), ==,
true);
621 solutionHistory->initWorkingState();
622 auto currentState = solutionHistory->getCurrentState();
623 auto workingState = solutionHistory->getWorkingState();
625 tsc->setNextTimeStep(solutionHistory, status);
627 TEST_FLOATING_EQUALITY( workingState->getTimeStep(), outputTime, 1.0e-14);
628 TEST_FLOATING_EQUALITY( workingState->getTime(), outputTime, 1.0e-14);
629 TEST_COMPARE(workingState->getOutput(), ==,
true);
634 solutionHistory->promoteWorkingState();
638 solutionHistory->initWorkingState();
639 currentState = solutionHistory->getCurrentState();
640 workingState = solutionHistory->getWorkingState();
642 tsc->setNextTimeStep(solutionHistory, status);
644 TEST_FLOATING_EQUALITY( workingState->getTimeStep(), dt, 1.0e-14);
645 TEST_FLOATING_EQUALITY(
646 currentState->getTime() + workingState->getTimeStep(),
647 workingState->getTime(), 1.0e-14);
649 TEST_COMPARE(workingState->getOutput(), ==,
false);
659 auto inArgsIC = model->getNominalValues();
660 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
661 auto icState = Tempus::createSolutionStateX<double>(icSolution);
663 solutionHistory->addState(icState);
665 solutionHistory->getCurrentState()->setTimeStep(dt);
669 std::vector<double> outputTimes;
670 double outputTime = 0.8;
671 outputTimes.push_back(outputTime);
672 tsc->setOutputTimes(outputTimes);
673 tsc->setMinTimeStep (dt/2.0);
674 tsc->setInitTimeStep(dt);
675 tsc->setMaxTimeStep (2.0*dt);
676 tsc->setOutputExactly(
false);
678 TEST_COMPARE(tsc->getOutputExactly(), ==,
false);
682 solutionHistory->initWorkingState();
683 auto currentState = solutionHistory->getCurrentState();
684 auto workingState = solutionHistory->getWorkingState();
686 tsc->setNextTimeStep(solutionHistory, status);
687 double timeN = workingState->getTime();
688 TEST_COMPARE(timeN, ==, dt);
690 TEST_COMPARE(workingState->getOutput(), ==,
true);
695 solutionHistory->promoteWorkingState();
698 solutionHistory->initWorkingState();
700 currentState = solutionHistory->getCurrentState();
701 workingState = solutionHistory->getWorkingState();
703 tsc->setNextTimeStep(solutionHistory, status);
704 timeN = workingState->getTime();
705 TEST_COMPARE( (timeN), ==, 2*dt);
707 double dtN = workingState->getTimeStep();
708 TEST_COMPARE( dt, ==, dtN);
710 TEST_COMPARE(workingState->getOutput(), ==,
false);
720 auto inArgsIC = model->getNominalValues();
721 auto icSolution =rcp_const_cast<Thyra::VectorBase<double> >(inArgsIC.get_x());
722 auto icState = Tempus::createSolutionStateX<double>(icSolution);
724 solutionHistory->addState(icState);
726 solutionHistory->getCurrentState()->setTimeStep(dt);
730 std::vector<double> outputTimes;
731 double outputTime = 0.8;
732 outputTimes.push_back(outputTime);
733 tsc->setOutputTimes(outputTimes);
734 tsc->setOutputExactly(
true);
735 tsc->setTimeStepControlStrategy();
736 tsc->setInitTimeStep(dt);
742 for (
int i=0; i < 10000; ++i) {
743 solutionHistory->initWorkingState();
744 tsc->setNextTimeStep(solutionHistory, status);
749 solutionHistory->promoteWorkingState();
752 auto currentState = solutionHistory->getCurrentState();
753 double time = currentState->getTime();
754 TEST_COMPARE( std::fabs(time-1.0), <, 1.0e-15);
764 auto pl = Tempus::getTimeStepControlPL<double>();
765 pl->remove(
"Time Step Control Strategy");
767 auto tsc = Tempus::createTimeStepControl<double>(pl,
false);
768 TEUCHOS_TEST_FOR_EXCEPT(tsc->isInitialized());
770 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
773 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Constant"));
774 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Constant"));
778 auto pl = Tempus::getTimeStepControlPL<double>();
779 pl->remove(
"Time Step Control Strategy");
780 pl->set(
"Time Step Control Strategy",
781 *(Tempus::getTimeStepControlStrategyBasicVS_PL<double>()));
783 auto tsc = Tempus::createTimeStepControl<double>(pl);
784 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
787 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Variable"));
788 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Basic VS"));
792 auto pl = Tempus::getTimeStepControlPL<double>();
793 pl->remove(
"Time Step Control Strategy");
794 pl->set(
"Time Step Control Strategy",
795 *(Tempus::getTimeStepControlStrategyIntegralControllerPL<double>()));
797 auto tsc = Tempus::createTimeStepControl<double>(pl);
798 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
801 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Variable"));
802 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Integral Controller"));
806 auto pl = Tempus::getTimeStepControlPL<double>();
807 pl->remove(
"Time Step Control Strategy");
808 pl->set(
"Time Step Control Strategy",
809 *(Tempus::getTimeStepControlStrategyCompositePL<double>()));
811 auto tsc = Tempus::createTimeStepControl<double>(pl);
812 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
815 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Constant"));
816 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Composite"));
820 auto pl = Tempus::getTimeStepControlPL<double>();
821 pl->remove(
"Time Step Control Strategy");
823 auto nonTempusStrategyPL =
824 Teuchos::parameterList(
"Time Step Control Strategy");
825 nonTempusStrategyPL->set<std::string>(
"Strategy Type",
"Application Strategy");
826 nonTempusStrategyPL->set<
double>(
"Secret Sauce", 1.2345);
828 pl->set(
"Time Step Control Strategy", *nonTempusStrategyPL);
830 auto tsc = Tempus::createTimeStepControl<double>(pl);
831 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
834 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getStepType() ==
"Constant"));
835 TEUCHOS_TEST_FOR_EXCEPT(!(tsc->getTimeStepControlStrategy()->getStrategyType() ==
"Constant"));
848 temp->addStrategy(tscsBasicVS);
850 temp->addStrategy(tscsIntCtrl);
852 TEUCHOS_TEST_FOR_EXCEPT(!temp->isInitialized());
855 tsc->setTimeStepControlStrategy(temp);
857 TEUCHOS_TEST_FOR_EXCEPT(!tsc->isInitialized());
859 Teuchos::RCP<Tempus::TimeStepControlStrategy<double>> strategy =
860 tsc->getTimeStepControlStrategy();
863 auto tscsc = rcp_dynamic_cast<Tempus::TimeStepControlStrategyComposite<double> >(strategy);
865 TEST_COMPARE(tscsc->size(), ==, 2);
867 std::vector<Teuchos::RCP<Tempus::TimeStepControlStrategy<double>>>
868 strategies = tscsc->getStrategies();
870 auto strategyBasicVS = Teuchos::rcp_dynamic_cast<Tempus::TimeStepControlStrategyBasicVS<double> > (strategies[0]);
872 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getStepType() !=
"Variable");
873 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getAmplFactor() != 1.75);
874 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getReductFactor() != 0.5);
875 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getMinEta() != 0.0);
876 TEUCHOS_TEST_FOR_EXCEPT(strategyBasicVS->getMaxEta() != 1.0e+16);
878 auto strategyIC = Teuchos::rcp_dynamic_cast<Tempus::TimeStepControlStrategyIntegralController<double> > (strategies[1]);
880 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getStepType() !=
"Variable");
881 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getController() !=
"PID");
882 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getKI() != 0.58);
883 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getKP() != 0.21);
884 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getKD() != 0.10);
885 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getSafetyFactor() != 0.90);
886 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getSafetyFactorAfterReject() != 0.90);
887 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getFacMax() != 5.0);
888 TEUCHOS_TEST_FOR_EXCEPT(strategyIC->getFacMin() != 0.5);
SolutionHistory is basically a container of SolutionStates. SolutionHistory maintains a collection of...
This composite TimeEvent loops over added TimeEvents.
TimeEventListIndex specifies a list of index events.
TimeEventList specifies a list of time events.
TimeEventRangeIndex specifies a start, stop and stride index.
TimeEventRange specifies a start, stop and stride time.
StepControlStrategy class for TimeStepControl.
TimeStepControlStrategyComposite loops over a vector of TimeStepControlStrategies.
StepControlStrategy class for TimeStepControl.
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)
Status
Status for the Integrator, the Stepper and the SolutionState.