9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
15 #include "Tempus_TimeEventRange.hpp"
16 #include "Tempus_TimeEventRangeIndex.hpp"
17 #include "Tempus_TimeEventList.hpp"
18 #include "Tempus_TimeEventListIndex.hpp"
21 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
24 static double PI = M_PI;
26 namespace Tempus_Unit_Test {
30 using Teuchos::rcp_const_cast;
31 using Teuchos::rcp_dynamic_cast;
39 "teRange1", 0.0, PI, 1.0, 1.0e-14,
true));
46 "teRange2", -PI/2.0, PI/2.0, PI/4.0, 1.0e-14,
true));
53 "teRange3", 4.0, 10.0, 4.0, 1.0e-14,
true));
62 std::vector<double> testList1;
63 testList1.push_back(-1.0);
64 testList1.push_back( 0.0);
65 testList1.push_back( 5.0);
66 testList1.push_back( 2.0);
67 testList1.push_back( PI);
70 "teList1", testList1, 1.0e-14,
true));
76 std::vector<double> testList2;
77 testList2.push_back(-0.5);
78 testList2.push_back( 1.25);
79 testList2.push_back( 4.95);
80 testList2.push_back(12.34);
83 "teList2", testList2, 1.0e-14,
true));
89 std::vector<double> testList3;
90 testList3.push_back(-5.0);
91 testList3.push_back(-PI);
94 "teList3", testList3, 1.0e-14,
true));
104 "teRangeIndex1", -1, 10, 3));
105 return teRangeIndex1;
111 "teRangeIndex2", -5, 8, 4));
112 return teRangeIndex2;
118 "teRangeIndex3", 10, 17, 5));
119 return teRangeIndex3;
127 std::vector<int> testListIndex1;
128 testListIndex1.push_back(-2);
129 testListIndex1.push_back( 0);
130 testListIndex1.push_back( 7);
131 testListIndex1.push_back( 3);
132 testListIndex1.push_back(-5);
135 "teListIndex1", testListIndex1));
141 std::vector<int> testListIndex2;
142 testListIndex2.push_back( 2);
145 "teListIndex2", testListIndex2));
151 std::vector<int> testListIndex3;
152 testListIndex3.push_back(14);
153 testListIndex3.push_back( 9);
156 "teListIndex3", testListIndex3));
168 TEST_COMPARE(te->isTime(0.0), ==,
false);
169 TEST_FLOATING_EQUALITY(te->timeToNextEvent(0.0), te->getDefaultTime(), 1.0e-14);
170 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(0.0), te->getDefaultTime(), 1.0e-14);
171 TEST_COMPARE(te->eventInRange(0.0, 1.0), ==,
false);
173 TEST_COMPARE(te->isIndex(0), ==,
false);
174 TEST_COMPARE(te->indexToNextEvent(0), ==, te->getDefaultIndex());
175 TEST_COMPARE(te->indexOfNextEvent(0), ==, te->getDefaultIndex());
176 TEST_COMPARE(te->eventInRange(0, 10), ==,
false);
187 te->addTimeEvent(teRange1);
189 TEST_COMPARE(te->isTime(0.0), ==, true );
190 TEST_FLOATING_EQUALITY(te->timeToNextEvent(0.0), 0.0, 1.0e-14);
191 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.1), 2.0, 1.0e-14);
192 TEST_COMPARE(te->eventInRange(0.0, 1.0), ==, true );
204 te->addTimeEvent(teRange1);
205 te->addTimeEvent(teRange2);
208 TEST_COMPARE(te->isTime(0.0), ==, true );
209 TEST_FLOATING_EQUALITY(te->timeToNextEvent(0.1), PI/4.0-0.1, 1.0e-14);
210 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.1), PI/2.0, 1.0e-14);
211 TEST_COMPARE(te->eventInRange(0.0, 1.0), ==, true );
223 te->addTimeEvent(teRange3);
224 te->addTimeEvent(teRange2);
227 TEST_COMPARE(te->isTime(4.0), ==, true );
228 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.1), PI/2.0, 1.0e-14);
229 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(3.0), 4.0, 1.0e-14);
230 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(5.0), 8.0, 1.0e-14);
231 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(10.0), 8.0, 1.0e-14);
232 TEST_COMPARE(te->eventInRange(-3.0, -2.0), ==,
false);
233 TEST_COMPARE(te->eventInRange(-1.0, 0.0), ==, true );
234 TEST_COMPARE(te->eventInRange( 1.0, 2.0), ==, true );
235 TEST_COMPARE(te->eventInRange( 2.0, 3.0), ==,
false);
236 TEST_COMPARE(te->eventInRange( 5.0, 7.0), ==,
false);
237 TEST_COMPARE(te->eventInRange( 7.0, 9.0), ==, true );
238 TEST_COMPARE(te->eventInRange( 9.0, 11.0), ==,
false);
249 te->addTimeEvent(teList1);
251 TEST_COMPARE(te->isTime(2.0), ==, true );
252 TEST_FLOATING_EQUALITY(te->timeToNextEvent(3.5), 1.5, 1.0e-14);
253 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-2.0), -1.0, 1.0e-14);
254 TEST_COMPARE(te->eventInRange(4.99, 10.0), ==, true );
266 te->addTimeEvent(teList1);
267 te->addTimeEvent(teList2);
270 TEST_COMPARE(te->isTime(1.25), ==, true );
271 TEST_FLOATING_EQUALITY(te->timeToNextEvent(4.0), 0.95, 1.0e-14);
272 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(6.5), 12.34, 1.0e-14);
273 TEST_COMPARE(te->eventInRange(0.1, 1.0), ==,
false);
285 te->addTimeEvent(teList3);
286 te->addTimeEvent(teList2);
289 TEST_COMPARE(te->isTime(4.0), ==,
false);
290 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-8.9), -5.0, 1.0e-14);
291 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-0.3), 1.25, 1.0e-14);
292 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-4.0), -PI, 1.0e-14);
293 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(20.0), 12.34, 1.0e-14);
294 TEST_COMPARE(te->eventInRange(-6.0, -4.0), ==, true );
295 TEST_COMPARE(te->eventInRange(-3.0, 0.0), ==, true );
296 TEST_COMPARE(te->eventInRange( 2.0, 3.0), ==,
false);
297 TEST_COMPARE(te->eventInRange( 4.9, 5.1), ==, true );
298 TEST_COMPARE(te->eventInRange(12.0, 12.4), ==, true );
299 TEST_COMPARE(te->eventInRange(14.0, 15.0), ==,
false);
310 te->addTimeEvent(teRangeIndex1);
312 TEST_COMPARE(te->isIndex(5), ==, true );
313 TEST_COMPARE(te->indexToNextEvent(3), ==, 2);
314 TEST_COMPARE(te->indexOfNextEvent(3), ==, 5);
315 TEST_COMPARE(te->eventInRangeIndex(3, 9), ==, true );
327 te->addTimeEvent(teRangeIndex1);
328 te->addTimeEvent(teRangeIndex2);
331 TEST_COMPARE(te->isIndex(-1), ==, true );
332 TEST_COMPARE(te->indexToNextEvent(-2), ==, 1);
333 TEST_COMPARE(te->indexOfNextEvent( 2), ==, 2);
334 TEST_COMPARE(te->eventInRangeIndex(0, 1), ==,
false);
346 te->addTimeEvent(teRangeIndex3);
347 te->addTimeEvent(teRangeIndex2);
350 TEST_COMPARE(te->isIndex(15), ==, true );
351 TEST_COMPARE(te->indexOfNextEvent( 9), ==, 10);
352 TEST_COMPARE(te->indexOfNextEvent(-6), ==, -5);
353 TEST_COMPARE(te->indexOfNextEvent( 6), ==, 7);
354 TEST_COMPARE(te->indexOfNextEvent(16), ==, 15);
355 TEST_COMPARE(te->eventInRangeIndex(-3, -2), ==,
false);
356 TEST_COMPARE(te->eventInRangeIndex(-1, 0), ==, true );
357 TEST_COMPARE(te->eventInRangeIndex( 1, 2), ==,
false);
358 TEST_COMPARE(te->eventInRangeIndex( 7, 8), ==, true );
359 TEST_COMPARE(te->eventInRangeIndex( 8, 9), ==,
false);
360 TEST_COMPARE(te->eventInRangeIndex(10, 13), ==, true );
361 TEST_COMPARE(te->eventInRangeIndex(14, 20), ==, true );
372 te->addTimeEvent(teListIndex1);
374 TEST_COMPARE(te->isIndex(3), ==, true );
375 TEST_COMPARE(te->indexToNextEvent(1), ==, 2);
376 TEST_COMPARE(te->indexOfNextEvent(4), ==, 7);
377 TEST_COMPARE(te->eventInRangeIndex(1, 3), ==, true );
389 te->addTimeEvent(teListIndex1);
390 te->addTimeEvent(teListIndex2);
393 TEST_COMPARE(te->isIndex(2), ==, true );
394 TEST_COMPARE(te->indexToNextEvent(0), ==, 0);
395 TEST_COMPARE(te->indexOfNextEvent(1), ==, 2);
396 TEST_COMPARE(te->eventInRangeIndex(-1, 3), ==, true );
408 te->addTimeEvent(teListIndex3);
409 te->addTimeEvent(teListIndex2);
412 TEST_COMPARE(te->isIndex(14), ==, true );
413 TEST_COMPARE(te->indexOfNextEvent(2), ==, 2);
414 TEST_COMPARE(te->indexOfNextEvent(5), ==, 9);
415 TEST_COMPARE(te->indexOfNextEvent(19), ==, 14);
416 TEST_COMPARE(te->eventInRangeIndex( 0, 1), ==,
false);
417 TEST_COMPARE(te->eventInRangeIndex( 3, 10), ==, true );
418 TEST_COMPARE(te->eventInRangeIndex(15, 20), ==,
false);
432 te->addTimeEvent(teRange1);
433 te->addTimeEvent(teList1);
434 te->addTimeEvent(teRangeIndex1);
435 te->addTimeEvent(teListIndex1);
437 TEST_COMPARE(te->isTime (3.0), ==, true );
438 TEST_COMPARE(te->isTime (2.0), ==, true );
439 TEST_COMPARE(te->isIndex( 2), ==, true );
440 TEST_COMPARE(te->isIndex( 3), ==, true );
442 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-2.5), 1.5, 1.0e-14);
443 TEST_FLOATING_EQUALITY(te->timeToNextEvent( 0.5), 0.5, 1.0e-14);
444 TEST_FLOATING_EQUALITY(te->timeToNextEvent( 4.5), 0.5, 1.0e-14);
445 TEST_FLOATING_EQUALITY(te->timeToNextEvent( 7.5), -2.5, 1.0e-14);
447 TEST_COMPARE(te->indexToNextEvent(-6), ==, 1);
448 TEST_COMPARE(te->indexToNextEvent( 1), ==, 1);
449 TEST_COMPARE(te->indexToNextEvent( 7), ==, 0);
450 TEST_COMPARE(te->indexToNextEvent( 9), ==, -1);
452 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( -PI), -1.0, 1.0e-14);
453 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-0.5), 0.0, 1.0e-14);
454 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( 2.5), 3.0, 1.0e-14);
455 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( 7.5), 5.0, 1.0e-14);
457 TEST_COMPARE(te->indexOfNextEvent(-6), ==, -5);
458 TEST_COMPARE(te->indexOfNextEvent( 1), ==, 2);
459 TEST_COMPARE(te->indexOfNextEvent( 7), ==, 7);
460 TEST_COMPARE(te->indexOfNextEvent( 9), ==, 8);
462 TEST_COMPARE(te->eventInRange(-5.0, -2.0), ==,
false);
463 TEST_COMPARE(te->eventInRange(-2.0, -0.5), ==, true );
464 TEST_COMPARE(te->eventInRange( 1.2, 1.8), ==,
false);
465 TEST_COMPARE(te->eventInRange( 3.1, 4.0), ==, true );
466 TEST_COMPARE(te->eventInRange( 4.5, 6.0), ==, true );
468 TEST_COMPARE(te->eventInRangeIndex(-8, -6), ==,
false);
469 TEST_COMPARE(te->eventInRangeIndex( 1, 1), ==,
false);
470 TEST_COMPARE(te->eventInRangeIndex( 5, 7), ==, true );
471 TEST_COMPARE(te->eventInRangeIndex( 8, 10), ==, true );
472 TEST_COMPARE(te->eventInRangeIndex(12, 14), ==,
false);
Teuchos::RCP< Tempus::TimeEventRange< double > > getTestRange3()
TimeEventRangeIndex specifies a start, stop and stride index.
Teuchos::RCP< Tempus::TimeEventRange< double > > getTestRange2()
Teuchos::RCP< Tempus::TimeEventListIndex< double > > getTestListIndex2()
TimeEventListIndex specifies a list of index events.
Teuchos::RCP< Tempus::TimeEventRangeIndex< double > > getTestRangeIndex3()
Teuchos::RCP< Tempus::TimeEventList< double > > getTestList3()
Teuchos::RCP< Tempus::TimeEventRange< double > > getTestRange1()
TimeEventRange specifies a start, stop and stride time.
Teuchos::RCP< Tempus::TimeEventList< double > > getTestList1()
This composite TimeEvent loops over added TimeEvents.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
Teuchos::RCP< Tempus::TimeEventListIndex< double > > getTestListIndex3()
Teuchos::RCP< Tempus::TimeEventListIndex< double > > getTestListIndex1()
Teuchos::RCP< Tempus::TimeEventRangeIndex< double > > getTestRangeIndex1()
Teuchos::RCP< Tempus::TimeEventList< double > > getTestList2()
Teuchos::RCP< Tempus::TimeEventRangeIndex< double > > getTestRangeIndex2()
TimeEventList specifies a list of time events.