9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
14 #include "Tempus_TimeEventList.hpp"
16 #include "../TestUtils/Tempus_ConvergenceTestUtils.hpp"
19 static double PI = M_PI;
21 namespace Tempus_Unit_Test {
25 using Teuchos::rcp_const_cast;
26 using Teuchos::rcp_dynamic_cast;
35 TEST_COMPARE(te->getName(), ==,
"TimeEventList");
37 TEST_COMPARE(te->getTimeList().size(), ==, 0);
38 TEST_FLOATING_EQUALITY(te->getRelTol(), 1.0e-14, 1.0e-14);
39 TEST_COMPARE(te->getLandOnExactly(), ==,
true);
42 TEST_COMPARE(te->isIndex(1), ==,
false);
43 TEST_COMPARE(te->indexToNextEvent(1), ==, te->getDefaultIndex());
44 TEST_COMPARE(te->indexOfNextEvent(1), ==, te->getDefaultIndex());
45 TEST_COMPARE(te->eventInRangeIndex(1,4), ==,
false);
53 std::vector<double> testVector;
54 testVector.push_back(-1.0);
55 testVector.push_back( 0.0);
56 testVector.push_back( 5.0);
57 testVector.push_back( 2.0);
58 testVector.push_back( PI);
61 "TestName", testVector, 1.0e-14,
true));
63 TEST_COMPARE(te->getName(), ==,
"TestName");
64 TEST_FLOATING_EQUALITY(te->getRelTol(), 1.0e-14, 1.0e-14);
65 TEST_COMPARE(te->getLandOnExactly(), ==,
true);
67 auto testList = te->getTimeList();
68 TEST_COMPARE(testList.size(), ==, 5);
69 TEST_FLOATING_EQUALITY(testList[0], -1.0, 1.0e-14);
70 TEST_FLOATING_EQUALITY(testList[1], 0.0, 1.0e-14);
71 TEST_FLOATING_EQUALITY(testList[2], 2.0, 1.0e-14);
72 TEST_FLOATING_EQUALITY(testList[3], PI, 1.0e-14);
73 TEST_FLOATING_EQUALITY(testList[4], 5.0, 1.0e-14);
83 te->setName(
"TestName");
84 TEST_COMPARE(te->getName(), ==,
"TestName");
86 TEST_FLOATING_EQUALITY(te->getRelTol(), 0.1, 1.0e-14);
87 te->setRelTol(1.0e-14);
88 te->setLandOnExactly(
false);
89 TEST_COMPARE(te->getLandOnExactly(), ==,
false);
102 auto testList = te->getTimeList();
103 TEST_COMPARE(testList.size(), ==, 5);
104 TEST_FLOATING_EQUALITY(testList[0], -1.0, 1.0e-14);
105 TEST_FLOATING_EQUALITY(testList[1], 0.0, 1.0e-14);
106 TEST_FLOATING_EQUALITY(testList[2], 2.0, 1.0e-14);
107 TEST_FLOATING_EQUALITY(testList[3], PI, 1.0e-14);
108 TEST_FLOATING_EQUALITY(testList[4], 5.0, 1.0e-14);
111 te->addTime( 2.0 + 1.0e-14);
112 TEST_COMPARE(te->getTimeList().size(), ==, 5);
113 te->addTime( 2.0 + 1.0e-13);
114 TEST_COMPARE(te->getTimeList().size(), ==, 6);
131 TEST_COMPARE(te->isTime(-10.0e-14), ==,
false);
132 TEST_COMPARE(te->isTime( -1.0e-14), ==, true );
133 TEST_COMPARE(te->isTime( 0.0 ), ==, true );
134 TEST_COMPARE(te->isTime( 1.0e-14), ==, true );
135 TEST_COMPARE(te->isTime( 10.0e-14), ==,
false);
138 TEST_COMPARE(te->isTime(PI + -10.0e-14), ==,
false);
139 TEST_COMPARE(te->isTime(PI + -1.0e-14), ==, true );
140 TEST_COMPARE(te->isTime(PI + 0.0 ), ==, true );
141 TEST_COMPARE(te->isTime(PI + 1.0e-14), ==, true );
142 TEST_COMPARE(te->isTime(PI + 10.0e-14), ==,
false);
145 TEST_COMPARE(te->isTime(5.0 + -10.0e-14), ==,
false);
146 TEST_COMPARE(te->isTime(5.0 + -1.0e-14), ==, true );
147 TEST_COMPARE(te->isTime(5.0 + 0.0 ), ==, true );
148 TEST_COMPARE(te->isTime(5.0 + 1.0e-14), ==, true );
149 TEST_COMPARE(te->isTime(5.0 + 10.0e-14), ==,
false);
157 std::vector<double> testList;
158 testList.push_back( 0.0);
159 testList.push_back( PI);
160 testList.push_back(-1.0);
161 testList.push_back( 2.0);
162 testList.push_back( 5.0);
165 "testList", testList, 1.0e-14,
true));
169 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-1.0 + -10.0e-14), 1.0e-13, 1.0e-02);
170 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-1.0 + -1.0e-14), 1.0e-14, 1.0e-02);
171 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-1.0 + 0.0 ), 0.0 , 1.0e-02);
172 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-1.0 + 1.0e-14), -1.0e-14, 1.0e-02);
173 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-1.0 + 10.0e-14), 1.0-1.0e-13, 1.0e-14);
176 TEST_FLOATING_EQUALITY(te->timeToNextEvent(PI + -10.0e-14), 1.0e-13, 1.0e-02);
177 TEST_FLOATING_EQUALITY(te->timeToNextEvent(PI + -1.0e-14), 1.0e-14, 1.0e-01);
178 TEST_FLOATING_EQUALITY(te->timeToNextEvent(PI + 0.0 ), 0.0 , 1.0e-02);
179 TEST_FLOATING_EQUALITY(te->timeToNextEvent(PI + 1.0e-14), -1.0e-14, 1.0e-01);
180 TEST_FLOATING_EQUALITY(te->timeToNextEvent(PI + 10.0e-14), 5.0-PI-1.0e-13, 1.0e-14);
183 TEST_FLOATING_EQUALITY(te->timeToNextEvent(5.0+ -10.0e-14), 1.0e-13, 1.0e-02);
184 TEST_FLOATING_EQUALITY(te->timeToNextEvent(5.0+ -1.0e-14), 1.0e-14, 1.0e-01);
185 TEST_FLOATING_EQUALITY(te->timeToNextEvent(5.0+ 0.0 ), 0.0 , 1.0e-02);
186 TEST_FLOATING_EQUALITY(te->timeToNextEvent(5.0+ 1.0e-14), -1.0e-14, 1.0e-01);
187 TEST_FLOATING_EQUALITY(te->timeToNextEvent(5.0+ 10.0e-14), -1.0e-13, 1.0e-02);
195 std::vector<double> testList;
196 testList.push_back( 0.0);
197 testList.push_back( PI);
198 testList.push_back(-1.0);
199 testList.push_back( 2.0);
200 testList.push_back( 5.0);
203 "testList", testList, 1.0e-14,
true));
207 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-1.0 + -10.0e-14), -1.0, 1.0e-14);
208 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-1.0 + -1.0e-14), -1.0, 1.0e-14);
209 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-1.0 + 0.0 ), -1.0, 1.0e-14);
210 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-1.0 + 1.0e-14), -1.0, 1.0e-14);
211 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-1.0 + 10.0e-14), 0.0, 1.0e-14);
214 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(2.0+ -10.0e-14), 2.0, 1.0e-14);
215 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(2.0+ -1.0e-14), 2.0, 1.0e-14);
216 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(2.0+ 0.0 ), 2.0, 1.0e-14);
217 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(2.0+ 1.0e-14), 2.0, 1.0e-14);
218 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(2.0+ 10.0e-14), PI, 1.0e-14);
221 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(5.0+ -10.0e-14), 5.0, 1.0e-14);
222 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(5.0+ -1.0e-14), 5.0, 1.0e-14);
223 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(5.0+ 0.0 ), 5.0, 1.0e-14);
224 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(5.0+ 1.0e-14), 5.0, 1.0e-14);
225 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(5.0+ 10.0e-14), 5.0, 1.0e-14);
233 std::vector<double> testList;
234 testList.push_back( 0.0);
235 testList.push_back( PI);
236 testList.push_back(-1.0);
237 testList.push_back( 2.0);
238 testList.push_back( 5.0);
241 "testList", testList, 1.0e-14,
true));
245 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + -10.0e-14), ==,
false);
246 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + -1.0e-14), ==, true );
247 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + 0.0 ), ==, true );
248 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + 1.0e-14), ==, true );
249 TEST_COMPARE(te->eventInRange(-2.0, -1.0 + 10.0e-14), ==, true );
251 TEST_COMPARE(te->eventInRange(3.0, PI + -10.0e-14), ==,
false);
252 TEST_COMPARE(te->eventInRange(3.0, PI + -1.0e-14), ==, true );
253 TEST_COMPARE(te->eventInRange(3.0, PI + 0.0 ), ==, true );
254 TEST_COMPARE(te->eventInRange(3.0, PI + 1.0e-14), ==, true );
255 TEST_COMPARE(te->eventInRange(3.0, PI + 10.0e-14), ==, true );
257 TEST_COMPARE(te->eventInRange(4.5, 5.0 + -10.0e-14), ==,
false);
258 TEST_COMPARE(te->eventInRange(4.5, 5.0 + -1.0e-14), ==, true );
259 TEST_COMPARE(te->eventInRange(4.5, 5.0 + 0.0 ), ==, true );
260 TEST_COMPARE(te->eventInRange(4.5, 5.0 + 1.0e-14), ==, true );
261 TEST_COMPARE(te->eventInRange(4.5, 5.0 + 10.0e-14), ==, true );
264 TEST_COMPARE(te->eventInRange(-1.0 + -10.0e-14, -0.5), ==, true );
265 TEST_COMPARE(te->eventInRange(-1.0 + -1.0e-14, -0.5), ==, true );
266 TEST_COMPARE(te->eventInRange(-1.0 + 0.0 , -0.5), ==, true );
267 TEST_COMPARE(te->eventInRange(-1.0 + 1.0e-14, -0.5), ==, true );
268 TEST_COMPARE(te->eventInRange(-1.0 + 10.0e-14, -0.5), ==, false );
270 TEST_COMPARE(te->eventInRange(PI + -10.0e-14, 3.5), ==, true );
271 TEST_COMPARE(te->eventInRange(PI + -1.0e-14, 3.5), ==, true );
272 TEST_COMPARE(te->eventInRange(PI + 0.0 , 3.5), ==, true );
273 TEST_COMPARE(te->eventInRange(PI + 1.0e-14, 3.5), ==, true );
274 TEST_COMPARE(te->eventInRange(PI + 10.0e-14, 3.5), ==,
false);
276 TEST_COMPARE(te->eventInRange(5.0 + -10.0e-14, 6.0), ==, true );
277 TEST_COMPARE(te->eventInRange(5.0 + -1.0e-14, 6.0), ==, true );
278 TEST_COMPARE(te->eventInRange(5.0 + 0.0 , 6.0), ==, true );
279 TEST_COMPARE(te->eventInRange(5.0 + 1.0e-14, 6.0), ==, true );
280 TEST_COMPARE(te->eventInRange(5.0 + 10.0e-14, 6.0), ==,
false);
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)
TimeEventList specifies a list of time events.