preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TimeHandlerTests.cpp
Go to the documentation of this file.
2#include "testing/Testing.hpp"
3
4BOOST_AUTO_TEST_SUITE(CplSchemeTests)
6
8
10BOOST_AUTO_TEST_CASE(ManyTinyTimesteps)
11{
13 TimeHandler th;
14
15 double tws = 1e-7;
16 int twc = 1'000'000;
17 int checkEvery = 1000;
18
19 for (int tw = 1; tw <= twc; ++tw) {
20 th.progressBy(tws);
21 if (tw % checkEvery == 0) {
22 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
23 BOOST_TEST(th.time() == tws * tw);
24 BOOST_TEST(th.reachedEndOfWindow(tws));
25 }
26 th.completeTimeWindow(tws);
27 if (tw % checkEvery == 0) {
28 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
29 BOOST_TEST(th.time() == tws * tw);
30 BOOST_TEST(!th.reachedEndOfWindow(tws));
31 BOOST_TEST(th.windowProgress() == 0.0);
32 }
33 }
34}
35
37BOOST_AUTO_TEST_CASE(ManyBigTimesteps)
38{
40 TimeHandler th;
41
42 double tws = 1000.0;
43 int twc = 1'000'000;
44 int checkEvery = 1000;
45
46 for (int tw = 1; tw <= twc; ++tw) {
47 th.progressBy(tws);
48 if (tw % checkEvery == 0) {
49 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
50 BOOST_TEST(th.time() == tws * tw);
51 BOOST_TEST(th.reachedEndOfWindow(tws));
52 }
53 th.completeTimeWindow(tws);
54 if (tw % checkEvery == 0) {
55 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
56 BOOST_TEST(th.time() == tws * tw);
57 BOOST_TEST(!th.reachedEndOfWindow(tws));
58 BOOST_TEST(th.windowProgress() == 0.0);
59 }
60 }
61}
62
64BOOST_AUTO_TEST_CASE(ManyMixedTimesteps)
65{
67 TimeHandler th;
68
69 double tws1 = 0.01;
70 double tws2 = 0.005;
71 int twc = 1'000'000;
72 int checkEvery = 1000;
73
74 int n1 = 0, n2 = 0;
75 for (int tw = 1; tw <= twc; ++tw) {
76 double tws;
77 if (tw % 2 == 1) {
78 tws = tws1;
79 ++n1;
80 } else {
81 tws = tws2;
82 ++n2;
83 }
84 th.progressBy(tws);
85 double t = n1 * tws1 + n2 * tws2;
86 if (tw % checkEvery == 0) {
87 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
88 BOOST_TEST_INFO_SCOPE("this time-window size is " << tws);
89 BOOST_TEST(th.time() == t);
90 BOOST_TEST(th.reachedEndOfWindow(tws));
91 }
92 th.completeTimeWindow(tws);
93 if (tw % checkEvery == 0) {
94 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
95 BOOST_TEST_INFO_SCOPE("this time-window size is " << tws);
96 BOOST_TEST(th.time() == t);
97 BOOST_TEST(th.windowProgress() == 0.0);
98 BOOST_TEST(!th.reachedEndOfWindow(tws));
99 }
100 }
101}
102
103BOOST_AUTO_TEST_SUITE(Subcycling)
104
105PRECICE_TEST_SETUP(1_rank)
106BOOST_AUTO_TEST_CASE(NormalTWSmallTS)
107{
108 PRECICE_TEST();
109 TimeHandler th;
110
111 double tws = 10.0;
112 double tss = 0.1;
113 int twc = 10'000;
114 int tsc = 100;
115 int checkEvery = 1000;
116
117 for (int tw = 1; tw <= twc; ++tw) {
118
119 for (int ts = 1; ts <= tsc; ++ts) {
120 th.progressBy(tss);
121 if (tw % checkEvery == 0) {
122 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
123 BOOST_TEST_INFO_SCOPE("time-step " << ts << "/" << tsc);
124 BOOST_TEST(th.time() == (tw - 1) * tws + ts * tss);
125 BOOST_TEST(th.untilWindowEnd(tws) == tws - tss * ts);
126 }
127 }
128 if (tw % checkEvery == 0) {
129 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
130 BOOST_TEST(th.reachedEndOfWindow(tws));
131 BOOST_TEST(th.time() == tws * tw);
132 }
133 th.completeTimeWindow(tws);
134 if (tw % checkEvery == 0) {
135 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
136 BOOST_TEST(th.time() == tws * tw);
137 BOOST_TEST(!th.reachedEndOfWindow(tws));
138 BOOST_TEST(th.windowProgress() == 0.0);
139 }
140 }
141}
142
143PRECICE_TEST_SETUP(1_rank)
145{
146 PRECICE_TEST();
147 TimeHandler th;
148
149 double tws = 0.001;
150 double tss = 1e-7;
151 int twc = 100;
152 int tsc = 10'000;
153 int checkEvery = 1000;
154
155 for (int tw = 1; tw <= twc; ++tw) {
156 for (int ts = 1; ts <= tsc; ++ts) {
157 th.progressBy(tss);
158 if (ts % checkEvery == 0) {
159 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
160 BOOST_TEST_INFO_SCOPE("time-step " << ts << "/" << tsc);
161 BOOST_TEST(th.time() == (tw - 1) * tws + ts * tss);
162 BOOST_TEST(th.untilWindowEnd(tws) == tws - tss * ts);
163 }
164 }
165 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
166 BOOST_TEST(th.reachedEndOfWindow(tws));
167 BOOST_TEST(th.time() == tws * tw);
168 th.completeTimeWindow(tws);
169 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
170 BOOST_TEST(th.time() == tws * tw);
171 BOOST_TEST(!th.reachedEndOfWindow(tws));
172 BOOST_TEST(th.windowProgress() == 0.0);
173 }
174}
175
176PRECICE_TEST_SETUP(1_rank)
177BOOST_AUTO_TEST_CASE(LargeTWNormalTS)
178{
179 PRECICE_TEST();
180 TimeHandler th;
181
182 double tws = 1000;
183 double tss = 0.1;
184 int twc = 100;
185 int tsc = 10'000;
186 int checkEvery = 1000;
187
188 for (int tw = 1; tw <= twc; ++tw) {
189 for (int ts = 1; ts <= tsc; ++ts) {
190 th.progressBy(tss);
191 if (ts % checkEvery == 0) {
192 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
193 BOOST_TEST_INFO_SCOPE("time-step " << ts << "/" << tsc);
194 BOOST_TEST(th.time() == (tw - 1) * tws + ts * tss);
195 BOOST_TEST(th.untilWindowEnd(tws) == tws - tss * ts);
196 }
197 }
198 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
199 BOOST_TEST(th.reachedEndOfWindow(tws));
200 BOOST_TEST(th.time() == tws * tw);
201 th.completeTimeWindow(tws);
202 BOOST_TEST_INFO_SCOPE("time-window " << tw << "/" << twc);
203 BOOST_TEST(th.time() == tws * tw);
204 BOOST_TEST(!th.reachedEndOfWindow(tws));
205 BOOST_TEST(th.windowProgress() == 0.0);
206 }
207}
208
210
212
213PRECICE_TEST_SETUP(1_rank)
215{
216 PRECICE_TEST();
217 TimeHandler th(1.0);
218
219 th.progressBy(1.0);
220 BOOST_TEST(th.time() == 1.0);
221 BOOST_TEST(th.reachedEndOfWindow(1.0));
222 BOOST_TEST(th.reachedEnd());
223 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
224
225 th.completeTimeWindow(1.0);
226 BOOST_TEST(th.windowProgress() == 0.0);
227 BOOST_TEST(th.reachedEnd());
228 BOOST_TEST(th.reachedEndOfWindow(1.0));
229 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
230}
231
232PRECICE_TEST_SETUP(1_rank)
234{
235 PRECICE_TEST();
236 TimeHandler th(1.0);
237
238 double tws = 2.0;
239
240 th.progressBy(1.0);
241
242 BOOST_TEST(th.time() == 1.0);
243 BOOST_TEST(th.reachedEndOfWindow(tws));
244 BOOST_TEST(th.reachedEnd());
245 BOOST_TEST(th.untilWindowEnd(tws) == 0.0);
246
247 th.completeTimeWindow(tws);
248 BOOST_TEST(th.windowProgress() == 0.0);
249 BOOST_TEST(th.reachedEnd());
250 BOOST_TEST(th.reachedEndOfWindow(tws));
251 BOOST_TEST(th.untilWindowEnd(tws) == 0.0);
252}
253
254PRECICE_TEST_SETUP(1_rank)
255BOOST_AUTO_TEST_CASE(StepCloseToEnd)
256{
257 PRECICE_TEST();
258 TimeHandler th(1.0);
259
260 th.progressBy(0.999999999999999999999999);
261 BOOST_TEST(th.time() == 1.0);
262 BOOST_TEST(th.reachedEndOfWindow(1.0));
263 BOOST_TEST(th.reachedEnd());
264 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
265
266 th.completeTimeWindow(1.0);
267 BOOST_TEST(th.windowProgress() == 0.0);
268 BOOST_TEST(th.reachedEnd());
269 BOOST_TEST(th.reachedEndOfWindow(1.0));
270 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
271}
272
273PRECICE_TEST_SETUP(1_rank)
274BOOST_AUTO_TEST_CASE(TinyTimestepsToEnd)
275{
276 PRECICE_TEST();
277 TimeHandler th(1.0);
278
279 double tss = 1e-6;
280 double tsc = 1'000'000;
281
282 for (int ts = 1; ts <= tsc; ++ts) {
283 th.progressBy(tss);
284 }
285
286 BOOST_TEST(th.time() == 1.0);
287 BOOST_TEST(th.reachedEndOfWindow(1.0));
288 BOOST_TEST(th.reachedEnd());
289 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
290
291 th.completeTimeWindow(1.0);
292 BOOST_TEST(th.windowProgress() == 0.0);
293 BOOST_TEST(th.reachedEnd());
294 BOOST_TEST(th.reachedEndOfWindow(1.0));
295 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
296}
297
298PRECICE_TEST_SETUP(1_rank)
299BOOST_AUTO_TEST_CASE(ManyTimeWindowsToEnd)
300{
301 PRECICE_TEST();
302 TimeHandler th(1.0);
303
304 double tws = 1e-6;
305 double twc = 1'000'000;
306
307 for (int tw = 1; tw <= twc; ++tw) {
308 th.progressBy(tws);
309 th.completeTimeWindow(tws);
310 }
311
312 BOOST_TEST(th.windowProgress() == 0.0);
313 BOOST_TEST(th.reachedEnd());
314 BOOST_TEST(th.reachedEndOfWindow(1.0));
315 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
316}
317
318PRECICE_TEST_SETUP(1_rank)
319BOOST_AUTO_TEST_CASE(TimeWindowsWithSubstepsToEnd)
320{
321 PRECICE_TEST();
322 TimeHandler th(1.0);
323
324 double tws = 1e-3;
325 double twc = 1'000;
326 double tss = 1e-6;
327 double tsc = 1'000;
328
329 for (int tw = 1; tw <= twc; ++tw) {
330 for (int ts = 1; ts <= tsc; ++ts) {
331 th.progressBy(tss);
332 }
333 BOOST_TEST(th.reachedEndOfWindow(tws));
334 th.completeTimeWindow(tws);
335 }
336 BOOST_TEST(th.windowProgress() == 0.0);
337 BOOST_TEST(th.reachedEnd());
338 BOOST_TEST(th.reachedEndOfWindow(1.0));
339 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
340}
341
342PRECICE_TEST_SETUP(1_rank)
343BOOST_AUTO_TEST_CASE(TinyTimestepsTruncated)
344{
345 PRECICE_TEST();
346 TimeHandler th(1.0);
347
348 double tss = 1e-6;
349 double tsc = 1'000'000;
350
351 for (int ts = 1; ts <= tsc; ++ts) {
352 th.progressBy(tss);
353 }
354
355 BOOST_TEST(th.time() == 1.0);
356 BOOST_TEST(th.reachedEndOfWindow(1.0));
357 BOOST_TEST(th.reachedEnd());
358 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
359
360 th.completeTimeWindow(1.0);
361 BOOST_TEST(th.windowProgress() == 0.0);
362 BOOST_TEST(th.reachedEnd());
363 BOOST_TEST(th.reachedEndOfWindow(1.0));
364 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
365}
366
367PRECICE_TEST_SETUP(1_rank)
368BOOST_AUTO_TEST_CASE(ManyTimeWindowsTrucated)
369{
370 PRECICE_TEST();
371 TimeHandler th(1.0);
372
373 double tws = 1e-6;
374 double twc = 1'000'000;
375 double twl = 0.001;
376
377 for (int tw = 1; tw <= twc; ++tw) {
378 th.progressBy(tws);
379 if (tw == twc) {
380 // extend last time window past the end, so it is truncated my maxTime
381 th.completeTimeWindow(twl);
382 } else {
383 th.completeTimeWindow(tws);
384 }
385 }
386 BOOST_TEST(th.windowProgress() == 0.0);
387 BOOST_TEST(th.reachedEnd());
388 BOOST_TEST(th.reachedEndOfWindow(1.0));
389 BOOST_TEST(th.untilWindowEnd(1.0) == 0.0);
390}
391
393
Eigen::Vector2d ts
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST()
Definition Testing.hpp:39
#define PRECICE_TEST_SETUP(...)
Creates and attaches a TestSetup to a Boost test case.
Definition Testing.hpp:29
BOOST_AUTO_TEST_CASE(ManyTinyTimesteps)
bool reachedEndOfWindow(double timeWindowSize) const
double time() const
Returns the current time as a double.
double untilWindowEnd(double timeWindowSize) const
Returns the time distance to the possibly truncated end of the current time window.
void completeTimeWindow(double timeWindowSize)
double windowProgress() const
Returns the window progress as a double.
void progressBy(double dt)
Progress the time window by the given amount.