Geometric queries
Interpret dimensions, entity counts, measures and attributes.
Query the stored mesh
A query acts on the mesh's current entities and geometry. Compute the required incidence relations before querying facets or boundaries. The MeshBasics example uses a rectangle of width two and height one, split into two triangles and one quadrilateral.
Dimensions and counts
Dimensions
getDimension() is the topological cell dimension; getSpaceDimension() is the embedding dimension. A surface mesh in three-dimensional space has dimensions two and three respectively.
Counts
getVertexCount(), getFaceCount() and getCellCount() count vertices, codimension-one facets and cells. getPolytopeCount(d) selects a dimension; its geometry-type overload selects a reference shape. Counts of discovered edges and faces depend on which incidence relations have been computed.
Empty meshes
isEmpty() tests whether a mesh contains cells. Check it before computing an average or evaluating a quantity that requires a cell.
Select the measure dimension
| Query | Entities included |
|---|---|
getMeasure(d) | All stored entities of dimension d |
getArea() | All two-dimensional entities |
getVolume() | All three-dimensional entities |
getPerimeter() | Boundary facets of the mesh |
Volume
A volume mesh has three-dimensional cells. getVolume() sums their geometric measures. Its attribute overloads restrict that sum to selected three-dimensional entities.
Area
On a planar or surface mesh, getArea() sums cell areas. In a volume mesh, it sums all stored faces, including interior faces. Boundary surface area is obtained from getPerimeter() after computing facet-to-cell incidence.
Boundary measure
getPerimeter() measures the lengths of boundary facets in a two-dimensional mesh and their areas in a three-dimensional mesh. Attribute overloads select boundary-facet labels.
Generic measure
mesh.getMeasure(mesh.getDimension()) sums the cell measures in the mesh's own dimension. Summing dimension-one entities of a triangular mesh includes its interior edges as well as its boundary edges.
const Real area = mesh.getArea(); const Real perimeter = mesh.getPerimeter(); std::cout << "Vertices: " << mesh.getVertexCount() << '\n' << "Edges: " << mesh.getFaceCount() << '\n' << "Cells: " << mesh.getCellCount() << '\n' << "Area: " << area << ", perimeter: " << perimeter << '\n' << "Region 1 area: " << mesh.getArea(1) << '\n' << "Region 2 area: " << mesh.getArea(2) << std::endl;
Expected values are six vertices, eight edges, three cells, area two, perimeter six and area one in each region.
Optional attributes
Read a label
An entity may have no attribute. getAttribute(), getCellAttribute(i) and getFaceAttribute(i) therefore return an optional value. Test presence before dereferencing it.
for (auto cell = mesh.getCell(); !cell.end(); ++cell) { std::cout << "Cell " << cell->getIndex(); if (const auto attribute = cell->getAttribute()) std::cout << ": attribute " << *attribute; std::cout << ", measure " << cell->getMeasure() << '\n'; } size_t boundaryCount = 0; for (auto face = mesh.getBoundary(); !face.end(); ++face) ++boundaryCount;
Set a label
mesh.setAttribute({dimension, index}, value) labels one entity. Region labels belong to cells; boundary-condition labels belong to facets. A cell label does not automatically label its boundary facets.
Coordinates and boundaries
Vertex coordinates
mesh.getVertexCoordinates(i) returns the coordinates of vertex i. The coordinate vector has getSpaceDimension() entries. For points inside a cell, construct a Geometry::Point from a cell and reference coordinates.
Surface meshes
isSurface() tests the mesh's surface classification. Compare the two dimensions when the embedding codimension itself is needed.
Boundary facets
After computing facet-to-cell connectivity, isBoundary(faceIndex) selects facets with one incident cell. isInterface(faceIndex) selects interior facets; attribute jumps can be selected separately through region labels.
Checked program
Build and run MeshBasics from a scratch directory. It compares the reported measures with analytic rectangle and cube-surface values and returns EXIT_FAILURE if the checks fail.