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