Mesh

class dolfin.cpp.mesh.Mesh(*args, **kwargs)

Bases: dolfin.cpp.common.Variable, dolfin.cpp.mesh.HierarchicalMesh

A Mesh consists of a set of connected and numbered mesh entities. Both the representation and the interface are dimension-independent, but a concrete interface is also provided for standard named mesh entities:

Entity Dimension Codimension
Vertex 0  
Edge 1  
Face 2  
Facet   1
Cell   0

When working with mesh iterators, all entities and connectivity are precomputed automatically the first time an iterator is created over any given topological dimension or connectivity. Note that for efficiency, only entities of dimension zero (vertices) and entities of the maximal dimension (cells) exist when creating a Mesh . Other entities must be explicitly created by calling init . For example, all edges in a mesh may be created by a call to mesh.init(1). Similarly, connectivities such as all edges connected to a given vertex must also be explicitly created (in this case by a call to mesh.init(0, 1)).

Friends: MeshEditor, MeshPartitioning, TopologyComputation, create_mesh.

Create a mesh from a filename or a geometry.

A mesh may be created from a given filename, which should contain mesh data stored in DOLFIN XML format:

mesh = Mesh("mesh.xml")

An empty mesh may be created as follows:

mesh = Mesh()

A copy of a mesh may be created as follows:

mesh_copy = Mesh(mesh)
bounding_box_tree()

Get bounding box tree for mesh. The bounding box tree is initialized and built upon the first call to this function. The bounding box tree can be used to compute collisions between the mesh and other objects. It is the responsibility of the caller to use (and possibly rebuild) the tree. It is stored as a (mutable) member of the mesh to enable sharing of the bounding box tree data structure.

Return type:std::shared_ptr< BoundingBoxTree >
Returns:std::shared_ptr<BoundingBoxTree>
cell_orientations()

Get the cell orientations set.

Returns
numpy.array(int)
Cell orientations
cells()

Get cell connectivity.

Returns
numpy.array(int)
Connectivity for all cells.
Example
>>> mesh = dolfin.UnitSquare(1,1)
>>> mesh.cells()
array([[0, 1, 3],
      [0, 2, 3]])
clean()

Clean out all auxiliary topology data. This clears all topological data, except the connectivity between cells and vertices.

Return type:void
color()

Color the cells of the mesh such that no two neighboring cells share the same color. A colored mesh keeps a MeshFunction<std::size_t> named “cell colors” as mesh data which holds the colors of the mesh.

Parameters:coloring_type (std::string) – (std::string) Coloring type, specifying what relation makes two cells neighbors, can be one of “vertex”, “edge” or “facet”.
Return type:const std::vector< std::size_t > &
Returns:std::vector<std::size_t>& The colors as a mesh function over the cells of the mesh.
coordinates()
  • coordinates()

    Get vertex coordinates.

    Returns
    numpy.array(float)

    Coordinates of all vertices.

    Example
    >>> mesh = dolfin.UnitSquare(1,1)
    >>> mesh.coordinates()
    array([[ 0.,  0.],
           [ 1.,  0.],
           [ 0.,  1.],
           [ 1.,  1.]])
    
data()

Get mesh data.

Return type:MeshData &
Returns:MeshData & The mesh data object associated with the mesh.
domains()

Get mesh (sub)domains.

Return type:MeshDomains &
Returns:MeshDomains The (sub)domains associated with the mesh.
geometry()

Get mesh geometry.

Return type:MeshGeometry &
Returns:MeshGeometry The geometry object associated with the mesh.
ghost_mode()

Ghost mode used for partitioning. Possible values are same as parameters["ghost_mode"] . WARNING: the interface may change in future without deprecation; the method is now intended for internal library use.

Return type:std::string
hash()

Compute hash of mesh, currently based on the has of the mesh geometry and mesh topology.

Return type:std::size_t
Returns:std::size_t A tree-hashed value of the coordinates over all MPI processes
hmax()

Compute maximum cell size in mesh, measured greatest distance between any two vertices of a cell.

Return type:double
Returns:double The maximum cell size. The size is computed using Cell::h
hmin()

Compute minimum cell size in mesh, measured greatest distance between any two vertices of a cell.

Return type:double
Returns:double The minimum cell size. The size is computed using Cell::h
init()

Compute connectivity between given pair of dimensions.

Parameters:
  • d0 (std::size_t) – (std::size_t) Topological dimension.
  • d1 (std::size_t) – (std::size_t) Topological dimension.
Return type:

void

init_cell_orientations()

Compute and initialize cell_orientations relative to a given global outward direction/normal/orientation. Only defined if mesh is orientable.

Parameters:Expression & global_normal (const) – (Expression ) A global normal direction to the mesh
Return type:void
init_global()

Compute global indices for entity dimension dim.

Parameters:dim (std::size_t) –
Return type:void
mpi_comm()

Mesh MPI communicator

Return type:MPI_Comm
Returns:MPI_Comm
num_cells()

Get number of cells in mesh.

Return type:std::size_t
Returns:std::size_t Number of cells.
num_edges()

Get number of edges in mesh.

Return type:std::size_t
Returns:std::size_t Number of edges.
num_entities()

Get number of entities of given topological dimension.

Parameters:d (std::size_t) – (std::size_t) Topological dimension.
Return type:std::size_t
Returns:std::size_t Number of entities of topological dimension d.
num_entities_global()

Get global number of entities of given topological dimension.

Parameters:dim (std::size_t) – (std::size_t) Topological dimension.
Return type:std::size_t
Returns:std::size_t Global number of entities of topological dimension d.
num_faces()

Get number of faces in mesh.

Return type:std::size_t
Returns:std::size_t Number of faces.
num_facets()

Get number of facets in mesh.

Return type:std::size_t
Returns:std::size_t Number of facets.
num_vertices()

Get number of vertices in mesh.

Return type:std::size_t
Returns:std::size_t Number of vertices.
order()

Order all mesh entities. See also: UFC documentation (put link here!)

Return type:void
ordered()

Check if mesh is ordered according to the UFC numbering convention.

Return type:bool
Returns:bool The return values is true iff the mesh is ordered.
renumber_by_color()

Renumber mesh entities by coloring. This function is currently restricted to renumbering by cell coloring. The cells (cell-vertex connectivity) and the coordinates of the mesh are renumbered to improve the locality within each color. It is assumed that the mesh has already been colored and that only cell-vertex connectivity exists as part of the mesh.

Return type:Mesh
Returns:Mesh
rmax()

Compute maximum cell inradius.

Return type:double
Returns:double The maximum of cells’ inscribed sphere radii
rmin()

Compute minimum cell inradius.

Return type:double
Returns:double The minimum of cells’ inscribed sphere radii
rotate()

Rotate mesh around a coordinate axis through center of mass of all mesh vertices

Parameters:
  • angle (double) – (double) The number of degrees (0-360) of rotation.
  • axis (std::size_t) – (std::size_t) The coordinate axis around which to rotate the mesh.
Return type:

void

scale()

Scale mesh coordinates with given factor. Arguments factor (double) The factor defining the scaling.

Parameters:factor (double) –
Return type:void
smooth()

Smooth internal vertices of mesh by local averaging.

Parameters:num_iterations (std::size_t) – (std::size_t) Number of iterations to perform smoothing, default value is 1.
Return type:void
smooth_boundary()

Smooth boundary vertices of mesh by local averaging.

Parameters:
  • num_iterations (std::size_t) – (std::size_t) Number of iterations to perform smoothing, default value is 1.
  • harmonic_smoothing (bool) – (bool) Flag to turn on harmonics smoothing, default value is true.
Return type:

void

snap_boundary()

Snap boundary vertices of mesh to match given sub domain.

Parameters:
  • SubDomain & sub_domain (const) – (SubDomain ) A SubDomain object.
  • harmonic_smoothing (bool) – (bool) Flag to turn on harmonics smoothing, default value is true.
Return type:

void

thisown

The membership flag

topology()

Get mesh topology.

Return type:MeshTopology &
Returns:MeshTopology The topology object associated with the mesh.
translate()

Translate mesh according to a given vector.

Parameters:Point & point (const) – (Point ) The vector defining the translation.
Return type:void
type()

Get mesh cell type.

Return type:CellType &
Returns:CellType & The cell type object associated with the mesh.
ufl_cell()

Returns the ufl cell of the mesh.

ufl_coordinate_element()

Return the finite element of the coordinate vector field of this domain.

ufl_domain()

Returns the ufl domain corresponding to the mesh.

ufl_id()

Returns an id that UFL can use to decide if two objects are the same.