General concepts » Meshes » Mesh operations

Change coordinates, extract submeshes and group cells.

Choose the operation

Coordinate changes modify the geometric map. Extraction selects entities into a submesh. Component labeling and partitioning assign groups to the existing cells. Establish the required connectivity before each operation and retain a parent mesh while a submesh refers to it.

Coordinate transformations

Scaling

mesh.scale(a) multiplies coordinates by a. Length, area and volume consequently scale by $|a|$ , $a^2$ and $|a|^3$ . A grid with 16 vertices per axis initially spans zero to 15; scaling by two gives side length 30. Normalize by $1/15$ first when a unit-square baseline is needed.

Displacement

mesh.displace(displacement) evaluates a vector-valued displacement on the mesh geometry and updates the coordinates. Supply one component for each embedding-space coordinate. The small Displace.cpp example writes its original and deformed meshes. Changes to geometry must preserve the cell regularity required by subsequent integration and solution procedures.

Extract a submesh

Keep a region

mesh.keep(attribute) extracts cells carrying the requested label. The result is a SubMesh with parent associations. getParent() gives access to the parent mesh; use the submesh mappings when corresponding indices between the two are needed.

Extract the boundary

mesh.skin() extracts boundary facets after facet-to-cell connectivity has been prepared. A planar rectangle gives a one-dimensional curve.

Connected components

mesh.ccl(predicate) groups adjacent cells accepted by the binary predicate. getComponents() returns those groups as collections of cell indices. In the example, equality of cell attributes gives one component for each of two connected regions.

  auto region = mesh.keep(1);
  auto boundary = mesh.skin();
  const auto components = mesh.ccl([](const Polytope& first, const Polytope& second) {
    return first.getAttribute() == second.getAttribute();
  });
  std::cout << "Region cells: " << region.getCellCount() << '\n'
            << "Boundary cells: " << boundary.getCellCount() << '\n'
            << "Attribute components: " << components.getComponents().size() << std::endl;

trace() assigns facet attributes from neighboring region labels. Region extraction uses keep(); the interface guide describes the trace-labeling operation.

Partition cell indices

Balanced partitioning

Construct the partitioner with the mesh, call partition(count) and query the resulting partition for each cell index. The mesh and its prepared adjacency remain alive during this procedure.

  BalancedCompactPartitioner partitioner(mesh);
  partitioner.partition(2);
  for (auto cell = mesh.getCell(); !cell.end(); ++cell)
  {
    std::cout << "Cell " << cell->getIndex() << ": partition "
              << partitioner.getPartition(cell->getIndex()) << '\n';
  }

The partition labels can be used by later distribution operations. MPI mesh distribution also establishes rank ownership, ghosts and communication state.

Greedy partitioning

GreedyPartitioner provides another partitioning policy. Consult its constructor and partition interface in the API reference when selecting that policy for an application.

Direct coordinate edits

Set coordinates

setVertexCoordinates(index, value, component) changes one coordinate; the vector overload changes the complete coordinate tuple. Coordinate edits affect any geometric quantities derived from the edited vertices.

Geometry cache lifetime

mesh.flush() clears the transformation and quadrature indices. Subsequent geometry queries construct default maps from vertex coordinates. Retain and reinstall the intended higher-order transformations when preserving curved geometry through an explicit flush. Follow the chosen mutation API's cache contract. Reacquire borrowed geometry after invalidation, and rebuild spaces and algebraic problems after topology changes. See Numerical contracts.

Checked source

The MeshBasics target checks region extraction, boundary extraction, component counts and analytic areas, and exercises balanced partitioning. Its complete source is Geometry/MeshBasics.cpp.

Lower-level control

Builder

The creation guide explains explicit vertex, cell and attribute construction. Builder reservation can reduce repeated allocation when the expected entity counts are known.

Transformations

Mesh polytopes provide their geometric transformations. A Point is the usual interface for evaluating physical coordinates and Jacobians at reference coordinates.

Continue