38 #ifndef STRUCTUREDMESH2D_HPP 39 #define STRUCTUREDMESH2D_HPP 1
41 #include <lifev/core/LifeV.hpp> 42 #include <lifev/core/mesh/RegionMesh.hpp> 43 #include <lifev/core/mesh/MeshChecks.hpp> 124 template <
typename MeshType>
129 bool verbose =
false,
130 const Real& l_x = 1.0,
131 const Real& l_y = 1.0,
132 const Real& t_x = 0.0,
133 const Real& t_y = 0.0 )
135 typedef MeshType mesh_Type;
137 ASSERT ( ( mesh_Type::geoShape_Type::S_shape == TRIANGLE )
138 || ( mesh_Type::geoShape_Type::S_shape == QUAD ),
139 "Type of 2d structured mesh not available." );
142 const Real dx ( l_x / m_x );
143 const Real dy ( l_y / m_y );
146 const UInt n_x ( m_x + 1 );
147 const UInt n_y ( m_y + 1 );
153 const UInt N_x ( 1 );
154 const UInt N_y ( n_x );
159 const UInt verticesNumber ( n_x * n_y );
160 const UInt boundaryVerticesNumber ( verticesNumber - ( n_x - 2 ) * ( n_y - 2 ) );
161 const UInt boundaryEdgesNumber (2 * ( m_x + m_y ) );
162 const UInt edgesNumber (
171 const UInt elementsNumber ( 2 * ( m_x * m_y ) );
180 mesh.setNumBoundaryRidges ( boundaryVerticesNumber );
181 mesh.setMaxNumRidges ( verticesNumber,
true );
182 mesh.setMaxNumGlobalRidges ( verticesNumber );
185 mesh.setNumVertices ( verticesNumber );
186 mesh.setNumGlobalVertices ( verticesNumber );
187 mesh.setNumBVertices ( boundaryVerticesNumber );
190 mesh.setNumFacets ( edgesNumber );
191 mesh.setNumBoundaryFacets ( boundaryEdgesNumber );
192 mesh.setMaxNumFacets ( edgesNumber );
193 mesh.setMaxNumGlobalFacets ( edgesNumber );
196 mesh.setMaxNumElements ( elementsNumber );
197 mesh.setMaxNumGlobalElements ( elementsNumber );
199 mesh.setMaxNumFaces ( elementsNumber );
200 mesh.setMaxNumGlobalFaces ( elementsNumber );
201 mesh.setNumFaces ( elementsNumber );
204 mesh.setMarkerID ( regionFlag );
207 typename mesh_Type::ridge_Type* pointPtr = 0;
208 typename mesh_Type::facet_Type* edgePtr = 0;
209 typename mesh_Type::element_Type* elementPtr = 0;
212 Real xPosition ( 0.0 ), yPosition ( 0.0 ), zPosition ( 0.0 );
215 UInt P0 ( 0 ), P1 ( 0 ), P2 ( 0 ), P3 ( 0 );
224 for (
UInt j (0); j < n_y; ++j )
228 for (
UInt i (0); i < n_x; ++i )
234 pointPtr = &mesh.addRidge ( nodeFlag > 0 );
238 nodeID = j * N_y + i;
239 pointPtr->setId ( nodeID );
241 pointPtr->setMarkerID ( nodeFlag );
242 pointPtr->x() = xPosition + t_x;
243 pointPtr->y() = yPosition + t_y;
244 pointPtr->z() = zPosition;
251 for (
UInt j (0); j < m_y; ++j )
253 for (
UInt i (0); i < m_x; ++i )
255 faceID = ( j * m_x + i ) * 2;
257 nodeID = j * N_y + i;
260 P2 = nodeID + N_x + N_y;
264 elementPtr = &mesh.addElement();
265 elementPtr->setId ( faceID );
266 elementPtr->setPoint ( 0, mesh.point (P1) );
267 elementPtr->setPoint ( 1, mesh.point (P2) );
268 elementPtr->setPoint ( 2, mesh.point (P0) );
269 elementPtr->setMarkerID ( regionFlag );
272 elementPtr = &mesh.addElement();
273 elementPtr->setId ( faceID + 1 );
274 elementPtr->setPoint ( 0, mesh.point (P3) );
275 elementPtr->setPoint ( 1, mesh.point (P0) );
276 elementPtr->setPoint ( 2, mesh.point (P2) );
277 elementPtr->setMarkerID ( regionFlag );
282 for (
UInt i = 0; i < boundaryEdgesNumber ; ++i )
298 else if (i < m_x + m_y)
300 nodeID = (i + 1 - m_x) * n_x - 1;
304 adjID = ( (i - m_x) * m_x + m_x - 1) * 2;
307 else if (i < 2 * m_x + m_y)
309 nodeID = n_x * n_y - 1 - (i - m_x - m_y);
313 adjID = 2 * m_x * m_y - (i - m_x - m_y) * 2 - 1;
318 nodeID = n_x * n_y - 1 - m_x - (i - 2 * m_x - m_y) * n_x ;
322 adjID = - (i - 2 * m_x - m_y) * (2 * m_x) + (m_x * (m_y - 1) ) * 2 + 1;
327 edgePtr = &mesh.addFacet (
true ) ;
328 edgePtr->setId ( mesh.facetList().size() - 1 );
329 edgePtr->setMarkerID ( edgeLabel );
330 edgePtr->setPoint ( 0, mesh.point ( P0 ) );
331 edgePtr->setPoint ( 1, mesh.point ( P1 ) );
332 edgePtr->firstAdjacentElementIdentity() = adjID;
333 edgePtr->firstAdjacentElementPosition() = pos;
337 mesh.updateElementFacets (
true, verbose, edgesNumber );
void regularMesh2D(MeshType &mesh, markerID_Type regionFlag, const UInt &m_x, const UInt &m_y, bool verbose=false, const Real &l_x=1.0, const Real &l_y=1.0, const Real &t_x=0.0, const Real &t_y=0.0)
This method generate a rectangular structured mesh.
const markerID_Type TOP_LEFT
Label for the top and left boundary corner.
const markerID_Type TOP
Label for the top boundary edge.
markerID_Type regularMeshPointPosition2D(const UInt &i_x, const UInt &i_y, const UInt &n_x, const UInt &n_y)
This method gives the flags for a rectangle.
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
const markerID_Type BOTTOM
Label for the bottom boundary edge.
const markerID_Type BOTTOM_RIGHT
Label for the bottom and right boundary corner.
const markerID_Type LEFT
Label for the left boundary edge.
const markerID_Type RIGHT
Label for the right boundary edge.
double Real
Generic real data.
const markerID_Type TOP_RIGHT
Label for the top and right boundary corner.
const markerID_Type INTERNAL
Label for the internal entities.
const markerID_Type BOTTOM_LEFT
Label for the bottom and left boundary corner.
uint32_type UInt
generic unsigned integer (used mainly for addressing)