preCICE v3.1.1
Loading...
Searching...
No Matches
WatchIntegralTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <istream>
4#include <iterator>
5#include <memory>
6#include <string>
7#include <vector>
9#include "mesh/Data.hpp"
10#include "mesh/Mesh.hpp"
14#include "testing/Testing.hpp"
15#include "utils/IntraComm.hpp"
16#include "utils/assertion.hpp"
17
18namespace precice::mesh {
19class Vertex;
20} // namespace precice::mesh
21
22using namespace precice;
23
24namespace {
25std::vector<double> readDoublesFromTXTFile(std::string const &filename, int skip = 0)
26{
27 std::ifstream is{filename};
28 if (skip > 0) {
30 while (skip--) {
31 is >> ignore;
32 }
33 }
35}
36} // namespace
37
38BOOST_AUTO_TEST_SUITE(PreciceTests)
39BOOST_AUTO_TEST_SUITE(WatchIntegral)
40
41BOOST_AUTO_TEST_CASE(ScalarDataNoConnectivity)
42{
43 PRECICE_TEST(1_rank);
44 using namespace mesh;
45 // Setup geometry
46 std::string name("rectangle");
47 int dimensions = 2;
48 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
49
50 mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
51 mesh->createVertex(Eigen::Vector2d(0.0, 1.0));
52 mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
53 mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
54
55 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
56 auto & doubleValues = doubleData->values();
57
58 mesh->allocateDataValues();
59
60 doubleValues(0) = 1.0;
61 doubleValues(1) = 2.0;
62 doubleValues(2) = 3.0;
63 doubleValues(3) = 4.0;
64
65 std::string fileName("precice-WatchIntegralTest-scalarData-noConnectivity.log");
66
67 {
68 impl::WatchIntegral watchIntegral(mesh, fileName, true);
69 watchIntegral.initialize();
70
71 // Write output
72 watchIntegral.exportIntegralData(0.0);
73
74 // Change data (next timestep)
75 doubleValues(0) = 2.0;
76 doubleValues(1) = 3.0;
77 doubleValues(2) = 4.0;
78 doubleValues(3) = 5.0;
79
80 // Write output again
81 watchIntegral.exportIntegralData(1.0);
82
83 watchIntegral.exportIntegralData(2.0);
84 }
85 // File Format: Time DoubleData
86 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData NoConnectivity")
87 {
88 auto result = readDoublesFromTXTFile(fileName, 2);
89 auto expected = std::vector<double>{
90 0.0, 10.0,
91 1.0, 14.0,
92 2.0, 14.0};
93 BOOST_TEST(result.size() == expected.size());
94 for (size_t i = 0; i < result.size(); ++i) {
95 BOOST_TEST_CONTEXT("entry index: " << i)
96 {
97 using testing::equals;
98 BOOST_TEST(equals(result.at(i), expected.at(i)));
99 }
100 }
101 }
102}
103
104BOOST_AUTO_TEST_CASE(VectorDataNoConnectivity)
105{
106 PRECICE_TEST(1_rank);
107 using namespace mesh;
108 // Setup geometry
109 std::string name("rectangle");
110 int dimensions = 2;
111 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
112
113 mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
114 mesh->createVertex(Eigen::Vector2d(0.0, 1.0));
115 mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
116 mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
117
118 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
119 auto & doubleValues = doubleData->values();
120
121 mesh->allocateDataValues();
122
123 doubleValues(0) = 1.0;
124 doubleValues(1) = 2.0;
125 doubleValues(2) = 3.0;
126 doubleValues(3) = 4.0;
127 doubleValues(4) = 5.0;
128 doubleValues(5) = 6.0;
129 doubleValues(6) = 7.0;
130 doubleValues(7) = 8.0;
131
132 std::string fileName("precice-WatchIntegralTest-vectorData-noConnectivity.log");
133
134 {
135 impl::WatchIntegral watchIntegral(mesh, fileName, true);
136 watchIntegral.initialize();
137
138 // Write output
139 watchIntegral.exportIntegralData(0.0);
140
141 // Change data (next timestep)
142 doubleValues(0) = 2.0;
143 doubleValues(1) = 3.0;
144 doubleValues(2) = 4.0;
145 doubleValues(3) = 5.0;
146 doubleValues(4) = 6.0;
147 doubleValues(5) = 7.0;
148 doubleValues(6) = 8.0;
149 doubleValues(7) = 9.0;
150
151 // Write output again
152 watchIntegral.exportIntegralData(1.0);
153
154 watchIntegral.exportIntegralData(2.0);
155 }
156 // File Format: Time DoubleData0 DoubleData1
157 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData NoConnectivity")
158 {
159 auto result = readDoublesFromTXTFile(fileName, 3);
160 auto expected = std::vector<double>{
161 0.0, 16.0, 20.0,
162 1.0, 20.0, 24.0,
163 2.0, 20.0, 24.0};
164 BOOST_TEST(result.size() == expected.size());
165 for (size_t i = 0; i < result.size(); ++i) {
166 BOOST_TEST_CONTEXT("entry index: " << i)
167 {
168 using testing::equals;
169 BOOST_TEST(equals(result.at(i), expected.at(i)));
170 }
171 }
172 }
173}
174
175BOOST_AUTO_TEST_CASE(ScalarDataEdgeConnectivity)
176{
177 PRECICE_TEST(1_rank);
178 using namespace mesh;
179 // Setup geometry
180 std::string name("rectangle");
181 int dimensions = 2;
182 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
183
184 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
185 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
186 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector2d(1.0, 2.0));
187
188 mesh->createEdge(v1, v2);
189 mesh->createEdge(v2, v3);
190
191 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
192 auto & doubleValues = doubleData->values();
193
194 mesh->allocateDataValues();
195
196 doubleValues(0) = 1.0;
197 doubleValues(1) = 2.0;
198 doubleValues(2) = 3.0;
199
200 std::string fileName("precice-WatchIntegralTest-scalarData-edgeConnectivity.log");
201
202 {
203 impl::WatchIntegral watchIntegral(mesh, fileName, true);
204 watchIntegral.initialize();
205
206 // Write output
207 watchIntegral.exportIntegralData(0.0);
208
209 // Change data (next timestep)
210 doubleValues(0) = 2.0;
211 doubleValues(1) = 3.0;
212 doubleValues(2) = 4.0;
213
214 // Write output again
215 watchIntegral.exportIntegralData(1.0);
216
217 watchIntegral.exportIntegralData(2.0);
218 }
219 // File Format: Time DoubleData SurfaceArea
220 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData EdgeConnectivity")
221 {
222 auto result = readDoublesFromTXTFile(fileName, 3);
223 auto expected = std::vector<double>{
224 0.0, 6.5, 3.0,
225 1.0, 9.5, 3.0,
226 2.0, 9.5, 3.0};
227 BOOST_TEST(result.size() == expected.size());
228 for (size_t i = 0; i < result.size(); ++i) {
229 BOOST_TEST_CONTEXT("entry index: " << i)
230 {
231 using testing::equals;
232 BOOST_TEST(equals(result.at(i), expected.at(i)));
233 }
234 }
235 }
236}
237
238BOOST_AUTO_TEST_CASE(ScalarDataEdgeConnectivityNoScale)
239{
240 PRECICE_TEST(1_rank);
241 using namespace mesh;
242 // Setup geometry
243 std::string name("rectangle");
244 int dimensions = 2;
245 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
246
247 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
248 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
249 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector2d(1.0, 2.0));
250
251 mesh->createEdge(v1, v2);
252 mesh->createEdge(v2, v3);
253
254 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
255 auto & doubleValues = doubleData->values();
256
257 mesh->allocateDataValues();
258
259 doubleValues(0) = 1.0;
260 doubleValues(1) = 2.0;
261 doubleValues(2) = 3.0;
262
263 std::string fileName("precice-WatchIntegralTest-scalarData-edgeConnectivity-noScale.log");
264
265 {
266 impl::WatchIntegral watchIntegral(mesh, fileName, false);
267 watchIntegral.initialize();
268
269 // Write output
270 watchIntegral.exportIntegralData(0.0);
271
272 // Change data (next timestep)
273 doubleValues(0) = 2.0;
274 doubleValues(1) = 3.0;
275 doubleValues(2) = 4.0;
276
277 // Write output again
278 watchIntegral.exportIntegralData(1.0);
279
280 watchIntegral.exportIntegralData(2.0);
281 }
282 // File Format: Time DoubleData SurfaceArea
283 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData EdgeConnectivity NoScale")
284 {
285 auto result = readDoublesFromTXTFile(fileName, 3);
286 auto expected = std::vector<double>{
287 0.0, 6.0, 3.0,
288 1.0, 9.0, 3.0,
289 2.0, 9.0, 3.0};
290 BOOST_TEST(result.size() == expected.size());
291 for (size_t i = 0; i < result.size(); ++i) {
292 BOOST_TEST_CONTEXT("entry index: " << i)
293 {
294 using testing::equals;
295 BOOST_TEST(equals(result.at(i), expected.at(i)));
296 }
297 }
298 }
299}
300
301BOOST_AUTO_TEST_CASE(VectorDataEdgeConnectivity)
302{
303 PRECICE_TEST(1_rank);
304 using namespace mesh;
305 // Setup geometry
306 std::string name("rectangle");
307 int dimensions = 2;
308 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
309
310 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
311 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
312 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector2d(1.0, 2.0));
313
314 mesh->createEdge(v1, v2);
315 mesh->createEdge(v2, v3);
316
317 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
318 auto & doubleValues = doubleData->values();
319
320 mesh->allocateDataValues();
321
322 doubleValues(0) = 1.0;
323 doubleValues(1) = 2.0;
324 doubleValues(2) = 3.0;
325 doubleValues(3) = 4.0;
326 doubleValues(4) = 5.0;
327 doubleValues(5) = 6.0;
328
329 std::string fileName("precice-WatchIntegralTest-scalarData-edgeConnectivity.log");
330
331 {
332 impl::WatchIntegral watchIntegral(mesh, fileName, true);
333 watchIntegral.initialize();
334
335 // Write output
336 watchIntegral.exportIntegralData(0.0);
337
338 // Change data (next timestep)
339 doubleValues(0) = 2.0;
340 doubleValues(1) = 3.0;
341 doubleValues(2) = 4.0;
342 doubleValues(3) = 5.0;
343 doubleValues(4) = 6.0;
344 doubleValues(5) = 7.0;
345
346 // Write output again
347 watchIntegral.exportIntegralData(1.0);
348
349 watchIntegral.exportIntegralData(2.0);
350 }
351 // File Format: Time DoubleData0 DoubleData1 SurfaceArea
352 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData EdgeConnectivity")
353 {
355 auto result = readDoublesFromTXTFile(fileName, 4);
356 auto expected = std::vector<double>{
357 0.0, 10.0, 13.0, 3.0,
358 1.0, 13.0, 56.0, 3.0,
359 2.0, 13.0, 56.0, 3.0};
360 BOOST_TEST(result.size() == expected.size());
361 for (size_t i = 0; i < result.size(); ++i) {
362 BOOST_TEST_CONTEXT("entry index: " << i)
363 {
364 using testing::equals;
365 BOOST_TEST(equals(result.at(i), expected.at(i)));
366 }
367 }
368 }
369 }
370}
371
372BOOST_AUTO_TEST_CASE(VectorDataEdgeConnectivityNoScale)
373{
374 PRECICE_TEST(1_rank);
375 using namespace mesh;
376 // Setup geometry
377 std::string name("rectangle");
378 int dimensions = 2;
379 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
380
381 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
382 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
383 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector2d(1.0, 2.0));
384
385 mesh->createEdge(v1, v2);
386 mesh->createEdge(v2, v3);
387
388 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
389 auto & doubleValues = doubleData->values();
390
391 mesh->allocateDataValues();
392
393 doubleValues(0) = 1.0;
394 doubleValues(1) = 2.0;
395 doubleValues(2) = 3.0;
396 doubleValues(3) = 4.0;
397 doubleValues(4) = 5.0;
398 doubleValues(5) = 6.0;
399
400 std::string fileName("precice-WatchIntegralTest-scalarData-edgeConnectivity-noScale.log");
401
402 {
403 impl::WatchIntegral watchIntegral(mesh, fileName, false);
404 watchIntegral.initialize();
405
406 // Write output
407 watchIntegral.exportIntegralData(0.0);
408
409 // Change data (next timestep)
410 doubleValues(0) = 2.0;
411 doubleValues(1) = 3.0;
412 doubleValues(2) = 4.0;
413 doubleValues(3) = 5.0;
414 doubleValues(4) = 6.0;
415 doubleValues(5) = 7.0;
416
417 // Write output again
418 watchIntegral.exportIntegralData(1.0);
419
420 watchIntegral.exportIntegralData(2.0);
421 }
422 // File Format: Time DoubleData0 DoubleData1 SurfaceArea
423 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData EdgeConnectivity NoScale")
424 {
426 auto result = readDoublesFromTXTFile(fileName, 4);
427 auto expected = std::vector<double>{
428 0.0, 9.0, 12.0, 3.0,
429 1.0, 12.0, 15.0, 3.0,
430 2.0, 12.0, 15.0, 3.0};
431 BOOST_TEST(result.size() == expected.size());
432 for (size_t i = 0; i < result.size(); ++i) {
433 BOOST_TEST_CONTEXT("entry index: " << i)
434 {
435 using testing::equals;
436 BOOST_TEST(equals(result.at(i), expected.at(i)));
437 }
438 }
439 }
440 }
441}
442
443BOOST_AUTO_TEST_CASE(ScalarDataFaceConnectivity)
444{
445 PRECICE_TEST(1_rank);
446 using namespace mesh;
447 // Setup geometry
448 std::string name("rectangle");
449 int dimensions = 3;
450 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
451
452 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
453 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
454 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
455 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
456
457 mesh::Edge &e1 = mesh->createEdge(v1, v2);
458 mesh::Edge &e2 = mesh->createEdge(v2, v3);
459 mesh::Edge &e3 = mesh->createEdge(v3, v4);
460 mesh::Edge &e4 = mesh->createEdge(v4, v1);
461 mesh::Edge &e5 = mesh->createEdge(v1, v3);
462
463 mesh->createTriangle(e1, e2, e5);
464 mesh->createTriangle(e3, e4, e5);
465
466 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
467 auto & doubleValues = doubleData->values();
468
469 mesh->allocateDataValues();
470
471 doubleValues(0) = 1.0;
472 doubleValues(1) = 2.0;
473 doubleValues(2) = 3.0;
474 doubleValues(3) = 4.0;
475
476 std::string fileName("precice-WatchIntegralTest-scalarData-faceConnectivity.log");
477
478 {
479 impl::WatchIntegral watchIntegral(mesh, fileName, true);
480 watchIntegral.initialize();
481
482 // Write output
483 watchIntegral.exportIntegralData(0.0);
484
485 // Change data (next timestep)
486 doubleValues(0) = 2.0;
487 doubleValues(1) = 3.0;
488 doubleValues(2) = 4.0;
489 doubleValues(3) = 5.0;
490
491 // Write output again
492 watchIntegral.exportIntegralData(1.0);
493
494 watchIntegral.exportIntegralData(2.0);
495 }
496 // File Format: Time DoubleData SurfaceArea
497 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData FaceConnectivity")
498 {
499 auto result = readDoublesFromTXTFile(fileName, 3);
500 auto expected = std::vector<double>{
501 0.0, 28.0, 12.0,
502 1.0, 40.0, 12.0,
503 2.0, 40.0, 12.0};
504 BOOST_TEST(result.size() == expected.size());
505 for (size_t i = 0; i < result.size(); ++i) {
506 BOOST_TEST_CONTEXT("entry index: " << i)
507 {
508 using testing::equals;
509 BOOST_TEST(equals(result.at(i), expected.at(i)));
510 }
511 }
512 }
513}
514
515BOOST_AUTO_TEST_CASE(ScalarDataFaceConnectivityNoScale)
516{
517 PRECICE_TEST(1_rank);
518 using namespace mesh;
519 // Setup geometry
520 std::string name("rectangle");
521 int dimensions = 3;
522 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
523
524 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
525 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
526 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
527 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
528
529 mesh::Edge &e1 = mesh->createEdge(v1, v2);
530 mesh::Edge &e2 = mesh->createEdge(v2, v3);
531 mesh::Edge &e3 = mesh->createEdge(v3, v4);
532 mesh::Edge &e4 = mesh->createEdge(v4, v1);
533 mesh::Edge &e5 = mesh->createEdge(v1, v3);
534
535 mesh->createTriangle(e1, e2, e5);
536 mesh->createTriangle(e3, e4, e5);
537
538 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
539 auto & doubleValues = doubleData->values();
540
541 mesh->allocateDataValues();
542
543 doubleValues(0) = 1.0;
544 doubleValues(1) = 2.0;
545 doubleValues(2) = 3.0;
546 doubleValues(3) = 4.0;
547
548 std::string fileName("precice-WatchIntegralTest-scalarData-faceConnectivity-noScale.log");
549
550 {
551 impl::WatchIntegral watchIntegral(mesh, fileName, false);
552 watchIntegral.initialize();
553
554 // Write output
555 watchIntegral.exportIntegralData(0.0);
556
557 // Change data (next timestep)
558 doubleValues(0) = 2.0;
559 doubleValues(1) = 3.0;
560 doubleValues(2) = 4.0;
561 doubleValues(3) = 5.0;
562
563 // Write output again
564 watchIntegral.exportIntegralData(1.0);
565
566 watchIntegral.exportIntegralData(2.0);
567 }
568 // File Format: Time DoubleData SurfaceArea
569 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData FaceConnectivity NoScale")
570 {
571 auto result = readDoublesFromTXTFile(fileName, 3);
572 auto expected = std::vector<double>{
573 0.0, 10.0, 12.0,
574 1.0, 14.0, 12.0,
575 2.0, 14.0, 12.0};
576 BOOST_TEST(result.size() == expected.size());
577 for (size_t i = 0; i < result.size(); ++i) {
578 BOOST_TEST_CONTEXT("entry index: " << i)
579 {
580 using testing::equals;
581 BOOST_TEST(equals(result.at(i), expected.at(i)));
582 }
583 }
584 }
585}
586
587BOOST_AUTO_TEST_CASE(VectorDataFaceConnectivity)
588{
589 PRECICE_TEST(1_rank);
590 using namespace mesh;
591 // Setup geometry
592 std::string name("rectangle");
593 int dimensions = 3;
594 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
595
596 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
597 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
598 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
599 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
600
601 mesh::Edge &e1 = mesh->createEdge(v1, v2);
602 mesh::Edge &e2 = mesh->createEdge(v2, v3);
603 mesh::Edge &e3 = mesh->createEdge(v3, v4);
604 mesh::Edge &e4 = mesh->createEdge(v4, v1);
605 mesh::Edge &e5 = mesh->createEdge(v1, v3);
606
607 mesh->createTriangle(e1, e2, e5);
608 mesh->createTriangle(e3, e4, e5);
609
610 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
611 auto & doubleValues = doubleData->values();
612
613 mesh->allocateDataValues();
614
615 doubleValues(0) = 1.0;
616 doubleValues(1) = 2.0;
617 doubleValues(2) = 3.0;
618 doubleValues(3) = 4.0;
619 doubleValues(4) = 5.0;
620 doubleValues(5) = 6.0;
621 doubleValues(6) = 7.0;
622 doubleValues(7) = 8.0;
623
624 std::string fileName("precice-WatchIntegralTest-vectorData-faceConnectivity.log");
625
626 {
627 impl::WatchIntegral watchIntegral(mesh, fileName, true);
628 watchIntegral.initialize();
629
630 // Write output
631 watchIntegral.exportIntegralData(0.0);
632
633 // Change data (next timestep)
634 doubleValues(0) = 2.0;
635 doubleValues(1) = 3.0;
636 doubleValues(2) = 4.0;
637 doubleValues(3) = 5.0;
638 doubleValues(4) = 6.0;
639 doubleValues(5) = 7.0;
640 doubleValues(6) = 8.0;
641 doubleValues(7) = 9.0;
642
643 // Write output again
644 watchIntegral.exportIntegralData(1.0);
645
646 watchIntegral.exportIntegralData(2.0);
647 }
648 // File Format: Time DoubleData0 DoubleData1 SurfaceArea
649 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData FaceConnectivity")
650 {
651 auto result = readDoublesFromTXTFile(fileName, 4);
652 auto expected = std::vector<double>{
653 0.0, 44.0, 56.0, 12.0,
654 1.0, 56.0, 68.0, 12.0,
655 2.0, 56.0, 68.0, 12.0};
656 BOOST_TEST(result.size() == expected.size());
657 for (size_t i = 0; i < result.size(); ++i) {
658 BOOST_TEST_CONTEXT("entry index: " << i)
659 {
660 using testing::equals;
661 BOOST_TEST(equals(result.at(i), expected.at(i)));
662 }
663 }
664 }
665}
666
667BOOST_AUTO_TEST_CASE(VectorDataFaceConnectivityNoScale)
668{
669 PRECICE_TEST(1_rank);
670 using namespace mesh;
671 // Setup geometry
672 std::string name("rectangle");
673 int dimensions = 3;
674 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
675
676 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
677 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
678 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
679 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
680
681 mesh::Edge &e1 = mesh->createEdge(v1, v2);
682 mesh::Edge &e2 = mesh->createEdge(v2, v3);
683 mesh::Edge &e3 = mesh->createEdge(v3, v4);
684 mesh::Edge &e4 = mesh->createEdge(v4, v1);
685 mesh::Edge &e5 = mesh->createEdge(v1, v3);
686
687 mesh->createTriangle(e1, e2, e5);
688 mesh->createTriangle(e3, e4, e5);
689
690 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
691 auto & doubleValues = doubleData->values();
692
693 mesh->allocateDataValues();
694
695 doubleValues(0) = 1.0;
696 doubleValues(1) = 2.0;
697 doubleValues(2) = 3.0;
698 doubleValues(3) = 4.0;
699 doubleValues(4) = 5.0;
700 doubleValues(5) = 6.0;
701 doubleValues(6) = 7.0;
702 doubleValues(7) = 8.0;
703
704 std::string fileName("precice-WatchIntegralTest-vectorData-faceConnectivity-noScale.log");
705
706 {
707 impl::WatchIntegral watchIntegral(mesh, fileName, false);
708 watchIntegral.initialize();
709
710 // Write output
711 watchIntegral.exportIntegralData(0.0);
712
713 // Change data (next timestep)
714 doubleValues(0) = 2.0;
715 doubleValues(1) = 3.0;
716 doubleValues(2) = 4.0;
717 doubleValues(3) = 5.0;
718 doubleValues(4) = 6.0;
719 doubleValues(5) = 7.0;
720 doubleValues(6) = 8.0;
721 doubleValues(7) = 9.0;
722
723 // Write output again
724 watchIntegral.exportIntegralData(1.0);
725
726 watchIntegral.exportIntegralData(2.0);
727 }
728 // File Format: Time DoubleData0 DoubleData1 SurfaceArea
729 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData FaceConnectivity NoScale")
730 {
731 auto result = readDoublesFromTXTFile(fileName, 4);
732 auto expected = std::vector<double>{
733 0.0, 16.0, 20.0, 12.0,
734 1.0, 20.0, 24.0, 12.0,
735 2.0, 20.0, 24.0, 12.0};
736 BOOST_TEST(result.size() == expected.size());
737 for (size_t i = 0; i < result.size(); ++i) {
738 BOOST_TEST_CONTEXT("entry index: " << i)
739 {
740 using testing::equals;
741 BOOST_TEST(equals(result.at(i), expected.at(i)));
742 }
743 }
744 }
745}
746
747BOOST_AUTO_TEST_CASE(MeshChangeFaceConnectivity)
748{
749 PRECICE_TEST(1_rank);
750 using namespace mesh;
751 // Setup geometry
752 std::string name("rectangle");
753 int dimensions = 3;
754 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
755
756 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
757 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
758 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
759 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
760
761 mesh::Edge &e1 = mesh->createEdge(v1, v2);
762 mesh::Edge &e2 = mesh->createEdge(v2, v3);
763 mesh::Edge &e3 = mesh->createEdge(v3, v4);
764 mesh::Edge &e4 = mesh->createEdge(v4, v1);
765 mesh::Edge &e5 = mesh->createEdge(v1, v3);
766
767 mesh->createTriangle(e1, e2, e5);
768 mesh->createTriangle(e3, e4, e5);
769
770 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
771 auto & doubleValues = doubleData->values();
772
773 mesh->allocateDataValues();
774
775 doubleValues(0) = 1.0;
776 doubleValues(1) = 2.0;
777 doubleValues(2) = 3.0;
778 doubleValues(3) = 4.0;
779
780 std::string fileName("precice-WatchIntegralTest-meshChange-faceConnectivity.log");
781
782 {
783 impl::WatchIntegral watchIntegral(mesh, fileName, true);
784 watchIntegral.initialize();
785
786 // Write output
787 watchIntegral.exportIntegralData(0.0);
788
789 // Change data (next timestep)
790 v2.setCoords(Eigen::Vector3d(3.0, -4.0, 0.0));
791
792 // Write output again
793 watchIntegral.exportIntegralData(1.0);
794
795 watchIntegral.exportIntegralData(2.0);
796 }
797 // File Format: Time DoubleData SurfaceArea
798 BOOST_TEST_CONTEXT("Validating WatchIntegral MeshChange FaceConnectivity")
799 {
800 auto result = readDoublesFromTXTFile(fileName, 3);
801 auto expected = std::vector<double>{
802 0.0, 28.0, 12.0,
803 1.0, 40.0, 18.0,
804 2.0, 40.0, 18.0};
805 BOOST_TEST(result.size() == expected.size());
806 for (size_t i = 0; i < result.size(); ++i) {
807 BOOST_TEST_CONTEXT("entry index: " << i)
808 {
809 using testing::equals;
810 BOOST_TEST(equals(result.at(i), expected.at(i)));
811 }
812 }
813 }
814}
815
816BOOST_AUTO_TEST_CASE(ScalarDataNoConnectivityParallel)
817{
818 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
819 using namespace mesh;
820 // Setup geometry
821 std::string name("rectangle");
822 int dimensions = 2;
823 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
824 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
825 auto & doubleValues = doubleData->values();
826
828 mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
829 mesh->createVertex(Eigen::Vector2d(0.0, 1.0));
830 } else if (context.isRank(1)) {
831 mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
832 mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
833 } else if (context.isRank(2)) {
834 mesh->createVertex(Eigen::Vector2d(2.0, 0.0));
835 mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
836 } else if (context.isRank(3)) {
837 mesh->createVertex(Eigen::Vector2d(3.0, 0.0));
838 mesh->createVertex(Eigen::Vector2d(0.0, 1.0));
839 }
840
841 mesh->allocateDataValues();
842
844 doubleValues(0) = 1.0;
845 doubleValues(1) = 2.0;
846 } else if (context.isRank(1)) {
847 doubleValues(0) = 3.0;
848 doubleValues(1) = 4.0;
849 } else if (context.isRank(2)) {
850 doubleValues(0) = 5.0;
851 doubleValues(1) = 6.0;
852 } else if (context.isRank(3)) {
853 doubleValues(0) = 7.0;
854 doubleValues(1) = 8.0;
855 }
856
857 std::string fileName("precice-WatchIntegralTest-scalarData-noConnectivity-parallel.log");
858
859 {
860 impl::WatchIntegral watchIntegral(mesh, fileName, true);
861 watchIntegral.initialize();
862
863 // Write output
864 watchIntegral.exportIntegralData(0.0);
865
866 // Change data (next timestep)
868 doubleValues(0) = 2.0;
869 doubleValues(1) = 3.0;
870 } else if (context.isRank(1)) {
871 doubleValues(0) = 4.0;
872 doubleValues(1) = 5.0;
873 } else if (context.isRank(2)) {
874 doubleValues(0) = 6.0;
875 doubleValues(1) = 7.0;
876 } else if (context.isRank(3)) {
877 doubleValues(0) = 8.0;
878 doubleValues(1) = 9.0;
879 }
880
881 // Write output again
882 watchIntegral.exportIntegralData(1.0);
883
884 watchIntegral.exportIntegralData(2.0);
885 }
886 // File Format: Time DoubleData
887 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData NoConnectivity Parallel")
888 {
890 auto result = readDoublesFromTXTFile(fileName, 2);
891 auto expected = std::vector<double>{
892 0.0, 36.0,
893 1.0, 44.0,
894 2.0, 44.0};
895 BOOST_TEST(result.size() == expected.size());
896 for (size_t i = 0; i < result.size(); ++i) {
897 BOOST_TEST_CONTEXT("entry index: " << i)
898 {
899 using testing::equals;
900 BOOST_TEST(equals(result.at(i), expected.at(i)));
901 }
902 }
903 }
904 }
905}
906
907BOOST_AUTO_TEST_CASE(VectorDataNoConnectivityParallel)
908{
909 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
910 using namespace mesh;
911 // Setup geometry
912 std::string name("rectangle");
913 int dimensions = 2;
914 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
915 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
916 auto & doubleValues = doubleData->values();
917
919 mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
920 mesh->createVertex(Eigen::Vector2d(0.0, 1.0));
921 } else if (context.isRank(1)) {
922 mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
923 mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
924 } else if (context.isRank(2)) {
925 mesh->createVertex(Eigen::Vector2d(2.0, 0.0));
926 mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
927 } else if (context.isRank(3)) {
928 mesh->createVertex(Eigen::Vector2d(3.0, 0.0));
929 mesh->createVertex(Eigen::Vector2d(0.0, 1.0));
930 }
931
932 mesh->allocateDataValues();
933
935 doubleValues(0) = 1.0;
936 doubleValues(1) = 2.0;
937 doubleValues(2) = 3.0;
938 doubleValues(3) = 4.0;
939 } else if (context.isRank(1)) {
940 doubleValues(0) = 5.0;
941 doubleValues(1) = 6.0;
942 doubleValues(2) = 7.0;
943 doubleValues(3) = 8.0;
944 } else if (context.isRank(2)) {
945 doubleValues(0) = 9.0;
946 doubleValues(1) = 10.0;
947 doubleValues(2) = 11.0;
948 doubleValues(3) = 12.0;
949 } else if (context.isRank(3)) {
950 doubleValues(0) = 13.0;
951 doubleValues(1) = 14.0;
952 doubleValues(2) = 15.0;
953 doubleValues(3) = 16.0;
954 }
955
956 std::string fileName("precice-WatchIntegralTest-vectorData-noConnectivity-parallel.log");
957
958 {
959 impl::WatchIntegral watchIntegral(mesh, fileName, true);
960 watchIntegral.initialize();
961
962 // Write output
963 watchIntegral.exportIntegralData(0.0);
964
965 // Change data (next timestep)
967 doubleValues(0) = 2.0;
968 doubleValues(1) = 3.0;
969 doubleValues(2) = 4.0;
970 doubleValues(3) = 5.0;
971 } else if (context.isRank(1)) {
972 doubleValues(0) = 6.0;
973 doubleValues(1) = 7.0;
974 doubleValues(2) = 8.0;
975 doubleValues(3) = 9.0;
976 } else if (context.isRank(2)) {
977 doubleValues(0) = 10.0;
978 doubleValues(1) = 11.0;
979 doubleValues(2) = 12.0;
980 doubleValues(3) = 13.0;
981 } else if (context.isRank(3)) {
982 doubleValues(0) = 14.0;
983 doubleValues(1) = 15.0;
984 doubleValues(2) = 16.0;
985 doubleValues(3) = 17.0;
986 }
987
988 // Write output again
989 watchIntegral.exportIntegralData(1.0);
990
991 watchIntegral.exportIntegralData(2.0);
992 }
993 // File Format: Time DoubleData
994 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData NoConnectivity Parallel")
995 {
997 auto result = readDoublesFromTXTFile(fileName, 3);
998 auto expected = std::vector<double>{
999 0.0, 64.0, 72.0,
1000 1.0, 72.0, 80.0,
1001 2.0, 72.0, 80.0};
1002 BOOST_TEST(result.size() == expected.size());
1003 for (size_t i = 0; i < result.size(); ++i) {
1004 BOOST_TEST_CONTEXT("entry index: " << i)
1005 {
1006 using testing::equals;
1007 BOOST_TEST(equals(result.at(i), expected.at(i)));
1008 }
1009 }
1010 }
1011 }
1012}
1013
1014BOOST_AUTO_TEST_CASE(ScalarDataEdgeConnectivityParallel)
1015{
1016 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
1017 using namespace mesh;
1018 // Setup geometry
1019 std::string name("rectangle");
1020 int dimensions = 2;
1021 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
1022
1024 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
1025 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
1026 mesh->createEdge(v1, v2);
1027 }
1028 if (context.isRank(1)) {
1029 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
1030 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector2d(1.0, 2.0));
1031 mesh->createEdge(v3, v4);
1032 }
1033 if (context.isRank(2)) {
1034 mesh::Vertex &v5 = mesh->createVertex(Eigen::Vector2d(2.0, 1.0));
1035 mesh::Vertex &v6 = mesh->createVertex(Eigen::Vector2d(2.0, 2.0));
1036 mesh->createEdge(v5, v6);
1037 }
1038 if (context.isRank(3)) {
1039 mesh::Vertex &v7 = mesh->createVertex(Eigen::Vector2d(3.0, 1.0));
1040 mesh::Vertex &v8 = mesh->createVertex(Eigen::Vector2d(3.0, 3.0));
1041 mesh->createEdge(v7, v8);
1042 }
1043
1044 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
1045 auto & doubleValues = doubleData->values();
1046
1047 mesh->allocateDataValues();
1048
1050 doubleValues(0) = 1.0;
1051 doubleValues(1) = 2.0;
1052 }
1053 if (context.isRank(1)) {
1054 doubleValues(0) = 3.0;
1055 doubleValues(1) = 4.0;
1056 }
1057 if (context.isRank(2)) {
1058 doubleValues(0) = 5.0;
1059 doubleValues(1) = 6.0;
1060 }
1061 if (context.isRank(3)) {
1062 doubleValues(0) = 7.0;
1063 doubleValues(1) = 8.0;
1064 }
1065
1066 std::string fileName("precice-WatchIntegralTest-scalarData-edgeConnectivity-parallel.log");
1067
1068 {
1069 impl::WatchIntegral watchIntegral(mesh, fileName, true);
1070 watchIntegral.initialize();
1071
1072 // Write output
1073 watchIntegral.exportIntegralData(0.0);
1074
1075 // Change data (next timestep)
1077 doubleValues(0) = 2.0;
1078 doubleValues(1) = 3.0;
1079 }
1080 if (context.isRank(1)) {
1081 doubleValues(0) = 4.0;
1082 doubleValues(1) = 5.0;
1083 }
1084 if (context.isRank(2)) {
1085 doubleValues(0) = 6.0;
1086 doubleValues(1) = 7.0;
1087 }
1088 if (context.isRank(3)) {
1089 doubleValues(0) = 8.0;
1090 doubleValues(1) = 9.0;
1091 }
1092
1093 // Write output again
1094 watchIntegral.exportIntegralData(1.0);
1095
1096 watchIntegral.exportIntegralData(2.0);
1097 }
1098 // File Format: Time DoubleData SurfaceArea
1099 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData EdgeConnectivity Parallel")
1100 {
1102 auto result = readDoublesFromTXTFile(fileName, 3);
1103 auto expected = std::vector<double>{
1104 0.0, 25.5, 5.0,
1105 1.0, 30.5, 5.0,
1106 2.0, 30.5, 5.0};
1107 BOOST_TEST(result.size() == expected.size());
1108 for (size_t i = 0; i < result.size(); ++i) {
1109 BOOST_TEST_CONTEXT("entry index: " << i)
1110 {
1111 using testing::equals;
1112 BOOST_TEST(equals(result.at(i), expected.at(i)));
1113 }
1114 }
1115 }
1116 }
1117}
1118
1119BOOST_AUTO_TEST_CASE(VectorDataEdgeConnectivityParallel)
1120{
1121 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
1122 using namespace mesh;
1123 // Setup geometry
1124 std::string name("rectangle");
1125 int dimensions = 2;
1126 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
1127
1129 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector2d(0.0, 0.0));
1130 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector2d(1.0, 0.0));
1131 mesh->createEdge(v1, v2);
1132 }
1133 if (context.isRank(1)) {
1134 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector2d(1.0, 1.0));
1135 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector2d(1.0, 2.0));
1136 mesh->createEdge(v3, v4);
1137 }
1138 if (context.isRank(2)) {
1139 mesh::Vertex &v5 = mesh->createVertex(Eigen::Vector2d(2.0, 1.0));
1140 mesh::Vertex &v6 = mesh->createVertex(Eigen::Vector2d(2.0, 2.0));
1141 mesh->createEdge(v5, v6);
1142 }
1143 if (context.isRank(3)) {
1144 mesh::Vertex &v7 = mesh->createVertex(Eigen::Vector2d(3.0, 1.0));
1145 mesh::Vertex &v8 = mesh->createVertex(Eigen::Vector2d(3.0, 3.0));
1146 mesh->createEdge(v7, v8);
1147 }
1148
1149 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
1150 auto & doubleValues = doubleData->values();
1151
1152 mesh->allocateDataValues();
1153
1155 doubleValues(0) = 1.0;
1156 doubleValues(1) = 2.0;
1157 doubleValues(2) = 3.0;
1158 doubleValues(3) = 4.0;
1159 }
1160 if (context.isRank(1)) {
1161 doubleValues(0) = 5.0;
1162 doubleValues(1) = 6.0;
1163 doubleValues(2) = 7.0;
1164 doubleValues(3) = 8.0;
1165 }
1166 if (context.isRank(2)) {
1167 doubleValues(0) = 9.0;
1168 doubleValues(1) = 10.0;
1169 doubleValues(2) = 11.0;
1170 doubleValues(3) = 12.0;
1171 }
1172 if (context.isRank(3)) {
1173 doubleValues(0) = 13.0;
1174 doubleValues(1) = 14.0;
1175 doubleValues(2) = 15.0;
1176 doubleValues(3) = 16.0;
1177 }
1178
1179 std::string fileName("precice-WatchIntegralTest-scalarData-edgeConnectivity-parallel.log");
1180
1181 {
1182 impl::WatchIntegral watchIntegral(mesh, fileName, true);
1183 watchIntegral.initialize();
1184
1185 // Write output
1186 watchIntegral.exportIntegralData(0.0);
1187
1188 // Change data (next timestep)
1190 doubleValues(0) = 2.0;
1191 doubleValues(1) = 3.0;
1192 doubleValues(2) = 4.0;
1193 doubleValues(3) = 5.0;
1194 }
1195 if (context.isRank(1)) {
1196 doubleValues(0) = 6.0;
1197 doubleValues(1) = 7.0;
1198 doubleValues(2) = 8.0;
1199 doubleValues(3) = 9.0;
1200 }
1201 if (context.isRank(2)) {
1202 doubleValues(0) = 10.0;
1203 doubleValues(1) = 11.0;
1204 doubleValues(2) = 12.0;
1205 doubleValues(3) = 13.0;
1206 }
1207 if (context.isRank(3)) {
1208 doubleValues(0) = 14.0;
1209 doubleValues(1) = 15.0;
1210 doubleValues(2) = 16.0;
1211 doubleValues(3) = 17.0;
1212 }
1213
1214 // Write output again
1215 watchIntegral.exportIntegralData(1.0);
1216
1217 watchIntegral.exportIntegralData(2.0);
1218 }
1219 // File Format: Time DoubleData0 DoubleData1 SurfaceArea
1220 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData EdgeConnectivity Parallel")
1221 {
1223 auto result = readDoublesFromTXTFile(fileName, 4);
1224 auto expected = std::vector<double>{
1225 0.0, 46.0, 51.0, 5.0,
1226 1.0, 51.0, 56.0, 5.0,
1227 2.0, 51.0, 56.0, 5.0};
1228 BOOST_TEST(result.size() == expected.size());
1229 for (size_t i = 0; i < result.size(); ++i) {
1230 BOOST_TEST_CONTEXT("entry index: " << i)
1231 {
1232 using testing::equals;
1233 BOOST_TEST(equals(result.at(i), expected.at(i)));
1234 }
1235 }
1236 }
1237 }
1238}
1239
1240BOOST_AUTO_TEST_CASE(ScalarDataFaceConnectivityParallel)
1241{
1242 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
1243 using namespace mesh;
1244 // Setup geometry
1245 std::string name("rectangle");
1246 int dimensions = 3;
1247 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
1248
1250 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1251 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
1252 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
1253 mesh::Edge & e1 = mesh->createEdge(v1, v2);
1254 mesh::Edge & e2 = mesh->createEdge(v2, v3);
1255 mesh::Edge & e5 = mesh->createEdge(v1, v3);
1256 mesh->createTriangle(e1, e2, e5);
1257 }
1258 if (context.isRank(1)) {
1259 }
1260 if (context.isRank(2)) {
1261 }
1262 if (context.isRank(3)) {
1263 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1264 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
1265 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
1266 mesh::Edge & e3 = mesh->createEdge(v3, v4);
1267 mesh::Edge & e4 = mesh->createEdge(v4, v1);
1268 mesh::Edge & e5 = mesh->createEdge(v1, v3);
1269 mesh->createTriangle(e3, e4, e5);
1270 }
1271
1272 PtrData doubleData = mesh->createData("DoubleData", 1, 0_dataID);
1273 auto & doubleValues = doubleData->values();
1274
1275 mesh->allocateDataValues();
1276
1278 doubleValues(0) = 1.0;
1279 doubleValues(1) = 2.0;
1280 doubleValues(2) = 3.0;
1281 }
1282 if (context.isRank(1)) {
1283 }
1284 if (context.isRank(2)) {
1285 }
1286 if (context.isRank(3)) {
1287 doubleValues(0) = 1.0;
1288 doubleValues(1) = 3.0;
1289 doubleValues(2) = 4.0;
1290 }
1291
1292 std::string fileName("precice-WatchIntegralTest-scalarData-faceConnectivity-parallel.log");
1293
1294 {
1295 impl::WatchIntegral watchIntegral(mesh, fileName, true);
1296 watchIntegral.initialize();
1297
1298 // Write output
1299 watchIntegral.exportIntegralData(0.0);
1300
1301 // Change data (next timestep)
1303 doubleValues(0) = 2.0;
1304 doubleValues(1) = 3.0;
1305 doubleValues(2) = 4.0;
1306 }
1307 if (context.isRank(1)) {
1308 }
1309 if (context.isRank(2)) {
1310 }
1311 if (context.isRank(3)) {
1312 doubleValues(0) = 2.0;
1313 doubleValues(1) = 4.0;
1314 doubleValues(2) = 5.0;
1315 }
1316
1317 // Write output again
1318 watchIntegral.exportIntegralData(1.0);
1319
1320 watchIntegral.exportIntegralData(2.0);
1321 }
1322 // File Format: Time DoubleData SurfaceArea
1323 BOOST_TEST_CONTEXT("Validating WatchIntegral ScalarData FaceConnectivity Parallel")
1324 {
1326 auto result = readDoublesFromTXTFile(fileName, 3);
1327 auto expected = std::vector<double>{
1328 0.0, 28.0, 12.0,
1329 1.0, 40.0, 12.0,
1330 2.0, 40.0, 12.0};
1331 BOOST_TEST(result.size() == expected.size());
1332 for (size_t i = 0; i < result.size(); ++i) {
1333 BOOST_TEST_CONTEXT("entry index: " << i)
1334 {
1335 using testing::equals;
1336 BOOST_TEST(equals(result.at(i), expected.at(i)));
1337 }
1338 }
1339 }
1340 }
1341}
1342
1343BOOST_AUTO_TEST_CASE(VectorDataFaceConnectivityParallel)
1344{
1345 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
1346 using namespace mesh;
1347 // Setup geometry
1348 std::string name("rectangle");
1349 int dimensions = 3;
1350 PtrMesh mesh(new Mesh(name, dimensions, testing::nextMeshID()));
1351
1353 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1354 mesh::Vertex &v2 = mesh->createVertex(Eigen::Vector3d(3.0, 0.0, 0.0));
1355 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
1356 mesh::Edge & e1 = mesh->createEdge(v1, v2);
1357 mesh::Edge & e2 = mesh->createEdge(v2, v3);
1358 mesh::Edge & e5 = mesh->createEdge(v1, v3);
1359 mesh->createTriangle(e1, e2, e5);
1360 }
1361 if (context.isRank(1)) {
1362 }
1363 if (context.isRank(2)) {
1364 }
1365 if (context.isRank(3)) {
1366 mesh::Vertex &v1 = mesh->createVertex(Eigen::Vector3d(0.0, 0.0, 0.0));
1367 mesh::Vertex &v3 = mesh->createVertex(Eigen::Vector3d(3.0, 4.0, 0.0));
1368 mesh::Vertex &v4 = mesh->createVertex(Eigen::Vector3d(0.0, 4.0, 0.0));
1369 mesh::Edge & e3 = mesh->createEdge(v3, v4);
1370 mesh::Edge & e4 = mesh->createEdge(v4, v1);
1371 mesh::Edge & e5 = mesh->createEdge(v1, v3);
1372 mesh->createTriangle(e3, e4, e5);
1373 }
1374
1375 PtrData doubleData = mesh->createData("DoubleData", 2, 0_dataID);
1376 auto & doubleValues = doubleData->values();
1377
1378 mesh->allocateDataValues();
1379
1381 doubleValues(0) = 1.0;
1382 doubleValues(1) = 2.0;
1383 doubleValues(2) = 3.0;
1384 doubleValues(3) = 4.0;
1385 doubleValues(4) = 5.0;
1386 doubleValues(5) = 6.0;
1387 }
1388 if (context.isRank(1)) {
1389 }
1390 if (context.isRank(2)) {
1391 }
1392 if (context.isRank(3)) {
1393 doubleValues(0) = 1.0;
1394 doubleValues(1) = 2.0;
1395 doubleValues(2) = 5.0;
1396 doubleValues(3) = 6.0;
1397 doubleValues(4) = 7.0;
1398 doubleValues(5) = 8.0;
1399 }
1400
1401 std::string fileName("precice-WatchIntegralTest-vectorData-faceConnectivity-parallel.log");
1402
1403 {
1404 impl::WatchIntegral watchIntegral(mesh, fileName, true);
1405 watchIntegral.initialize();
1406
1407 // Write output
1408 watchIntegral.exportIntegralData(0.0);
1409
1410 // Change data (next timestep)
1412 doubleValues(0) = 2.0;
1413 doubleValues(1) = 3.0;
1414 doubleValues(2) = 4.0;
1415 doubleValues(3) = 5.0;
1416 doubleValues(4) = 6.0;
1417 doubleValues(5) = 7.0;
1418 }
1419 if (context.isRank(1)) {
1420 }
1421 if (context.isRank(2)) {
1422 }
1423 if (context.isRank(3)) {
1424 doubleValues(0) = 2.0;
1425 doubleValues(1) = 3.0;
1426 doubleValues(2) = 6.0;
1427 doubleValues(3) = 7.0;
1428 doubleValues(4) = 8.0;
1429 doubleValues(5) = 9.0;
1430 }
1431
1432 // Write output again
1433 watchIntegral.exportIntegralData(1.0);
1434
1435 watchIntegral.exportIntegralData(2.0);
1436 }
1437 // File Format: Time DoubleData SurfaceArea
1438 BOOST_TEST_CONTEXT("Validating WatchIntegral VectorData FaceConnectivity Parallel")
1439 {
1441 auto result = readDoublesFromTXTFile(fileName, 4);
1442 auto expected = std::vector<double>{
1443 0.0, 44.0, 56.0, 12.0,
1444 1.0, 56.0, 68.0, 12.0,
1445 2.0, 56.0, 68.0, 12.0};
1446 BOOST_TEST(result.size() == expected.size());
1447 for (size_t i = 0; i < result.size(); ++i) {
1448 BOOST_TEST_CONTEXT("entry index: " << i)
1449 {
1450 using testing::equals;
1451 BOOST_TEST(equals(result.at(i), expected.at(i)));
1452 }
1453 }
1454 }
1455 }
1456}
1457
1459BOOST_AUTO_TEST_SUITE_END() // Precice
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
std::string name
#define PRECICE_TEST(...)
Definition Testing.hpp:27
BOOST_AUTO_TEST_CASE(ScalarDataNoConnectivity)
Track and output transient integral data on a mesh.
void initialize()
Adds surface area information based on mesh connectivity.
void exportIntegralData(double time)
Writes one line with data of the integral over the mesh into the output file.
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
Vertex of a mesh.
Definition Vertex.hpp:16
void setCoords(const VECTOR_T &coordinates)
Sets the coordinates of the vertex.
Definition Vertex.hpp:102
static bool isPrimary()
True if this process is running the primary rank.
Definition IntraComm.cpp:52
provides Mesh, Data and primitives.
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
void ignore(Arguments &&...)
Definition ignore.hpp:10
Main namespace of the precice library.