preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WaveformTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
3#include "testing/Testing.hpp"
5#include "time/Time.hpp"
6#include "time/Waveform.hpp"
7
8using namespace precice;
9using namespace precice::time;
10
11BOOST_AUTO_TEST_SUITE(TimeTests)
12BOOST_AUTO_TEST_SUITE(WaveformTests)
13
15BOOST_AUTO_TEST_CASE(testInitialization)
16{
18 const int interpolationDegree = 0;
19 const int valuesSize = 1;
20 Eigen::VectorXd value(valuesSize);
21 Waveform waveform(interpolationDegree);
22 value(0) = 0.0;
23 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
24
26 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
27
28 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
29 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 0.0));
30}
31
33BOOST_AUTO_TEST_CASE(testInitializationVector)
34{
36
37 const int interpolationDegree = 0;
38 const int valuesSize = 3;
39 Eigen::VectorXd value(valuesSize);
40 Waveform waveform(interpolationDegree);
41 value << 0, 0, 0;
42 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
43
45 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
46
47 for (int i = 0; i < valuesSize; i++) {
48 BOOST_TEST(testing::equals(waveform.sample(0.0)(i), 0.0));
49 BOOST_TEST(testing::equals(waveform.sample(1.0)(i), 0.0));
50 }
51}
52
53BOOST_AUTO_TEST_SUITE(InterpolationTests)
54
56BOOST_AUTO_TEST_CASE(testInterpolateDataZerothDegree)
57{
59
61
62 // Test zeroth degree interpolation
63 const int interpolationDegree = 0;
64 const int valuesSize = 1;
65 Eigen::VectorXd value(valuesSize);
66 Waveform waveform(interpolationDegree);
67 value(0) = 0.0;
68 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
69 value(0) = 1.0;
70 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
71
72 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
73 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 2);
74
75 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
76 BOOST_TEST(testing::equals(waveform.sample(0.5)(0), 1.0));
77 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 1.0));
78
79 value(0) = 2.0;
80 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
81
82 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
83 BOOST_TEST(testing::equals(waveform.sample(0.5)(0), 2.0));
84 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
85
86 waveform.timeStepsStorage().move();
87 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
88
89 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
90 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 2.0));
91 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 2.0));
92
93 value(0) = 3.0;
94 waveform.timeStepsStorage().setSampleAtTime(2, time::Sample{1, value});
95
96 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
97 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 3.0));
98 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 3.0));
99}
100
101PRECICE_TEST_SETUP(1_rank)
102BOOST_AUTO_TEST_CASE(testInterpolateDataFirstDegree)
103{
104 PRECICE_TEST();
105
107
108 // Test first degree interpolation
109 const int interpolationDegree = 1;
110 const int valuesSize = 1;
111 Eigen::VectorXd value(valuesSize);
112 Waveform waveform(interpolationDegree);
113 value(0) = 0.0;
114 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
115 value(0) = 1.0;
116 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
117
118 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
119 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 2);
120
121 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
122 BOOST_TEST(testing::equals(waveform.sample(0.5)(0), 0.5));
123 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 1.0));
124
125 value(0) = 2.0;
126 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
127
128 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
129 BOOST_TEST(testing::equals(waveform.sample(0.5)(0), 1.0));
130 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
131
132 waveform.timeStepsStorage().move();
133 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
134
135 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
136 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 2.0));
137 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 2.0));
138
139 value(0) = 3.0;
140 waveform.timeStepsStorage().setSampleAtTime(2, time::Sample{1, value});
141
142 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
143 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 2.5));
144 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 3.0));
145}
146
147// Remove or modify this feature? Creating a second degree interpolant by using data from previous windows is difficult, because this would require several pieces of data during initialization. What would be useful: Generating a second degree interpolant from multiple samples in a single window (if available). This would go into the least-squares direction
148PRECICE_TEST_SETUP(1_rank)
149BOOST_AUTO_TEST_CASE(testInterpolateDataSecondDegree)
150{
151 PRECICE_TEST();
152
154
155 // Test second degree interpolation, but there are not enough samples. Therefore, always only first degree.
156 const int interpolationDegree = 2;
157 const int valuesSize = 1;
158 Eigen::VectorXd value(valuesSize);
159 Waveform waveform(interpolationDegree);
160 value(0) = 0.0;
161 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
162 value(0) = 1.0;
163 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
164
165 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
166 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 2);
167
168 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
169 BOOST_TEST(testing::equals(waveform.sample(0.5)(0), 0.5));
170 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 1.0));
171
172 waveform.timeStepsStorage().trim();
173
174 value(0) = 2.0;
175 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
176
177 BOOST_TEST(testing::equals(waveform.sample(0.0)(0), 0.0));
178 BOOST_TEST(testing::equals(waveform.sample(0.5)(0), 1.0));
179 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
180
181 waveform.timeStepsStorage().move();
182 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
183
184 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
185 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 2.0));
186 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 2.0));
187
188 value(0) = 8.0;
189 waveform.timeStepsStorage().setSampleAtTime(2, time::Sample{1, value});
190
191 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
192 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 5.0));
193 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 8.0));
194
195 waveform.timeStepsStorage().trim();
196
197 value(0) = 4.0;
198 waveform.timeStepsStorage().setSampleAtTime(2, time::Sample{1, value});
199
200 BOOST_TEST(testing::equals(waveform.sample(1.0)(0), 2.0));
201 BOOST_TEST(testing::equals(waveform.sample(1.5)(0), 3.0));
202 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 4.0));
203
204 waveform.timeStepsStorage().move();
205 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
206
207 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 4.0));
208 BOOST_TEST(testing::equals(waveform.sample(2.5)(0), 4.0));
209 BOOST_TEST(testing::equals(waveform.sample(3.0)(0), 4.0));
210
211 value(0) = 8.0;
212 waveform.timeStepsStorage().setSampleAtTime(3, time::Sample{1, value});
213
214 BOOST_TEST(testing::equals(waveform.sample(2.0)(0), 4.0));
215 BOOST_TEST(testing::equals(waveform.sample(2.5)(0), 6.0));
216 BOOST_TEST(testing::equals(waveform.sample(3.0)(0), 8.0));
217}
218
219PRECICE_TEST_SETUP(1_rank)
220BOOST_AUTO_TEST_CASE(testInterpolateDataFirstDegreeVector)
221{
222 PRECICE_TEST();
223
225
226 // Test first degree interpolation
227 const int interpolationDegree = 1;
228 const int valuesSize = 3;
229 Eigen::VectorXd value(valuesSize);
230 Waveform waveform(interpolationDegree);
231 value << 0, 0, 0;
232 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
233 value << 1, 2, 3;
234 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
235
236 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
237 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 2);
238
239 for (int i = 0; i < valuesSize; i++) {
240 BOOST_TEST(testing::equals(waveform.sample(0.0)(i), 0 * value[i]));
241 BOOST_TEST(testing::equals(waveform.sample(0.5)(i), 0.5 * value[i]));
242 BOOST_TEST(testing::equals(waveform.sample(1.0)(i), value[i]));
243 }
244
245 waveform.timeStepsStorage().trim();
246
247 value << 2, 4, 2;
248 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
249
250 for (int i = 0; i < valuesSize; i++) {
251 BOOST_TEST(testing::equals(waveform.sample(0.0)(i), 0 * value[i]));
252 BOOST_TEST(testing::equals(waveform.sample(0.5)(i), 0.5 * value[i]));
253 BOOST_TEST(testing::equals(waveform.sample(1.0)(i), value[i]));
254 }
255
256 waveform.timeStepsStorage().move();
257 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
258
259 for (int i = 0; i < valuesSize; i++) {
260 BOOST_TEST(testing::equals(waveform.sample(1.0)(i), value[i]));
261 BOOST_TEST(testing::equals(waveform.sample(1.5)(i), value[i]));
262 BOOST_TEST(testing::equals(waveform.sample(2.0)(i), value[i]));
263 }
264
265 Eigen::VectorXd value0 = value;
266 value << 1, 2, 3;
267 waveform.timeStepsStorage().setSampleAtTime(2, time::Sample{1, value});
268
269 for (int i = 0; i < valuesSize; i++) {
270 BOOST_TEST(testing::equals(waveform.sample(1.0)(i), value0[i]));
271 BOOST_TEST(testing::equals(waveform.sample(1.5)(i), 0.5 * value0[i] + 0.5 * value[i]));
272 }
273}
274
275PRECICE_TEST_SETUP(1_rank)
276BOOST_AUTO_TEST_CASE(testPiecewiseInterpolateDataZerothDegree)
277{
278 PRECICE_TEST();
279
281
282 // Test zeroth degree interpolation
283 const int interpolationDegree = 0;
284 const int valuesSize = 1;
285 Eigen::VectorXd value(valuesSize);
286 Waveform waveform(interpolationDegree);
287 value(0) = 0.0;
288 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
289 value(0) = 0.5;
290 waveform.timeStepsStorage().setSampleAtTime(0.5, time::Sample{1, value});
291 value(0) = 1.0;
292 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
293
294 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
295 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 3);
296 BOOST_TEST(testing::equals(waveform.sample(0.00)(0), 0.0));
297 BOOST_TEST(testing::equals(waveform.sample(0.25)(0), 0.5));
298 BOOST_TEST(testing::equals(waveform.sample(0.50)(0), 0.5));
299 BOOST_TEST(testing::equals(waveform.sample(0.75)(0), 1.0));
300 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 1.0));
301
302 waveform.timeStepsStorage().trim();
303
304 value(0) = 1.5;
305 waveform.timeStepsStorage().setSampleAtTime(0.5, time::Sample{1, value});
306
307 value(0) = 2.0;
308 waveform.timeStepsStorage().setSampleAtTime(1.0, time::Sample{1, value});
309 BOOST_TEST(testing::equals(waveform.sample(0.00)(0), 0.0));
310 BOOST_TEST(testing::equals(waveform.sample(0.25)(0), 1.5));
311 BOOST_TEST(testing::equals(waveform.sample(0.50)(0), 1.5));
312 BOOST_TEST(testing::equals(waveform.sample(0.75)(0), 2.0));
313 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.0));
314
315 waveform.timeStepsStorage().move();
316 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
317
318 BOOST_TEST(testing::equals(waveform.sample(0.00)(0), 2.0));
319 BOOST_TEST(testing::equals(waveform.sample(0.25)(0), 2.0));
320 BOOST_TEST(testing::equals(waveform.sample(0.50)(0), 2.0));
321 BOOST_TEST(testing::equals(waveform.sample(0.75)(0), 2.0));
322 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.0));
323
324 value(0) = 3.0;
325 waveform.timeStepsStorage().setSampleAtTime(2.0, time::Sample{1, value});
326 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.0));
327 BOOST_TEST(testing::equals(waveform.sample(1.25)(0), 3.0));
328 BOOST_TEST(testing::equals(waveform.sample(1.50)(0), 3.0));
329 BOOST_TEST(testing::equals(waveform.sample(1.75)(0), 3.0));
330 BOOST_TEST(testing::equals(waveform.sample(2.00)(0), 3.0));
331
332 waveform.timeStepsStorage().trim();
333
334 value(0) = 1.5;
335 waveform.timeStepsStorage().setSampleAtTime(1.5, time::Sample{1, value});
336
337 value(0) = 4.0;
338 waveform.timeStepsStorage().setSampleAtTime(2.0, time::Sample{1, value});
339 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.0));
340 BOOST_TEST(testing::equals(waveform.sample(1.25)(0), 1.5));
341 BOOST_TEST(testing::equals(waveform.sample(1.50)(0), 1.5));
342 BOOST_TEST(testing::equals(waveform.sample(1.75)(0), 4.0));
343 BOOST_TEST(testing::equals(waveform.sample(2.00)(0), 4.0));
344}
345
346PRECICE_TEST_SETUP(1_rank)
347BOOST_AUTO_TEST_CASE(testPiecewiseInterpolateDataFirstDegree)
348{
349 PRECICE_TEST();
350
352
353 // Test zeroth degree interpolation
354 const int interpolationDegree = 1;
355 const int valuesSize = 1;
356 Eigen::VectorXd value(valuesSize);
357 Waveform waveform(interpolationDegree);
358 value(0) = 0.0;
359 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
360 value(0) = 0.5;
361 waveform.timeStepsStorage().setSampleAtTime(0.5, time::Sample{1, value});
362 value(0) = 1.0;
363 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
364
365 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
366 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 3);
367 BOOST_TEST(testing::equals(waveform.sample(0.00)(0), 0.00));
368 BOOST_TEST(testing::equals(waveform.sample(0.25)(0), 0.25));
369 BOOST_TEST(testing::equals(waveform.sample(0.50)(0), 0.50));
370 BOOST_TEST(testing::equals(waveform.sample(0.75)(0), 0.75));
371 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 1.00));
372
373 value(0) = 1.5;
374 waveform.timeStepsStorage().setSampleAtTime(0.5, time::Sample{1, value});
375
376 value(0) = 2.0;
377 waveform.timeStepsStorage().setSampleAtTime(1.0, time::Sample{1, value});
378 BOOST_TEST(testing::equals(waveform.sample(0.00)(0), 0.00));
379 BOOST_TEST(testing::equals(waveform.sample(0.25)(0), 0.75));
380 BOOST_TEST(testing::equals(waveform.sample(0.50)(0), 1.50));
381 BOOST_TEST(testing::equals(waveform.sample(0.75)(0), 1.75));
382 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.00));
383
384 waveform.timeStepsStorage().move();
385 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 1);
386
387 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.00));
388 BOOST_TEST(testing::equals(waveform.sample(1.25)(0), 2.00));
389 BOOST_TEST(testing::equals(waveform.sample(1.50)(0), 2.00));
390 BOOST_TEST(testing::equals(waveform.sample(1.75)(0), 2.00));
391 BOOST_TEST(testing::equals(waveform.sample(2.00)(0), 2.00));
392
393 value(0) = 3.0;
394 waveform.timeStepsStorage().setSampleAtTime(2.0, time::Sample{1, value});
395 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.00));
396 BOOST_TEST(testing::equals(waveform.sample(1.25)(0), 2.25));
397 BOOST_TEST(testing::equals(waveform.sample(1.50)(0), 2.50));
398 BOOST_TEST(testing::equals(waveform.sample(1.75)(0), 2.75));
399 BOOST_TEST(testing::equals(waveform.sample(2.00)(0), 3.00));
400
401 waveform.timeStepsStorage().trim();
402
403 value(0) = 1.5;
404 waveform.timeStepsStorage().setSampleAtTime(1.5, time::Sample{1, value});
405
406 value(0) = 4.0;
407 waveform.timeStepsStorage().setSampleAtTime(2.0, time::Sample{1, value});
408 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.00));
409 BOOST_TEST(testing::equals(waveform.sample(1.25)(0), 1.75));
410 BOOST_TEST(testing::equals(waveform.sample(1.50)(0), 1.50));
411 BOOST_TEST(testing::equals(waveform.sample(1.75)(0), 2.75));
412 BOOST_TEST(testing::equals(waveform.sample(2.00)(0), 4.00));
413}
414
415PRECICE_TEST_SETUP(1_rank)
416BOOST_AUTO_TEST_CASE(testPiecewiseInterpolateDataSecondDegree)
417{
418 PRECICE_TEST();
419
421
422 // Test zeroth degree interpolation
423 const int interpolationDegree = 2;
424 const int valuesSize = 1;
425 Waveform waveform(interpolationDegree);
426 Eigen::VectorXd value(valuesSize);
427 value(0) = 0.0;
428 waveform.timeStepsStorage().setSampleAtTime(0, time::Sample{1, value});
429 value(0) = 0.0;
430 waveform.timeStepsStorage().setSampleAtTime(0.5, time::Sample{1, value});
431 value(0) = 2.0;
432 waveform.timeStepsStorage().setSampleAtTime(1, time::Sample{1, value});
433
434 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
435 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 3);
436 BOOST_TEST(testing::equals(waveform.sample(0.00)(0), 0.00));
437 BOOST_TEST(testing::equals(waveform.sample(0.25)(0), -0.25));
438 BOOST_TEST(testing::equals(waveform.sample(0.50)(0), 0.00));
439 BOOST_TEST(testing::equals(waveform.sample(0.75)(0), 0.75));
440 BOOST_TEST(testing::equals(waveform.sample(1.00)(0), 2.00));
441}
442
443PRECICE_TEST_SETUP(1_rank)
444BOOST_AUTO_TEST_CASE(testPiecewiseInterpolateDataThirdDegree)
445{
446 PRECICE_TEST();
447
449
450 // Test zeroth degree interpolation
451 const int interpolationDegree = 3;
452 const int valuesSize = 1;
453 Waveform waveform(interpolationDegree);
454
455 // linearly increasing values
456 Eigen::VectorXd value(valuesSize);
457 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
458 value(0) = t;
459 waveform.timeStepsStorage().setSampleAtTime(t, time::Sample{1, value});
460 }
461
462 BOOST_TEST(fixture.valuesSize(waveform) == valuesSize);
463 BOOST_TEST(fixture.numberOfStoredSamples(waveform) == 5);
464
465 for (double t : std::vector<double>{0.1, 0.2, 0.3, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}) {
466 BOOST_TEST(testing::equals(waveform.sample(t)(0), t));
467 }
468
469 waveform.timeStepsStorage().trim();
470
471 // quadratically increasing values
472 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
473 value(0) = t * t;
474 waveform.timeStepsStorage().setSampleAtTime(t, time::Sample{1, value});
475 }
476
477 // interpolates given values
478 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
479 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t));
480 }
481
482 // introduces no approximation error w.r.t function
483 for (double t : std::vector<double>{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}) {
484 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t));
485 }
486
487 waveform.timeStepsStorage().trim();
488
489 // cubically increasing values
490 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
491 value(0) = t * t * t;
492 waveform.timeStepsStorage().setSampleAtTime(t, time::Sample{1, value});
493 }
494
495 // interpolates given values
496 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
497 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t * t));
498 }
499
500 // introduces no approximation error w.r.t function
501 for (double t : std::vector<double>{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}) {
502 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t * t));
503 }
504
505 waveform.timeStepsStorage().trim();
506
507 // cubically increasing values, but with non-uniform spacing
508 for (double t : std::vector<double>{0, 0.01, 0.1, 0.2, 1}) {
509 value(0) = t * t * t;
510 waveform.timeStepsStorage().setSampleAtTime(t, time::Sample{1, value});
511 }
512
513 // interpolates given values
514 for (double t : std::vector<double>{0, 0.01, 0.1, 0.2, 1}) {
515 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t * t));
516 }
517
518 // introduces no approximation error w.r.t function
519 for (double t : std::vector<double>{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}) {
520 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t * t));
521 }
522
523 waveform.timeStepsStorage().trim();
524
525 // quadratically increasing values, but with non-uniform spacing
526 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
527 value(0) = t * t * t * t;
528 waveform.timeStepsStorage().setSampleAtTime(t, time::Sample{1, value});
529 }
530
531 // interpolates given values
532 for (double t : std::vector<double>{0, 0.25, 0.5, 0.75, 1}) {
533 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t * t * t));
534 }
535
536 // introduces approximation error w.r.t function
537 for (double t : std::vector<double>{0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0}) {
538 double tol = 0.015625; // error < h**3 = 0.015625
539 BOOST_TEST(testing::equals(waveform.sample(t)(0), t * t * t * t, tol));
540 }
541}
542
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(testInitialization)
int valuesSize(time::Waveform &waveform)
int numberOfStoredSamples(time::Waveform &waveform)
void setSampleAtTime(double time, const Sample &sample)
Store Sample at a specific time.
Definition Storage.cpp:27
void trim()
Trims this Storage by deleting all values except values associated with the window start.
Definition Storage.cpp:105
void move()
Move this Storage by deleting all stamples except the one at the end of the window.
Definition Storage.cpp:93
Allows to perform interpolation on samples in storage of given data.
Definition Waveform.hpp:25
time::Storage & timeStepsStorage()
Returns a reference to the _timeStepsStorage.
Definition Waveform.cpp:16
SampleResult sample(const double time) const
Evaluate waveform at specific point in time. Uses interpolation if necessary.
Definition Waveform.cpp:26
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:93
contains the time interpolation logic.
Definition Sample.hpp:8
Main namespace of the precice library.