preCICE v3.2.0
Loading...
Searching...
No Matches
NearestNeighborMappingTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <memory>
4#include <string_view>
6#include "mapping/Mapping.hpp"
8#include "math/constants.hpp"
9#include "mesh/Data.hpp"
10#include "mesh/Mesh.hpp"
12#include "mesh/Utils.hpp"
13#include "mesh/Vertex.hpp"
15#include "testing/Testing.hpp"
16#include "time/Sample.hpp"
17
18using namespace precice;
19using namespace precice::mesh;
20
21BOOST_AUTO_TEST_SUITE(MappingTests)
22BOOST_AUTO_TEST_SUITE(NearestNeighborMapping)
23
25BOOST_AUTO_TEST_CASE(ConsistentNonIncremental)
26{
28 int dimensions = 2;
29 using testing::equals;
30
31 // Create mesh to map from
32 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
33 Vertex &inVertex0 = inMesh->createVertex(Eigen::Vector2d::Constant(0.0));
34 Vertex &inVertex1 = inMesh->createVertex(Eigen::Vector2d::Constant(1.0));
35
36 Eigen::VectorXd inValuesScalar = Eigen::VectorXd::Zero(2);
37 Eigen::VectorXd inValuesVector = Eigen::VectorXd::Zero(4);
38 inValuesScalar << 1.0, 2.0;
39 inValuesVector << 1.0, 2.0, 3.0, 4.0;
40
41 // Create mesh to map to
42 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
43 Vertex &outVertex0 = outMesh->createVertex(Eigen::Vector2d::Constant(0.0));
44 Vertex &outVertex1 = outMesh->createVertex(Eigen::Vector2d::Constant(1.0));
45
46 // Setup mapping with mapping coordinates and geometry used
48 mapping.setMeshes(inMesh, outMesh);
49 BOOST_TEST(mapping.hasComputedMapping() == false);
50
51 // Map data with coinciding vertices, has to result in equal values.
52 mapping.computeMapping();
53 Eigen::VectorXd outValuesScalar = Eigen::VectorXd::Zero(2);
54 time::Sample inSample(1, inValuesScalar);
55 mapping.map(inSample, outValuesScalar);
56 BOOST_TEST(mapping.hasComputedMapping() == true);
57 BOOST_TEST(outValuesScalar(0) == inValuesScalar(0));
58 BOOST_TEST(outValuesScalar(1) == inValuesScalar(1));
59 Eigen::VectorXd outValuesVector = Eigen::VectorXd::Zero(4);
60 inSample = time::Sample(2, inValuesVector);
61 mapping.map(inSample, outValuesVector);
62 BOOST_CHECK(equals(inValuesVector, outValuesVector));
63
64 // Map data with almost coinciding vertices, has to result in equal values.
65 inVertex0.setCoords(outVertex0.getCoords() + Eigen::Vector2d::Constant(0.1));
66 inVertex1.setCoords(outVertex1.getCoords() + Eigen::Vector2d::Constant(0.1));
67 mapping.computeMapping();
68 inSample = time::Sample(1, inValuesScalar);
69 mapping.map(inSample, outValuesScalar);
70 BOOST_TEST(mapping.hasComputedMapping() == true);
71 BOOST_TEST(outValuesScalar(0) == inValuesScalar(0));
72 BOOST_TEST(outValuesScalar(1) == inValuesScalar(1));
73 inSample = time::Sample(2, inValuesVector);
74 mapping.map(inSample, outValuesVector);
75 BOOST_CHECK(equals(inValuesVector, outValuesVector));
76
77 // Map data with exchanged vertices, has to result in exchanged values.
78 inVertex0.setCoords(outVertex1.getCoords());
79 inVertex1.setCoords(outVertex0.getCoords());
80 mapping.computeMapping();
81 inSample = time::Sample(1, inValuesScalar);
82 mapping.map(inSample, outValuesScalar);
83 BOOST_TEST(mapping.hasComputedMapping() == true);
84 BOOST_TEST(outValuesScalar(1) == inValuesScalar(0));
85 BOOST_TEST(outValuesScalar(0) == inValuesScalar(1));
86 inSample = time::Sample(2, inValuesVector);
87 mapping.map(inSample, outValuesVector);
88 Eigen::Vector4d expected(3.0, 4.0, 1.0, 2.0);
89 BOOST_CHECK(equals(expected, outValuesVector));
90
91 // Map data with coinciding output vertices, has to result in same values.
92 outVertex1.setCoords(outVertex0.getCoords());
93 mapping.computeMapping();
94 inSample = time::Sample(1, inValuesScalar);
95 mapping.map(inSample, outValuesScalar);
96 BOOST_TEST(mapping.hasComputedMapping() == true);
97 BOOST_TEST(outValuesScalar(1) == inValuesScalar(1));
98 BOOST_TEST(outValuesScalar(0) == inValuesScalar(1));
99 inSample = time::Sample(2, inValuesVector);
100 mapping.map(inSample, outValuesVector);
101 expected << 3.0, 4.0, 3.0, 4.0;
102 BOOST_CHECK(equals(expected, outValuesVector));
103}
104
105PRECICE_TEST_SETUP(1_rank)
106BOOST_AUTO_TEST_CASE(ConservativeNonIncremental)
107{
108 PRECICE_TEST();
109 int dimensions = 2;
110
111 // Create mesh to map from
112 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
113 Vertex &inVertex0 = inMesh->createVertex(Eigen::Vector2d::Constant(0.0));
114 Vertex &inVertex1 = inMesh->createVertex(Eigen::Vector2d::Constant(1.0));
115 Eigen::VectorXd inValues = Eigen::VectorXd::Zero(2);
116 inValues(0) = 1.0;
117 inValues(1) = 2.0;
118
119 // Create mesh to map to
120 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
121 Vertex &outVertex0 = outMesh->createVertex(Eigen::Vector2d::Constant(0.0));
122 Vertex &outVertex1 = outMesh->createVertex(Eigen::Vector2d::Constant(1.0));
123
124 // Setup mapping with mapping coordinates and geometry used
126 mapping.setMeshes(inMesh, outMesh);
127 BOOST_TEST(mapping.hasComputedMapping() == false);
128
129 // Map data with coinciding vertices, has to result in equal values.
130 mapping.computeMapping();
131 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(2);
132 time::Sample inSample(1, inValues);
133 mapping.map(inSample, outValues);
134 BOOST_TEST(mapping.hasComputedMapping() == true);
135 BOOST_TEST(outValues(0) == inValues(0));
136 BOOST_TEST(outValues(1) == inValues(1));
137 outValues = Eigen::VectorXd::Constant(outValues.size(), 0.0);
138
139 // Map data with almost coinciding vertices, has to result in equal values.
140 inVertex0.setCoords(outVertex0.getCoords() + Eigen::Vector2d::Constant(0.1));
141 inVertex1.setCoords(outVertex1.getCoords() + Eigen::Vector2d::Constant(0.1));
142 mapping.computeMapping();
143 inSample = time::Sample(1, inValues);
144 mapping.map(inSample, outValues);
145 BOOST_TEST(mapping.hasComputedMapping() == true);
146 BOOST_TEST(outValues(0) == inValues(0));
147 BOOST_TEST(outValues(1) == inValues(1));
148 outValues = Eigen::VectorXd::Constant(outValues.size(), 0.0);
149
150 // Map data with exchanged vertices, has to result in exchanged values.
151 inVertex0.setCoords(outVertex1.getCoords());
152 inVertex1.setCoords(outVertex0.getCoords());
153 mapping.computeMapping();
154 inSample = time::Sample(1, inValues);
155 mapping.map(inSample, outValues);
156 BOOST_TEST(mapping.hasComputedMapping() == true);
157 BOOST_TEST(outValues(1) == inValues(0));
158 BOOST_TEST(outValues(0) == inValues(1));
159 outValues = Eigen::VectorXd::Constant(outValues.size(), 0.0);
160
161 // Map data with coinciding output vertices, has to result in double values.
162 outVertex1.setCoords(Eigen::Vector2d::Constant(-1.0));
163 mapping.computeMapping();
164 inSample = time::Sample(1, inValues);
165 mapping.map(inSample, outValues);
166 BOOST_TEST(mapping.hasComputedMapping() == true);
167 BOOST_TEST(outValues(0) == inValues(0) + inValues(1));
168 BOOST_TEST(outValues(1) == 0.0);
169}
170
171PRECICE_TEST_SETUP(1_rank)
172BOOST_AUTO_TEST_CASE(ScaledConsistentNonIncremental)
173{
174 PRECICE_TEST();
175 int dimensions = 2;
176
177 // Create mesh to map from
178 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
179 Vertex &inVertex0 = inMesh->createVertex(Eigen::Vector2d(0.0, 0.0));
180 Vertex &inVertex1 = inMesh->createVertex(Eigen::Vector2d{1.0, 0.0});
181 Vertex &inVertex2 = inMesh->createVertex(Eigen::Vector2d{3.0, 0.0});
182 Vertex &inVertex3 = inMesh->createVertex(Eigen::Vector2d{6.0, 0.0});
183
184 inMesh->createEdge(inVertex0, inVertex1);
185 inMesh->createEdge(inVertex1, inVertex2);
186 inMesh->createEdge(inVertex2, inVertex3);
187
188 Eigen::VectorXd inValues = Eigen::VectorXd::Zero(4);
189 inValues(0) = 1.0;
190 inValues(1) = 2.0;
191 inValues(2) = 3.0;
192 inValues(3) = 4.0;
193
194 // Create mesh to map to
195 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
196 Vertex &outVertex0 = outMesh->createVertex(Eigen::Vector2d(0.0, 0.0));
197 Vertex &outVertex1 = outMesh->createVertex(Eigen::Vector2d(0.8, 0.0));
198 Vertex &outVertex2 = outMesh->createVertex(Eigen::Vector2d(3.0, 0.0));
199 Vertex &outVertex3 = outMesh->createVertex(Eigen::Vector2d(6.2, 0.0));
200
201 outMesh->createEdge(outVertex0, outVertex1);
202 outMesh->createEdge(outVertex1, outVertex2);
203 outMesh->createEdge(outVertex2, outVertex3);
204
205 // Setup mapping with mapping coordinates and geometry used
207
208 mapping.setMeshes(inMesh, outMesh);
209 BOOST_TEST(mapping.hasComputedMapping() == false);
210
211 mapping.computeMapping();
212
213 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(4);
214 BOOST_TEST(mapping.hasComputedMapping() == true);
215 time::Sample inSample(1, inValues);
216 mapping.map(inSample, outValues);
217
218 auto inputIntegral = mesh::integrateSurface(inMesh, inValues);
219 auto outputIntegral = mesh::integrateSurface(outMesh, outValues);
220
221 for (int dim = 0; dim < inputIntegral.size(); ++dim) {
222 BOOST_TEST(inputIntegral(dim) == outputIntegral(dim));
223 }
224
225 double scaleFactor = outValues(0) / inValues(0);
226 BOOST_TEST(scaleFactor != 1.0);
227
228 BOOST_TEST(inValues(0) * scaleFactor == outValues(0));
229 BOOST_TEST(inValues(1) * scaleFactor == outValues(1));
230 BOOST_TEST(inValues(2) * scaleFactor == outValues(2));
231 BOOST_TEST(inValues(3) * scaleFactor == outValues(3));
232}
233
234namespace {
235template <int N>
236PtrMesh create2DLinSpaceMesh(std::string_view name, int dims, double x0, double x1)
237{
238 static_assert(N > 1, "More than 1 vertex required");
239 PtrMesh mesh(new Mesh("InMesh", dims, testing::nextMeshID()));
240 std::vector<Vertex *> vertices;
241 double dx = (x1 - x0) / (double) (N - 1);
242 for (int i = 0; i < N; ++i) {
243 double x = x0 + dx * i;
244 vertices.push_back(&mesh->createVertex(Eigen::Vector2d{x, 0.0}));
245 }
246 auto first = vertices.begin();
247 auto second = ++vertices.begin();
248 while (second != vertices.end()) {
249 mesh->createEdge(**first, **second);
250 ++first;
251 ++second;
252 }
253 return mesh;
254}
255} // namespace
256
257PRECICE_TEST_SETUP(1_rank)
258BOOST_AUTO_TEST_CASE(ScaledConsistentZeroData)
259{
260 PRECICE_TEST();
261 int dimensions = 2;
262
263 // Create mesh to map from
264 PtrMesh inMesh = create2DLinSpaceMesh<4>("InMesh", dimensions, 0, 1);
265
266 // Create mesh to map to
267 PtrMesh outMesh = create2DLinSpaceMesh<3>("OutMesh", dimensions, 0, 1);
268
269 // Setup mapping with mapping coordinates and geometry used
271
272 mapping.setMeshes(inMesh, outMesh);
273 BOOST_TEST(mapping.hasComputedMapping() == false);
274 mapping.computeMapping();
275 BOOST_TEST(mapping.hasComputedMapping() == true);
276
277 Eigen::VectorXd inValues = Eigen::VectorXd::Zero(4);
278 time::Sample inSample(1, inValues);
279 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
280 mapping.map(inSample, outValues);
281
282 BOOST_TEST(!outValues.hasNaN());
283 BOOST_TEST(outValues.isZero());
284
285 auto inputIntegral = mesh::integrateSurface(inMesh, inValues);
286 BOOST_TEST(!inputIntegral.hasNaN());
287 BOOST_TEST(inputIntegral.isZero());
288
289 auto outputIntegral = mesh::integrateSurface(outMesh, outValues);
290 BOOST_TEST(!outputIntegral.hasNaN());
291 BOOST_TEST(outputIntegral.isZero());
292}
293
294PRECICE_TEST_SETUP(1_rank)
295BOOST_AUTO_TEST_CASE(ScaledConsistentZeroIntegral)
296{
297 PRECICE_TEST();
298 int dimensions = 2;
299
300 // Create mesh to map from
301 PtrMesh inMesh = create2DLinSpaceMesh<4>("InMesh", dimensions, 0, 1);
302
303 // Create mesh to map to
304 PtrMesh outMesh = create2DLinSpaceMesh<3>("OutMesh", dimensions, 0, 1);
305
306 // Setup mapping with mapping coordinates and geometry used
308
309 mapping.setMeshes(inMesh, outMesh);
310 BOOST_TEST(mapping.hasComputedMapping() == false);
311 mapping.computeMapping();
312 BOOST_TEST(mapping.hasComputedMapping() == true);
313
314 Eigen::Vector4d inValues{1, 1, -1, -1};
315 time::Sample inSample(1, inValues);
316 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(3);
317 mapping.map(inSample, outValues);
318
319 BOOST_TEST(!outValues.hasNaN());
320 BOOST_TEST((outValues.array() == 0.0).count() == 0);
321
322 auto inputIntegral = mesh::integrateSurface(inMesh, inValues);
323 BOOST_TEST(!inputIntegral.hasNaN());
324 BOOST_TEST(inputIntegral(0) == 0.0);
325
326 auto outputIntegral = mesh::integrateSurface(outMesh, outValues);
327 BOOST_TEST(!outputIntegral.hasNaN());
328 BOOST_TEST(outputIntegral(0) == 0.0);
329}
330
331PRECICE_TEST_SETUP(1_rank)
332BOOST_AUTO_TEST_CASE(ScaledConsistentZeroDataComponent)
333{
334 PRECICE_TEST();
335 int dimensions = 2;
336
337 // Create mesh to map from
338 PtrMesh inMesh = create2DLinSpaceMesh<4>("InMesh", dimensions, 0, 1);
339
340 // Create mesh to map to
341 PtrMesh outMesh = create2DLinSpaceMesh<3>("OutMesh", dimensions, 0, 1);
342
343 // Setup mapping with mapping coordinates and geometry used
345
346 mapping.setMeshes(inMesh, outMesh);
347 BOOST_TEST(mapping.hasComputedMapping() == false);
348 mapping.computeMapping();
349 BOOST_TEST(mapping.hasComputedMapping() == true);
350
351 Eigen::VectorXd inValues(8);
352 inValues << 1, 0, 0.5, 0, 1.5, 0, 1, 0;
353 time::Sample inSample(2, inValues);
354 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(6);
355 mapping.map(inSample, outValues);
356
357 BOOST_TEST(!outValues.hasNaN());
358 BOOST_TEST((outValues.array() == 0.0).count() == 3);
359
360 auto inputIntegral = mesh::integrateSurface(inMesh, inValues);
361 BOOST_TEST(!inputIntegral.hasNaN());
362 BOOST_TEST(inputIntegral(0) == 1.0);
363 BOOST_TEST(inputIntegral(1) == 0.0);
364
365 auto outputIntegral = mesh::integrateSurface(outMesh, outValues);
366 BOOST_TEST(!outputIntegral.hasNaN());
367 BOOST_TEST(outputIntegral(0) == 1.0);
368 BOOST_TEST(outputIntegral(1) == 0.0);
369}
370
371PRECICE_TEST_SETUP(1_rank)
372BOOST_AUTO_TEST_CASE(ScaledConsistentZeroIntegralComponent)
373{
374 PRECICE_TEST();
375 int dimensions = 2;
376
377 // Create mesh to map from
378 PtrMesh inMesh = create2DLinSpaceMesh<4>("InMesh", dimensions, 0, 1);
379
380 // Create mesh to map to
381 PtrMesh outMesh = create2DLinSpaceMesh<3>("OutMesh", dimensions, 0, 1);
382
383 // Setup mapping with mapping coordinates and geometry used
385
386 mapping.setMeshes(inMesh, outMesh);
387 BOOST_TEST(mapping.hasComputedMapping() == false);
388 mapping.computeMapping();
389 BOOST_TEST(mapping.hasComputedMapping() == true);
390
391 Eigen::VectorXd inValues(8);
392 inValues << 2, 1, 3, 1, 1, -1, 2, -1;
393 time::Sample inSample(2, inValues);
394 Eigen::VectorXd outValues = Eigen::VectorXd::Zero(6);
395 mapping.map(inSample, outValues);
396
397 BOOST_TEST(!outValues.hasNaN());
398 BOOST_TEST((outValues.array() == 0.0).count() == 0);
399
400 auto inputIntegral = mesh::integrateSurface(inMesh, inValues);
401 BOOST_TEST(!inputIntegral.hasNaN());
402 BOOST_TEST(inputIntegral(0) == 2.0);
403 BOOST_TEST(inputIntegral(1) == 0.0);
404
405 auto outputIntegral = mesh::integrateSurface(outMesh, outValues);
406 BOOST_TEST(!outputIntegral.hasNaN());
407 BOOST_TEST(outputIntegral(0) == 2.0);
408 BOOST_TEST(outputIntegral(1) == 0.0);
409}
410
411PRECICE_TEST_SETUP(1_rank)
412BOOST_AUTO_TEST_CASE(ScaledConsistentVolume2D)
413{
414 PRECICE_TEST();
415 int dimensions = 2;
416
417 // Create mesh to map from
418 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
419
420 // One square with 3 triangles
421 Vertex &inVertex0 = inMesh->createVertex(Eigen::Vector2d(0.0, 0.0));
422 Vertex &inVertex1 = inMesh->createVertex(Eigen::Vector2d{1.0, 0.0});
423 Vertex &inVertex2 = inMesh->createVertex(Eigen::Vector2d{1.0, 1.0});
424 Vertex &inVertex3 = inMesh->createVertex(Eigen::Vector2d{0.0, 1.0});
425 Vertex &inVertex4 = inMesh->createVertex(Eigen::Vector2d{0.5, 1.0});
426
427 inMesh->createTriangle(inVertex0, inVertex1, inVertex4);
428 inMesh->createTriangle(inVertex0, inVertex3, inVertex4);
429 inMesh->createTriangle(inVertex1, inVertex2, inVertex4);
430
431 Eigen::VectorXd inValues(5);
432 inValues(0) = 1.0;
433 inValues(1) = 2.0;
434 inValues(2) = 3.0;
435 inValues(3) = 4.0;
436 inValues(4) = 5.0;
437
438 // Create mesh to map to
439 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
440
441 // Unit square as 2 triangles
442 Vertex &outVertex0 = outMesh->createVertex(Eigen::Vector2d(0.0, 0.0));
443 Vertex &outVertex1 = outMesh->createVertex(Eigen::Vector2d(1.0, 0.0));
444 Vertex &outVertex2 = outMesh->createVertex(Eigen::Vector2d(1.0, 1.0));
445 Vertex &outVertex3 = outMesh->createVertex(Eigen::Vector2d(0.0, 1.0));
446
447 outMesh->createTriangle(outVertex0, outVertex1, outVertex2);
448 outMesh->createTriangle(outVertex0, outVertex2, outVertex3);
449
450 // Setup mapping with mapping coordinates and geometry used
452
453 mapping.setMeshes(inMesh, outMesh);
454 BOOST_TEST(mapping.hasComputedMapping() == false);
455
456 Eigen::VectorXd outValues(5);
457 mapping.computeMapping();
458 time::Sample inSample(1, inValues);
459 mapping.map(inSample, outValues);
460
461 BOOST_TEST(mapping.hasComputedMapping() == true);
462
463 auto inputIntegral = mesh::integrateVolume(inMesh, inValues);
464 auto outputIntegral = mesh::integrateVolume(outMesh, outValues);
465
466 Eigen::VectorXd expectedIntegral(1);
467 expectedIntegral << 3.0;
468
469 BOOST_TEST(inputIntegral(0) == expectedIntegral(0));
470
471 for (int dim = 0; dim < inputIntegral.size(); ++dim) {
472 BOOST_TEST(inputIntegral(dim) == outputIntegral(dim));
473 }
474
475 double scaleFactor = outValues(0) / inValues(0);
476 BOOST_TEST(scaleFactor != 1.0);
477
478 BOOST_TEST(math::equals(inValues(0) * scaleFactor, outValues(0)));
479 BOOST_TEST(inValues(1) * scaleFactor == outValues(1));
480 BOOST_TEST(inValues(2) * scaleFactor == outValues(2));
481 BOOST_TEST(inValues(3) * scaleFactor == outValues(3));
482}
483
484PRECICE_TEST_SETUP(1_rank)
485BOOST_AUTO_TEST_CASE(ScaledConsistentVolume3D)
486{
487 PRECICE_TEST();
488 int dimensions = 3;
489
490 // Create mesh to map from
491 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
492
493 // One tetra on "out". The "in" has the same but split into two
494 Vertex &inVertex0 = inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
495 Vertex &inVertex1 = inMesh->createVertex(Eigen::Vector3d{0.5, 1.0, 0.0});
496 Vertex &inVertex2 = inMesh->createVertex(Eigen::Vector3d{1.0, 0.0, 0.0});
497 Vertex &inVertex3 = inMesh->createVertex(Eigen::Vector3d{0.5, 0.0, 1.0});
498 Vertex &inVertex4 = inMesh->createVertex(Eigen::Vector3d{0.5, 0.0, 0.0});
499
500 inMesh->createTetrahedron(inVertex0, inVertex1, inVertex3, inVertex4);
501 inMesh->createTetrahedron(inVertex1, inVertex2, inVertex3, inVertex4);
502
503 Eigen::VectorXd inValues(5);
504 inValues(0) = 1.0;
505 inValues(1) = 2.0;
506 inValues(2) = 3.0;
507 inValues(3) = 4.0;
508 inValues(4) = 5.0;
509
510 // Create mesh to map to
511 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
512
513 // One big tetra
514 Vertex &outVertex0 = outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
515 Vertex &outVertex1 = outMesh->createVertex(Eigen::Vector3d{0.5, 1.0, 0.0});
516 Vertex &outVertex2 = outMesh->createVertex(Eigen::Vector3d{1.0, 0.0, 0.0});
517 Vertex &outVertex3 = outMesh->createVertex(Eigen::Vector3d{0.5, 0.0, 1.0});
518
519 outMesh->createTetrahedron(outVertex0, outVertex1, outVertex2, outVertex3);
520
521 // Setup mapping with mapping coordinates and geometry used
523
524 mapping.setMeshes(inMesh, outMesh);
525 BOOST_TEST(mapping.hasComputedMapping() == false);
526
527 Eigen::VectorXd outValues(5);
528 mapping.computeMapping();
529 time::Sample inSample(1, inValues);
530 mapping.map(inSample, outValues);
531
532 BOOST_TEST(mapping.hasComputedMapping() == true);
533
534 auto inputIntegral = mesh::integrateVolume(inMesh, inValues);
535 auto outputIntegral = mesh::integrateVolume(outMesh, outValues);
536
537 Eigen::VectorXd expectedIntegral(1);
538 expectedIntegral << 6.5 * 1. / 12;
539
540 BOOST_TEST(inputIntegral(0) == expectedIntegral(0));
541
542 for (int dim = 0; dim < inputIntegral.size(); ++dim) {
543 BOOST_TEST(inputIntegral(dim) == outputIntegral(dim));
544 }
545
546 double scaleFactor = outValues(0) / inValues(0);
547 BOOST_TEST(scaleFactor != 1.0);
548
549 BOOST_TEST(math::equals(inValues(0) * scaleFactor, outValues(0)));
550 BOOST_TEST(inValues(1) * scaleFactor == outValues(1));
551 BOOST_TEST(inValues(2) * scaleFactor == outValues(2));
552 BOOST_TEST(inValues(3) * scaleFactor == outValues(3));
553}
554
BOOST_AUTO_TEST_CASE(testIQNIMVJPPWithSubsteps)
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
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
T begin(T... args)
Mapping using nearest neighboring vertices.
Container and creator for meshes.
Definition Mesh.hpp:38
Triangle & createTriangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Creates and initializes a Triangle object.
Definition Mesh.cpp:121
Tetrahedron & createTetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Creates and initializes a Tetrahedron object.
Definition Mesh.cpp:143
Edge & createEdge(Vertex &vertexOne, Vertex &vertexTwo)
Creates and initializes an Edge object.
Definition Mesh.cpp:113
Vertex & createVertex(const Eigen::Ref< const Eigen::VectorXd > &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:105
Vertex of a mesh.
Definition Vertex.hpp:16
void setCoords(const VECTOR_T &coordinates)
Sets the coordinates of the vertex.
Definition Vertex.hpp:101
Eigen::VectorXd getCoords() const
Returns the coordinates of the vertex.
Definition Vertex.hpp:114
T end(T... args)
contains data mapping from points to meshes.
constexpr bool equals(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
Compares two Eigen::MatrixBase for equality up to tolerance.
provides Mesh, Data and primitives.
Eigen::VectorXd integrateSurface(const PtrMesh &mesh, const Eigen::VectorXd &input)
Given the data and the mesh, this function returns the surface integral. Assumes no overlap exists fo...
Definition Utils.cpp:11
Eigen::VectorXd integrateVolume(const PtrMesh &mesh, const Eigen::VectorXd &input)
Given the data and the mesh, this function returns the volume integral. Assumes no overlap exists for...
Definition Utils.cpp:41
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.
T push_back(T... args)