preCICE v3.1.2
Loading...
Searching...
No Matches
FilterTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <iosfwd>
3#include <string>
4#include "logging/Logger.hpp"
5#include "mesh/Filter.hpp"
6#include "mesh/Mesh.hpp"
8#include "testing/Testing.hpp"
9
10using namespace precice;
11using namespace Eigen;
12
13BOOST_AUTO_TEST_SUITE(MeshTests)
14BOOST_AUTO_TEST_SUITE(FilterTests)
15
17{
18 PRECICE_TEST(1_rank);
19
20 mesh::Mesh dest("2D dest", 2, testing::nextMeshID());
21 mesh::Mesh src("2D src", 2, testing::nextMeshID());
22
23 auto &v0 = dest.createVertex(Vector2d::Constant(4.0)); // Add dummy data to check additivity
24 auto &v1 = src.createVertex(Vector2d::Constant(3.0));
25 src.createVertex(Vector2d::Constant(2.0));
26
27 v1.tag();
28
29 auto p = [](const mesh::Vertex &v) { return v.isTagged(); };
30
31 mesh::filterMesh(dest, src, p);
32
33 // dest should contain Constante(4) and Constant(3), but not Constant(2)
34 BOOST_TEST(dest.nVertices() == 2);
35 BOOST_TEST(dest.vertex(0) == v0);
36 BOOST_TEST(dest.vertex(1) == v1);
37}
38
40{
41 PRECICE_TEST(1_rank);
42
43 mesh::Mesh dest("3D dest", 3, testing::nextMeshID());
44 mesh::Mesh src("3D src", 3, testing::nextMeshID());
45
46 auto &v0 = dest.createVertex(Vector3d::Constant(4.0)); // Add dummy data to check additivity
47 auto &v1 = src.createVertex(Vector3d::Constant(3.0));
48 src.createVertex(Vector3d::Constant(2.0));
49
50 v1.tag();
51
52 auto p = [](const mesh::Vertex &v) { return v.isTagged(); };
53
54 mesh::filterMesh(dest, src, p);
55
56 // dest should contain Constante(4) and Constant(3), but not Constant(2)
57 BOOST_TEST(dest.nVertices() == 2);
58 BOOST_TEST(dest.vertex(0) == v0);
59 BOOST_TEST(dest.vertex(1) == v1);
60}
61
63{
64 PRECICE_TEST(1_rank);
65
66 mesh::Mesh dest("3D dest", 3, testing::nextMeshID());
67 mesh::Mesh src("3D src", 3, testing::nextMeshID());
68
69 auto &v0 = dest.createVertex(Vector3d::Constant(4.0)); // Add dummy data to check additivity
70 auto &v1 = src.createVertex(Vector3d::Constant(0.0));
71 auto &v2 = src.createVertex(Vector3d::Constant(1.0));
72 auto &v3 = src.createVertex(Vector3d::Constant(2.0));
73
74 auto &e0 = src.createEdge(v1, v2);
75 src.createEdge(v2, v3);
76
77 v1.tag();
78 v2.tag();
79
80 auto p = [](const mesh::Vertex &v) { return v.isTagged(); };
81
82 mesh::filterMesh(dest, src, p);
83
84 BOOST_TEST(dest.nVertices() == 3);
85 BOOST_TEST(dest.vertex(0) == v0);
86 BOOST_TEST(dest.vertex(1) == v1);
87 BOOST_TEST(dest.vertex(2) == v2);
88
89 // Only e0 should survive
90 BOOST_TEST(dest.edges().size() == 1);
91 BOOST_TEST(dest.edges()[0] == e0);
92}
93
95{
96 PRECICE_TEST(1_rank);
97
98 mesh::Mesh dest("3D dest", 3, testing::nextMeshID());
99 mesh::Mesh src("3D src", 3, testing::nextMeshID());
100
101 dest.createVertex(Vector3d::Constant(4.0)); // Add dummy data to check additivity
102 auto &v1 = src.createVertex(Vector3d::Constant(0.0));
103 auto &v2 = src.createVertex(Vector3d{1.0, 0.0, 0.0});
104 auto &v3 = src.createVertex(Vector3d{0.0, 1.0, 0.0});
105 auto &v4 = src.createVertex(Vector3d{0.0, 0.0, 1.0});
106
107 auto &t1 = src.createTriangle(v1, v2, v3);
108 src.createTriangle(v2, v3, v4);
109
110 v1.tag();
111 v2.tag();
112 v3.tag();
113
114 auto p = [](const mesh::Vertex &v) { return v.isTagged(); };
115
116 mesh::filterMesh(dest, src, p);
117
118 BOOST_TEST(dest.nVertices() == 4);
119
120 // Only t1 should survive (because v4 not passed)
121 BOOST_TEST(dest.triangles().size() == 1);
122 BOOST_TEST(dest.triangles()[0] == t1);
123}
124
126{
127 PRECICE_TEST(1_rank);
128
129 mesh::Mesh dest("3D dest", 3, testing::nextMeshID());
130 mesh::Mesh src("3D src", 3, testing::nextMeshID());
131
132 dest.createVertex(Vector3d::Constant(4.0)); // Add dummy data to check additivity
133 auto &v1 = src.createVertex(Vector3d::Constant(0.0));
134 auto &v2 = src.createVertex(Vector3d{1.0, 0.0, 0.0});
135 auto &v3 = src.createVertex(Vector3d{0.0, 1.0, 0.0});
136 auto &v4 = src.createVertex(Vector3d{0.0, 0.0, 1.0});
137 auto &v5 = src.createVertex(Vector3d{0.0, 2.0, 1.0});
138
139 auto &t1 = src.createTetrahedron(v1, v2, v3, v4);
140 src.createTetrahedron(v2, v3, v4, v5);
141
142 v1.tag();
143 v2.tag();
144 v3.tag();
145 v4.tag();
146
147 auto p = [](const mesh::Vertex &v) { return v.isTagged(); };
148
149 mesh::filterMesh(dest, src, p);
150
151 BOOST_TEST(dest.nVertices() == 5);
152
153 // Only t1 should survive (because v5 not passed)
154 BOOST_TEST(dest.tetrahedra().size() == 1);
155 BOOST_TEST(dest.tetrahedra()[0] == t1);
156}
157
BOOST_AUTO_TEST_CASE(Vertices2D)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
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
Tetrahedron & createTetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Creates and initializes a Tetrahedron object.
Definition Mesh.cpp:141
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
Vertex of a mesh.
Definition Vertex.hpp:16
void filterMesh(Mesh &destination, const Mesh &source, UnaryPredicate p)
Definition Filter.hpp:17
Main namespace of the precice library.