preCICE v3.1.2
Loading...
Searching...
No Matches
RadialBasisFctHelper.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <memory>
6#include <ostream>
7#include <string>
8#include <utility>
9#include <vector>
10#include "logging/Logger.hpp"
11#include "mapping/Mapping.hpp"
15#include "mesh/Data.hpp"
16#include "mesh/Mesh.hpp"
18#include "mesh/Utils.hpp"
19#include "mesh/Vertex.hpp"
21#include "testing/Testing.hpp"
22
23using namespace precice;
24using namespace precice::mesh;
25using namespace precice::mapping;
26using namespace precice::testing;
28
29// We use internal linkage in order to avoid a separate TU for these functions
30namespace {
31
32void addGlobalIndex(mesh::PtrMesh &mesh, int offset = 0)
33{
34 for (mesh::Vertex &v : mesh->vertices()) {
35 v.setGlobalIndex(v.getID() + offset);
36 }
37}
38
40{
41 auto inputIntegral = mesh::integrateSurface(inMesh, inData->values());
42 auto outputIntegral = mesh::integrateSurface(outMesh, outData->values());
43
44 for (int dim = 0; dim < inputIntegral.size(); ++dim) {
45 BOOST_TEST(inputIntegral(dim) == outputIntegral(dim));
46 }
47}
48
49// Definition of the helper functions such that we can test different solver setups
51{
52 int dimensions = 2;
53 using Eigen::Vector2d;
54
55 // Create mesh to map from
56 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
57 mesh::PtrData inData = inMesh->createData("InData", 1, 0_dataID);
58 int inDataID = inData->getID();
59 inMesh->createVertex(Vector2d(0.0, 0.0));
60 inMesh->createVertex(Vector2d(1.0, 0.0));
61 inMesh->createVertex(Vector2d(1.0, 1.0));
62 inMesh->createVertex(Vector2d(0.0, 1.0));
63 inMesh->allocateDataValues();
64 addGlobalIndex(inMesh);
65 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
66
67 auto &values = inData->values();
68 values << 1.0, 2.0, 2.0, 1.0;
69
70 // Create mesh to map to
71 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
72 mesh::PtrData outData = outMesh->createData("OutData", 1, 1_dataID);
73 int outDataID = outData->getID();
74 mesh::Vertex &vertex = outMesh->createVertex(Vector2d(0, 0));
75 outMesh->allocateDataValues();
76 addGlobalIndex(outMesh);
77 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
78
79 // Setup mapping with mapping coordinates and geometry used
80 mapping.setMeshes(inMesh, outMesh);
81 BOOST_TEST(mapping.hasComputedMapping() == false);
82
83 vertex.setCoords(Vector2d(0.0, 0.0));
84 mapping.computeMapping();
85 mapping.map(inDataID, outDataID);
86 double value = outData->values()(0);
87 BOOST_TEST(mapping.hasComputedMapping() == true);
88 BOOST_TEST(value == 1.0);
89
90 vertex.setCoords(Vector2d(0.0, 0.5));
91 mapping.computeMapping();
92 mapping.map(inDataID, outDataID);
93 value = outData->values()(0);
94 BOOST_TEST(mapping.hasComputedMapping() == true);
95 BOOST_TEST(value == 1.0);
96
97 vertex.setCoords(Vector2d(0.0, 1.0));
98 mapping.computeMapping();
99 mapping.map(inDataID, outDataID);
100 value = outData->values()(0);
101 BOOST_TEST(mapping.hasComputedMapping() == true);
102 BOOST_TEST(value == 1.0);
103
104 vertex.setCoords(Vector2d(1.0, 0.0));
105 mapping.computeMapping();
106 mapping.map(inDataID, outDataID);
107 value = outData->values()(0);
108 BOOST_TEST(mapping.hasComputedMapping() == true);
109 BOOST_TEST(value == 2.0);
110
111 vertex.setCoords(Vector2d(1.0, 0.5));
112 mapping.computeMapping();
113 mapping.map(inDataID, outDataID);
114 value = outData->values()(0);
115 BOOST_TEST(mapping.hasComputedMapping() == true);
116 BOOST_TEST(value == 2.0);
117
118 vertex.setCoords(Vector2d(1.0, 1.0));
119 mapping.computeMapping();
120 mapping.map(inDataID, outDataID);
121 value = outData->values()(0);
122 BOOST_TEST(mapping.hasComputedMapping() == true);
123 BOOST_TEST(value == 2.0);
124
125 vertex.setCoords(Vector2d(0.5, 0.0));
126 mapping.computeMapping();
127 mapping.map(inDataID, outDataID);
128 value = outData->values()(0);
129 BOOST_TEST(mapping.hasComputedMapping() == true);
130 BOOST_TEST(value == 1.5);
131
132 vertex.setCoords(Vector2d(0.5, 0.5));
133 mapping.computeMapping();
134 mapping.map(inDataID, outDataID);
135 value = outData->values()(0);
136 BOOST_TEST(mapping.hasComputedMapping() == true);
137 BOOST_TEST(value == 1.5);
138
139 vertex.setCoords(Vector2d(0.5, 1.0));
140 mapping.computeMapping();
141 mapping.map(inDataID, outDataID);
142 value = outData->values()(0);
143 BOOST_TEST(mapping.hasComputedMapping() == true);
144 BOOST_TEST(value == 1.5);
145}
146
148{
149 int dimensions = 2;
150 using Eigen::Vector2d;
151
152 // Create mesh to map from
153 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
154 mesh::PtrData inData = inMesh->createData("InData", 2, 0_dataID);
155 int inDataID = inData->getID();
156 inMesh->createVertex(Vector2d(0.0, 0.0));
157 inMesh->createVertex(Vector2d(1.0, 0.0));
158 inMesh->createVertex(Vector2d(1.0, 1.0));
159 inMesh->createVertex(Vector2d(0.0, 1.0));
160 inMesh->allocateDataValues();
161 addGlobalIndex(inMesh);
162 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
163
164 auto &values = inData->values();
165 values << 1.0, 4.0, 2.0, 5.0, 2.0, 5.0, 1.0, 4.0;
166
167 // Create mesh to map to
168 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
169 mesh::PtrData outData = outMesh->createData("OutData", 2, 1_dataID);
170 int outDataID = outData->getID();
171 mesh::Vertex &vertex = outMesh->createVertex(Vector2d(0, 0));
172 outMesh->allocateDataValues();
173 addGlobalIndex(outMesh);
174 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
175
176 // Setup mapping with mapping coordinates and geometry used
177 mapping.setMeshes(inMesh, outMesh);
178 BOOST_TEST(mapping.hasComputedMapping() == false);
179
180 vertex.setCoords(Vector2d(0.0, 0.0));
181 mapping.computeMapping();
182 mapping.map(inDataID, outDataID);
183 double value1 = outData->values()(0);
184 double value2 = outData->values()(1);
185 BOOST_TEST(mapping.hasComputedMapping() == true);
186 BOOST_TEST(value1 == 1.0);
187 BOOST_TEST(value2 == 4.0);
188
189 vertex.setCoords(Vector2d(0.0, 0.5));
190 mapping.computeMapping();
191 mapping.map(inDataID, outDataID);
192 value1 = outData->values()(0);
193 value2 = outData->values()(1);
194 BOOST_TEST(mapping.hasComputedMapping() == true);
195 BOOST_TEST(value1 == 1.0);
196 BOOST_TEST(value2 == 4.0);
197
198 vertex.setCoords(Vector2d(0.0, 1.0));
199 mapping.computeMapping();
200 mapping.map(inDataID, outDataID);
201 value1 = outData->values()(0);
202 value2 = outData->values()(1);
203 BOOST_TEST(mapping.hasComputedMapping() == true);
204 BOOST_TEST(value1 == 1.0);
205 BOOST_TEST(value2 == 4.0);
206
207 vertex.setCoords(Vector2d(1.0, 0.0));
208 mapping.computeMapping();
209 mapping.map(inDataID, outDataID);
210 value1 = outData->values()(0);
211 value2 = outData->values()(1);
212 BOOST_TEST(mapping.hasComputedMapping() == true);
213 BOOST_TEST(value1 == 2.0);
214 BOOST_TEST(value2 == 5.0);
215
216 vertex.setCoords(Vector2d(1.0, 0.5));
217 mapping.computeMapping();
218 mapping.map(inDataID, outDataID);
219 value1 = outData->values()(0);
220 value2 = outData->values()(1);
221 BOOST_TEST(mapping.hasComputedMapping() == true);
222 BOOST_TEST(value1 == 2.0);
223 BOOST_TEST(value2 == 5.0);
224
225 vertex.setCoords(Vector2d(1.0, 1.0));
226 mapping.computeMapping();
227 mapping.map(inDataID, outDataID);
228 value1 = outData->values()(0);
229 value2 = outData->values()(1);
230 BOOST_TEST(mapping.hasComputedMapping() == true);
231 BOOST_TEST(value1 == 2.0);
232 BOOST_TEST(value2 == 5.0);
233
234 vertex.setCoords(Vector2d(0.5, 0.0));
235 mapping.computeMapping();
236 mapping.map(inDataID, outDataID);
237 value1 = outData->values()(0);
238 value2 = outData->values()(1);
239 BOOST_TEST(mapping.hasComputedMapping() == true);
240 BOOST_TEST(value1 == 1.5);
241 BOOST_TEST(value2 == 4.5);
242
243 vertex.setCoords(Vector2d(0.5, 0.5));
244 mapping.computeMapping();
245 mapping.map(inDataID, outDataID);
246 value1 = outData->values()(0);
247 value2 = outData->values()(1);
248 BOOST_TEST(mapping.hasComputedMapping() == true);
249 BOOST_TEST(value1 == 1.5);
250 BOOST_TEST(value2 == 4.5);
251
252 vertex.setCoords(Vector2d(0.5, 1.0));
253 mapping.computeMapping();
254 mapping.map(inDataID, outDataID);
255 value1 = outData->values()(0);
256 value2 = outData->values()(1);
257 BOOST_TEST(mapping.hasComputedMapping() == true);
258 BOOST_TEST(value1 == 1.5);
259 BOOST_TEST(value2 == 4.5);
260}
261
263{
264 int dimensions = 3;
265
266 // Create mesh to map from
267 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
268 mesh::PtrData inData = inMesh->createData("InData", 1, 0_dataID);
269 int inDataID = inData->getID();
270 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
271 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
272 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.0));
273 inMesh->createVertex(Eigen::Vector3d(1.0, 1.0, 0.0));
274 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0));
275 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 1.0));
276 inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 1.0));
277 inMesh->createVertex(Eigen::Vector3d(1.0, 1.0, 1.0));
278 inMesh->allocateDataValues();
279 addGlobalIndex(inMesh);
280 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
281
282 auto &values = inData->values();
283 values << 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0, 2.0;
284
285 // Create mesh to map to
286 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
287 mesh::PtrData outData = outMesh->createData("OutData", 1, 1_dataID);
288 int outDataID = outData->getID();
289 mesh::Vertex &vertex = outMesh->createVertex(Eigen::Vector3d::Zero());
290 outMesh->allocateDataValues();
291 addGlobalIndex(outMesh);
292 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
293
294 // Setup mapping with mapping coordinates and geometry used
295 mapping.setMeshes(inMesh, outMesh);
296 BOOST_TEST(mapping.hasComputedMapping() == false);
297
298 vertex.setCoords(Eigen::Vector3d(0.0, 0.0, 0.0));
299 mapping.computeMapping();
300 mapping.map(inDataID, outDataID);
301 double value = outData->values()(0);
302 BOOST_TEST(mapping.hasComputedMapping() == true);
303 BOOST_TEST(value == 1.0);
304
305 vertex.setCoords(Eigen::Vector3d(0.0, 0.5, 0.0));
306 mapping.computeMapping();
307 mapping.map(inDataID, outDataID);
308 value = outData->values()(0);
309 BOOST_TEST(mapping.hasComputedMapping() == true);
310 BOOST_TEST(value == 1.0);
311
312 vertex.setCoords(Eigen::Vector3d(0.5, 0.5, 0.0));
313 mapping.computeMapping();
314 mapping.map(inDataID, outDataID);
315 value = outData->values()(0);
316 BOOST_TEST(mapping.hasComputedMapping() == true);
317 BOOST_TEST(value == 1.0);
318
319 vertex.setCoords(Eigen::Vector3d(1.0, 0.0, 0.0));
320 mapping.computeMapping();
321 mapping.map(inDataID, outDataID);
322 value = outData->values()(0);
323 BOOST_TEST(mapping.hasComputedMapping() == true);
324 BOOST_TEST(value == 1.0);
325
326 vertex.setCoords(Eigen::Vector3d(1.0, 1.0, 0.0));
327 mapping.computeMapping();
328 mapping.map(inDataID, outDataID);
329 value = outData->values()(0);
330 BOOST_TEST(mapping.hasComputedMapping() == true);
331 BOOST_TEST(value == 1.0);
332
333 vertex.setCoords(Eigen::Vector3d(0.0, 0.0, 1.0));
334 mapping.computeMapping();
335 mapping.map(inDataID, outDataID);
336 value = outData->values()(0);
337 BOOST_TEST(mapping.hasComputedMapping() == true);
338 BOOST_TEST(value == 2.0);
339
340 vertex.setCoords(Eigen::Vector3d(1.0, 0.0, 1.0));
341 mapping.computeMapping();
342 mapping.map(inDataID, outDataID);
343 value = outData->values()(0);
344 BOOST_TEST(mapping.hasComputedMapping() == true);
345 BOOST_TEST(value == 2.0);
346
347 vertex.setCoords(Eigen::Vector3d(1.0, 1.0, 1.0));
348 mapping.computeMapping();
349 mapping.map(inDataID, outDataID);
350 value = outData->values()(0);
351 BOOST_TEST(mapping.hasComputedMapping() == true);
352 BOOST_TEST(value == 2.0);
353
354 vertex.setCoords(Eigen::Vector3d(0.5, 0.5, 1.0));
355 mapping.computeMapping();
356 mapping.map(inDataID, outDataID);
357 value = outData->values()(0);
358 BOOST_TEST(mapping.hasComputedMapping() == true);
359 BOOST_TEST(value == 2.0);
360
361 vertex.setCoords(Eigen::Vector3d(0.0, 0.0, 0.5));
362 mapping.computeMapping();
363 mapping.map(inDataID, outDataID);
364 value = outData->values()(0);
365 BOOST_TEST(mapping.hasComputedMapping() == true);
366 BOOST_TEST(value, 1.5);
367
368 vertex.setCoords(Eigen::Vector3d(1.0, 0.0, 0.5));
369 mapping.computeMapping();
370 mapping.map(inDataID, outDataID);
371 value = outData->values()(0);
372 BOOST_TEST(mapping.hasComputedMapping() == true);
373 BOOST_TEST(value == 1.5);
374
375 vertex.setCoords(Eigen::Vector3d(0.0, 1.0, 0.5));
376 mapping.computeMapping();
377 mapping.map(inDataID, outDataID);
378 value = outData->values()(0);
379 BOOST_TEST(mapping.hasComputedMapping() == true);
380 BOOST_TEST(value == 1.5);
381
382 vertex.setCoords(Eigen::Vector3d(1.0, 1.0, 0.5));
383 mapping.computeMapping();
384 mapping.map(inDataID, outDataID);
385 value = outData->values()(0);
386 BOOST_TEST(mapping.hasComputedMapping() == true);
387 BOOST_TEST(value == 1.5);
388
389 vertex.setCoords(Eigen::Vector3d(0.5, 0.5, 0.5));
390 mapping.computeMapping();
391 mapping.map(inDataID, outDataID);
392 value = outData->values()(0);
393 BOOST_TEST(mapping.hasComputedMapping() == true);
394 BOOST_TEST(value == 1.5);
395}
396
398{
399 int dimensions = 2;
400 using Eigen::Vector2d;
401
402 // Create mesh to map from
403 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
404 mesh::PtrData inData = inMesh->createData("InData", 1, 0_dataID);
405 int inDataID = inData->getID();
406 auto & inV1 = inMesh->createVertex(Vector2d(0.0, 0.0));
407 auto & inV2 = inMesh->createVertex(Vector2d(1.0, 0.0));
408 auto & inV3 = inMesh->createVertex(Vector2d(1.0, 1.0));
409 auto & inV4 = inMesh->createVertex(Vector2d(0.0, 1.0));
410
411 inMesh->createEdge(inV1, inV2);
412 inMesh->createEdge(inV2, inV3);
413 inMesh->createEdge(inV3, inV4);
414 inMesh->createEdge(inV1, inV4);
415
416 inMesh->allocateDataValues();
417 addGlobalIndex(inMesh);
418 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
419
420 auto &inValues = inData->values();
421 inValues << 1.0, 2.0, 2.0, 1.0;
422
423 // Create mesh to map to
424 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
425 mesh::PtrData outData = outMesh->createData("OutData", 1, 1_dataID);
426 int outDataID = outData->getID();
427 auto & outV1 = outMesh->createVertex(Vector2d(0.0, 0.0));
428 auto & outV2 = outMesh->createVertex(Vector2d(0.0, 1.0));
429 auto & outV3 = outMesh->createVertex(Vector2d(1.1, 1.1));
430 auto & outV4 = outMesh->createVertex(Vector2d(0.1, 1.1));
431 outMesh->createEdge(outV1, outV2);
432 outMesh->createEdge(outV2, outV3);
433 outMesh->createEdge(outV3, outV4);
434 outMesh->createEdge(outV1, outV4);
435 outMesh->allocateDataValues();
436 addGlobalIndex(outMesh);
437 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
438
439 // Setup mapping with mapping coordinates and geometry used
440 mapping.setMeshes(inMesh, outMesh);
441 BOOST_TEST(mapping.hasComputedMapping() == false);
442
443 mapping.computeMapping();
444 mapping.map(inDataID, outDataID);
445
446 testSerialScaledConsistent(inMesh, outMesh, inData, outData);
447}
448
450{
451 int dimensions = 3;
452
453 // Create mesh to map from
454 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
455 mesh::PtrData inData = inMesh->createData("InData", 1, 0_dataID);
456 int inDataID = inData->getID();
457 auto & inV1 = inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
458 auto & inV2 = inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
459 auto & inV3 = inMesh->createVertex(Eigen::Vector3d(0.0, 1.0, 0.5));
460 auto & inV4 = inMesh->createVertex(Eigen::Vector3d(2.0, 0.0, 0.0));
461 auto & inV5 = inMesh->createVertex(Eigen::Vector3d(0.0, 2.0, 0.0));
462 auto & inV6 = inMesh->createVertex(Eigen::Vector3d(0.0, 2.0, 1.0));
463 auto & inE1 = inMesh->createEdge(inV1, inV2);
464 auto & inE2 = inMesh->createEdge(inV2, inV3);
465 auto & inE3 = inMesh->createEdge(inV1, inV3);
466 auto & inE4 = inMesh->createEdge(inV4, inV5);
467 auto & inE5 = inMesh->createEdge(inV5, inV6);
468 auto & inE6 = inMesh->createEdge(inV4, inV6);
469 inMesh->createTriangle(inE1, inE2, inE3);
470 inMesh->createTriangle(inE4, inE5, inE6);
471
472 inMesh->allocateDataValues();
473 addGlobalIndex(inMesh);
474 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
475
476 auto &inValues = inData->values();
477 inValues << 1.0, 2.0, 4.0, 6.0, 8.0, 9.0;
478
479 // Create mesh to map to
480 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
481 mesh::PtrData outData = outMesh->createData("OutData", 1, 1_dataID);
482 int outDataID = outData->getID();
483 auto & outV1 = outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
484 auto & outV2 = outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0));
485 auto & outV3 = outMesh->createVertex(Eigen::Vector3d(0.0, 1.1, 0.6));
486 auto & outE1 = outMesh->createEdge(outV1, outV2);
487 auto & outE2 = outMesh->createEdge(outV2, outV3);
488 auto & outE3 = outMesh->createEdge(outV1, outV3);
489 outMesh->createTriangle(outE1, outE2, outE3);
490
491 outMesh->allocateDataValues();
492 addGlobalIndex(outMesh);
493 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
494
495 // Setup mapping with mapping coordinates and geometry used
496 mapping.setMeshes(inMesh, outMesh);
497 BOOST_TEST(mapping.hasComputedMapping() == false);
498 mapping.computeMapping();
499 BOOST_TEST(mapping.hasComputedMapping() == true);
500 mapping.map(inDataID, outDataID);
501
502 testSerialScaledConsistent(inMesh, outMesh, inData, outData);
503}
504
506{
507 const int dimensions = 2;
508 const double tolerance = 1e-6;
509 using Eigen::Vector2d;
510
511 // Create mesh to map from
512 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
513 mesh::PtrData inData = inMesh->createData("InData", 1, 0_dataID);
514 int inDataID = inData->getID();
515 mesh::Vertex &vertex0 = inMesh->createVertex(Vector2d(0, 0));
516 mesh::Vertex &vertex1 = inMesh->createVertex(Vector2d(0, 0));
517 inMesh->allocateDataValues();
518 inData->values() << 1.0, 2.0;
519 addGlobalIndex(inMesh);
520 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
521
522 // Create mesh to map to
523 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
524 mesh::PtrData outData = outMesh->createData("OutData", 1, 1_dataID);
525 int outDataID = outData->getID();
526 outMesh->createVertex(Vector2d(0.0, 0.0));
527 outMesh->createVertex(Vector2d(1.0, 0.0));
528 outMesh->createVertex(Vector2d(1.0, 1.0));
529 outMesh->createVertex(Vector2d(0.0, 1.0));
530 outMesh->allocateDataValues();
531 addGlobalIndex(outMesh);
532 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
533
534 auto &values = outData->values();
535
536 mapping.setMeshes(inMesh, outMesh);
537 BOOST_TEST(mapping.hasComputedMapping() == false);
538
539 vertex0.setCoords(Vector2d(0.5, 0.0));
540 vertex1.setCoords(Vector2d(0.5, 1.0));
541 mapping.computeMapping();
542 mapping.map(inDataID, outDataID);
543 BOOST_TEST(mapping.hasComputedMapping() == true);
544 BOOST_TEST(testing::equals(values, Eigen::Vector4d(0.5, 0.5, 1.0, 1.0), tolerance));
545
546 vertex0.setCoords(Vector2d(0.0, 0.5));
547 vertex1.setCoords(Vector2d(1.0, 0.5));
548 mapping.computeMapping();
549 mapping.map(inDataID, outDataID);
550 BOOST_TEST(mapping.hasComputedMapping() == true);
551 BOOST_TEST(testing::equals(values, Eigen::Vector4d(0.5, 1.0, 1.0, 0.5), tolerance));
552
553 vertex0.setCoords(Vector2d(0.0, 1.0));
554 vertex1.setCoords(Vector2d(1.0, 0.0));
555 mapping.computeMapping();
556 mapping.map(inDataID, outDataID);
557 BOOST_TEST(mapping.hasComputedMapping() == true);
558 BOOST_TEST(testing::equals(values, Eigen::Vector4d(0.0, 2.0, 0.0, 1.0), tolerance));
559
560 vertex0.setCoords(Vector2d(0.0, 0.0));
561 vertex1.setCoords(Vector2d(1.0, 1.0));
562 mapping.computeMapping();
563 mapping.map(inDataID, outDataID);
564 BOOST_TEST(mapping.hasComputedMapping() == true);
565 BOOST_TEST(testing::equals(values, Eigen::Vector4d(1.0, 0.0, 2.0, 0.0), tolerance));
566
567 vertex0.setCoords(Vector2d(0.4, 0.5));
568 vertex1.setCoords(Vector2d(0.6, 0.5));
569 mapping.computeMapping();
570 mapping.map(inDataID, outDataID);
571 BOOST_TEST(mapping.hasComputedMapping() == true);
572 BOOST_TEST(values.sum() == 3.0);
573}
574
576{
577 const int dimensions = 2;
578 const double tolerance = 1e-6;
579 using Eigen::Vector2d;
580
581 // Create mesh to map from
582 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
583 mesh::PtrData inData = inMesh->createData("InData", 2, 0_dataID);
584 int inDataID = inData->getID();
585 mesh::Vertex &vertex0 = inMesh->createVertex(Vector2d(0, 0));
586 mesh::Vertex &vertex1 = inMesh->createVertex(Vector2d(0, 0));
587 inMesh->allocateDataValues();
588 inData->values() << 1.0, 4.0, 2.0, 5.0;
589 addGlobalIndex(inMesh);
590 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
591
592 // Create mesh to map to
593 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
594 mesh::PtrData outData = outMesh->createData("OutData", 2, 1_dataID);
595 int outDataID = outData->getID();
596 outMesh->createVertex(Vector2d(0.0, 0.0));
597 outMesh->createVertex(Vector2d(1.0, 0.0));
598 outMesh->createVertex(Vector2d(1.0, 1.0));
599 outMesh->createVertex(Vector2d(0.0, 1.0));
600 outMesh->allocateDataValues();
601 addGlobalIndex(outMesh);
602 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
603
604 auto &values = outData->values();
605
606 mapping.setMeshes(inMesh, outMesh);
607 BOOST_TEST(mapping.hasComputedMapping() == false);
608
609 vertex0.setCoords(Vector2d(0.5, 0.0));
610 vertex1.setCoords(Vector2d(0.5, 1.0));
611 mapping.computeMapping();
612 mapping.map(inDataID, outDataID);
613 BOOST_TEST(mapping.hasComputedMapping() == true);
614 Eigen::VectorXd refValues(8);
615 refValues << 0.5, 2, 0.5, 2, 1.0, 2.5, 1.0, 2.5;
616 BOOST_TEST(testing::equals(values, refValues, tolerance)); // fails
617
618 vertex0.setCoords(Vector2d(0.0, 0.5));
619 vertex1.setCoords(Vector2d(1.0, 0.5));
620 mapping.computeMapping();
621 mapping.map(inDataID, outDataID);
622 BOOST_TEST(mapping.hasComputedMapping() == true);
623 refValues << 0.5, 2, 1.0, 2.5, 1.0, 2.5, 0.5, 2;
624 BOOST_TEST(testing::equals(values, refValues, tolerance)); // fails
625
626 vertex0.setCoords(Vector2d(0.0, 1.0));
627 vertex1.setCoords(Vector2d(1.0, 0.0));
628 mapping.computeMapping();
629 mapping.map(inDataID, outDataID);
630 BOOST_TEST(mapping.hasComputedMapping() == true);
631 refValues << 0.0, 0.0, 2.0, 5.0, 0.0, 0.0, 1.0, 4.0;
632 BOOST_TEST(testing::equals(values, refValues, tolerance)); // fails
633
634 vertex0.setCoords(Vector2d(0.0, 0.0));
635 vertex1.setCoords(Vector2d(1.0, 1.0));
636 mapping.computeMapping();
637 mapping.map(inDataID, outDataID);
638 BOOST_TEST(mapping.hasComputedMapping() == true);
639 refValues << 1.0, 4.0, 0.0, 0.0, 2.0, 5.0, 0.0, 0.0;
640 BOOST_TEST(testing::equals(values, refValues, tolerance)); // fails
641
642 vertex0.setCoords(Vector2d(0.4, 0.5));
643 vertex1.setCoords(Vector2d(0.6, 0.5));
644 mapping.computeMapping();
645 mapping.map(inDataID, outDataID);
646 BOOST_TEST(mapping.hasComputedMapping() == true);
647 BOOST_TEST(values.sum() == 12.0); // fails
648}
649
651{
652 using Eigen::Vector3d;
653 int dimensions = 3;
654
655 // Create mesh to map from
656 mesh::PtrMesh inMesh(new mesh::Mesh("InMesh", dimensions, testing::nextMeshID()));
657 mesh::PtrData inData = inMesh->createData("InData", 1, 0_dataID);
658 int inDataID = inData->getID();
659 mesh::Vertex &vertex0 = inMesh->createVertex(Vector3d(0, 0, 0));
660 mesh::Vertex &vertex1 = inMesh->createVertex(Vector3d(0, 0, 0));
661 inMesh->allocateDataValues();
662 inData->values() << 1.0, 2.0;
663 addGlobalIndex(inMesh);
664 inMesh->setGlobalNumberOfVertices(inMesh->nVertices());
665
666 // Create mesh to map to
667 mesh::PtrMesh outMesh(new mesh::Mesh("OutMesh", dimensions, testing::nextMeshID()));
668 mesh::PtrData outData = outMesh->createData("OutData", 1, 1_dataID);
669 int outDataID = outData->getID();
670 outMesh->createVertex(Vector3d(0.0, 0.0, 0.0));
671 outMesh->createVertex(Vector3d(1.0, 0.0, 0.0));
672 outMesh->createVertex(Vector3d(1.0, 1.0, 0.0));
673 outMesh->createVertex(Vector3d(0.0, 1.0, 0.0));
674 outMesh->createVertex(Vector3d(0.0, 0.0, 1.0));
675 outMesh->createVertex(Vector3d(1.0, 0.0, 1.0));
676 outMesh->createVertex(Vector3d(1.0, 1.0, 1.0));
677 outMesh->createVertex(Vector3d(0.0, 1.0, 1.0));
678 outMesh->allocateDataValues();
679 addGlobalIndex(outMesh);
680 outMesh->setGlobalNumberOfVertices(outMesh->nVertices());
681
682 auto & values = outData->values();
683 double expectedSum = inData->values().sum();
684
685 mapping.setMeshes(inMesh, outMesh);
686 BOOST_TEST(mapping.hasComputedMapping() == false);
687
688 vertex0.setCoords(Vector3d(0.5, 0.0, 0.0));
689 vertex1.setCoords(Vector3d(0.5, 1.0, 0.0));
690 mapping.computeMapping();
691 mapping.map(inDataID, outDataID);
692 BOOST_TEST(mapping.hasComputedMapping());
693 BOOST_TEST(values.sum() == expectedSum);
694}
695} // namespace
void addGlobalIndex(mesh::PtrMesh &mesh, int offset=0)
void perform2DTestConservativeMappingVector(Mapping &mapping)
void perform2DTestConsistentMappingVector(Mapping &mapping)
void perform2DTestConsistentMapping(Mapping &mapping)
void perform3DTestConsistentMapping(Mapping &mapping)
void perform3DTestConservativeMapping(Mapping &mapping)
void perform2DTestConservativeMapping(Mapping &mapping)
void perform3DTestScaledConsistentMapping(Mapping &mapping)
void perform2DTestScaledConsistentMapping(Mapping &mapping)
void testSerialScaledConsistent(mesh::PtrMesh inMesh, mesh::PtrMesh outMesh, PtrData inData, PtrData outData)
Abstract base class for mapping of data from one mesh to another.
Definition Mapping.hpp:15
void setMeshes(const mesh::PtrMesh &input, const mesh::PtrMesh &output)
Sets input and output meshes carrying data to be mapped.
Definition Mapping.cpp:27
virtual void computeMapping()=0
Computes the mapping coefficients from the in- and output mesh.
bool hasComputedMapping() const
Returns true, if the mapping has been computed.
Definition Mapping.cpp:252
void map(int inputDataID, int outputDataID)
Definition Mapping.cpp:126
DataID getID() const
Returns the ID of the data set (supposed to be unique).
Definition Data.cpp:93
Eigen::VectorXd & values()
Returns a reference to the data values.
Definition Data.cpp:28
Container and creator for meshes.
Definition Mesh.hpp:39
Triangle & createTriangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Creates and initializes a Triangle object.
Definition Mesh.cpp:119
void setGlobalNumberOfVertices(int num)
Definition Mesh.hpp:264
std::size_t nVertices() const
Returns the number of vertices.
Definition Mesh.cpp:63
PtrData & createData(const std::string &name, int dimension, DataID id, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE)
Create only data for vertex.
Definition Mesh.cpp:151
Edge & createEdge(Vertex &vertexOne, Vertex &vertexTwo)
Creates and initializes an Edge object.
Definition Mesh.cpp:111
Vertex & createVertex(const Eigen::VectorXd &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:103
void allocateDataValues()
Allocates memory for the vertex data values and corresponding gradient values.
Definition Mesh.cpp:233
Vertex of a mesh.
Definition Vertex.hpp:16
void setCoords(const VECTOR_T &coordinates)
Sets the coordinates of the vertex.
Definition Vertex.hpp:102
contains data mapping from points to meshes.
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
contains the testing framework.
Definition helper.hpp:9
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:65
Main namespace of the precice library.