11 #include "Tempus_TimeEventList.hpp"
13 static double PI = M_PI;
15 namespace Tempus_Unit_Test {
19 using Teuchos::rcp_const_cast;
20 using Teuchos::rcp_dynamic_cast;
32 te->getRelTol(), std::numeric_limits<double>::epsilon() * 100.0, 1.0e-14);
34 te->getAbsTol(), std::numeric_limits<double>::epsilon() * 100.0, 1.0e-14);
40 TEST_COMPARE(te->indexToNextEvent(1), ==, te->getDefaultIndex());
41 TEST_COMPARE(te->indexOfNextEvent(1), ==, te->getDefaultIndex());
49 std::vector<double> testVector;
50 testVector.push_back(-1.0);
51 testVector.push_back(0.0);
52 testVector.push_back(5.0);
53 testVector.push_back(2.0);
54 testVector.push_back(
PI);
63 auto testList = te->getTimeList();
66 TEST_FLOATING_EQUALITY(testList[1], 0.0, 1.0e-14);
67 TEST_FLOATING_EQUALITY(testList[2], 2.0, 1.0e-14);
68 TEST_FLOATING_EQUALITY(testList[3],
PI, 1.0e-14);
69 TEST_FLOATING_EQUALITY(testList[4], 5.0, 1.0e-14);
78 te->setName(
"TestName");
82 te->setRelTol(1.0e-14);
83 te->setLandOnExactly(
false);
97 auto testList = te->getTimeList();
100 TEST_FLOATING_EQUALITY(testList[1], 0.0, 1.0e-14);
101 TEST_FLOATING_EQUALITY(testList[2], 2.0, 1.0e-14);
102 TEST_FLOATING_EQUALITY(testList[3],
PI, 1.0e-14);
103 TEST_FLOATING_EQUALITY(testList[4], 5.0, 1.0e-14);
106 te->addTime(2.0 + 1.0e-14);
108 te->addTime(2.0 + 1.0e-13);
113 te->setTimeList(testList);
115 TEST_FLOATING_EQUALITY(testList[0], -1.0, 1.0e-14);
116 TEST_FLOATING_EQUALITY(testList[1], 0.0, 1.0e-14);
117 TEST_FLOATING_EQUALITY(testList[2], 2.0, 1.0e-14);
118 TEST_FLOATING_EQUALITY(testList[3],
PI, 1.0e-14);
119 TEST_FLOATING_EQUALITY(testList[4], 5.0, 1.0e-14);
132 te->setRelTol(1.0e-14);
165 std::vector<double> testList;
166 testList.push_back(0.0);
167 testList.push_back(
PI);
168 testList.push_back(-1.0);
169 testList.push_back(2.0);
170 testList.push_back(5.0);
202 te->getDefaultTime(), 1.0e-01);
206 te->getDefaultTime(), 1.0e-01);
208 te->getDefaultTime(), 1.0e-02);
215 std::vector<double> testList;
216 testList.push_back(0.0);
217 testList.push_back(
PI);
218 testList.push_back(-1.0);
219 testList.push_back(2.0);
220 testList.push_back(5.0);
243 te->getDefaultTime(), 1.0e-14);
247 te->getDefaultTime(), 1.0e-14);
249 te->getDefaultTime(), 1.0e-14);
256 std::vector<double> testList;
257 testList.push_back(0.0);
258 testList.push_back(
PI);
259 testList.push_back(-1.0);
260 testList.push_back(2.0);
261 testList.push_back(5.0);
268 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + -10.0e-14), ==,
270 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + -0.1e-14), ==,
true);
271 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + 0.0), ==,
true);
272 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + 0.1e-14), ==,
true);
273 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + 10.0e-14), ==,
true);
282 TEST_COMPARE(te->eventInRange(4.5, 5.0 + -10.0e-14), ==,
284 TEST_COMPARE(te->eventInRange(4.5, 5.0 + -0.1e-14), ==,
true);
285 TEST_COMPARE(te->eventInRange(4.5, 5.0 + 0.0), ==,
true);
286 TEST_COMPARE(te->eventInRange(4.5, 5.0 + 0.1e-14), ==,
true);
287 TEST_COMPARE(te->eventInRange(4.5, 5.0 + 10.0e-14), ==,
true);
290 TEST_COMPARE(te->eventInRange(-1.0 + -10.0e-14, -0.5), ==,
292 TEST_COMPARE(te->eventInRange(-1.0 + -0.1e-14, -0.5), ==,
false);
293 TEST_COMPARE(te->eventInRange(-1.0 + 0.0, -0.5), ==,
false);
294 TEST_COMPARE(te->eventInRange(-1.0 + 0.1e-14, -0.5), ==,
false);
295 TEST_COMPARE(te->eventInRange(-1.0 + 10.0e-14, -0.5), ==,
false);
304 TEST_COMPARE(te->eventInRange(5.0 + -10.0e-14, 6.0), ==,
306 TEST_COMPARE(te->eventInRange(5.0 + -0.1e-14, 6.0), ==,
false);
307 TEST_COMPARE(te->eventInRange(5.0 + 0.0, 6.0), ==,
false);
308 TEST_COMPARE(te->eventInRange(5.0 + 0.1e-14, 6.0), ==,
false);
309 TEST_COMPARE(te->eventInRange(5.0 + 10.0e-14, 6.0), ==,
false);
318 auto pl = tel->getValidParameters();
321 TEST_COMPARE(pl->get<std::string>(
"Name"), ==,
"TimeEventList");
323 std::numeric_limits<double>::epsilon() * 100.0,
325 TEST_COMPARE(pl->get<
bool>(
"Land On Exactly"), ==,
true);
326 TEST_COMPARE(pl->get<std::string>(
"Time List"), ==,
"");
329 std::ostringstream unusedParameters;
330 pl->unused(unusedParameters);
341 Teuchos::parameterList(
"Time Event List");
343 pl->
set(
"Name",
"Unit Test Time Event List");
344 pl->
set(
"Type",
"List");
345 pl->
set(
"Relative Tolerance", 1.0e-10);
346 pl->
set(
"Land On Exactly",
false);
348 std::vector<double> times;
349 times.push_back(-0.1);
350 times.push_back(0.1);
351 times.push_back(0.5);
352 times.push_back(1.1);
353 std::ostringstream list;
354 for (std::size_t i = 0; i < times.size() - 1; ++i) list << times[i] <<
", ";
355 list << times[times.size() - 1];
356 pl->
set<std::string>(
"Time List", list.str());
359 auto tel = Tempus::createTimeEventList<double>(pl);
363 TEST_COMPARE(tel->getName(), ==,
"Unit Test Time Event List");
367 auto teList = tel->getTimeList();
#define TEST_COMPARE(v1, comp, v2)
#define TEST_FLOATING_EQUALITY(v1, v2, tol)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeEventList specifies a list of time events.
Teuchos::RCP< TimeEventList< Scalar > > createTimeEventList(Teuchos::RCP< Teuchos::ParameterList > pList)
Nonmember Constructor via ParameterList.