8 #ifndef MESHEXTRACTOR_HPP_ 9 #define MESHEXTRACTOR_HPP_ 11 #include <lifev/core/mesh/RegionMesh.hpp> 16 template<
typename geoShape_Type>
21 typedef RegionMesh<geoShape_Type> mesh_Type;
22 typedef typename mesh_Type::facetShape_Type facetShape_Type;
23 typedef typename mesh_Type::facet_Type facet_Type;
24 typedef RegionMesh<facetShape_Type> boundaryRegionMesh_Type;
27 std::vector<facet_Type
const*> boundaryFaces;
28 Predicates::EntityMarkerIDInterrogator<facet_Type> predicator (boundaryFaceMarker);
29 boundaryFaces = mesh3D.faceList.extractAccordingToPredicate (predicator);
32 std::map<UInt, UInt> vertexIdMap, inverseVertexIdMap;
33 for (
typename std::vector<facet_Type
const*>::iterator it (boundaryFaces.begin() ); it != boundaryFaces.end(); ++it )
35 for (UInt i (0); i < boundaryRegionMesh_Type::face_Type::S_numPoints; ++i)
37 UInt originalId = (*it)->point (i).id();
38 vertexIdMap.insert (std::pair<UInt, UInt> (originalId, vertexIdMap.size() ) );
39 inverseVertexIdMap.insert (std::pair<UInt, UInt> (inverseVertexIdMap.size(), originalId) );
44 std::map<UInt, UInt> boundaryPointsOnEdges;
46 for (std::list<UInt>::const_iterator it (otherBoundaryFaceMarkerList.begin() ); it != otherBoundaryFaceMarkerList.end(); ++it)
49 Predicates::EntityMarkerIDInterrogator<facet_Type> predicator (marker);
50 std::vector<facet_Type
const*> otherboundaryFaces;
51 otherboundaryFaces = ( mesh3D.faceList.extractAccordingToPredicate (predicator) );
52 std::cout <<
"Extract " << otherboundaryFaces.size() <<
" bd faces on Marker" << marker <<
"\n";
53 for (
typename std::vector<facet_Type
const*>::iterator it1 (otherboundaryFaces.begin() ); it1 != otherboundaryFaces.end(); ++it1 )
55 for (UInt i (0); i < boundaryRegionMesh_Type::face_Type::S_numPoints; ++i)
57 UInt originalId = (*it1)->point (i).id();
58 if (vertexIdMap.count (originalId) )
60 boundaryPointsOnEdges.insert (std::pair<UInt, UInt> (originalId, marker) );
67 boundaryRegionMesh_Type* mesh2D (
new boundaryRegionMesh_Type ( mesh3D.comm() ) );
68 typename boundaryRegionMesh_Type::point_Type* pp = 0;
69 typename boundaryRegionMesh_Type::edge_Type* pe = 0;
70 typename boundaryRegionMesh_Type::face_Type* pf = 0;
72 UInt __nv (vertexIdMap.size() ), __ne (boundaryPointsOnEdges.size() ), __nt (boundaryFaces.size() );
74 debugStream (8000) <<
"number of vertices: " << __nv <<
"\n";
75 debugStream (8000) <<
"number of edges: " << __ne <<
"\n";
76 debugStream (8000) <<
"number of triangles: " << __nt <<
"\n";
79 std::vector<Real> __x (3 * __nv);
80 std::vector<
bool> __isonboundary (__nv);
81 std::vector<UInt> __whichboundary (__nv);
87 for ( std::map<UInt, UInt>::iterator it (vertexIdMap.begin() ); it != vertexIdMap.end(); ++it)
89 UInt pointId (it->second);
90 for (UInt icoor (0); icoor < 3; ++icoor)
92 __x[3 * pointId + icoor] = mesh3D.point (it->first).coordinatesArray() [icoor];
95 if ( boundaryPointsOnEdges.count (it->first) )
97 __whichboundary[ pointId ] = boundaryPointsOnEdges[it->first];
98 __isonboundary[ pointId ] =
true;
103 __whichboundary[ pointId ] = 0;
104 __isonboundary[ pointId ] =
false;
109 std::vector<
int> __triangle_nodes ( 3 * __nt );
110 std::vector<
int> __triangle_label ( __nt );
113 std::pair<BareEdge,
bool> _edge;
115 UInt nTotalEdges (0);
116 for (
typename std::vector<facet_Type
const*>::iterator it (boundaryFaces.begin() ); it != boundaryFaces.end(); ++it, ++counter )
118 for (UInt i (0); i < boundaryRegionMesh_Type::face_Type::S_numPoints; ++i)
120 UInt originalId = (*it)->point (i).id();
121 __triangle_nodes[ boundaryRegionMesh_Type::face_Type::S_numPoints * counter + i] = vertexIdMap[originalId];
124 std::pair<UInt,
bool> _check;
126 UInt i1 = __triangle_nodes[ 3 * counter ];
127 UInt i2 = __triangle_nodes[ 3 * counter + 1 ];
128 UInt i3 = __triangle_nodes[ 3 * counter + 2 ];
130 _edge = makeBareEdge ( i1, i2 );
131 _check = _be.addIfNotThere ( _edge.first );
134 _be.deleteIfThere ( _edge.first );
141 _edge = makeBareEdge ( i2, i3 );
142 _check = _be.addIfNotThere ( _edge.first );
145 _be.deleteIfThere ( _edge.first );
152 _edge = makeBareEdge ( i3, i1 );
153 _check = _be.addIfNotThere ( _edge.first );
156 _be.deleteIfThere ( _edge.first );
163 __triangle_label[ counter ] = 1;
167 debugStream (8000) <<
"Found " << _be.size() <<
" boundary edges \n";
168 debugStream (8000) <<
"Found " << nTotalEdges - _be.size() <<
" internal edges \n";
173 std::vector<
int> __edge_nodes;
174 __edge_nodes.reserve ( 2 * __ne );
175 std::vector<
int> __edge_label;
176 __edge_label.reserve ( __ne );
178 for (MeshElementBareHandler<BareEdge>::iterator it (_be.begin() ); it != _be.end(); ++it)
180 BareEdge edge (it->first);
181 UInt first2dId = edge.first;
182 UInt second2dId = edge.second;
183 __edge_nodes.push_back (first2dId);
184 __edge_nodes.push_back (second2dId);
185 __edge_label.push_back ( boundaryFaceMarker );
189 mesh2D->setMarkerID ( 1 );
191 mesh2D->setMaxNumEdges ( nTotalEdges );
192 mesh2D->setMaxNumGlobalEdges ( nTotalEdges );
194 mesh2D->setNumEdges ( nTotalEdges );
196 mesh2D->setNumBEdges ( __ne );
198 mesh2D->setMaxNumFaces ( __nt );
199 mesh2D->setMaxNumGlobalFaces ( __nt );
201 mesh2D->setNumFaces ( __nt);
203 mesh2D->setMaxNumPoints ( __nv,
true );
204 mesh2D->setMaxNumGlobalPoints ( __nv );
206 mesh2D->setNumVertices ( __nv );
207 mesh2D->setNumGlobalVertices ( __nv );
209 mesh2D->numBVertices() = __nbv;
210 mesh2D->setNumBPoints ( mesh2D->numBVertices() );
212 debugStream (8000) <<
"number of points : " << mesh2D->numPoints() <<
"\n";
213 debugStream (8000) <<
"number of edges : " << mesh2D->numEdges() <<
"\n";
214 debugStream (8000) <<
"number of boundary edges : " << mesh2D->numBEdges() <<
"\n";
215 debugStream (8000) <<
"number of vertices : " << mesh2D->numVertices() <<
"\n";
216 debugStream (8000) <<
"number of boundary vertices : " << mesh2D->numBVertices() <<
"\n";
220 for (
UInt __i = 0; __i < __nv; ++__i )
222 pp = & (mesh2D->addPoint ( __isonboundary[ __i ],
false ) );
223 pp->setMarkerID ( __whichboundary[ __i ] );
224 pp->x() = __x[ 3 * __i ];
225 pp->y() = __x[ 3 * __i + 1 ];
226 pp->z() = __x[ 3 * __i + 2];
231 for (
UInt __i = 0; __i < __ne; ++__i )
233 pe = & ( mesh2D->addEdge (
true ) );
235 pe->setMarkerID ( markerID_Type ( __edge_label[ __i ] ) );
236 pe->setPoint ( 0, mesh2D->point ( __edge_nodes[ 2 * __i ] ) );
237 pe->setPoint ( 1, mesh2D->point ( __edge_nodes[ 2 * __i + 1 ] ) );
241 for (
UInt __i = 0; __i < __nt; ++__i )
243 pf = & ( mesh2D->addFace (
true) );
245 pf->setMarkerID ( markerID_Type ( __triangle_label[ __i ] ) );
246 pf->setPoint ( 0, mesh2D->point ( __triangle_nodes[ 3 * __i ] ) );
247 pf->setPoint ( 1, mesh2D->point ( __triangle_nodes[ 3 * __i + 1 ] ) );
248 pf->setPoint ( 2, mesh2D->point ( __triangle_nodes[ 3 * __i + 2 ] ) );
253 mesh2D->updateElementFacets (
true);
RegionMesh< typename RegionMesh< geoShape_Type >::facetShape_Type > * extractBoundaryMesh(const RegionMesh< geoShape_Type > &mesh3D, const UInt &boundaryFaceMarker, const std::list< UInt > &otherBoundaryFaceMarkerList)
container_Type::const_iterator containerConstIterator_Type
uint32_type UInt
generic unsigned integer (used mainly for addressing)