preCICE
Loading...
Searching...
No Matches
AxialGeoMultiscaleMappingTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <memory>
6#include "mapping/Mapping.hpp"
7#include "math/constants.hpp"
8#include "mesh/Data.hpp"
9#include "mesh/Mesh.hpp"
11#include "mesh/Utils.hpp"
12#include "mesh/Vertex.hpp"
14#include "testing/Testing.hpp"
15
16using namespace precice;
17using namespace precice::mesh;
18
19BOOST_AUTO_TEST_SUITE(MappingTests)
20BOOST_AUTO_TEST_SUITE(AxialGeoMultiscaleMapping)
21
23BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorParabolicZ1D3D)
24{
26 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the z-axis.
27 Then, the data is mapped from the single vertex of the 1D mesh to defined vertices on the circular inlet of the 3D mesh (hence, "spread").
28 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
29 Finally, this expected behavior is tested.
30 */
31 constexpr int dimensions = 3;
32 using testing::equals;
33
34 // Create mesh to map from
35 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
36 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (1D)
37 inMesh->allocateDataValues();
38
39 // Create mesh to map to
40 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
41 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (3D): center, equal to incoming mesh node
42 outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0)); // Point B (3D): distance of 1.0 = r to center
43 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point C (3D): distance of 0.5 = r/2 to center
44 outMesh->allocateDataValues();
45
46 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
47
48 // Setup mapping with mapping coordinates and geometry used
50 mapping.setMeshes(inMesh, outMesh);
51 BOOST_TEST(mapping.hasComputedMapping() == false);
52
53 // Create data to map
54 Eigen::VectorXd inValues(3);
55 inValues << 0.0, 0.0, 2.0;
56 const time::Sample inSample{3, inValues};
57 Eigen::VectorXd outValues(9);
58 outValues = Eigen::VectorXd::Zero(9);
59
60 // Map data
61 mapping.computeMapping();
62 mapping.map(inSample, outValues);
63
64 BOOST_TEST(mapping.hasComputedMapping() == true);
65
66 // Point A (3D): Check if x axis data is doubled at center node
67 BOOST_TEST(outValues(0) == 0.0);
68 BOOST_TEST(outValues(1) == 0.0);
69 BOOST_TEST(outValues(2) == 2 * inSample.values(2));
70
71 // Point B (3D): Check if x axis data at distance = r is equal to zero
72 BOOST_TEST(outValues(3) == 0.0);
73 BOOST_TEST(outValues(4) == 0.0);
74 BOOST_TEST(outValues(5) == 0.0);
75
76 // Point C (3D): Check if x axis data at distance = r/2 is 3/2 times invalue data
77 BOOST_TEST(outValues(6) == 0.0);
78 BOOST_TEST(outValues(7) == 0.0);
79 BOOST_TEST(outValues(8) == 1.5 * inSample.values(2));
80}
81
82PRECICE_TEST_SETUP(1_rank);
83BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorUniformX1D3D)
84{
86 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the x-axis.
87 Then, the data is mapped from the single vertex of the 1D mesh to defined vertices on the circular inlet of the 3D mesh (hence, "spread").
88 The values are spread following a uniform spread, meaning that all vertices from the 3D mesh receive the same values.
89 Finally, this expected behavior is tested.
90 */
91 constexpr int dimensions = 3;
92 using testing::equals;
93
94 // Create mesh to map from
95 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
96 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (1D)
97 inMesh->allocateDataValues();
98
99 // Create mesh to map to
100 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
101 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (3D): center, equal to incoming mesh node
102 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0)); // Point B (3D): distance of 1.0 = r to center
103 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point C (3D): distance of 0.5 = r/2 to center
104 outMesh->allocateDataValues();
105
106 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
107
108 // Setup mapping with mapping coordinates and geometry used
110 mapping.setMeshes(inMesh, outMesh);
111 BOOST_TEST(mapping.hasComputedMapping() == false);
112
113 // Create data to map
114 Eigen::VectorXd inValues(3);
115 inValues << 4.0, 0.0, 0.0;
116 const time::Sample inSample{3, inValues};
117 Eigen::VectorXd outValues(9);
118 outValues = Eigen::VectorXd::Zero(9);
119
120 // Map data
121 mapping.computeMapping();
122 mapping.map(inSample, outValues);
123
124 BOOST_TEST(mapping.hasComputedMapping() == true);
125
126 // Check that the 3D data is initialized to zero and the MultiscaleAxis-component is assigned the same value on all points
127 // Point A (3D)
128 BOOST_TEST(outValues(0) == 4.0);
129 BOOST_TEST(outValues(1) == 0.0);
130 BOOST_TEST(outValues(2) == 0.0);
131
132 // Point B (3D)
133 BOOST_TEST(outValues(3) == 4.0);
134 BOOST_TEST(outValues(4) == 0.0);
135 BOOST_TEST(outValues(5) == 0.0);
136
137 // Point C (3D)
138 BOOST_TEST(outValues(6) == 4.0);
139 BOOST_TEST(outValues(7) == 0.0);
140 BOOST_TEST(outValues(8) == 0.0);
141}
142
143PRECICE_TEST_SETUP(1_rank);
144BOOST_AUTO_TEST_CASE(ConsistentCollectVectorX1D3D)
145{
146 PRECICE_TEST();
147 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the x-axis.
148 Then, the data is mapped from multiple defined vertices on the circular inlet of the 3D mesh to the single vertex of the 1D mesh (hence, "collect").
149 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
150 Finally, this expected behavior is tested.
151 */
152 constexpr int dimensions = 3;
153 using testing::equals;
154
155 // Create mesh to map from
156 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
157 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (3D): center
158 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0)); // Point b (3D): distance of 1.0 = r to center
159 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point c (3D): distance of 0.5 = r/2 to center
160 inMesh->allocateDataValues();
161
162 // Create mesh to map to
163 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
164 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (1D): equal to center of incoming mesh (averaging)
165 outMesh->allocateDataValues();
166
167 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
168
169 // Setup mapping with mapping coordinates and geometry used
171 mapping.setMeshes(inMesh, outMesh);
172 BOOST_TEST(mapping.hasComputedMapping() == false);
173
174 // Create data to map
175 Eigen::VectorXd inValues(9);
176 inValues << 1.0, 0.0, 0.0, 2.0, 0.0, 0.0, 3.0, 0.0, 0.0;
177 const time::Sample inSample{3, inValues};
178 Eigen::VectorXd outValues(3);
179 outValues = Eigen::VectorXd::Zero(3);
180
181 // Map data
182 mapping.computeMapping();
183 mapping.map(inSample, outValues);
184
185 BOOST_TEST(mapping.hasComputedMapping() == true);
186
187 // Point A (1D): Check if data is averaged at center node
188 BOOST_TEST(outValues(0) == (1 / 3.0) * (inSample.values(0) + inSample.values(3) + inSample.values(6)));
189 BOOST_TEST(outValues(1) == 0.0);
190 BOOST_TEST(outValues(2) == 0.0);
191}
192
193PRECICE_TEST_SETUP(1_rank);
194BOOST_AUTO_TEST_CASE(ConsistentCollectZ1D3D)
195{
196 PRECICE_TEST();
197 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the z-axis.
198 Then, the data is mapped from multiple defined vertices on the circular inlet of the 3D mesh to the single vertex of the 1D mesh (hence, "collect").
199 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
200 Finally, this expected behavior is tested.
201 */
202 constexpr int dimensions = 3;
203 using testing::equals;
204
205 // Create mesh to map from
206 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
207 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (3D): center
208 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0)); // Point b (3D): distance of 1.0 = r to center
209 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point c (3D): distance of 0.5 = r/2 to center
210 inMesh->allocateDataValues();
211
212 // Create mesh to map to
213 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
214 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (1D): equal to center of incoming mesh
215 outMesh->allocateDataValues();
216
217 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
218
219 // Setup mapping with mapping coordinates and geometry used
221 mapping.setMeshes(inMesh, outMesh);
222 BOOST_TEST(mapping.hasComputedMapping() == false);
223
224 // Create data to map
225 Eigen::VectorXd inValues(9);
226 inValues << 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.0, 0.0, 3.0;
227 const time::Sample inSample{3, inValues};
228 Eigen::VectorXd outValues(3);
229 outValues = Eigen::VectorXd::Zero(3);
230
231 // Map data
232 mapping.computeMapping();
233 mapping.map(inSample, outValues);
234
235 BOOST_TEST(mapping.hasComputedMapping() == true);
236
237 // Point A (1D): Check if data is averaged at center node
238 BOOST_TEST(outValues(0) == 0.0);
239 BOOST_TEST(outValues(1) == 0.0);
240 BOOST_TEST(outValues(2) == (1 / 3.0) * (inSample.values(2) + inSample.values(5) + inSample.values(8)));
241}
242
243PRECICE_TEST_SETUP(1_rank);
244BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarParabolicY1D3D)
245{
246 PRECICE_TEST();
247 // 1D -> 3D, scalar data, parabolic spread along the Y axis
248 constexpr int dimensions = 3;
249 using testing::equals;
250
251 // Create mesh to map from
252 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
253 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (1D)
254 inMesh->allocateDataValues();
255
256 // Create mesh to map to
257 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
258 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (3D): center, equal to incoming mesh node
259 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0)); // Point B (3D): distance of 1.0 = r to center
260 outMesh->createVertex(Eigen::Vector3d(0.5, 0.0, 0.0)); // Point C (3D): distance of 0.5 = r/2 to center
261 outMesh->allocateDataValues();
262
263 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
264
265 // Setup mapping with mapping coordinates and geometry used
267 mapping.setMeshes(inMesh, outMesh);
268 BOOST_TEST(mapping.hasComputedMapping() == false);
269
270 // Create data to map
271 Eigen::VectorXd inValues(1);
272 inValues << 30.0;
273 const time::Sample inSample{1, inValues};
274 Eigen::VectorXd outValues(3);
275 outValues = Eigen::VectorXd::Zero(3);
276
277 // Map data
278 mapping.computeMapping();
279 mapping.map(inSample, outValues);
280
281 BOOST_TEST(mapping.hasComputedMapping() == true);
282
283 // Point A (3D): Check if point data is doubled at center node
284 BOOST_TEST(outValues(0) == 2 * inSample.values(0));
285 // Point B (3D): Check if point data at distance = r is equal to zero
286 BOOST_TEST(outValues(1) == 0);
287 // Point C (3D): Check if point data at distance = r/2 is 3/2 times invalue data
288 BOOST_TEST(outValues(2) == 1.5 * inSample.values(0));
289}
290
291PRECICE_TEST_SETUP(1_rank);
292BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarUniformX1D3D)
293{
294 PRECICE_TEST();
295 // 1D -> 3D, scalar data, uniform spread along the X axis
296 constexpr int dimensions = 3;
297 using testing::equals;
298
299 // Create mesh to map from
300 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
301 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (1D)
302 inMesh->allocateDataValues();
303
304 // Create mesh to map to
305 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
306 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (3D): center, equal to incoming mesh node
307 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0)); // Point B (3D): distance of 1.0 = r to center
308 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point C (3D): distance of 0.5 = r/2 to center
309 outMesh->allocateDataValues();
310
311 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
312
313 // Setup mapping with mapping coordinates and geometry used
315 mapping.setMeshes(inMesh, outMesh);
316 BOOST_TEST(mapping.hasComputedMapping() == false);
317
318 // Create data to map
319 Eigen::VectorXd inValues(1);
320 inValues << 42.0;
321 const time::Sample inSample{1, inValues};
322 Eigen::VectorXd outValues(3);
323 outValues = Eigen::VectorXd::Zero(3);
324
325 // Map data
326 mapping.computeMapping();
327 mapping.map(inSample, outValues);
328
329 BOOST_TEST(mapping.hasComputedMapping() == true);
330
331 // All outputs equal to the scalar input
332 BOOST_TEST(outValues(0) == 42.0);
333 BOOST_TEST(outValues(1) == 42.0);
334 BOOST_TEST(outValues(2) == 42.0);
335}
336
337PRECICE_TEST_SETUP(1_rank);
338BOOST_AUTO_TEST_CASE(ConsistentCollectScalarZ1D3D)
339{
340 PRECICE_TEST();
341 // 3D -> 1D, scalar data: average over input vertices to the single output vertex, along Z axis
342 constexpr int dimensions = 3;
343 using testing::equals;
344
345 // Create mesh to map from
346 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
347 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (3D): center
348 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0)); // Point b (3D): distance of 1.0 = r to center
349 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point c (3D): distance of 0.5 = r/2 to center
350 inMesh->allocateDataValues();
351
352 // Create mesh to map to
353 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
354 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (1D): equal to center of incoming mesh
355 outMesh->allocateDataValues();
356
357 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
358
359 // Setup mapping with mapping coordinates and geometry used
361 mapping.setMeshes(inMesh, outMesh);
362 BOOST_TEST(mapping.hasComputedMapping() == false);
363
364 // Create data to map
365 Eigen::VectorXd inValues(3);
366 inValues << 3.0, 7.0, 5.0;
367 const time::Sample inSample{1, inValues};
368 Eigen::VectorXd outValues(1);
369 outValues = Eigen::VectorXd::Zero(1);
370
371 // Map data
372 mapping.computeMapping();
373 mapping.map(inSample, outValues);
374
375 BOOST_TEST(mapping.hasComputedMapping() == true);
376
377 // All outputs equal to the scalar input
378 BOOST_TEST(outValues(0) == (3.0 + 7.0 + 5.0) / 3);
379}
380
381PRECICE_TEST_SETUP(1_rank);
382BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarUniformZ2D3D)
383{
384 PRECICE_TEST();
385 // 2D -> 3D, scalar data, uniform spread along the Z axis
386 constexpr int dimensions = 3;
387 using testing::equals;
388
389 // Create mesh to map from
390 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
391 inMesh->createVertex(Eigen::Vector3d(0.0, -1.0, 0.0));
392 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
393 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
394 inMesh->allocateDataValues();
395
396 // Create mesh to map to
397 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
398 outMesh->createVertex(Eigen::Vector3d(0.0, -1.1, 0.0)); // w0 -> nearest v0
399 outMesh->createVertex(Eigen::Vector3d(0.0, -0.2, 0.0)); // w1 -> nearest v1
400 outMesh->createVertex(Eigen::Vector3d(0.0, 0.3, 0.0)); // w2 -> nearest v1 (banding)
401 outMesh->createVertex(Eigen::Vector3d(0.0, 0.9, 0.0)); // w3 -> nearest v2
402 outMesh->allocateDataValues();
403
404 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
405
406 // Setup mapping with mapping coordinates and geometry used
408 mapping.setMeshes(inMesh, outMesh);
409 BOOST_TEST(mapping.hasComputedMapping() == false);
410
411 // Create data to map
412 Eigen::VectorXd inValues(3);
413 inValues << 10.0, 20.0, 30.0;
414 const time::Sample inSample{1, inValues};
415 Eigen::VectorXd outValues(4);
416 outValues = Eigen::VectorXd::Zero(4);
417
418 // Map data
419 mapping.computeMapping();
420 mapping.map(inSample, outValues);
421
422 BOOST_TEST(mapping.hasComputedMapping() == true);
423
424 BOOST_TEST(outValues(0) == 10.0);
425 BOOST_TEST(outValues(1) == 20.0);
426 BOOST_TEST(outValues(2) == 20.0);
427 BOOST_TEST(outValues(3) == 30.0);
428}
429
430PRECICE_TEST_SETUP(1_rank);
431BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarParabolicZ2D3D)
432{
433 PRECICE_TEST();
434 // 2D -> 3D, scalar data, uniform spread along the Z axis
435 constexpr int dimensions = 3;
436 using testing::equals;
437
438 // Create mesh to map from
439 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
440 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
441 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
442 inMesh->allocateDataValues();
443
444 // Create mesh to map to
445 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
446 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
447 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
448 outMesh->createVertex(Eigen::Vector3d(1.0, 0.5, 0.0));
449 outMesh->createVertex(Eigen::Vector3d(1.0, 1.0, 0.0));
450 outMesh->allocateDataValues();
451
452 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
453
454 // Setup mapping with mapping coordinates and geometry used
456 mapping.setMeshes(inMesh, outMesh);
457 BOOST_TEST(mapping.hasComputedMapping() == false);
458
459 // Create data to map
460 Eigen::VectorXd inValues(2);
461 inValues << 10.0, 20.0;
462 const time::Sample inSample{1, inValues};
463 Eigen::VectorXd outValues(4);
464 outValues = Eigen::VectorXd::Zero(4);
465
466 // Map data
467 mapping.computeMapping();
468 mapping.map(inSample, outValues);
469
470 BOOST_TEST(mapping.hasComputedMapping() == true);
471
472 BOOST_TEST(outValues(0) == 40.0 / 3.0);
473 BOOST_TEST(outValues(1) == 0.0);
474 BOOST_TEST(outValues(2) == 20.0);
475 BOOST_TEST(outValues(3) == 0.0);
476}
477
478PRECICE_TEST_SETUP(1_rank);
479BOOST_AUTO_TEST_CASE(ConsistentSpreadUniformVectorY2D3D)
480{
481 PRECICE_TEST();
482 // 2D -> 3D, scalar data, uniform spread along the Y axis
483 constexpr int dimensions = 3;
484 using testing::equals;
485
486 // Create mesh to map from
487 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
488 inMesh->createVertex(Eigen::Vector3d(-1.0, 0.0, 0.0));
489 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
490 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
491 inMesh->allocateDataValues();
492
493 // Create mesh to map to
494 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
495 outMesh->createVertex(Eigen::Vector3d(-1.1, 0.0, 0.0)); // w0 -> nearest v0
496 outMesh->createVertex(Eigen::Vector3d(-0.2, 0.0, 0.0)); // w1 -> nearest v1
497 outMesh->createVertex(Eigen::Vector3d(0.3, 0.0, 0.0)); // w2 -> nearest v1 (banding)
498 outMesh->createVertex(Eigen::Vector3d(0.9, 0.0, 0.0)); // w3 -> nearest v2
499 outMesh->allocateDataValues();
500
501 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
502
503 // Setup mapping with mapping coordinates and geometry used
505 mapping.setMeshes(inMesh, outMesh);
506 BOOST_TEST(mapping.hasComputedMapping() == false);
507
508 // Create data to map
509 Eigen::VectorXd inValues(9);
510 inValues << 0.0, 10.0, 0.0,
511 0.0, 20.0, 0.0,
512 0.0, 30.0, 0.0;
513 const time::Sample inSample{3, inValues};
514 Eigen::VectorXd outValues(12);
515 outValues = Eigen::VectorXd::Zero(12);
516
517 // Map data
518 mapping.computeMapping();
519 mapping.map(inSample, outValues);
520
521 BOOST_TEST(mapping.hasComputedMapping() == true);
522
523 BOOST_TEST(outValues(1) == 10.0);
524 BOOST_TEST(outValues(4) == 20.0);
525 BOOST_TEST(outValues(7) == 20.0);
526 BOOST_TEST(outValues(10) == 30.0);
527}
528
529PRECICE_TEST_SETUP(1_rank);
530BOOST_AUTO_TEST_CASE(ConsistentSpreadParabolicVectorY2D3D)
531{
532 PRECICE_TEST();
533 // 2D -> 3D, scalar data, uniform spread along the Y axis
534 constexpr int dimensions = 3;
535 using testing::equals;
536
537 // Create mesh to map from
538 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
539 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
540 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
541 inMesh->allocateDataValues();
542
543 // Create mesh to map to
544 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
545 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
546 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.5));
547 outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.5));
548 outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 1.0));
549 outMesh->allocateDataValues();
550
551 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
552
553 // Setup mapping with mapping coordinates and geometry used
555 mapping.setMeshes(inMesh, outMesh);
556 BOOST_TEST(mapping.hasComputedMapping() == false);
557
558 // Create data to map
559 Eigen::VectorXd inValues(6);
560 inValues << 0.0, 10.0, 0.0,
561 0.0, 20.0, 0.0;
562 const time::Sample inSample{3, inValues};
563 Eigen::VectorXd outValues(12);
564 outValues = Eigen::VectorXd::Zero(12);
565
566 // Map data
567 mapping.computeMapping();
568 mapping.map(inSample, outValues);
569
570 BOOST_TEST(mapping.hasComputedMapping() == true);
571
572 BOOST_TEST(outValues(1) == 40.0 / 3.0);
573 BOOST_TEST(outValues(4) == 0.0);
574 BOOST_TEST(outValues(7) == 20.0);
575 BOOST_TEST(outValues(10) == 0.0);
576}
577
578PRECICE_TEST_SETUP(1_rank);
579BOOST_AUTO_TEST_CASE(ConsistentCollectScalarX2D3D)
580{
581 PRECICE_TEST();
582 // 3D -> 2D, scalar data, collect along the X axis
583 constexpr int dimensions = 3;
584 using testing::equals;
585
586 // Create mesh to map from
587 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
588 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -1.1));
589 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.9));
590 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.2));
591 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.8));
592 inMesh->allocateDataValues();
593
594 // Create mesh to map to
595 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
596 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -1.0));
597 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
598 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0));
599 outMesh->allocateDataValues();
600
601 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
602
603 // Setup mapping with mapping coordinates and geometry used
605 mapping.setMeshes(inMesh, outMesh);
606 BOOST_TEST(mapping.hasComputedMapping() == false);
607
608 // Create data to map
609 Eigen::VectorXd inValues(4);
610 inValues << 10.0, 20.0, 30.0, 40.0;
611 const time::Sample inSample{1, inValues};
612 Eigen::VectorXd outValues(3);
613 outValues = Eigen::VectorXd::Zero(3);
614
615 // Map data
616 mapping.computeMapping();
617 mapping.map(inSample, outValues);
618
619 BOOST_TEST(mapping.hasComputedMapping() == true);
620
621 BOOST_TEST(outValues(0) == 15.0);
622 BOOST_TEST(outValues(1) == 30.0);
623 BOOST_TEST(outValues(2) == 40.0);
624}
625
626PRECICE_TEST_SETUP(1_rank);
627BOOST_AUTO_TEST_CASE(ConsistentCollectVectorY2D3D)
628{
629 PRECICE_TEST();
630 // 3D -> 2D, scalar data, collect along the X axis
631 constexpr int dimensions = 3;
632 using testing::equals;
633
634 // Create mesh to map from
635 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
636 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -1.1));
637 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.9));
638 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.2));
639 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.8));
640 inMesh->allocateDataValues();
641
642 // Create mesh to map to
643 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
644 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -1.0));
645 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
646 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0));
647 outMesh->allocateDataValues();
648
649 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
650
651 // Setup mapping with mapping coordinates and geometry used
653 mapping.setMeshes(inMesh, outMesh);
654 BOOST_TEST(mapping.hasComputedMapping() == false);
655
656 // Create data to map
657 Eigen::VectorXd inValues(12);
658 inValues << 0.0, 10.0, 0.0,
659 0.0, 20.0, 0.0,
660 0.0, 30.0, 0.0,
661 0.0, 40.0, 0.0;
662 const time::Sample inSample{3, inValues};
663 Eigen::VectorXd outValues(9);
664 outValues = Eigen::VectorXd::Zero(9);
665
666 // Map data
667 mapping.computeMapping();
668 mapping.map(inSample, outValues);
669
670 BOOST_TEST(mapping.hasComputedMapping() == true);
671
672 BOOST_TEST(outValues(1) == 15.0);
673 BOOST_TEST(outValues(4) == 30.0);
674 BOOST_TEST(outValues(7) == 40.0);
675}
676
677PRECICE_TEST_SETUP(1_rank);
678BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarParabolicZ1D2D)
679{
680 PRECICE_TEST();
681 constexpr int dimensions = 3;
682
683 // 1D mesh (single vertex)
684 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
685 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
686 inMesh->allocateDataValues();
687
688 // 2D mesh (we place points such that distance-from-center is in Y)
689 // center: y=0, wall: y=h, mid: y=h/2
690 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
691 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0)); // center
692 outMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0)); // wall (h)
693 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // mid (h/2)
694 outMesh->allocateDataValues();
695
696 double radius = 1.0; // interpret as half-gap h for parallel plates
697
703 radius,
706
707 mapping.setMeshes(inMesh, outMesh);
708
709 Eigen::VectorXd inValues(1);
710 inValues << 30.0;
711 const time::Sample inSample{1, inValues};
712
713 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
714
715 mapping.computeMapping();
716 mapping.map(inSample, outValues);
717
718 // 2D Poiseuille between parallel plates:
719 // center: (3/2)*avg, wall: 0, mid (h/2): (9/8)*avg
720 BOOST_TEST(outValues(0) == 1.5 * inSample.values(0));
721 BOOST_TEST(outValues(1) == 0.0);
722 BOOST_TEST(outValues(2) == 1.125 * inSample.values(0));
723}
724
725PRECICE_TEST_SETUP(1_rank);
726BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarUniformZ1D2D)
727{
728 PRECICE_TEST();
729 constexpr int dimensions = 3;
730
731 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
732 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
733 inMesh->allocateDataValues();
734
735 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
736 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
737 outMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
738 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
739 outMesh->allocateDataValues();
740
741 double radius = 1.0;
742
748 radius,
751
752 mapping.setMeshes(inMesh, outMesh);
753
754 Eigen::VectorXd inValues(1);
755 inValues << 42.0;
756 const time::Sample inSample{1, inValues};
757
758 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
759
760 mapping.computeMapping();
761 mapping.map(inSample, outValues);
762
763 BOOST_TEST(outValues(0) == 42.0);
764 BOOST_TEST(outValues(1) == 42.0);
765 BOOST_TEST(outValues(2) == 42.0);
766}
767
768PRECICE_TEST_SETUP(1_rank);
769BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorParabolicY1D2D)
770{
771 PRECICE_TEST();
772 constexpr int dimensions = 3;
773
774 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
775 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
776 inMesh->allocateDataValues();
777
778 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
779 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0)); // center
780 outMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0)); // wall
781 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // mid
782 outMesh->allocateDataValues();
783
784 double radius = 1.0;
785
791 radius,
794
795 mapping.setMeshes(inMesh, outMesh);
796
797 Eigen::VectorXd inValues(3);
798 inValues << 0.0, 8.0, 0.0; // only Y component
799 const time::Sample inSample{3, inValues};
800
801 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(9);
802
803 mapping.computeMapping();
804 mapping.map(inSample, outValues);
805
806 // Check that only Y-components are populated according to 2D Poiseuille factors
807 // Vertex 0 (center)
808 BOOST_TEST(outValues(0) == 0.0);
809 BOOST_TEST(outValues(1) == 1.5 * inSample.values(1));
810 BOOST_TEST(outValues(2) == 0.0);
811
812 // Vertex 1 (wall)
813 BOOST_TEST(outValues(3) == 0.0);
814 BOOST_TEST(outValues(4) == 0.0);
815 BOOST_TEST(outValues(5) == 0.0);
816
817 // Vertex 2 (mid)
818 BOOST_TEST(outValues(6) == 0.0);
819 BOOST_TEST(outValues(7) == 1.125 * inSample.values(1));
820 BOOST_TEST(outValues(8) == 0.0);
821}
822
823PRECICE_TEST_SETUP(1_rank);
824BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorUniformY1D2D)
825{
826 PRECICE_TEST();
827 constexpr int dimensions = 3;
828
829 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
830 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
831 inMesh->allocateDataValues();
832
833 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
834 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
835 outMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
836 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
837 outMesh->allocateDataValues();
838
839 double radius = 1.0;
840
846 radius,
849
850 mapping.setMeshes(inMesh, outMesh);
851
852 Eigen::VectorXd inValues(3);
853 inValues << 0.0, 3.0, 0.0;
854 const time::Sample inSample{3, inValues};
855
856 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(9);
857
858 mapping.computeMapping();
859 mapping.map(inSample, outValues);
860
861 // All points get the same vector
862 BOOST_TEST(outValues(1) == 3.0);
863 BOOST_TEST(outValues(4) == 3.0);
864 BOOST_TEST(outValues(7) == 3.0);
865
866 // other components remain 0
867 BOOST_TEST(outValues(0) == 0.0);
868 BOOST_TEST(outValues(2) == 0.0);
869 BOOST_TEST(outValues(3) == 0.0);
870 BOOST_TEST(outValues(5) == 0.0);
871 BOOST_TEST(outValues(6) == 0.0);
872 BOOST_TEST(outValues(8) == 0.0);
873}
874
875PRECICE_TEST_SETUP(1_rank);
876BOOST_AUTO_TEST_CASE(ConsistentCollectScalarX1D2D)
877{
878 PRECICE_TEST();
879 constexpr int dimensions = 3;
880
881 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
882 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
883 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
884 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
885 inMesh->allocateDataValues();
886
887 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
888 outMesh->createVertex(Eigen::Vector3d::Constant(0.0));
889 outMesh->allocateDataValues();
890
891 double radius = 1.0;
892
898 radius);
899
900 mapping.setMeshes(inMesh, outMesh);
901
902 Eigen::VectorXd inValues(3);
903 inValues << 3.0, 7.0, 5.0;
904 const time::Sample inSample{1, inValues};
905
906 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(1);
907
908 mapping.computeMapping();
909 mapping.map(inSample, outValues);
910
911 BOOST_TEST(outValues(0) == (3.0 + 7.0 + 5.0) / 3.0);
912}
913
914PRECICE_TEST_SETUP(1_rank);
915BOOST_AUTO_TEST_CASE(ConsistentCollectVectorX1D2D)
916{
917 PRECICE_TEST();
918 constexpr int dimensions = 3;
919
920 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
921 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
922 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
923 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
924 inMesh->allocateDataValues();
925
926 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
927 outMesh->createVertex(Eigen::Vector3d::Constant(0.0));
928 outMesh->allocateDataValues();
929
930 double radius = 1.0;
931
937 radius);
938
939 mapping.setMeshes(inMesh, outMesh);
940
941 Eigen::VectorXd inValues(9);
942 inValues << 10.0, 0.0, 0.0,
943 20.0, 0.0, 0.0,
944 30.0, 0.0, 0.0;
945 const time::Sample inSample{3, inValues};
946
947 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
948
949 mapping.computeMapping();
950 mapping.map(inSample, outValues);
951
952 BOOST_TEST(outValues(0) == (10.0 + 20.0 + 30.0) / 3.0);
953 BOOST_TEST(outValues(1) == 0.0);
954 BOOST_TEST(outValues(2) == 0.0);
955}
956
957PRECICE_TEST_SETUP(1_rank);
958BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarParabolicZ1D3D_Square)
959{
960 PRECICE_TEST();
961 constexpr int dimensions = 3;
962 const auto tol = boost::test_tools::tolerance(1e-12);
963
964 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
965 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
966 inMesh->allocateDataValues();
967
968 // Axis=Z => transverse coords are X,Y. Include a corner to test product term.
969 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
970 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0)); // center (s1=0,s2=0)
971 outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0)); // edge (s1=1,s2=0)
972 outMesh->createVertex(Eigen::Vector3d(0.5, 0.0, 0.0)); // mid (s1=0.5,s2=0)
973 outMesh->createVertex(Eigen::Vector3d(0.5, 0.5, 0.0)); // corner (s1=0.5,s2=0.5)
974 outMesh->allocateDataValues();
975
976 const double radius = 1.0;
977
983 radius,
986
987 mapping.setMeshes(inMesh, outMesh);
988
989 Eigen::VectorXd inValues(1);
990 inValues << 30.0;
991 const time::Sample inSample{1, inValues};
992
993 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(4);
994
995 mapping.computeMapping();
996 mapping.map(inSample, outValues);
997
998 constexpr double factor = 2.096;
999 constexpr double m = 0.879;
1000
1001 const double u = inSample.values(0);
1002
1003 const double b_center = 1.0; // 1 - 0^2
1004 const double b_mid = 1.0 - 0.5 * 0.5; // 0.75
1005 const double b_corner = 1.0 - 0.5 * 0.5; // 0.75
1006
1007 const double expected_center = factor * u * std::pow(b_center, m) * std::pow(b_center, m);
1008 const double expected_mid = factor * u * std::pow(b_mid, m) * std::pow(b_center, m);
1009 const double expected_corner = factor * u * std::pow(b_corner, m) * std::pow(b_corner, m);
1010
1011 BOOST_TEST(outValues(0) == expected_center, tol);
1012 BOOST_TEST(outValues(1) == 0.0, tol);
1013 BOOST_TEST(outValues(2) == expected_mid, tol);
1014 BOOST_TEST(outValues(3) == expected_corner, tol);
1015}
1016
1017PRECICE_TEST_SETUP(1_rank);
1018BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarUniformZ1D3D_Square)
1019{
1020 PRECICE_TEST();
1021 constexpr int dimensions = 3;
1022
1023 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1024 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1025 inMesh->allocateDataValues();
1026
1027 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1028 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1029 outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
1030 outMesh->createVertex(Eigen::Vector3d(0.5, 0.0, 0.0));
1031 outMesh->createVertex(Eigen::Vector3d(0.5, 0.5, 0.0));
1032 outMesh->allocateDataValues();
1033
1034 const double radius = 1.0;
1035
1037 mapping::Mapping::CONSISTENT, dimensions,
1041 radius,
1044
1045 mapping.setMeshes(inMesh, outMesh);
1046
1047 Eigen::VectorXd inValues(1);
1048 inValues << 42.0;
1049 const time::Sample inSample{1, inValues};
1050
1051 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(4);
1052
1053 mapping.computeMapping();
1054 mapping.map(inSample, outValues);
1055
1056 BOOST_TEST(outValues(0) == 42.0);
1057 BOOST_TEST(outValues(1) == 42.0);
1058 BOOST_TEST(outValues(2) == 42.0);
1059 BOOST_TEST(outValues(3) == 42.0);
1060}
1061
1062PRECICE_TEST_SETUP(1_rank);
1063BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorParabolicX1D3D_Square)
1064{
1065 PRECICE_TEST();
1066 constexpr int dimensions = 3;
1067 const auto tol = boost::test_tools::tolerance(1e-12);
1068
1069 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1070 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1071 inMesh->allocateDataValues();
1072
1073 // Axis=X => transverse coords are Y,Z. Include a corner point (0.5,0.5) in YZ.
1074 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1075 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0)); // center
1076 outMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0)); // edge (s1=1)
1077 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // mid (s1=0.5)
1078 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.5)); // corner (s1=0.5,s2=0.5)
1079 outMesh->allocateDataValues();
1080
1081 const double radius = 1.0;
1082
1084 mapping::Mapping::CONSISTENT, dimensions,
1088 radius,
1091
1092 mapping.setMeshes(inMesh, outMesh);
1093
1094 Eigen::VectorXd inValues(3);
1095 inValues << 2.0, 0.0, 0.0; // only X component
1096 const time::Sample inSample{3, inValues};
1097
1098 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(12);
1099
1100 mapping.computeMapping();
1101 mapping.map(inSample, outValues);
1102
1103 constexpr double factor = 2.096;
1104 constexpr double m = 0.879;
1105
1106 const double u = inSample.values(0);
1107
1108 const double b_center = 1.0;
1109 const double b_mid = 1.0 - 0.5 * 0.5; // 0.75
1110 const double b_corner = 1.0 - 0.5 * 0.5; // 0.75
1111
1112 const double expected_center = factor * u * std::pow(b_center, m) * std::pow(b_center, m);
1113 const double expected_edge = 0.0;
1114 const double expected_mid = factor * u * std::pow(b_mid, m) * std::pow(b_center, m);
1115 const double expected_corner = factor * u * std::pow(b_corner, m) * std::pow(b_corner, m);
1116
1117 // vertex 0
1118 BOOST_TEST(outValues(0) == expected_center, tol);
1119 BOOST_TEST(outValues(1) == 0.0, tol);
1120 BOOST_TEST(outValues(2) == 0.0, tol);
1121 // vertex 1
1122 BOOST_TEST(outValues(3) == expected_edge, tol);
1123 BOOST_TEST(outValues(4) == 0.0, tol);
1124 BOOST_TEST(outValues(5) == 0.0, tol);
1125 // vertex 2
1126 BOOST_TEST(outValues(6) == expected_mid, tol);
1127 BOOST_TEST(outValues(7) == 0.0, tol);
1128 BOOST_TEST(outValues(8) == 0.0, tol);
1129 // vertex 3
1130 BOOST_TEST(outValues(9) == expected_corner, tol);
1131 BOOST_TEST(outValues(10) == 0.0, tol);
1132 BOOST_TEST(outValues(11) == 0.0, tol);
1133}
1134
1135PRECICE_TEST_SETUP(1_rank);
1136BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorUniformX1D3D_Square)
1137{
1138 PRECICE_TEST();
1139 constexpr int dimensions = 3;
1140
1141 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1142 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1143 inMesh->allocateDataValues();
1144
1145 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1146 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1147 outMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
1148 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
1149 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.5));
1150 outMesh->allocateDataValues();
1151
1152 const double radius = 1.0;
1153
1155 mapping::Mapping::CONSISTENT, dimensions,
1159 radius,
1162
1163 mapping.setMeshes(inMesh, outMesh);
1164
1165 Eigen::VectorXd inValues(3);
1166 inValues << 4.0, 0.0, 0.0;
1167 const time::Sample inSample{3, inValues};
1168
1169 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(12);
1170
1171 mapping.computeMapping();
1172 mapping.map(inSample, outValues);
1173
1174 for (int v = 0; v < 4; ++v) {
1175 BOOST_TEST(outValues(3 * v + 0) == 4.0);
1176 BOOST_TEST(outValues(3 * v + 1) == 0.0);
1177 BOOST_TEST(outValues(3 * v + 2) == 0.0);
1178 }
1179}
1180
1181PRECICE_TEST_SETUP(1_rank);
1182BOOST_AUTO_TEST_CASE(ConsistentCollectScalarUniformX1D3D_Square)
1183{
1184 PRECICE_TEST();
1185 constexpr int dimensions = 3;
1186
1187 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1188 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1189 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
1190 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
1191 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.5));
1192 inMesh->allocateDataValues();
1193
1194 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1195 outMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1196 outMesh->allocateDataValues();
1197
1198 const double radius = 1.0;
1199
1201 mapping::Mapping::CONSISTENT, dimensions,
1205 radius,
1208
1209 mapping.setMeshes(inMesh, outMesh);
1210
1211 Eigen::VectorXd inValues(4);
1212 inValues << 1.0, 2.0, 3.0, 4.0;
1213 const time::Sample inSample{1, inValues};
1214
1215 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(1);
1216
1217 mapping.computeMapping();
1218 mapping.map(inSample, outValues);
1219
1220 BOOST_TEST(outValues(0) == (1.0 + 2.0 + 3.0 + 4.0) / 4.0);
1221}
1222
1223PRECICE_TEST_SETUP(1_rank);
1224BOOST_AUTO_TEST_CASE(ConsistentCollectVectorUniformX1D3D_Square)
1225{
1226 PRECICE_TEST();
1227 constexpr int dimensions = 3;
1228
1229 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1230 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1231 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
1232 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
1233 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.5));
1234 inMesh->allocateDataValues();
1235
1236 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1237 outMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1238 outMesh->allocateDataValues();
1239
1240 const double radius = 1.0;
1241
1243 mapping::Mapping::CONSISTENT, dimensions,
1247 radius,
1250
1251 mapping.setMeshes(inMesh, outMesh);
1252
1253 Eigen::VectorXd inValues(12);
1254 inValues << 1.0, 0.0, 0.0,
1255 2.0, 0.0, 0.0,
1256 3.0, 0.0, 0.0,
1257 4.0, 0.0, 0.0;
1258 const time::Sample inSample{3, inValues};
1259
1260 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
1261
1262 mapping.computeMapping();
1263 mapping.map(inSample, outValues);
1264
1265 BOOST_TEST(outValues(0) == (1.0 + 2.0 + 3.0 + 4.0) / 4.0);
1266 BOOST_TEST(outValues(1) == 0.0);
1267 BOOST_TEST(outValues(2) == 0.0);
1268}
1269
1270PRECICE_TEST_SETUP(1_rank);
1271BOOST_AUTO_TEST_CASE(ConsistentCollectScalarParabolicX1D3D_Square)
1272{
1273 PRECICE_TEST();
1274 constexpr int dimensions = 3;
1275
1276 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1277 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1278 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
1279 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
1280 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.5));
1281 inMesh->allocateDataValues();
1282
1283 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1284 outMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1285 outMesh->allocateDataValues();
1286
1287 const double radius = 1.0;
1288
1290 mapping::Mapping::CONSISTENT, dimensions,
1294 radius,
1297
1298 mapping.setMeshes(inMesh, outMesh);
1299
1300 Eigen::VectorXd inValues(4);
1301 inValues << 10.0, 20.0, 30.0, 40.0;
1302 const time::Sample inSample{1, inValues};
1303
1304 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(1);
1305
1306 mapping.computeMapping();
1307 mapping.map(inSample, outValues);
1308
1309 BOOST_TEST(outValues(0) == (10.0 + 20.0 + 30.0 + 40.0) / 4.0);
1310}
1311
1312PRECICE_TEST_SETUP(1_rank);
1313BOOST_AUTO_TEST_CASE(ConsistentCollectVectorParabolicX1D3D_Square)
1314{
1315 PRECICE_TEST();
1316 constexpr int dimensions = 3;
1317
1318 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1319 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1320 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
1321 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0));
1322 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.5));
1323 inMesh->allocateDataValues();
1324
1325 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1326 outMesh->createVertex(Eigen::Vector3d::Constant(0.0));
1327 outMesh->allocateDataValues();
1328
1329 const double radius = 1.0;
1330
1332 mapping::Mapping::CONSISTENT, dimensions,
1336 radius,
1339
1340 mapping.setMeshes(inMesh, outMesh);
1341
1342 Eigen::VectorXd inValues(12);
1343 inValues << 10.0, 0.0, 0.0,
1344 20.0, 0.0, 0.0,
1345 30.0, 0.0, 0.0,
1346 40.0, 0.0, 0.0;
1347 const time::Sample inSample{3, inValues};
1348
1349 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
1350
1351 mapping.computeMapping();
1352 mapping.map(inSample, outValues);
1353
1354 BOOST_TEST(outValues(0) == (10.0 + 20.0 + 30.0 + 40.0) / 4.0);
1355 BOOST_TEST(outValues(1) == 0.0);
1356 BOOST_TEST(outValues(2) == 0.0);
1357}
1358
1359PRECICE_TEST_SETUP(1_rank);
1360BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarUniformZ2D3D_Square)
1361{
1362 PRECICE_TEST();
1363 constexpr int dimensions = 3;
1364
1365 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1366 inMesh->createVertex(Eigen::Vector3d(0.0, -1.0, 0.0));
1367 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1368 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
1369 inMesh->allocateDataValues();
1370
1371 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1372 outMesh->createVertex(Eigen::Vector3d(0.0, -1.1, 0.0)); // -> v0
1373 outMesh->createVertex(Eigen::Vector3d(0.0, -0.2, 0.0)); // -> v1
1374 outMesh->createVertex(Eigen::Vector3d(0.0, 0.3, 0.0)); // -> v1
1375 outMesh->createVertex(Eigen::Vector3d(0.0, 0.9, 0.0)); // -> v2
1376 outMesh->allocateDataValues();
1377
1378 const double radius = 1.0;
1379
1381 mapping::Mapping::CONSISTENT, dimensions,
1385 radius,
1388
1389 mapping.setMeshes(inMesh, outMesh);
1390
1391 Eigen::VectorXd inValues(3);
1392 inValues << 10.0, 20.0, 30.0;
1393 const time::Sample inSample{1, inValues};
1394
1395 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(4);
1396
1397 mapping.computeMapping();
1398 mapping.map(inSample, outValues);
1399
1400 BOOST_TEST(outValues(0) == 10.0);
1401 BOOST_TEST(outValues(1) == 20.0);
1402 BOOST_TEST(outValues(2) == 20.0);
1403 BOOST_TEST(outValues(3) == 30.0);
1404}
1405
1406PRECICE_TEST_SETUP(1_rank);
1407BOOST_AUTO_TEST_CASE(ConsistentSpreadScalarParabolicZ2D3D_Square)
1408{
1409 PRECICE_TEST();
1410 constexpr int dimensions = 3;
1411 const auto tol = boost::test_tools::tolerance(1e-12);
1412
1413 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1414 // line along Y -> _lineCoord = 1
1415 inMesh->createVertex(Eigen::Vector3d(0.0, -0.5, 0.0)); // v0
1416 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // v1
1417 inMesh->allocateDataValues();
1418
1419 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1420 // near v0
1421 outMesh->createVertex(Eigen::Vector3d(0.0, -0.5, 0.0)); // dist=0
1422 outMesh->createVertex(Eigen::Vector3d(0.5, -0.5, 0.0)); // dist=0.5
1423 // near v1
1424 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // dist=0
1425 outMesh->createVertex(Eigen::Vector3d(0.5, 0.5, 0.0)); // dist=0.5
1426 outMesh->allocateDataValues();
1427
1428 const double radius = 1.0;
1429
1431 mapping::Mapping::CONSISTENT, dimensions,
1435 radius,
1438
1439 mapping.setMeshes(inMesh, outMesh);
1440
1441 Eigen::VectorXd inValues(2);
1442 inValues << 10.0, 20.0;
1443 const time::Sample inSample{1, inValues};
1444
1445 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(4);
1446
1447 mapping.computeMapping();
1448 mapping.map(inSample, outValues);
1449
1450 // Expected from your D2D3 square parabolic formula
1451 constexpr double umax_over_umean = 2.096;
1452 constexpr double line_factor = 1.5;
1453 constexpr double m = 0.879;
1454 constexpr double eps = 1e-12;
1455
1456 // For v0 and v1: s1 = y_in / radius = +/- 0.5 -> b1raw = 1 - 0.25 = 0.75
1457 const double s1 = 0.5;
1458 const double b1raw = 1.0 - s1 * s1; // 0.75
1459 const double b1 = std::max(eps, b1raw);
1460
1461 const double pref = (umax_over_umean / line_factor) * std::pow(b1, m - 1.0);
1462
1463 // dist=0 -> s2=0 -> b2=1
1464 const double b2_0 = 1.0;
1465 // dist=0.5 -> s2=0.5 -> b2=0.75
1466 const double s2_h = 0.5;
1467 const double b2_h = std::max(0.0, 1.0 - s2_h * s2_h); // 0.75
1468
1469 const double expected_v0_d0 = inSample.values(0) * pref * std::pow(b2_0, m);
1470 const double expected_v0_dh = inSample.values(0) * pref * std::pow(b2_h, m);
1471 const double expected_v1_d0 = inSample.values(1) * pref * std::pow(b2_0, m);
1472 const double expected_v1_dh = inSample.values(1) * pref * std::pow(b2_h, m);
1473
1474 BOOST_TEST(outValues(0) == expected_v0_d0, tol);
1475 BOOST_TEST(outValues(1) == expected_v0_dh, tol);
1476 BOOST_TEST(outValues(2) == expected_v1_d0, tol);
1477 BOOST_TEST(outValues(3) == expected_v1_dh, tol);
1478}
1479
1480PRECICE_TEST_SETUP(1_rank);
1481BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorUniformY2D3D_Square)
1482{
1483 PRECICE_TEST();
1484 constexpr int dimensions = 3;
1485
1486 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1487 inMesh->createVertex(Eigen::Vector3d(-1.0, 0.0, 0.0));
1488 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1489 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
1490 inMesh->allocateDataValues();
1491
1492 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1493 outMesh->createVertex(Eigen::Vector3d(-1.1, 0.0, 0.0)); // -> v0
1494 outMesh->createVertex(Eigen::Vector3d(-0.2, 0.0, 0.0)); // -> v1
1495 outMesh->createVertex(Eigen::Vector3d(0.3, 0.0, 0.0)); // -> v1
1496 outMesh->createVertex(Eigen::Vector3d(0.9, 0.0, 0.0)); // -> v2
1497 outMesh->allocateDataValues();
1498
1499 const double radius = 1.0;
1500
1502 mapping::Mapping::CONSISTENT, dimensions,
1506 radius,
1509
1510 mapping.setMeshes(inMesh, outMesh);
1511
1512 Eigen::VectorXd inValues(9);
1513 inValues << 0.0, 10.0, 0.0,
1514 0.0, 20.0, 0.0,
1515 0.0, 30.0, 0.0;
1516 const time::Sample inSample{3, inValues};
1517
1518 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(12);
1519
1520 mapping.computeMapping();
1521 mapping.map(inSample, outValues);
1522
1523 BOOST_TEST(outValues(1) == 10.0);
1524 BOOST_TEST(outValues(4) == 20.0);
1525 BOOST_TEST(outValues(7) == 20.0);
1526 BOOST_TEST(outValues(10) == 30.0);
1527}
1528
1529PRECICE_TEST_SETUP(1_rank);
1530BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorParabolicY2D3D_Square)
1531{
1532 PRECICE_TEST();
1533 constexpr int dimensions = 3;
1534 const auto tol = boost::test_tools::tolerance(1e-12);
1535
1536 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1537 inMesh->createVertex(Eigen::Vector3d(0.0, -0.5, 0.0)); // v0
1538 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // v1
1539 inMesh->allocateDataValues();
1540
1541 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1542 outMesh->createVertex(Eigen::Vector3d(0.0, -0.5, 0.0)); // dist=0
1543 outMesh->createVertex(Eigen::Vector3d(0.5, -0.5, 0.0)); // dist=0.5
1544 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // dist=0
1545 outMesh->createVertex(Eigen::Vector3d(0.5, 0.5, 0.0)); // dist=0.5
1546 outMesh->allocateDataValues();
1547
1548 const double radius = 1.0;
1549
1551 mapping::Mapping::CONSISTENT, dimensions,
1555 radius,
1558
1559 mapping.setMeshes(inMesh, outMesh);
1560
1561 Eigen::VectorXd inValues(6);
1562 inValues << 0.0, 10.0, 0.0,
1563 0.0, 20.0, 0.0;
1564 const time::Sample inSample{3, inValues};
1565
1566 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(12);
1567
1568 mapping.computeMapping();
1569 mapping.map(inSample, outValues);
1570
1571 constexpr double umax_over_umean = 2.096;
1572 constexpr double line_factor = 1.5;
1573 constexpr double m = 0.879;
1574 constexpr double eps = 1e-12;
1575
1576 const double s1 = 0.5;
1577 const double b1raw = 1.0 - s1 * s1; // 0.75
1578 const double b1 = std::max(eps, b1raw);
1579 const double pref = (umax_over_umean / line_factor) * std::pow(b1, m - 1.0);
1580
1581 const double b2_0 = 1.0;
1582 const double s2_h = 0.5;
1583 const double b2_h = std::max(0.0, 1.0 - s2_h * s2_h); // 0.75
1584
1585 const double expected_v0_d0 = 10.0 * pref * std::pow(b2_0, m);
1586 const double expected_v0_dh = 10.0 * pref * std::pow(b2_h, m);
1587 const double expected_v1_d0 = 20.0 * pref * std::pow(b2_0, m);
1588 const double expected_v1_dh = 20.0 * pref * std::pow(b2_h, m);
1589
1590 // Check only Y components: indices 1,4,7,10
1591 BOOST_TEST(outValues(1) == expected_v0_d0, tol);
1592 BOOST_TEST(outValues(4) == expected_v0_dh, tol);
1593 BOOST_TEST(outValues(7) == expected_v1_d0, tol);
1594 BOOST_TEST(outValues(10) == expected_v1_dh, tol);
1595
1596 // Other components should remain zero
1597 BOOST_TEST(outValues(0) == 0.0);
1598 BOOST_TEST(outValues(2) == 0.0);
1599 BOOST_TEST(outValues(3) == 0.0);
1600 BOOST_TEST(outValues(5) == 0.0);
1601 BOOST_TEST(outValues(6) == 0.0);
1602 BOOST_TEST(outValues(8) == 0.0);
1603 BOOST_TEST(outValues(9) == 0.0);
1604 BOOST_TEST(outValues(11) == 0.0);
1605}
1606
1607PRECICE_TEST_SETUP(1_rank);
1608BOOST_AUTO_TEST_CASE(ConsistentCollectScalarUniformX2D3D_Square)
1609{
1610 PRECICE_TEST();
1611 constexpr int dimensions = 3;
1612
1613 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1614 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.6));
1615 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.4));
1616 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.2));
1617 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.6));
1618 inMesh->allocateDataValues();
1619
1620 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1621 // span along Z -> _lineCoord = 2
1622 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.5));
1623 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1624 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.5));
1625 outMesh->allocateDataValues();
1626
1627 const double radius = 1.0;
1628
1630 mapping::Mapping::CONSISTENT, dimensions,
1634 radius,
1637
1638 mapping.setMeshes(inMesh, outMesh);
1639
1640 Eigen::VectorXd inValues(4);
1641 inValues << 10.0, 20.0, 30.0, 40.0;
1642 const time::Sample inSample{1, inValues};
1643
1644 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
1645
1646 mapping.computeMapping();
1647 mapping.map(inSample, outValues);
1648
1649 // Bands: [-0.6,-0.4] -> -0.5 => avg 15; [0.2] -> 0 => 30; [0.6] -> 0.5 => 40
1650 BOOST_TEST(outValues(0) == 15.0);
1651 BOOST_TEST(outValues(1) == 30.0);
1652 BOOST_TEST(outValues(2) == 40.0);
1653}
1654
1655PRECICE_TEST_SETUP(1_rank);
1656BOOST_AUTO_TEST_CASE(ConsistentCollectVectorUniformY2D3D_Square)
1657{
1658 PRECICE_TEST();
1659 constexpr int dimensions = 3;
1660
1661 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1662 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.6));
1663 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.4));
1664 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.2));
1665 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.6));
1666 inMesh->allocateDataValues();
1667
1668 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1669 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.5));
1670 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1671 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.5));
1672 outMesh->allocateDataValues();
1673
1674 const double radius = 1.0;
1675
1677 mapping::Mapping::CONSISTENT, dimensions,
1681 radius,
1684
1685 mapping.setMeshes(inMesh, outMesh);
1686
1687 Eigen::VectorXd inValues(12);
1688 inValues << 0.0, 10.0, 0.0,
1689 0.0, 20.0, 0.0,
1690 0.0, 30.0, 0.0,
1691 0.0, 40.0, 0.0;
1692 const time::Sample inSample{3, inValues};
1693
1694 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(9);
1695
1696 mapping.computeMapping();
1697 mapping.map(inSample, outValues);
1698
1699 // Y-components at outputs: 15, 30, 40
1700 BOOST_TEST(outValues(1) == 15.0);
1701 BOOST_TEST(outValues(4) == 30.0);
1702 BOOST_TEST(outValues(7) == 40.0);
1703}
1704
1705PRECICE_TEST_SETUP(1_rank);
1706BOOST_AUTO_TEST_CASE(ConsistentCollectScalarParabolicX2D3D_Square)
1707{
1708 PRECICE_TEST();
1709 constexpr int dimensions = 3;
1710 const auto tol = boost::test_tools::tolerance(1e-12);
1711
1712 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1713 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.6));
1714 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.4));
1715 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.2));
1716 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.6));
1717 inMesh->allocateDataValues();
1718
1719 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1720 // Keep within [-1,1] so b1 > 0
1721 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.5));
1722 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1723 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.5));
1724 outMesh->allocateDataValues();
1725
1726 const double radius = 1.0;
1727
1729 mapping::Mapping::CONSISTENT, dimensions,
1733 radius,
1736
1737 mapping.setMeshes(inMesh, outMesh);
1738
1739 Eigen::VectorXd inValues(4);
1740 inValues << 10.0, 20.0, 30.0, 40.0;
1741 const time::Sample inSample{1, inValues};
1742
1743 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
1744
1745 mapping.computeMapping();
1746 mapping.map(inSample, outValues);
1747
1748 // Base averages (same as uniform case)
1749 const double avg0 = 15.0;
1750 const double avg1 = 30.0;
1751 const double avg2 = 40.0;
1752
1753 // Square parabolic collect scaling: 1.03745 * pow(b1, 0.121), b1=max(0,1-s1^2), s1=z/radius
1754 constexpr double scaleC = 1.03745;
1755 constexpr double expP = 0.121;
1756
1757 const double z0 = -0.5, z1 = 0.0, z2 = 0.5;
1758
1759 const double b10 = std::max(0.0, 1.0 - z0 * z0); // 0.75
1760 const double b11 = std::max(0.0, 1.0 - z1 * z1); // 1.0
1761 const double b12 = std::max(0.0, 1.0 - z2 * z2); // 0.75
1762
1763 const double expected0 = avg0 * scaleC * std::pow(b10, expP);
1764 const double expected1 = avg1 * scaleC * std::pow(b11, expP);
1765 const double expected2 = avg2 * scaleC * std::pow(b12, expP);
1766
1767 BOOST_TEST(outValues(0) == expected0, tol);
1768 BOOST_TEST(outValues(1) == expected1, tol);
1769 BOOST_TEST(outValues(2) == expected2, tol);
1770}
1771
1772PRECICE_TEST_SETUP(1_rank);
1773BOOST_AUTO_TEST_CASE(ConsistentCollectVectorParabolicY2D3D_Square)
1774{
1775 PRECICE_TEST();
1776 constexpr int dimensions = 3;
1777 const auto tol = boost::test_tools::tolerance(1e-12);
1778
1779 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
1780 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.6));
1781 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.4));
1782 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.2));
1783 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.6));
1784 inMesh->allocateDataValues();
1785
1786 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
1787 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, -0.5));
1788 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1789 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.5));
1790 outMesh->allocateDataValues();
1791
1792 const double radius = 1.0;
1793
1795 mapping::Mapping::CONSISTENT, dimensions,
1799 radius,
1802
1803 mapping.setMeshes(inMesh, outMesh);
1804
1805 Eigen::VectorXd inValues(12);
1806 inValues << 0.0, 10.0, 0.0,
1807 0.0, 20.0, 0.0,
1808 0.0, 30.0, 0.0,
1809 0.0, 40.0, 0.0;
1810 const time::Sample inSample{3, inValues};
1811
1812 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(9);
1813
1814 mapping.computeMapping();
1815 mapping.map(inSample, outValues);
1816
1817 // Base averages for Y component
1818 const double avg0 = 15.0;
1819 const double avg1 = 30.0;
1820 const double avg2 = 40.0;
1821
1822 constexpr double scaleC = 1.03745;
1823 constexpr double expP = 0.121;
1824
1825 const double z0 = -0.5, z1 = 0.0, z2 = 0.5;
1826
1827 const double b10 = std::max(0.0, 1.0 - z0 * z0); // 0.75
1828 const double b11 = std::max(0.0, 1.0 - z1 * z1); // 1.0
1829 const double b12 = std::max(0.0, 1.0 - z2 * z2); // 0.75
1830
1831 const double expected0 = avg0 * scaleC * std::pow(b10, expP);
1832 const double expected1 = avg1 * scaleC * std::pow(b11, expP);
1833 const double expected2 = avg2 * scaleC * std::pow(b12, expP);
1834
1835 // Check only Y-components
1836 BOOST_TEST(outValues(1) == expected0, tol);
1837 BOOST_TEST(outValues(4) == expected1, tol);
1838 BOOST_TEST(outValues(7) == expected2, tol);
1839
1840 // other components remain 0
1841 BOOST_TEST(outValues(0) == 0.0);
1842 BOOST_TEST(outValues(2) == 0.0);
1843 BOOST_TEST(outValues(3) == 0.0);
1844 BOOST_TEST(outValues(5) == 0.0);
1845 BOOST_TEST(outValues(6) == 0.0);
1846 BOOST_TEST(outValues(8) == 0.0);
1847}
1848
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
BOOST_AUTO_TEST_CASE(ConsistentSpreadVectorParabolicZ1D3D)
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
Geometric multiscale mapping in axial direction.
Container and creator for meshes.
Definition Mesh.hpp:38
Vertex & createVertex(const Eigen::Ref< const Eigen::VectorXd > &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:104
void allocateDataValues()
Allocates memory for the vertex data values and corresponding gradient values.
Definition Mesh.cpp:257
contains data mapping from points to meshes.
provides Mesh, Data and primitives.
std::shared_ptr< Mesh > PtrMesh
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
Main namespace of the precice library.
Eigen::VectorXd values
Definition Sample.hpp:64