Generating uniform grids
Creating structured meshes with UniformGrid.
Introduction
The Mesh::UniformGrid() method creates structured grids of various polytope types. This is the quickest way to get started with Rodin — no mesh files needed.
2D Grids
#include <Rodin/Geometry.h> using namespace Rodin; using namespace Rodin::Geometry; int main() { Mesh mesh; // Triangular grid: 16×16 subdivisions → 512 triangles, 289 vertices mesh = mesh.UniformGrid(Polytope::Type::Triangle, { 16, 16 }); // Quadrilateral grid: 32×32 subdivisions → 1024 quads, 1089 vertices mesh = mesh.UniformGrid(Polytope::Type::Quadrilateral, { 32, 32 }); return 0; }
The grid is created on the unit square where are the subdivision counts. Use Mesh::scale() to rescale to a different domain:
// Create grid on [0,1]^2 mesh = mesh.UniformGrid(Polytope::Type::Triangle, { 32, 32 }); mesh.scale(1.0 / 31.0); // Normalize to unit square
3D Grids
// Tetrahedral grid: 8×8×8 subdivisions mesh = mesh.UniformGrid(Polytope::Type::Tetrahedron, { 8, 8, 8 }); // Hexahedral grid: 16×16×16 subdivisions mesh = mesh.UniformGrid(Polytope::Type::Hexahedron, { 16, 16, 16 }); // Wedge (prism) grid: 4×4×4 subdivisions mesh = mesh.UniformGrid(Polytope::Type::Wedge, { 4, 4, 4 });
Computing Connectivity
After creating a mesh, compute the boundary connectivity before defining boundary conditions:
mesh = mesh.UniformGrid(Polytope::Type::Triangle, { 16, 16 }); mesh.getConnectivity().compute(1, 2); // edges → cells (required for BC)
Mesh Queries
std::cout << "Vertices: " << mesh.getVertexCount() << std::endl; std::cout << "Cells: " << mesh.getCellCount() << std::endl; std::cout << "Volume: " << mesh.getVolume() << std::endl; std::cout << "Perimeter: " << mesh.getPerimeter() << std::endl;
Full Source Code
See Also
- Meshes guide — Full mesh documentation
- Polytopes — Element types
- Connectivity — Incidence relations
- Poisson example — Uses UniformGrid