9 #include "Teuchos_UnitTestHarness.hpp"
10 #include "Teuchos_XMLParameterListHelpers.hpp"
11 #include "Teuchos_TimeMonitor.hpp"
12 #include "Teuchos_DefaultComm.hpp"
14 #include "Tempus_TimeEventRange.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(), ==,
"TimeEventRange");
36 te->setName(
"TestName");
37 TEST_COMPARE(te->getName(), ==,
"TestName");
39 TEST_FLOATING_EQUALITY(te->getTimeStart (), te->getDefaultTime(), 1.0e-14);
40 TEST_FLOATING_EQUALITY(te->getTimeStop (), te->getDefaultTime(), 1.0e-14);
41 TEST_FLOATING_EQUALITY(te->getTimeStride(), 0.0, 1.0e-14);
42 TEST_COMPARE(te->getNumEvents (), ==, 1);
44 TEST_FLOATING_EQUALITY(te->getRelTol(), 1.0e-14, 1.0e-14);
45 TEST_COMPARE(te->getLandOnExactly(), ==,
true);
54 "TestName", 0.0, PI, 1.0, 1.0e-14,
true));
56 TEST_COMPARE(te->getName(), ==,
"TestName");
59 TEST_FLOATING_EQUALITY(te->getTimeStart (), 0.0 , 1.0e-14);
60 TEST_FLOATING_EQUALITY(te->getTimeStop (), PI, 1.0e-14);
61 TEST_FLOATING_EQUALITY(te->getTimeStride(), 1.0, 1.0e-14);
62 TEST_COMPARE(te->getNumEvents (), ==, 4);
65 "teRange2", -PI/2.0, PI/2.0, PI/4.0, 1.0e-14,
true));
67 TEST_FLOATING_EQUALITY(teRange2->timeToNextEvent(0.1), PI/4.0-0.1, 1.0e-14);
77 "TestName", 0.0, PI, 5, 1.0e-14,
true));
79 TEST_COMPARE(te->getName(), ==,
"TestName");
82 TEST_FLOATING_EQUALITY(te->getTimeStart (), 0.0, 1.0e-14);
83 TEST_FLOATING_EQUALITY(te->getTimeStop (), PI, 1.0e-14);
84 TEST_FLOATING_EQUALITY(te->getTimeStride(), PI/4.0, 1.0e-14);
85 TEST_COMPARE(te->getNumEvents (), ==, 5);
96 TEST_FLOATING_EQUALITY(te->getRelTol(), 0.1, 1.0e-14);
97 te->setRelTol(1.0e-14);
98 te->setLandOnExactly(
false);
99 TEST_COMPARE(te->getLandOnExactly(), ==,
false);
100 te->setLandOnExactly(
true);
103 te->setTimeStart(1.0);
104 TEST_FLOATING_EQUALITY(te->getTimeStart (), 1.0, 1.0e-14);
105 TEST_FLOATING_EQUALITY(te->getTimeStop (), 1.0, 1.0e-14);
106 TEST_FLOATING_EQUALITY(te->getTimeStride(), 0.0, 1.0e-14);
107 TEST_COMPARE(te->getNumEvents (), ==, 1);
110 te->setTimeStop(4.0);
111 TEST_FLOATING_EQUALITY(te->getTimeStart (), 1.0, 1.0e-14);
112 TEST_FLOATING_EQUALITY(te->getTimeStop (), 4.0, 1.0e-14);
113 TEST_FLOATING_EQUALITY(te->getTimeStride(), 3.0, 1.0e-14);
114 TEST_COMPARE(te->getNumEvents (), ==, 2);
117 te->setTimeStride(0.5);
118 TEST_FLOATING_EQUALITY(te->getTimeStart (), 1.0, 1.0e-14);
119 TEST_FLOATING_EQUALITY(te->getTimeStop (), 4.0, 1.0e-14);
120 TEST_FLOATING_EQUALITY(te->getTimeStride(), 0.5, 1.0e-14);
121 TEST_COMPARE(te->getNumEvents (), ==, 7);
130 te->setTimeStart(1.0);
131 te->setTimeStop(4.0);
132 te->setTimeStride(0.5);
135 te->setTimeStride(-0.5);
136 TEST_FLOATING_EQUALITY(te->getTimeStart (), 1.0, 1.0e-14);
137 TEST_FLOATING_EQUALITY(te->getTimeStop (), 4.0, 1.0e-14);
138 TEST_FLOATING_EQUALITY(te->getTimeStride(), 3.0, 1.0e-14);
139 TEST_COMPARE(te->getNumEvents (), ==, 2);
142 te->setTimeStride(5.0);
143 TEST_FLOATING_EQUALITY(te->getTimeStart (), 1.0, 1.0e-14);
144 TEST_FLOATING_EQUALITY(te->getTimeStop (), 4.0, 1.0e-14);
145 TEST_FLOATING_EQUALITY(te->getTimeStride(), 3.0, 1.0e-14);
146 TEST_COMPARE(te->getNumEvents (), ==, 2);
149 te->setTimeStride(1.0e-14);
150 TEST_FLOATING_EQUALITY(te->getTimeStart (), 1.0, 1.0e-14);
151 TEST_FLOATING_EQUALITY(te->getTimeStop (), 4.0, 1.0e-14);
152 TEST_FLOATING_EQUALITY(te->getTimeStride(), 3.0, 1.0e-14);
153 TEST_COMPARE(te->getNumEvents (), ==, 2);
164 te->setTimeRange(0.0, PI, 1.0);
165 TEST_FLOATING_EQUALITY(te->getTimeStart (), 0.0, 1.0e-14);
166 TEST_FLOATING_EQUALITY(te->getTimeStop (), PI, 1.0e-14);
167 TEST_FLOATING_EQUALITY(te->getTimeStride(), 1.0, 1.0e-14);
168 TEST_COMPARE(te->getNumEvents (), ==, 4);
177 te->setTimeRange(0.0, PI, 1.0);
181 TEST_COMPARE(te->isTime(-10.0e-14), ==,
false);
182 TEST_COMPARE(te->isTime( -1.0e-14), ==, true );
183 TEST_COMPARE(te->isTime( 0.0 ), ==, true );
184 TEST_COMPARE(te->isTime( 1.0e-14), ==, true );
185 TEST_COMPARE(te->isTime( 10.0e-14), ==,
false);
188 TEST_COMPARE(te->isTime(1.0 + -10.0e-14), ==,
false);
189 TEST_COMPARE(te->isTime(1.0 + -1.0e-14), ==, true );
190 TEST_COMPARE(te->isTime(1.0 + 0.0 ), ==, true );
191 TEST_COMPARE(te->isTime(1.0 + 1.0e-14), ==, true );
192 TEST_COMPARE(te->isTime(1.0 + 10.0e-14), ==,
false);
195 TEST_COMPARE(te->isTime(3.0 + -10.0e-14), ==,
false);
196 TEST_COMPARE(te->isTime(3.0 + -1.0e-14), ==, true );
197 TEST_COMPARE(te->isTime(3.0 + 0.0 ), ==, true );
198 TEST_COMPARE(te->isTime(3.0 + 1.0e-14), ==, true );
199 TEST_COMPARE(te->isTime(3.0 + 10.0e-14), ==,
false);
208 te->setTimeRange(0.0, PI, 1.0);
212 TEST_FLOATING_EQUALITY(te->timeToNextEvent(-10.0e-14), 1.0e-13, 1.0e-14);
213 TEST_FLOATING_EQUALITY(te->timeToNextEvent( -1.0e-14), 1.0e-14, 1.0e-14);
214 TEST_FLOATING_EQUALITY(te->timeToNextEvent( 0.0 ), 0.0 , 1.0e-14);
215 TEST_FLOATING_EQUALITY(te->timeToNextEvent( 1.0e-14), -1.0e-14, 1.0e-14);
216 TEST_FLOATING_EQUALITY(te->timeToNextEvent( 10.0e-14), 1.0-1.0e-13, 1.0e-14);
219 TEST_FLOATING_EQUALITY(te->timeToNextEvent(1.0+ -10.0e-14), 1.0e-13, 1.0e-02);
220 TEST_FLOATING_EQUALITY(te->timeToNextEvent(1.0+ -1.0e-14), 1.0e-14, 1.0e-01);
221 TEST_FLOATING_EQUALITY(te->timeToNextEvent(1.0+ 0.0 ), 0.0 , 1.0e-02);
222 TEST_FLOATING_EQUALITY(te->timeToNextEvent(1.0+ 1.0e-14), -1.0e-14, 1.0e-01);
223 TEST_FLOATING_EQUALITY(te->timeToNextEvent(1.0+ 10.0e-14), 1.0-1.0e-13, 1.0e-14);
226 TEST_FLOATING_EQUALITY(te->timeToNextEvent(3.0+ -10.0e-14), 1.0e-13, 1.0e-02);
227 TEST_FLOATING_EQUALITY(te->timeToNextEvent(3.0+ -1.0e-14), 1.0e-14, 1.0e-01);
228 TEST_FLOATING_EQUALITY(te->timeToNextEvent(3.0+ 0.0 ), 0.0 , 1.0e-02);
229 TEST_FLOATING_EQUALITY(te->timeToNextEvent(3.0+ 1.0e-14), -1.0e-14, 1.0e-01);
230 TEST_FLOATING_EQUALITY(te->timeToNextEvent(3.0+ 10.0e-14), -1.0e-13, 1.0e-02);
239 te->setTimeRange(0.0, PI, 1.0);
243 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(-10.0e-14), 0.0, 1.0e-14);
244 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( -1.0e-14), 0.0, 1.0e-14);
245 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( 0.0 ), 0.0, 1.0e-14);
246 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( 1.0e-14), 0.0, 1.0e-14);
247 TEST_FLOATING_EQUALITY(te->timeOfNextEvent( 10.0e-14), 1.0, 1.0e-14);
250 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.0+ -10.0e-14), 1.0, 1.0e-14);
251 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.0+ -1.0e-14), 1.0, 1.0e-14);
252 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.0+ 0.0 ), 1.0, 1.0e-14);
253 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.0+ 1.0e-14), 1.0, 1.0e-14);
254 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(1.0+ 10.0e-14), 2.0, 1.0e-14);
257 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(3.0+ -10.0e-14), 3.0, 1.0e-14);
258 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(3.0+ -1.0e-14), 3.0, 1.0e-14);
259 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(3.0+ 0.0 ), 3.0, 1.0e-14);
260 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(3.0+ 1.0e-14), 3.0, 1.0e-14);
261 TEST_FLOATING_EQUALITY(te->timeOfNextEvent(3.0+ 10.0e-14), 3.0, 1.0e-14);
270 te->setTimeRange(0.0, PI, 1.0);
275 TEST_COMPARE(te->eventInRange(-1.0, -10.0e-14), ==,
false);
276 TEST_COMPARE(te->eventInRange(-1.0, -1.0e-14), ==, true );
277 TEST_COMPARE(te->eventInRange(-1.0, 0.0 ), ==, true );
278 TEST_COMPARE(te->eventInRange(-1.0, 1.0e-14), ==, true );
279 TEST_COMPARE(te->eventInRange(-1.0, 10.0e-14), ==, true );
282 TEST_COMPARE(te->eventInRange(0.5, 1.0 + -10.0e-14), ==,
false);
283 TEST_COMPARE(te->eventInRange(0.5, 1.0 + -1.0e-14), ==, true );
284 TEST_COMPARE(te->eventInRange(0.5, 1.0 + 0.0 ), ==, true );
285 TEST_COMPARE(te->eventInRange(0.5, 1.0 + 1.0e-14), ==, true );
286 TEST_COMPARE(te->eventInRange(0.5, 1.0 + 10.0e-14), ==, true );
289 TEST_COMPARE(te->eventInRange(2.5, 3.0 + -10.0e-14), ==,
false);
290 TEST_COMPARE(te->eventInRange(2.5, 3.0 + -1.0e-14), ==, true );
291 TEST_COMPARE(te->eventInRange(2.5, 3.0 + 0.0 ), ==, true );
292 TEST_COMPARE(te->eventInRange(2.5, 3.0 + 1.0e-14), ==, true );
293 TEST_COMPARE(te->eventInRange(2.5, 3.0 + 10.0e-14), ==, true );
297 TEST_COMPARE(te->eventInRange(-10.0e-14, 0.5), ==, true );
298 TEST_COMPARE(te->eventInRange( -1.0e-14, 0.5), ==, true );
299 TEST_COMPARE(te->eventInRange( 0.0 , 0.5), ==, true );
300 TEST_COMPARE(te->eventInRange( 1.0e-14, 0.5), ==, true );
301 TEST_COMPARE(te->eventInRange( 10.0e-14, 0.5), ==,
false);
304 TEST_COMPARE(te->eventInRange(1.0 + -10.0e-14, 1.5), ==, true );
305 TEST_COMPARE(te->eventInRange(1.0 + -1.0e-14, 1.5), ==, true );
306 TEST_COMPARE(te->eventInRange(1.0 + 0.0 , 1.5), ==, true );
307 TEST_COMPARE(te->eventInRange(1.0 + 1.0e-14, 1.5), ==, true );
308 TEST_COMPARE(te->eventInRange(1.0 + 10.0e-14, 1.5), ==,
false);
311 TEST_COMPARE(te->eventInRange(3.0 + -10.0e-14, 4.0), ==, true );
312 TEST_COMPARE(te->eventInRange(3.0 + -1.0e-14, 4.0), ==, true );
313 TEST_COMPARE(te->eventInRange(3.0 + 0.0 , 4.0), ==, true );
314 TEST_COMPARE(te->eventInRange(3.0 + 1.0e-14, 4.0), ==, true );
315 TEST_COMPARE(te->eventInRange(3.0 + 10.0e-14, 4.0), ==,
false);
TimeEventRange specifies a start, stop and stride time.
TEUCHOS_UNIT_TEST(BackwardEuler, Default_Construction)