Tempus  Version of the Day
Time Integration
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Tempus_UnitTest_TimeEventComposite.cpp
Go to the documentation of this file.
1 //@HEADER
2 // *****************************************************************************
3 // Tempus: Time Integration and Sensitivity Analysis Package
4 //
5 // Copyright 2017 NTESS and the Tempus contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 //@HEADER
9 
11 
13 #include "Tempus_TimeEventRange.hpp"
14 #include "Tempus_TimeEventRangeIndex.hpp"
15 #include "Tempus_TimeEventList.hpp"
16 #include "Tempus_TimeEventListIndex.hpp"
17 
18 static double PI = M_PI;
19 
20 namespace Tempus_Unit_Test {
21 
22 using Teuchos::RCP;
23 using Teuchos::rcp;
24 using Teuchos::rcp_const_cast;
25 using Teuchos::rcp_dynamic_cast;
26 
27 // TimeEventRanges for testing.
28 // ------------------------------------------------------------
30 {
31  auto teRange1 = rcp(new Tempus::TimeEventRange<double>(
32  0.0, PI, 1.0, "teRange1", true, 1.0e-14));
33  return teRange1;
34 }
35 
37 {
38  auto teRange2 = rcp(new Tempus::TimeEventRange<double>(
39  -PI / 2.0, PI / 2.0, PI / 4.0, "teRange2", true, 1.0e-14));
40  return teRange2;
41 }
42 
44 {
45  auto teRange3 = rcp(new Tempus::TimeEventRange<double>(
46  4.0, 10.0, 4.0, "teRange3", true, 1.0e-14));
47  return teRange3;
48 }
49 
50 // TimeEventLists for testing.
51 // ------------------------------------------------------------
53 {
54  std::vector<double> testList1;
55  testList1.push_back(-1.0);
56  testList1.push_back(0.0);
57  testList1.push_back(5.0);
58  testList1.push_back(2.0);
59  testList1.push_back(PI);
60 
61  auto teList1 = rcp(
62  new Tempus::TimeEventList<double>(testList1, "teList1", true, 1.0e-14));
63  return teList1;
64 }
65 
67 {
68  std::vector<double> testList2;
69  testList2.push_back(-0.5);
70  testList2.push_back(1.25);
71  testList2.push_back(4.95);
72  testList2.push_back(12.34);
73 
74  auto teList2 = rcp(
75  new Tempus::TimeEventList<double>(testList2, "teList2", true, 1.0e-14));
76  return teList2;
77 }
78 
80 {
81  std::vector<double> testList3;
82  testList3.push_back(-5.0);
83  testList3.push_back(-PI);
84 
85  auto teList3 = rcp(
86  new Tempus::TimeEventList<double>(testList3, "teList3", true, 1.0e-14));
87  return teList3;
88 }
89 
90 // TimeEventRangeIndices for testing.
91 // ------------------------------------------------------------
93 {
94  auto teRangeIndex1 =
95  rcp(new Tempus::TimeEventRangeIndex<double>(-1, 10, 3, "teRangeIndex1"));
96  return teRangeIndex1;
97 }
98 
100 {
101  auto teRangeIndex2 =
102  rcp(new Tempus::TimeEventRangeIndex<double>(-5, 8, 4, "teRangeIndex2"));
103  return teRangeIndex2;
104 }
105 
107 {
108  auto teRangeIndex3 =
109  rcp(new Tempus::TimeEventRangeIndex<double>(10, 17, 5, "teRangeIndex3"));
110  return teRangeIndex3;
111 }
112 
113 // TimeEventRangeIndices for testing.
114 // ------------------------------------------------------------
116 {
117  std::vector<int> testListIndex1;
118  testListIndex1.push_back(-2);
119  testListIndex1.push_back(0);
120  testListIndex1.push_back(7);
121  testListIndex1.push_back(3);
122  testListIndex1.push_back(-5);
123 
124  auto teListIndex1 = rcp(
125  new Tempus::TimeEventListIndex<double>(testListIndex1, "teListIndex1"));
126  return teListIndex1;
127 }
128 
130 {
131  std::vector<int> testListIndex2;
132  testListIndex2.push_back(2);
133 
134  auto teListIndex2 = rcp(
135  new Tempus::TimeEventListIndex<double>(testListIndex2, "teListIndex2"));
136  return teListIndex2;
137 }
138 
140 {
141  std::vector<int> testListIndex3;
142  testListIndex3.push_back(14);
143  testListIndex3.push_back(9);
144 
145  auto teListIndex3 = rcp(
146  new Tempus::TimeEventListIndex<double>(testListIndex3, "teListIndex3"));
147 
148  return teListIndex3;
149 }
150 
151 // ************************************************************
152 // ************************************************************
153 TEUCHOS_UNIT_TEST(TimeEventComposite, Default_Construction)
154 {
155  auto tec = rcp(new Tempus::TimeEventComposite<double>());
156 
157  TEST_COMPARE(tec->getType(), ==, "Composite");
158  TEST_COMPARE(tec->getName(), ==, "TimeEventComposite");
159  TEST_COMPARE(tec->isTime(0.0), ==, false);
160  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(0.0), tec->getDefaultTime(),
161  1.0e-14);
162  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(0.0), tec->getDefaultTime(),
163  1.0e-14);
164  TEST_COMPARE(tec->eventInRange(0.0, 1.0), ==, false);
165 
166  TEST_COMPARE(tec->isIndex(0), ==, false);
167  TEST_COMPARE(tec->indexToNextEvent(0), ==, tec->getDefaultIndex());
168  TEST_COMPARE(tec->indexOfNextEvent(0), ==, tec->getDefaultIndex());
169  TEST_COMPARE(tec->eventInRange(0, 10), ==, false);
170 
171  auto timeEvents = tec->getTimeEvents();
172  TEST_COMPARE(timeEvents.size(), ==, 0);
173 }
174 
175 // ************************************************************
176 // ************************************************************
177 TEUCHOS_UNIT_TEST(TimeEventComposite, Full_Construction)
178 {
179  std::vector<Teuchos::RCP<Tempus::TimeEventBase<double> > > timeEvents;
180  timeEvents.push_back(getTestRange1());
181  timeEvents.push_back(getTestList1());
182  timeEvents.push_back(getTestRangeIndex1());
183  timeEvents.push_back(getTestListIndex1());
184 
186  timeEvents, "Test TimeEventComposite"));
187  // tec->describe(out, Teuchos::VERB_EXTREME);
188 
189  TEST_COMPARE(tec->getType(), ==, "Composite");
190  TEST_COMPARE(tec->getName(), ==, "Test TimeEventComposite");
191 
192  TEST_COMPARE(tec->isTime(3.0), ==, true);
193  TEST_COMPARE(tec->isTime(2.0), ==, true);
194  TEST_COMPARE(tec->isIndex(2), ==, true);
195  TEST_COMPARE(tec->isIndex(3), ==, true);
196 
197  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(-2.5), 1.5, 1.0e-14);
198  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(0.5), 0.5, 1.0e-14);
199  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(4.5), 0.5, 1.0e-14);
200  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(7.5), tec->getDefaultTime(),
201  1.0e-14);
202 
203  TEST_COMPARE(tec->indexToNextEvent(-6), ==, 1);
204  TEST_COMPARE(tec->indexToNextEvent(1), ==, 1);
205  TEST_COMPARE(tec->indexToNextEvent(7), ==, 1);
206  TEST_COMPARE(tec->indexToNextEvent(9), ==, tec->getDefaultIndex() - 9);
207 
208  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-PI), -1.0, 1.0e-14);
209  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-0.5), 0.0, 1.0e-14);
210  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(2.5), 3.0, 1.0e-14);
211  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(7.5), tec->getDefaultTime(),
212  1.0e-14);
213 
214  TEST_COMPARE(tec->indexOfNextEvent(-6), ==, -5);
215  TEST_COMPARE(tec->indexOfNextEvent(1), ==, 2);
216  TEST_COMPARE(tec->indexOfNextEvent(7), ==, 8);
217  TEST_COMPARE(tec->indexOfNextEvent(9), ==, tec->getDefaultIndex());
218 
219  TEST_COMPARE(tec->eventInRange(-5.0, -2.0), ==, false);
220  TEST_COMPARE(tec->eventInRange(-2.0, -0.5), ==, true);
221  TEST_COMPARE(tec->eventInRange(1.2, 1.8), ==, false);
222  TEST_COMPARE(tec->eventInRange(3.1, 4.0), ==, true);
223  TEST_COMPARE(tec->eventInRange(4.5, 6.0), ==, true);
224 
225  TEST_COMPARE(tec->eventInRangeIndex(-8, -6), ==, false);
226  TEST_COMPARE(tec->eventInRangeIndex(1, 1), ==, false);
227  TEST_COMPARE(tec->eventInRangeIndex(5, 7), ==, true);
228  TEST_COMPARE(tec->eventInRangeIndex(8, 10), ==, false);
229  TEST_COMPARE(tec->eventInRangeIndex(12, 14), ==, false);
230 
231  timeEvents = tec->getTimeEvents();
232  TEST_COMPARE(timeEvents.size(), ==, 4);
233 }
234 
235 // ************************************************************
236 // ************************************************************
237 TEUCHOS_UNIT_TEST(TimeEventComposite, setTimeEvents)
238 {
239  std::vector<Teuchos::RCP<Tempus::TimeEventBase<double> > > timeEvents;
240  timeEvents.push_back(getTestRange1());
241  timeEvents.push_back(getTestList1());
242  timeEvents.push_back(getTestRangeIndex1());
243  timeEvents.push_back(getTestListIndex1());
244 
245  auto tec = rcp(new Tempus::TimeEventComposite<double>());
246 
247  tec->setTimeEvents(timeEvents);
248 
249  auto timeEventsSet = tec->getTimeEvents();
250  TEST_COMPARE(timeEventsSet.size(), ==, 4);
251 }
252 
253 // ************************************************************
254 // ************************************************************
255 TEUCHOS_UNIT_TEST(TimeEventComposite, One_TimeEventRange)
256 {
257  auto tec = rcp(new Tempus::TimeEventComposite<double>());
258  auto teRange1 = getTestRange1();
259 
260  tec->add(teRange1);
261  // tec->describe(out, Teuchos::VERB_EXTREME);
262 
263  TEST_COMPARE(tec->isTime(0.0), ==, true);
264  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(0.0), 1.0, 1.0e-14);
265  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(1.1), 2.0, 1.0e-14);
266  TEST_COMPARE(tec->eventInRange(0.0, 1.0), ==, true);
267 
268  auto timeEvents = tec->getTimeEvents();
269  TEST_COMPARE(timeEvents.size(), ==, 1);
270 }
271 
272 // ************************************************************
273 // ************************************************************
274 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoOverlapping_TimeEventRanges)
275 {
276  auto tec = rcp(new Tempus::TimeEventComposite<double>());
277  auto teRange1 = getTestRange1();
278  auto teRange2 = getTestRange2();
279 
280  tec->add(teRange1);
281  tec->add(teRange2);
282  // tec->describe(out, Teuchos::VERB_EXTREME);
283 
284  TEST_COMPARE(tec->isTime(0.0), ==, true);
285  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(0.1), PI / 4.0 - 0.1, 1.0e-14);
286  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(1.1), PI / 2.0, 1.0e-14);
287  TEST_COMPARE(tec->eventInRange(0.0, 1.0), ==, true);
288 
289  auto timeEvents = tec->getTimeEvents();
290  TEST_COMPARE(timeEvents.size(), ==, 2);
291 }
292 
293 // ************************************************************
294 // ************************************************************
295 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoSeparated_TimeEventRanges)
296 {
297  auto tec = rcp(new Tempus::TimeEventComposite<double>());
298  auto teRange3 = getTestRange3();
299  auto teRange2 = getTestRange2();
300 
301  tec->add(teRange3);
302  tec->add(teRange2);
303  tec->describe(out, Teuchos::VERB_EXTREME);
304 
305  TEST_COMPARE(tec->isTime(4.0), ==, true);
306  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(1.1), PI / 2.0, 1.0e-14);
307  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(3.0), 4.0, 1.0e-14);
308  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(5.0), 8.0, 1.0e-14);
309  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(10.0), tec->getDefaultTime(),
310  1.0e-14);
311  TEST_COMPARE(tec->eventInRange(-3.0, -2.0), ==, false);
312  TEST_COMPARE(tec->eventInRange(-1.0, 0.0), ==, true);
313  TEST_COMPARE(tec->eventInRange(1.0, 2.0), ==, true);
314  TEST_COMPARE(tec->eventInRange(2.0, 3.0), ==, false);
315  TEST_COMPARE(tec->eventInRange(5.0, 7.0), ==, false);
316  TEST_COMPARE(tec->eventInRange(7.0, 9.0), ==, true);
317  TEST_COMPARE(tec->eventInRange(9.0, 11.0), ==, false);
318 
319  auto timeEvents = tec->getTimeEvents();
320  TEST_COMPARE(timeEvents.size(), ==, 2);
321 }
322 
323 // ************************************************************
324 // ************************************************************
325 TEUCHOS_UNIT_TEST(TimeEventComposite, One_TimeEventList)
326 {
327  auto tec = rcp(new Tempus::TimeEventComposite<double>());
328  auto teList1 = getTestList1();
329 
330  tec->add(teList1);
331  // tec->describe(out, Teuchos::VERB_EXTREME);
332 
333  TEST_COMPARE(tec->isTime(2.0), ==, true);
334  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(3.5), 1.5, 1.0e-14);
335  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-2.0), -1.0, 1.0e-14);
336  TEST_COMPARE(tec->eventInRange(4.99, 10.0), ==, true);
337 
338  auto timeEvents = tec->getTimeEvents();
339  TEST_COMPARE(timeEvents.size(), ==, 1);
340 }
341 
342 // ************************************************************
343 // ************************************************************
344 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoOverlapping_TimeEventLists)
345 {
346  auto tec = rcp(new Tempus::TimeEventComposite<double>());
347  auto teList1 = getTestList1();
348  auto teList2 = getTestList2();
349 
350  tec->add(teList1);
351  tec->add(teList2);
352  // tec->describe(out, Teuchos::VERB_EXTREME);
353 
354  TEST_COMPARE(tec->isTime(1.25), ==, true);
355  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(4.0), 0.95, 1.0e-14);
356  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(6.5), 12.34, 1.0e-14);
357  TEST_COMPARE(tec->eventInRange(0.1, 1.0), ==, false);
358 
359  auto timeEvents = tec->getTimeEvents();
360  TEST_COMPARE(timeEvents.size(), ==, 2);
361 }
362 
363 // ************************************************************
364 // ************************************************************
365 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoSeparated_TimeEventLists)
366 {
367  auto tec = rcp(new Tempus::TimeEventComposite<double>());
368  auto teList3 = getTestList3();
369  auto teList2 = getTestList2();
370 
371  tec->add(teList3);
372  tec->add(teList2);
373  // tec->describe(out, Teuchos::VERB_EXTREME);
374 
375  TEST_COMPARE(tec->isTime(4.0), ==, false);
376  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-8.9), -5.0, 1.0e-14);
377  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-0.3), 1.25, 1.0e-14);
378  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-4.0), -PI, 1.0e-14);
379  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(20.0), tec->getDefaultTime(),
380  1.0e-14);
381  TEST_COMPARE(tec->eventInRange(-6.0, -4.0), ==, true);
382  TEST_COMPARE(tec->eventInRange(-3.0, 0.0), ==, true);
383  TEST_COMPARE(tec->eventInRange(2.0, 3.0), ==, false);
384  TEST_COMPARE(tec->eventInRange(4.9, 5.1), ==, true);
385  TEST_COMPARE(tec->eventInRange(12.0, 12.4), ==, true);
386  TEST_COMPARE(tec->eventInRange(14.0, 15.0), ==, false);
387 
388  auto timeEvents = tec->getTimeEvents();
389  TEST_COMPARE(timeEvents.size(), ==, 2);
390 }
391 
392 // ************************************************************
393 // ************************************************************
394 TEUCHOS_UNIT_TEST(TimeEventComposite, One_TimeEventRangeIndex)
395 {
396  auto tec = rcp(new Tempus::TimeEventComposite<double>());
397  auto teRangeIndex1 = getTestRangeIndex1();
398 
399  tec->add(teRangeIndex1);
400  // tec->describe(out, Teuchos::VERB_EXTREME);
401 
402  TEST_COMPARE(tec->isIndex(5), ==, true);
403  TEST_COMPARE(tec->indexToNextEvent(3), ==, 2);
404  TEST_COMPARE(tec->indexOfNextEvent(3), ==, 5);
405  TEST_COMPARE(tec->eventInRangeIndex(3, 9), ==, true);
406 
407  auto timeEvents = tec->getTimeEvents();
408  TEST_COMPARE(timeEvents.size(), ==, 1);
409 }
410 
411 // ************************************************************
412 // ************************************************************
413 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoOverlapping_TimeEventRangeIndex)
414 {
415  auto tec = rcp(new Tempus::TimeEventComposite<double>());
416  auto teRangeIndex1 = getTestRangeIndex1();
417  auto teRangeIndex2 = getTestRangeIndex2();
418 
419  tec->add(teRangeIndex1);
420  tec->add(teRangeIndex2);
421  // tec->describe(out, Teuchos::VERB_EXTREME);
422 
423  TEST_COMPARE(tec->isIndex(-1), ==, true);
424  TEST_COMPARE(tec->indexToNextEvent(-2), ==, 1);
425  TEST_COMPARE(tec->indexOfNextEvent(2), ==, 3);
426  TEST_COMPARE(tec->eventInRangeIndex(0, 1), ==, false);
427 
428  auto timeEvents = tec->getTimeEvents();
429  TEST_COMPARE(timeEvents.size(), ==, 2);
430 }
431 
432 // ************************************************************
433 // ************************************************************
434 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoSeparate_TimeEventRangeIndex)
435 {
436  auto tec = rcp(new Tempus::TimeEventComposite<double>());
437  auto teRangeIndex3 = getTestRangeIndex3();
438  auto teRangeIndex2 = getTestRangeIndex2();
439 
440  tec->add(teRangeIndex3);
441  tec->add(teRangeIndex2);
442  // tec->describe(out, Teuchos::VERB_EXTREME);
443 
444  TEST_COMPARE(tec->isIndex(15), ==, true);
445  TEST_COMPARE(tec->indexOfNextEvent(9), ==, 10);
446  TEST_COMPARE(tec->indexOfNextEvent(-6), ==, -5);
447  TEST_COMPARE(tec->indexOfNextEvent(6), ==, 7);
448  TEST_COMPARE(tec->indexOfNextEvent(16), ==, tec->getDefaultIndex());
449  TEST_COMPARE(tec->eventInRangeIndex(-3, -2), ==, false);
450  TEST_COMPARE(tec->eventInRangeIndex(-2, 0), ==, true);
451  TEST_COMPARE(tec->eventInRangeIndex(1, 2), ==, false);
452  TEST_COMPARE(tec->eventInRangeIndex(6, 7), ==, true);
453  TEST_COMPARE(tec->eventInRangeIndex(7, 8), ==, false);
454  TEST_COMPARE(tec->eventInRangeIndex(10, 13), ==, false);
455  TEST_COMPARE(tec->eventInRangeIndex(14, 20), ==, true);
456 
457  auto timeEvents = tec->getTimeEvents();
458  TEST_COMPARE(timeEvents.size(), ==, 2);
459 }
460 
461 // ************************************************************
462 // ************************************************************
463 TEUCHOS_UNIT_TEST(TimeEventComposite, One_TimeEventListIndex)
464 {
465  auto tec = rcp(new Tempus::TimeEventComposite<double>());
466  auto teListIndex1 = getTestListIndex1();
467 
468  tec->add(teListIndex1);
469  // tec->describe(out, Teuchos::VERB_EXTREME);
470 
471  TEST_COMPARE(tec->isIndex(3), ==, true);
472  TEST_COMPARE(tec->indexToNextEvent(1), ==, 2);
473  TEST_COMPARE(tec->indexOfNextEvent(4), ==, 7);
474  TEST_COMPARE(tec->eventInRangeIndex(1, 3), ==, true);
475 
476  auto timeEvents = tec->getTimeEvents();
477  TEST_COMPARE(timeEvents.size(), ==, 1);
478 }
479 
480 // ************************************************************
481 // ************************************************************
482 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoOverlapping_TimeEventListIndex)
483 {
484  auto tec = rcp(new Tempus::TimeEventComposite<double>());
485  auto teListIndex1 = getTestListIndex1();
486  auto teListIndex2 = getTestListIndex2();
487 
488  tec->add(teListIndex1);
489  tec->add(teListIndex2);
490  // tec->describe(out, Teuchos::VERB_EXTREME);
491 
492  TEST_COMPARE(tec->isIndex(2), ==, true);
493  TEST_COMPARE(tec->indexToNextEvent(0), ==, 2);
494  TEST_COMPARE(tec->indexOfNextEvent(1), ==, 2);
495  TEST_COMPARE(tec->eventInRangeIndex(-1, 3), ==, true);
496 
497  auto timeEvents = tec->getTimeEvents();
498  TEST_COMPARE(timeEvents.size(), ==, 2);
499 }
500 
501 // ************************************************************
502 // ************************************************************
503 TEUCHOS_UNIT_TEST(TimeEventComposite, TwoSeparate_TimeEventListIndex)
504 {
505  auto tec = rcp(new Tempus::TimeEventComposite<double>());
506  auto teListIndex3 = getTestListIndex3();
507  auto teListIndex2 = getTestListIndex2();
508 
509  tec->add(teListIndex3);
510  tec->add(teListIndex2);
511  // tec->describe(out, Teuchos::VERB_EXTREME);
512 
513  TEST_COMPARE(tec->isIndex(14), ==, true);
514  TEST_COMPARE(tec->indexOfNextEvent(2), ==, 9);
515  TEST_COMPARE(tec->indexOfNextEvent(5), ==, 9);
516  TEST_COMPARE(tec->indexOfNextEvent(19), ==, tec->getDefaultIndex());
517  TEST_COMPARE(tec->eventInRangeIndex(0, 1), ==, false);
518  TEST_COMPARE(tec->eventInRangeIndex(3, 10), ==, true);
519  TEST_COMPARE(tec->eventInRangeIndex(15, 20), ==, false);
520 
521  auto timeEvents = tec->getTimeEvents();
522  TEST_COMPARE(timeEvents.size(), ==, 2);
523 }
524 
525 // ************************************************************
526 // ************************************************************
527 TEUCHOS_UNIT_TEST(TimeEventComposite, OneOfEach_TimeEvent)
528 {
529  auto tec = rcp(new Tempus::TimeEventComposite<double>());
530  auto teRange1 = getTestRange1();
531  auto teList1 = getTestList1();
532  auto teRangeIndex1 = getTestRangeIndex1();
533  auto teListIndex1 = getTestListIndex1();
534 
535  tec->add(teRange1);
536  tec->add(teList1);
537  tec->add(teRangeIndex1);
538  tec->add(teListIndex1);
539  // tec->describe(out, Teuchos::VERB_EXTREME);
540 
541  TEST_COMPARE(tec->isTime(3.0), ==, true);
542  TEST_COMPARE(tec->isTime(2.0), ==, true);
543  TEST_COMPARE(tec->isIndex(2), ==, true);
544  TEST_COMPARE(tec->isIndex(3), ==, true);
545 
546  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(-2.5), 1.5, 1.0e-14);
547  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(0.5), 0.5, 1.0e-14);
548  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(4.5), 0.5, 1.0e-14);
549  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(7.5), tec->getDefaultTime(),
550  1.0e-14);
551 
552  TEST_COMPARE(tec->indexToNextEvent(-6), ==, 1);
553  TEST_COMPARE(tec->indexToNextEvent(1), ==, 1);
554  TEST_COMPARE(tec->indexToNextEvent(7), ==, 1);
555  TEST_COMPARE(tec->indexToNextEvent(9), ==, tec->getDefaultIndex() - 9);
556 
557  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-PI), -1.0, 1.0e-14);
558  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-0.5), 0.0, 1.0e-14);
559  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(2.5), 3.0, 1.0e-14);
560  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(7.5), tec->getDefaultTime(),
561  1.0e-14);
562 
563  TEST_COMPARE(tec->indexOfNextEvent(-6), ==, -5);
564  TEST_COMPARE(tec->indexOfNextEvent(1), ==, 2);
565  TEST_COMPARE(tec->indexOfNextEvent(7), ==, 8);
566  TEST_COMPARE(tec->indexOfNextEvent(9), ==, tec->getDefaultIndex());
567 
568  TEST_COMPARE(tec->eventInRange(-5.0, -2.0), ==, false);
569  TEST_COMPARE(tec->eventInRange(-2.0, -0.5), ==, true);
570  TEST_COMPARE(tec->eventInRange(1.2, 1.8), ==, false);
571  TEST_COMPARE(tec->eventInRange(3.1, 4.0), ==, true);
572  TEST_COMPARE(tec->eventInRange(4.5, 6.0), ==, true);
573 
574  TEST_COMPARE(tec->eventInRangeIndex(-8, -6), ==, false);
575  TEST_COMPARE(tec->eventInRangeIndex(1, 1), ==, false);
576  TEST_COMPARE(tec->eventInRangeIndex(5, 7), ==, true);
577  TEST_COMPARE(tec->eventInRangeIndex(7, 10), ==, true);
578  TEST_COMPARE(tec->eventInRangeIndex(12, 14), ==, false);
579 
580  auto timeEvents = tec->getTimeEvents();
581  TEST_COMPARE(timeEvents.size(), ==, 4);
582 }
583 
584 // ************************************************************
585 // ************************************************************
586 TEUCHOS_UNIT_TEST(TimeEventComposite, OneOfEach_Plus_TimeEvent)
587 {
588  auto tec = rcp(new Tempus::TimeEventComposite<double>());
589  auto teRange1 = getTestRange1();
590  auto teList1 = getTestList1();
591  auto teRangeIndex1 = getTestRangeIndex1();
592  auto teListIndex1 = getTestListIndex1();
593 
594  tec->add(teRange1);
595  tec->add(teList1);
596  tec->add(teRangeIndex1);
597  tec->add(teListIndex1);
598  // tec->describe(out, Teuchos::VERB_EXTREME);
599 
600  // Constraining TimeEvent(s)
601  std::vector<Teuchos::RCP<Tempus::TimeEventBase<double> > > teCons;
602 
603  TEST_COMPARE(tec->isTime(3.0, teCons), ==, true);
604  TEST_COMPARE(teCons.size(), ==, 1);
605  TEST_COMPARE(teCons[0]->getName(), ==, "teRange1");
606 
607  TEST_COMPARE(tec->isTime(-1.0, teCons), ==, true);
608  TEST_COMPARE(teCons.size(), ==, 1);
609  TEST_COMPARE(teCons[0]->getName(), ==, "teList1");
610 
611  TEST_COMPARE(tec->isIndex(2, teCons), ==, true);
612  TEST_COMPARE(teCons.size(), ==, 1);
613  TEST_COMPARE(teCons[0]->getName(), ==, "teRangeIndex1");
614 
615  TEST_COMPARE(tec->isIndex(-2, teCons), ==, true);
616  TEST_COMPARE(teCons.size(), ==, 1);
617  TEST_COMPARE(teCons[0]->getName(), ==, "teListIndex1");
618 
619  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(-2.5, teCons), 1.5, 1.0e-14);
620  TEST_COMPARE(teCons.size(), ==, 1);
621  TEST_COMPARE(teCons[0]->getName(), ==, "teList1");
622 
623  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(0.5, teCons), 0.5, 1.0e-14);
624  TEST_COMPARE(teCons.size(), ==, 1);
625  TEST_COMPARE(teCons[0]->getName(), ==, "teRange1");
626 
627  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(4.5, teCons), 0.5, 1.0e-14);
628  TEST_COMPARE(teCons.size(), ==, 1);
629  TEST_COMPARE(teCons[0]->getName(), ==, "teList1");
630 
631  TEST_FLOATING_EQUALITY(tec->timeToNextEvent(7.5, teCons),
632  tec->getDefaultTime(), 1.0e-14);
633  TEST_COMPARE(teCons.size(), ==, 0);
634 
635  TEST_COMPARE(tec->indexToNextEvent(-6, teCons), ==, 1);
636  TEST_COMPARE(teCons.size(), ==, 1);
637  TEST_COMPARE(teCons[0]->getName(), ==, "teListIndex1");
638 
639  TEST_COMPARE(tec->indexToNextEvent(1, teCons), ==, 1);
640  TEST_COMPARE(teCons.size(), ==, 1);
641  TEST_COMPARE(teCons[0]->getName(), ==, "teRangeIndex1");
642 
643  TEST_COMPARE(tec->indexToNextEvent(7, teCons), ==, 1);
644  TEST_COMPARE(teCons.size(), ==, 1);
645  TEST_COMPARE(teCons[0]->getName(), ==, "teRangeIndex1");
646 
647  TEST_COMPARE(tec->indexToNextEvent(9, teCons), ==,
648  tec->getDefaultIndex() - 9);
649  TEST_COMPARE(teCons.size(), ==, 0);
650 
651  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-PI, teCons), -1.0, 1.0e-14);
652  TEST_COMPARE(teCons.size(), ==, 1);
653  TEST_COMPARE(teCons[0]->getName(), ==, "teList1");
654 
655  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-0.5, teCons), 0.0, 1.0e-14);
656  TEST_COMPARE(teCons.size(), ==, 2);
657  TEST_COMPARE(teCons[0]->getName(), ==, "teRange1");
658  TEST_COMPARE(teCons[1]->getName(), ==, "teList1");
659 
660  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(2.5, teCons), 3.0, 1.0e-14);
661  TEST_COMPARE(teCons.size(), ==, 1);
662  TEST_COMPARE(teCons[0]->getName(), ==, "teRange1");
663 
664  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(7.5, teCons),
665  tec->getDefaultTime(), 1.0e-14);
666  TEST_COMPARE(teCons.size(), ==, 0);
667 
668  TEST_COMPARE(tec->indexOfNextEvent(-6, teCons), ==, -5);
669  TEST_COMPARE(teCons.size(), ==, 1);
670  TEST_COMPARE(teCons[0]->getName(), ==, "teListIndex1");
671 
672  TEST_COMPARE(tec->indexOfNextEvent(1, teCons), ==, 2);
673  TEST_COMPARE(teCons.size(), ==, 1);
674  TEST_COMPARE(teCons[0]->getName(), ==, "teRangeIndex1");
675 
676  TEST_COMPARE(tec->indexOfNextEvent(7, teCons), ==, 8);
677  TEST_COMPARE(teCons.size(), ==, 1);
678  TEST_COMPARE(teCons[0]->getName(), ==, "teRangeIndex1");
679 
680  TEST_COMPARE(tec->indexOfNextEvent(9, teCons), ==, tec->getDefaultIndex());
681  TEST_COMPARE(teCons.size(), ==, 0);
682 
683  TEST_COMPARE(tec->eventInRange(-5.0, -2.0, teCons), ==, false);
684  TEST_COMPARE(teCons.size(), ==, 0);
685  TEST_COMPARE(tec->eventInRange(-2.0, -0.5, teCons), ==, true);
686  TEST_COMPARE(teCons.size(), ==, 1);
687  TEST_COMPARE(tec->eventInRange(1.2, 1.8, teCons), ==, false);
688  TEST_COMPARE(teCons.size(), ==, 0);
689  TEST_COMPARE(tec->eventInRange(3.1, 4.0, teCons), ==, true);
690  TEST_COMPARE(teCons.size(), ==, 1);
691  TEST_COMPARE(tec->eventInRange(4.5, 6.0, teCons), ==, true);
692  TEST_COMPARE(teCons.size(), ==, 1);
693 
694  TEST_COMPARE(tec->eventInRangeIndex(-8, -6, teCons), ==, false);
695  TEST_COMPARE(teCons.size(), ==, 0);
696  TEST_COMPARE(tec->eventInRangeIndex(1, 1, teCons), ==, false);
697  TEST_COMPARE(teCons.size(), ==, 0);
698  TEST_COMPARE(tec->eventInRangeIndex(5, 7, teCons), ==, true);
699  TEST_COMPARE(teCons.size(), ==, 1);
700  TEST_COMPARE(tec->eventInRangeIndex(8, 10, teCons), ==, false);
701  TEST_COMPARE(teCons.size(), ==, 0);
702  TEST_COMPARE(tec->eventInRangeIndex(12, 14, teCons), ==, false);
703  TEST_COMPARE(teCons.size(), ==, 0);
704 
705  auto timeEvents = tec->getTimeEvents();
706  TEST_COMPARE(timeEvents.size(), ==, 4);
707 }
708 
709 // ************************************************************
710 // ************************************************************
711 TEUCHOS_UNIT_TEST(TimeEventComposite, Multiple_Simultaneous_Events)
712 {
713  // Define Events
714  auto ter1 = rcp(new Tempus::TimeEventRange<double>(0.0, 20.0, 5.0, "ter1",
715  true, 1.0e-14));
716  auto ter2 = rcp(new Tempus::TimeEventRange<double>(0.0, 20.0, 2.0, "ter2",
717  false, 1.0e-14));
718 
719  std::vector<double> testList1;
720  testList1.push_back(0.0);
721  testList1.push_back(4.0);
722  testList1.push_back(5.0);
723  testList1.push_back(9.0);
724  testList1.push_back(20.0);
725  auto tel1 =
726  rcp(new Tempus::TimeEventList<double>(testList1, "tel1", true, 1.0e-14));
727 
728  std::vector<double> testList2;
729  testList2.push_back(0.0);
730  testList2.push_back(3.0);
731  testList2.push_back(5.0);
732  testList2.push_back(13.0);
733  testList2.push_back(20.0);
734  auto tel2 =
735  rcp(new Tempus::TimeEventList<double>(testList2, "tel2", false, 1.0e-14));
736 
737  auto teri1 =
738  rcp(new Tempus::TimeEventRangeIndex<double>(0, 200, 50, "teri1"));
739  auto teri2 =
740  rcp(new Tempus::TimeEventRangeIndex<double>(0, 200, 20, "teri2"));
741 
742  std::vector<int> testListIndex1;
743  testListIndex1.push_back(0);
744  testListIndex1.push_back(40);
745  testListIndex1.push_back(50);
746  testListIndex1.push_back(90);
747  testListIndex1.push_back(200);
748  auto teli1 =
749  rcp(new Tempus::TimeEventListIndex<double>(testListIndex1, "teli1"));
750 
751  std::vector<int> testListIndex2;
752  testListIndex2.push_back(0);
753  testListIndex2.push_back(30);
754  testListIndex2.push_back(50);
755  testListIndex2.push_back(130);
756  testListIndex2.push_back(200);
757  auto teli2 =
758  rcp(new Tempus::TimeEventListIndex<double>(testListIndex2, "teli2"));
759 
760  auto tec = rcp(new Tempus::TimeEventComposite<double>());
761  tec->add(ter1);
762  tec->add(ter2);
763  tec->add(tel1);
764  tec->add(tel2);
765  tec->add(teri1);
766  tec->add(teri2);
767  tec->add(teli1);
768  tec->add(teli2);
769 
770  // tec->describe(out, Teuchos::VERB_EXTREME);
771 
772  // Constraining TimeEvent(s)
773  std::vector<Teuchos::RCP<Tempus::TimeEventBase<double> > > teCons;
774 
775  TEST_COMPARE(tec->isTime(0.0, teCons), ==, true);
776  TEST_COMPARE(teCons.size(), ==, 4);
777  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
778  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
779  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
780  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
781 
782  TEST_COMPARE(tec->isTime(5.0, teCons), ==, true);
783  TEST_COMPARE(teCons.size(), ==, 3);
784  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
785  TEST_COMPARE(teCons[1]->getName(), ==, "tel1");
786  TEST_COMPARE(teCons[2]->getName(), ==, "tel2");
787 
788  TEST_COMPARE(tec->isTime(10.0, teCons), ==, true);
789  TEST_COMPARE(teCons.size(), ==, 2);
790  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
791  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
792 
793  TEST_COMPARE(tec->isTime(20.0, teCons), ==, true);
794  TEST_COMPARE(teCons.size(), ==, 4);
795  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
796  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
797  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
798  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
799 
800  TEST_COMPARE(tec->isIndex(0, teCons), ==, true);
801  TEST_COMPARE(teCons.size(), ==, 4);
802  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
803  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
804  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
805  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
806 
807  TEST_COMPARE(tec->isIndex(50, teCons), ==, true);
808  TEST_COMPARE(teCons.size(), ==, 3);
809  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
810  TEST_COMPARE(teCons[1]->getName(), ==, "teli1");
811  TEST_COMPARE(teCons[2]->getName(), ==, "teli2");
812 
813  TEST_COMPARE(tec->isIndex(100, teCons), ==, true);
814  TEST_COMPARE(teCons.size(), ==, 2);
815  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
816  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
817 
818  TEST_COMPARE(tec->isIndex(200, teCons), ==, true);
819  TEST_COMPARE(teCons.size(), ==, 4);
820  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
821  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
822  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
823  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
824 
825  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(-1.0, teCons), 0.0, 1.0e-14);
826  TEST_COMPARE(teCons.size(), ==, 4);
827  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
828  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
829  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
830  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
831 
832  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(4.0, teCons), 5.0, 1.0e-14);
833  TEST_COMPARE(teCons.size(), ==, 3);
834  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
835  TEST_COMPARE(teCons[1]->getName(), ==, "tel1");
836  TEST_COMPARE(teCons[2]->getName(), ==, "tel2");
837 
838  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(9.0, teCons), 10.0, 1.0e-14);
839  TEST_COMPARE(teCons.size(), ==, 2);
840  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
841  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
842 
843  TEST_FLOATING_EQUALITY(tec->timeOfNextEvent(19.0, teCons), 20.0, 1.0e-14);
844  TEST_COMPARE(teCons.size(), ==, 4);
845  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
846  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
847  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
848  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
849 
850  TEST_COMPARE(tec->indexOfNextEvent(-1, teCons), ==, 0);
851  TEST_COMPARE(teCons.size(), ==, 4);
852  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
853  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
854  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
855  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
856 
857  TEST_COMPARE(tec->indexOfNextEvent(40, teCons), ==, 50);
858  TEST_COMPARE(teCons.size(), ==, 3);
859  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
860  TEST_COMPARE(teCons[1]->getName(), ==, "teli1");
861  TEST_COMPARE(teCons[2]->getName(), ==, "teli2");
862 
863  TEST_COMPARE(tec->indexOfNextEvent(90, teCons), ==, 100);
864  TEST_COMPARE(teCons.size(), ==, 2);
865  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
866  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
867 
868  TEST_COMPARE(tec->indexOfNextEvent(190, teCons), ==, 200);
869  TEST_COMPARE(teCons.size(), ==, 4);
870  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
871  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
872  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
873  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
874 
875  // Sorted order is still input order.
876  TEST_COMPARE(tec->eventInRange(-1.0, 21.0, teCons), ==, true);
877  TEST_COMPARE(teCons.size(), ==, 4);
878  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
879  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
880  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
881  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
882 
883  // Sorted order is based on "time of next event".
884  TEST_COMPARE(tec->eventInRange(0.0, 21.0, teCons), ==, true);
885  TEST_COMPARE(teCons.size(), ==, 4);
886  TEST_COMPARE(teCons[0]->getName(), ==, "ter2");
887  TEST_FLOATING_EQUALITY(teCons[0]->timeOfNextEvent(0.0), 2.0, 1.0e-14);
888  TEST_COMPARE(teCons[1]->getName(), ==, "tel2");
889  TEST_FLOATING_EQUALITY(teCons[1]->timeOfNextEvent(0.0), 3.0, 1.0e-14);
890  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
891  TEST_FLOATING_EQUALITY(teCons[2]->timeOfNextEvent(0.0), 4.0, 1.0e-14);
892  TEST_COMPARE(teCons[3]->getName(), ==, "ter1");
893  TEST_FLOATING_EQUALITY(teCons[3]->timeOfNextEvent(0.0), 5.0, 1.0e-14);
894 
895  TEST_COMPARE(tec->eventInRange(7.0, 21.0, teCons), ==, true);
896  TEST_COMPARE(teCons.size(), ==, 4);
897  TEST_COMPARE(teCons[0]->getName(), ==, "ter2");
898  TEST_FLOATING_EQUALITY(teCons[0]->timeOfNextEvent(7.0), 8.0, 1.0e-14);
899  TEST_COMPARE(teCons[1]->getName(), ==, "tel1");
900  TEST_FLOATING_EQUALITY(teCons[1]->timeOfNextEvent(7.0), 9.0, 1.0e-14);
901  TEST_COMPARE(teCons[2]->getName(), ==, "ter1");
902  TEST_FLOATING_EQUALITY(teCons[2]->timeOfNextEvent(7.0), 10.0, 1.0e-14);
903  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
904  TEST_FLOATING_EQUALITY(teCons[3]->timeOfNextEvent(7.0), 13.0, 1.0e-14);
905 
906  TEST_COMPARE(tec->eventInRange(19.0, 21.0, teCons), ==, true);
907  TEST_COMPARE(teCons.size(), ==, 4);
908  TEST_COMPARE(teCons[0]->getName(), ==, "ter1");
909  TEST_FLOATING_EQUALITY(teCons[0]->timeOfNextEvent(19.0), 20.0, 1.0e-14);
910  TEST_COMPARE(teCons[1]->getName(), ==, "ter2");
911  TEST_FLOATING_EQUALITY(teCons[1]->timeOfNextEvent(19.0), 20.0, 1.0e-14);
912  TEST_COMPARE(teCons[2]->getName(), ==, "tel1");
913  TEST_FLOATING_EQUALITY(teCons[2]->timeOfNextEvent(19.0), 20.0, 1.0e-14);
914  TEST_COMPARE(teCons[3]->getName(), ==, "tel2");
915  TEST_FLOATING_EQUALITY(teCons[3]->timeOfNextEvent(19.0), 20.0, 1.0e-14);
916 
917  // Sorted order is still input order.
918  TEST_COMPARE(tec->eventInRangeIndex(-10, 210, teCons), ==, true);
919  TEST_COMPARE(teCons.size(), ==, 4);
920  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
921  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
922  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
923  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
924 
925  // Sorted order is based on "time of next event".
926  TEST_COMPARE(tec->eventInRangeIndex(0, 210, teCons), ==, true);
927  TEST_COMPARE(teCons.size(), ==, 4);
928  TEST_COMPARE(teCons[0]->getName(), ==, "teri2");
929  TEST_COMPARE(teCons[0]->indexOfNextEvent(0), ==, 20);
930  TEST_COMPARE(teCons[1]->getName(), ==, "teli2");
931  TEST_COMPARE(teCons[1]->indexOfNextEvent(0), ==, 30);
932  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
933  TEST_COMPARE(teCons[2]->indexOfNextEvent(0), ==, 40);
934  TEST_COMPARE(teCons[3]->getName(), ==, "teri1");
935  TEST_COMPARE(teCons[3]->indexOfNextEvent(0), ==, 50);
936 
937  TEST_COMPARE(tec->eventInRangeIndex(70, 210, teCons), ==, true);
938  TEST_COMPARE(teCons.size(), ==, 4);
939  TEST_COMPARE(teCons[0]->getName(), ==, "teri2");
940  TEST_COMPARE(teCons[0]->indexOfNextEvent(70), ==, 80);
941  TEST_COMPARE(teCons[1]->getName(), ==, "teli1");
942  TEST_COMPARE(teCons[1]->indexOfNextEvent(70), ==, 90);
943  TEST_COMPARE(teCons[2]->getName(), ==, "teri1");
944  TEST_COMPARE(teCons[2]->indexOfNextEvent(70), ==, 100);
945  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
946  TEST_COMPARE(teCons[3]->indexOfNextEvent(70), ==, 130);
947 
948  TEST_COMPARE(tec->eventInRangeIndex(190, 210, teCons), ==, true);
949  TEST_COMPARE(teCons.size(), ==, 4);
950  TEST_COMPARE(teCons[0]->getName(), ==, "teri1");
951  TEST_COMPARE(teCons[0]->indexOfNextEvent(190), ==, 200);
952  TEST_COMPARE(teCons[1]->getName(), ==, "teri2");
953  TEST_COMPARE(teCons[1]->indexOfNextEvent(190), ==, 200);
954  TEST_COMPARE(teCons[2]->getName(), ==, "teli1");
955  TEST_COMPARE(teCons[2]->indexOfNextEvent(190), ==, 200);
956  TEST_COMPARE(teCons[3]->getName(), ==, "teli2");
957  TEST_COMPARE(teCons[3]->indexOfNextEvent(190), ==, 200);
958 }
959 
960 // ************************************************************
961 // ************************************************************
962 TEUCHOS_UNIT_TEST(TimeEventComposite, remove)
963 {
964  // Construct ParmeterList for testing.
965  auto tec = rcp(new Tempus::TimeEventComposite<double>());
966  auto ter = rcp(new Tempus::TimeEventRange<double>());
967  auto teri = rcp(new Tempus::TimeEventRangeIndex<double>());
968  auto tel = rcp(new Tempus::TimeEventList<double>());
969  auto teli = rcp(new Tempus::TimeEventListIndex<double>());
970 
971  ter->setName("Test Range");
972  teri->setName("Test Range Index");
973  tel->setName("Test List");
974  teli->setName("Test List Index");
975 
976  tec->add(ter);
977  tec->add(teri);
978  tec->add(tel);
979  tec->add(teli);
980  // tec->describe(out, Teuchos::VERB_EXTREME);
981 
982  tec->remove("Blah Blah");
983  TEST_COMPARE(tec->getSize(), ==, 4);
984 
985  tec->remove("Test Range Index");
986  TEST_COMPARE(tec->getSize(), ==, 3);
987  auto names = tec->getTimeEventNames();
988  TEST_COMPARE(names, ==, "Test Range, Test List, Test List Index");
989 
990  tec->remove("Test List Index");
991  TEST_COMPARE(tec->getSize(), ==, 2);
992  names = tec->getTimeEventNames();
993  TEST_COMPARE(names, ==, "Test Range, Test List");
994 
995  tec->remove("Test Range");
996  TEST_COMPARE(tec->getSize(), ==, 1);
997  names = tec->getTimeEventNames();
998  TEST_COMPARE(names, ==, "Test List");
999 
1000  tec->remove("Test List");
1001  TEST_COMPARE(tec->getSize(), ==, 0);
1002  names = tec->getTimeEventNames();
1003  TEST_COMPARE(names, ==, "");
1004 }
1005 
1006 // ************************************************************
1007 // ************************************************************
1008 TEUCHOS_UNIT_TEST(TimeEventComposite, find)
1009 {
1010  // Construct ParmeterList for testing.
1011  auto tec = rcp(new Tempus::TimeEventComposite<double>());
1012  auto ter = rcp(new Tempus::TimeEventRange<double>());
1013  auto teri = rcp(new Tempus::TimeEventRangeIndex<double>());
1014  auto tel = rcp(new Tempus::TimeEventList<double>());
1015  auto teli = rcp(new Tempus::TimeEventListIndex<double>());
1016 
1017  ter->setName("Test Range");
1018  teri->setName("Test Range Index");
1019  tel->setName("Test List");
1020  teli->setName("Test List Index");
1021 
1022  tec->add(ter);
1023  tec->add(teri);
1024  tec->add(tel);
1025  tec->add(teli);
1026  // tec->describe(out, Teuchos::VERB_EXTREME);
1027 
1028  auto teTest = tec->find("Test Range");
1029  TEST_COMPARE(teTest->getName(), ==, "Test Range");
1030 
1031  teTest = tec->find("Test Range Index");
1032  TEST_COMPARE(teTest->getName(), ==, "Test Range Index");
1033 
1034  teTest = tec->find("Test List");
1035  TEST_COMPARE(teTest->getName(), ==, "Test List");
1036 
1037  teTest = tec->find("Test List Index");
1038  TEST_COMPARE(teTest->getName(), ==, "Test List Index");
1039 
1040  teTest = tec->find("Blah Blah");
1041  TEST_COMPARE(teTest, ==, Teuchos::null);
1042 }
1043 
1044 // ************************************************************
1045 // ************************************************************
1046 TEUCHOS_UNIT_TEST(TimeEventComposite, clear)
1047 {
1048  // Construct ParmeterList for testing.
1049  auto tec = rcp(new Tempus::TimeEventComposite<double>());
1050  auto ter = rcp(new Tempus::TimeEventRange<double>());
1051  auto teri = rcp(new Tempus::TimeEventRangeIndex<double>());
1052  auto tel = rcp(new Tempus::TimeEventList<double>());
1053  auto teli = rcp(new Tempus::TimeEventListIndex<double>());
1054 
1055  tec->add(ter);
1056  tec->add(teri);
1057  tec->add(tel);
1058  tec->add(teli);
1059  // tec->describe(out, Teuchos::VERB_EXTREME);
1060 
1061  TEST_COMPARE(tec->getSize(), ==, 4);
1062  tec->clear();
1063  TEST_COMPARE(tec->getSize(), ==, 0);
1064 }
1065 
1066 // ************************************************************
1067 // ************************************************************
1068 TEUCHOS_UNIT_TEST(TimeEventComposite, getValidParameters)
1069 {
1070  // Construct ParmeterList for testing.
1071  auto tec = rcp(new Tempus::TimeEventComposite<double>());
1072  auto ter = rcp(new Tempus::TimeEventRange<double>());
1073  auto teri = rcp(new Tempus::TimeEventRangeIndex<double>());
1074  auto tel = rcp(new Tempus::TimeEventList<double>());
1075  auto teli = rcp(new Tempus::TimeEventListIndex<double>());
1076 
1077  ter->setName("Test Range");
1078  teri->setName("Test Range Index");
1079  tel->setName("Test List");
1080  teli->setName("Test List Index");
1081 
1082  tec->add(ter);
1083  tec->add(teri);
1084  tec->add(tel);
1085  tec->add(teli);
1086  // tec->describe(out, Teuchos::VERB_EXTREME);
1087 
1088  auto timeEvents = tec->getTimeEvents();
1089  TEST_COMPARE(timeEvents.size(), ==, 4);
1090 
1091  auto pl = tec->getValidParameters();
1092 
1093  TEST_COMPARE(pl->get<std::string>("Name"), ==, "TimeEventComposite");
1094  TEST_COMPARE(pl->get<std::string>("Type"), ==, "Composite");
1095  TEST_COMPARE(pl->get<std::string>("Time Events"), ==,
1096  "Test Range, Test Range Index, Test List, Test List Index");
1097  TEST_COMPARE(pl->isSublist("Test Range"), ==, true);
1098  TEST_COMPARE(pl->isSublist("Test Range Index"), ==, true);
1099  TEST_COMPARE(pl->isSublist("Test List"), ==, true);
1100  TEST_COMPARE(pl->isSublist("Test List Index"), ==, true);
1101 
1102  { // Ensure that parameters are "used", excluding sublists.
1103  std::ostringstream unusedParameters;
1104  pl->unused(unusedParameters);
1105  TEST_COMPARE(
1106  unusedParameters.str(), ==,
1107  "WARNING: Parameter \"Test Range\" [unused] is unused\n"
1108  "WARNING: Parameter \"Test Range Index\" [unused] is unused\n"
1109  "WARNING: Parameter \"Test List\" [unused] is unused\n"
1110  "WARNING: Parameter \"Test List Index\" [unused] is unused\n");
1111  }
1112 
1113  auto terPL = pl->sublist("Test Range");
1114  TEST_COMPARE(terPL.get<std::string>("Type"), ==, "Range");
1115  TEST_COMPARE(terPL.get<std::string>("Name"), ==, "Test Range");
1116  TEST_FLOATING_EQUALITY(terPL.get<double>("Start Time"), 0.0, 1.0e-14);
1117  TEST_FLOATING_EQUALITY(terPL.get<double>("Stop Time"), 0.0, 1.0e-14);
1118  TEST_FLOATING_EQUALITY(terPL.get<double>("Stride Time"), 0.0, 1.0e-14);
1119  TEST_COMPARE(terPL.get<int>("Number of Events"), ==, 1);
1120  TEST_FLOATING_EQUALITY(terPL.get<double>("Relative Tolerance"),
1121  std::numeric_limits<double>::epsilon() * 100.0,
1122  1.0e-14);
1123 
1124  TEST_COMPARE(terPL.get<bool>("Land On Exactly"), ==, true);
1125 
1126  { // Ensure that parameters are "used", excluding sublists.
1127  std::ostringstream unusedParameters;
1128  terPL.unused(unusedParameters);
1129  TEST_COMPARE(unusedParameters.str(), ==, "");
1130  }
1131 
1132  auto teriPL = pl->sublist("Test Range Index");
1133  TEST_COMPARE(teriPL.get<std::string>("Type"), ==, "Range Index");
1134  TEST_COMPARE(teriPL.get<std::string>("Name"), ==, "Test Range Index");
1135  TEST_COMPARE(teriPL.get<int>("Start Index"), ==, 0);
1136  TEST_COMPARE(teriPL.get<int>("Stop Index"), ==, 0);
1137  TEST_COMPARE(teriPL.get<int>("Stride Index"), ==, 1);
1138 
1139  { // Ensure that parameters are "used", excluding sublists.
1140  std::ostringstream unusedParameters;
1141  teriPL.unused(unusedParameters);
1142  TEST_COMPARE(unusedParameters.str(), ==, "");
1143  }
1144 
1145  auto telPL = pl->sublist("Test List");
1146  TEST_COMPARE(telPL.get<std::string>("Type"), ==, "List");
1147  TEST_COMPARE(telPL.get<std::string>("Name"), ==, "Test List");
1148  TEST_FLOATING_EQUALITY(telPL.get<double>("Relative Tolerance"),
1149  std::numeric_limits<double>::epsilon() * 100.0,
1150  1.0e-14);
1151  TEST_COMPARE(telPL.get<bool>("Land On Exactly"), ==, true);
1152  TEST_COMPARE(telPL.get<std::string>("Time List"), ==, "");
1153 
1154  { // Ensure that parameters are "used", excluding sublists.
1155  std::ostringstream unusedParameters;
1156  telPL.unused(unusedParameters);
1157  TEST_COMPARE(unusedParameters.str(), ==, "");
1158  }
1159 
1160  auto teliPL = pl->sublist("Test List Index");
1161  TEST_COMPARE(teliPL.get<std::string>("Type"), ==, "List Index");
1162  TEST_COMPARE(teliPL.get<std::string>("Name"), ==, "Test List Index");
1163  TEST_COMPARE(teliPL.get<std::string>("Index List"), ==, "");
1164 
1165  { // Ensure that parameters are "used", excluding sublists.
1166  std::ostringstream unusedParameters;
1167  teliPL.unused(unusedParameters);
1168  TEST_COMPARE(unusedParameters.str(), ==, "");
1169  }
1170 }
1171 
1172 // ************************************************************
1173 // ************************************************************
1175 {
1176  using Teuchos::ParameterList;
1177  using Teuchos::rcp_const_cast;
1178 
1179  { // Construct from default ParameterList.
1180  auto tecTmp = rcp(new Tempus::TimeEventComposite<double>());
1181  auto pl = rcp_const_cast<ParameterList>(tecTmp->getValidParameters());
1182 
1183  auto tec = Tempus::createTimeEventComposite<double>(pl);
1184  // tec->describe(out, Teuchos::VERB_EXTREME);
1185 
1186  TEST_COMPARE(tec->getName(), ==, "TimeEventComposite");
1187  TEST_COMPARE(tec->getType(), ==, "Composite");
1188  TEST_COMPARE(tec->getSize(), ==, 0);
1189  TEST_COMPARE(tec->getTimeEventNames(), ==, "");
1190  }
1191 
1192  { // Construct with TimeEvents.
1193  auto tecTmp = rcp(new Tempus::TimeEventComposite<double>());
1194  auto ter = rcp(new Tempus::TimeEventRange<double>());
1195  auto teri = rcp(new Tempus::TimeEventRangeIndex<double>());
1196  auto tel = rcp(new Tempus::TimeEventList<double>());
1197  auto teli = rcp(new Tempus::TimeEventListIndex<double>());
1198 
1199  ter->setName("Test Range");
1200  teri->setName("Test Range Index");
1201  tel->setName("Test List");
1202  teli->setName("Test List Index");
1203 
1204  tecTmp->add(ter);
1205  tecTmp->add(teri);
1206  tecTmp->add(tel);
1207  tecTmp->add(teli);
1208 
1209  auto pl = rcp_const_cast<ParameterList>(tecTmp->getValidParameters());
1210 
1211  auto tec = Tempus::createTimeEventComposite<double>(pl);
1212  // tec->describe(out, Teuchos::VERB_EXTREME);
1213 
1214  TEST_COMPARE(tec->getName(), ==, "TimeEventComposite");
1215  TEST_COMPARE(tec->getType(), ==, "Composite");
1216  TEST_COMPARE(tec->getSize(), ==, 4);
1217  TEST_COMPARE(tec->getTimeEventNames(), ==,
1218  "Test Range, Test Range Index, Test List, Test List Index");
1219  }
1220 
1221  { // Construct with non-Tempus TimeEvent.
1222  auto tecTmp = rcp(new Tempus::TimeEventComposite<double>());
1223  auto pl = rcp_const_cast<ParameterList>(tecTmp->getValidParameters());
1224 
1225  auto nonTempusTE = Teuchos::parameterList("Application Time Event");
1226  nonTempusTE->set<std::string>("Name", "Application Time Event");
1227  nonTempusTE->set<std::string>("Type", "Application Time Event Type");
1228  nonTempusTE->set<double>("Secret Sauce", 1.2345);
1229  pl->set("Application Time Event", *nonTempusTE);
1230  pl->set("Time Events", "Application Time Event");
1231 
1232  auto tec = Tempus::createTimeEventComposite<double>(pl);
1233  // tec->describe(out, Teuchos::VERB_EXTREME);
1234 
1235  TEST_COMPARE(tec->getName(), ==, "TimeEventComposite");
1236  TEST_COMPARE(tec->getType(), ==, "Composite");
1237  TEST_COMPARE(tec->getSize(), ==, 0);
1238  TEST_COMPARE(tec->getTimeEventNames(), ==, "");
1239  }
1240 }
1241 
1242 } // namespace Tempus_Unit_Test
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.
#define TEST_COMPARE(v1, comp, v2)
Teuchos::RCP< Tempus::TimeEventRangeIndex< double > > getTestRangeIndex3()
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
Teuchos::RCP< Tempus::TimeEventList< double > > getTestList3()
Teuchos::RCP< Tempus::TimeEventRange< double > > getTestRange1()
TimeEventRange specifies a start, stop and stride time.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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.
Teuchos::RCP< TimeEventComposite< Scalar > > createTimeEventComposite(Teuchos::RCP< Teuchos::ParameterList > const &pList)
TimeEventComposite nonmember constructor via ParameterList.