Mesh

class Mesh

Class representing a mesh.

A mesh is a collection of points and elements. Each element is a collection of points. A point has 3 coordinates (x, y, z). Cell sets, face sets, and edge sets can be defined on the mesh. Boundary edges and faces can be computed and obtained via API. Simple operations like scaling, and translation are supported. General transformations can be applied to the mesh as well. They are based on homogeneous coordinates and supported by Trsf class.

This class should be used for procedural mesh generation.

Public Functions

Mesh()

Construct empty mesh.

Mesh(std::vector<Point> points, std::vector<Element> elements)

Construct mesh from set of points and elements (useful for reading meshes from files)

Parameters:
  • points – Points

  • elements – Elements

const std::vector<Point> &points() const

Get mesh points.

Returns:

Mesh points

const Point &point(gidx_t idx) const

Get a point by index.

Parameters:

idx – Index of the point

Returns:

Point

const std::vector<Element> &elements() const

Get elements.

Returns:

Mesh elements

const Element &element(gidx_t idx) const

Get element of the mesh.

Parameters:

idx – Index of the element

Returns:

Element

Mesh scaled(double factor) const

Scale mesh by a factor (isotropic)

Parameters:

factor – Scaling factor

Returns:

Scaled mesh

Mesh &scale(double factor)

Scale mesh by a factor (isotropic)

Parameters:

factor – Scaling factor

Returns:

Reference to this mesh which is scaled

Mesh scaled(double factor_x, double factor_y, double factor_z = 1.) const

Scale mesh by a factor (unisotropic)

Parameters:
  • factor_x – Scaling factor in x-direction

  • factor_y – Scaling factor in y-direction

  • factor_z – Scaling factor in z-direction

Returns:

Scaled mesh

Mesh &scale(double factor_x, double factor_y, double factor_z = 1.)

Scale mesh by a factor (unisotropic)

Parameters:
  • factor_x – Scaling factor in x-direction

  • factor_y – Scaling factor in y-direction

  • factor_z – Scaling factor in z-direction

Returns:

Reference to this mesh which is scaled

Mesh translated(double tx, double ty = 0., double tz = 0.) const

Translate mesh.

Parameters:
  • tx – Translation in x-direction

  • ty – Translation in y-direction

  • tz – Translation in z-direction

Returns:

Translated mesh

Mesh &translate(double tx, double ty = 0., double tz = 0.)

Translate mesh.

Parameters:
  • tx – Translation in x-direction

  • ty – Translation in y-direction

  • tz – Translation in z-direction

Returns:

Reference to this mesh which is translated

Mesh transformed(const Trsf &tr) const

Transform mesh.

Parameters:

tr – Transformation

Returns:

Transformed mesh

Mesh &transform(const Trsf &tr)

Transform mesh.

Parameters:

tr – Transformation

Returns:

Reference to this mesh which is transformed

Mesh &add(const Mesh &other)

Add another mesh to this mesh.

Parameters:

otherMesh to add

Returns:

Reference to this mesh

Mesh &remove_duplicate_points(double tolerance = 1e-12)

Remove duplicate points.

Parameters:

tolerance – Tolerance for point comparison

Returns:

Reference to this mesh

BoundingBox3D compute_bounding_box() const

Compute bounding box around the mesh.

Returns:

Bounding box

Mesh duplicate() const

Duplicate mesh.

Returns:

Duplicated mesh

Mesh &set_cell_set_name(marker_t cell_set_id, const std::string &name)

Set cell set name.

Parameters:
  • cell_set_id – Cell set ID (marker)

  • name – Cell set name

Returns:

Reference to this mesh

std::string cell_set_name(marker_t cell_set_id) const

Get cell set name.

Parameters:

cell_set_id – Cell set ID (marker)

Returns:

Cell set name

std::vector<marker_t> cell_set_ids() const

Get cell set IDs.

const std::vector<gidx_t> &cell_set(marker_t id) const

Get cell set.

Parameters:

id – Cell set ID

Returns:

Cell set

Mesh &set_cell_set(marker_t id, const std::vector<gidx_t> &cell_ids)

Set cell set.

Parameters:
  • id – Cell set ID

  • cell_ids – Cell IDs

Returns:

Reference to this mesh

Mesh &remove_cell_sets()

Remove cell sets.

Returns:

Reference to this mesh

Mesh &set_face_set_name(marker_t face_set_id, const std::string &name)

Set face set name.

Parameters:
  • face_set_id – Face set ID (marker)

  • name – Face set name

Returns:

Reference to this mesh

std::string face_set_name(marker_t cell_set_id) const

Get face set name.

Parameters:

face_set_id – Face set ID (marker)

Returns:

Face set name

std::vector<marker_t> face_set_ids() const

Get face set IDs.

const std::vector<gidx_t> &face_set(marker_t id) const

Get face set.

Parameters:

id – Face set ID

Returns:

Face set

Mesh &set_face_set(marker_t id, const std::vector<gidx_t> &face_ids)

Set face set.

Parameters:
  • id – Face set ID

  • face_ids – Face IDs

Returns:

Reference to this mesh

Mesh &remove_face_sets()

Remove face sets.

Returns:

Reference to this mesh

Mesh &set_edge_set_name(marker_t edge_set_id, const std::string &name)

Set edge set name.

Parameters:
  • edge_set_id – Edge set ID (marker)

  • name – Edge set name

Returns:

Reference to this mesh

std::string edge_set_name(marker_t edge_set_id) const

Get edge set name.

Parameters:

edge_set_id – Edge set ID (marker)

Returns:

Edge set name

std::vector<marker_t> edge_set_ids() const

Get edge set IDs.

const std::vector<gidx_t> &edge_set(marker_t id) const

Get edge set.

Parameters:

id – Edge set ID

Returns:

Edge set

Mesh &set_edge_set(marker_t id, const std::vector<gidx_t> &edge_ids)

Set edge set.

Parameters:
  • id – Edge set ID

  • edge_ids – Edge IDs

Returns:

Reference to this mesh

Mesh &remove_edge_sets()

Remove edge sets.

Returns:

Reference to this mesh

Mesh &set_side_set_name(marker_t id, const std::string &name)

Set side set name.

Parameters:
  • id – Side set ID

  • name – Side set name

Returns:

Reference to this mesh

std::string side_set_name(marker_t id) const

Get side set name.

Parameters:

id – Side set ID

Returns:

Side set name

std::vector<marker_t> side_set_ids() const

Get side set IDs.

const std::vector<side_set_entry_t> &side_set(marker_t id) const

Get side set.

Parameters:

id – Side set ID

Returns:

Side set

Mesh &set_side_set(marker_t id, const std::vector<gidx_t> &elem_ids)

Set side set.

Parameters:
  • id – Side set ID

  • elem_idsElement IDs

Returns:

Reference to this mesh

Mesh &set_side_set(marker_t id, const std::vector<side_set_entry_t> &side_set_entries)

Set side set.

Parameters:
  • id – Side set ID

  • side_set_entries – Side set entries

Returns:

Reference to this mesh

Mesh &remove_side_sets()

Remove side sets.

Returns:

Reference to this mesh

Mesh &remap_block_ids(const std::map<marker_t, marker_t> &block_map)

Remap block IDs.

Parameters:

block_map – Map of old block IDs to new block IDs

Returns:

Reference to this mesh

const Range &point_ids() const

Get mesh point IDs.

Returns:

Mesh point IDs

const Range &edge_ids() const

Get mesh edge IDs.

Returns:

Mesh edge IDs

const Range &face_ids() const

Get mesh face IDs.

Returns:

Mesh face IDs

const Range &cell_ids() const

Get mesh cell IDs.

Returns:

Mesh cell IDs

std::vector<gidx_t> support(gidx_t index) const

Get support of a mesh node.

Parameters:

index – Index of the node

std::vector<gidx_t> cone(gidx_t index) const

Get connectivity of a mesh node.

Parameters:

index – Index of the node

std::set<gidx_t> cone_vertices(gidx_t index) const

Get cone vertices of a mesh node.

Parameters:

index – Index of the node

Returns:

Cone vertices

ElementType element_type(gidx_t index) const

Get element type.

Parameters:

index – Index of the element

Returns:

Element type

void set_up()

Prepare mesh.

std::vector<gidx_t> boundary_edges() const

Get all boundary edge IDs.

Returns:

Boundary edge IDs

std::vector<gidx_t> boundary_faces() const

Get all boundary face IDs.

Returns:

Boundary face IDs

Point compute_centroid(gidx_t index) const

Compute centroid.

Parameters:

index – Index of the element

Returns:

Centroid

Vector outward_normal(gidx_t index) const

Compute outward normal.

Parameters:

index – Index of the edge/face

Returns:

Outward normal