preCICE v3.1.2
Loading...
Searching...
No Matches
Filter.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <boost/container/flat_map.hpp>
4
5#include "mesh/Mesh.hpp"
7
8namespace precice {
9namespace mesh {
10
16template <typename UnaryPredicate>
17void filterMesh(Mesh &destination, const Mesh &source, UnaryPredicate p)
18{
19 // Create a flat_map which can contain all vertices of the original mesh.
20 // This prevents resizes during the map build-up.
21 boost::container::flat_map<VertexID, Vertex *> vertexMap;
22 vertexMap.reserve(source.nVertices());
23
24 for (const Vertex &vertex : source.vertices()) {
25 if (p(vertex)) {
26 Vertex &v = destination.createVertex(vertex.getCoords());
27 v.setGlobalIndex(vertex.getGlobalIndex());
28 if (vertex.isTagged())
29 v.tag();
30 v.setOwner(vertex.isOwner());
31 vertexMap[vertex.getID()] = &v;
32 }
33 }
34
35 // Add all edges formed by the contributing vertices
36 for (const Edge &edge : source.edges()) {
37 VertexID vertexIndex1 = edge.vertex(0).getID();
38 VertexID vertexIndex2 = edge.vertex(1).getID();
39 if (vertexMap.count(vertexIndex1) == 1 &&
40 vertexMap.count(vertexIndex2) == 1) {
41 destination.createEdge(*vertexMap[vertexIndex1], *vertexMap[vertexIndex2]);
42 }
43 }
44
45 // Add all triangles formed by the contributing vertices
46 for (const Triangle &triangle : source.triangles()) {
47 VertexID vertexIndex1 = triangle.vertex(0).getID();
48 VertexID vertexIndex2 = triangle.vertex(1).getID();
49 VertexID vertexIndex3 = triangle.vertex(2).getID();
50 if (vertexMap.count(vertexIndex1) == 1 &&
51 vertexMap.count(vertexIndex2) == 1 &&
52 vertexMap.count(vertexIndex3) == 1) {
53 destination.createTriangle(*vertexMap[vertexIndex1], *vertexMap[vertexIndex2], *vertexMap[vertexIndex3]);
54 }
55 }
56
57 // Add all tetrahedra formed by the contributing vertices
58 for (const Tetrahedron &tetra : source.tetrahedra()) {
59 VertexID vertexIndex1 = tetra.vertex(0).getID();
60 VertexID vertexIndex2 = tetra.vertex(1).getID();
61 VertexID vertexIndex3 = tetra.vertex(2).getID();
62 VertexID vertexIndex4 = tetra.vertex(3).getID();
63 if (vertexMap.count(vertexIndex1) == 1 &&
64 vertexMap.count(vertexIndex2) == 1 &&
65 vertexMap.count(vertexIndex3) == 1 &&
66 vertexMap.count(vertexIndex4) == 1) {
67 destination.createTetrahedron(*vertexMap[vertexIndex1], *vertexMap[vertexIndex2], *vertexMap[vertexIndex3], *vertexMap[vertexIndex4]);
68 }
69 }
70}
71
72} // namespace mesh
73} // namespace precice
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
Vertex & vertex(int i)
Returns the edge's vertex with index 0 or 1.
Definition Edge.hpp:77
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
VertexContainer & vertices()
Returns modifieable container holding all vertices.
Definition Mesh.cpp:53
std::size_t nVertices() const
Returns the number of vertices.
Definition Mesh.cpp:63
TetraContainer & tetrahedra()
Returns modifiable container holding all tetrahedra.
Definition Mesh.cpp:93
Tetrahedron & createTetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Creates and initializes a Tetrahedron object.
Definition Mesh.cpp:141
TriangleContainer & triangles()
Returns modifiable container holding all triangles.
Definition Mesh.cpp:78
Edge & createEdge(Vertex &vertexOne, Vertex &vertexTwo)
Creates and initializes an Edge object.
Definition Mesh.cpp:111
EdgeContainer & edges()
Returns modifiable container holding all edges.
Definition Mesh.cpp:68
Vertex & createVertex(const Eigen::VectorXd &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:103
Tetrahedron of a mesh, defined by 4 vertices.
Triangle of a mesh, defined by three vertices.
Definition Triangle.hpp:27
Vertex & vertex(int i)
Returns triangle vertex with index 0, 1 or 2.
Definition Triangle.hpp:143
Vertex of a mesh.
Definition Vertex.hpp:16
VertexID getID() const
Returns the unique (among vertices of one mesh on one processor) ID of the vertex.
Definition Vertex.hpp:111
void setGlobalIndex(int globalIndex)
Definition Vertex.cpp:17
void setOwner(bool owner)
Definition Vertex.cpp:27
void filterMesh(Mesh &destination, const Mesh &source, UnaryPredicate p)
Definition Filter.hpp:17
Main namespace of the precice library.
int VertexID
Definition Types.hpp:13