DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
Topology Class Reference

Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relations for the mesh entities). More...

#include <Topology.h>

Public Member Functions

 Topology (std::vector< CellType > cell_types, std::shared_ptr< const common::IndexMap > vertex_map, std::vector< std::shared_ptr< const common::IndexMap > > cell_maps, std::vector< std::shared_ptr< graph::AdjacencyList< std::int32_t > > > cells, const std::optional< std::vector< std::vector< std::int64_t > > > &original_cell_index=std::nullopt, int num_threads=1)
 Create a mesh topology.
 Topology (const Topology &topology)=default
 Copy constructor.
 Topology (Topology &&topology)=default
 Move constructor.
 ~Topology ()=default
 Destructor.
Topology & operator= (const Topology &topology)=delete
Topology & operator= (Topology &&topology)=default
 Move assignment.
int dim () const noexcept
 Topological dimension of the mesh.
const std::vector< CellType > & entity_types (int dim) const
 Entity types in the topology for a given dimension.
CellType cell_type () const
 Cell type.
std::vector< std::shared_ptr< const common::IndexMap > > index_maps (int dim) const
 Get the index maps that describe the parallel distribution of the mesh entities of a given topological dimension.
std::shared_ptr< const common::IndexMap > index_map (int dim) const
 Get the IndexMap that describes the parallel distribution of the mesh entities.
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity (std::array< int, 2 > d0, std::array< int, 2 > d1) const
 Get the connectivity from entities of topological dimension d0 to dimension d1.
std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity (int d0, int d1) const
 Return connectivity from entities of dimension d0 to entities of dimension d1. Assumes only one entity type per dimension.
const std::vector< std::uint32_t > & get_cell_permutation_info () const
 Get the cell permutation information.
void create_facet_orientations ()
 Sign the facets on which two cells disagree on the normal.
std::vector< std::int8_t > facet_orientations () const
 Get the sign carried by each facet of each cell (see create_facet_orientations).
bool has_facet_orientations () const noexcept
 Check if the facet signs have been computed (see create_facet_orientations).
const std::vector< std::uint8_t > & get_entity_permutations (int dim) const
 Get the numbers that encode the permutation to apply to each cell-local entity of a given dimension.
std::vector< CellType > cell_types () const
 Get the types of cells in the topology.
const std::vector< std::int32_t > & interprocess_facets (int index) const
 List of inter-process facets of a given type.
const std::vector< std::int32_t > & interprocess_facets () const
 List of inter-process facets.
bool create_entities (int dim, int num_threads=1)
 Create entities of given topological dimension.
void create_connectivity (int d0, int d1)
 Create connectivity between given pair of dimensions, d0 -> d1.
void create_entity_permutations (int dim, int num_threads=1)
 Compute entity permutations and reflections.
void create_cell_permutations (int num_threads=1)
 Compute the packed per-cell permutation info.
MPI_Comm comm () const
 Mesh MPI communicator.

Public Attributes

std::vector< std::vector< std::int64_t > > original_cell_index
 Original cell index for each cell type.

Detailed Description

Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relations for the mesh entities).

A mesh entity e may be identified globally as a pair e = (dim, i), where dim is the topological dimension and i is the index of the entity within that topological dimension.

Todo
Rework memory management and associated API. Currently, the caching policy is not clear.

Constructor & Destructor Documentation

◆ Topology()

Topology ( std::vector< CellType > cell_types,
std::shared_ptr< const common::IndexMap > vertex_map,
std::vector< std::shared_ptr< const common::IndexMap > > cell_maps,
std::vector< std::shared_ptr< graph::AdjacencyList< std::int32_t > > > cells,
const std::optional< std::vector< std::vector< std::int64_t > > > & original_cell_index = std::nullopt,
int num_threads = 1 )

Create a mesh topology.

A Topology represents the connectivity of a mesh. Mesh entities, i.e. vertices, edges, faces and cells, are defined in terms of their vertices. Connectivity represents the relationships between entities, e.g. the cells that are connected to a given edge in the mesh.

Parameters
[in]cell_typesTypes of cells.
[in]vertex_mapIndex map describing the distribution of mesh vertices.
[in]cell_mapsIndex maps describing the distribution of mesh cells for each cell type in cell_types.
[in]cellsCell-to-vertex connectivities for each cell type in cell_types.
[in]original_cell_indexOriginal indices for each cell in cells.
[in]num_threadsNumber of threads to use. Must be >= 1.

Member Function Documentation

◆ cell_type()

CellType cell_type ( ) const

Cell type.

This function is for topologies with one cell type only.

Returns
Cell type that the topology is for.

◆ cell_types()

std::vector< CellType > cell_types ( ) const

Get the types of cells in the topology.

Returns
The cell types

◆ comm()

MPI_Comm comm ( ) const

Mesh MPI communicator.

Returns
Communicator on which the topology is distributed.

◆ connectivity() [1/2]

std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity ( int d0,
int d1 ) const

Return connectivity from entities of dimension d0 to entities of dimension d1. Assumes only one entity type per dimension.

Parameters
[in]d0Topological dimension.
[in]d1Topological dimension.
Returns
The adjacency list that for each entity of dimension d0 gives the list of incident entities of dimension d1. Returns nullptr if connectivity has not been computed.

◆ connectivity() [2/2]

std::shared_ptr< const graph::AdjacencyList< std::int32_t > > connectivity ( std::array< int, 2 > d0,
std::array< int, 2 > d1 ) const

Get the connectivity from entities of topological dimension d0 to dimension d1.

The entity type and incident entity type are each described by a pair (dim, index). The index within a topological dimension dim, is that of the cell type given in entity_types(dim).

Parameters
[in]d0Pair of (topological dimension of entities, index of "entity type" within topological dimension).
[in]d1Pair of (topological dimension of entities, index of incident "entity type" within topological dimension).
Returns
AdjacencyList of connectivity from entity type in d0 to entity types in d1, or nullptr if not yet computed.

◆ create_cell_permutations()

void create_cell_permutations ( int num_threads = 1)

Compute the packed per-cell permutation info.

Encodes, for each cell, the orientation of every sub-entity of that cell relative to a low-to-high ordering of global vertex indices, packed into one 32-bit integer per cell. See ::get_cell_permutation_info for the bit layout.

Required by elements whose DOF transformations are not the identity. Where those transformations are permutations, e.g. higher-order Lagrange, the correction is applied once to the dofmap when it is built; otherwise, e.g. N1curl and Raviart-Thomas, the correction is applied to the element tensor on each cell at assembly time.

Does nothing if the cell permutations have already been computed.

Note
Not collective. Uses the cell vertices; creates no entities.
Parameters
[in]num_threadsNumber of threads to use. Must be >= 1.
See also
create_entity_permutations, which gives the orientations of one entity dimension unpacked, for permuting quadrature points.

◆ create_connectivity()

void create_connectivity ( int d0,
int d1 )

Create connectivity between given pair of dimensions, d0 -> d1.

Note
Collective.
Parameters
[in]d0Topological dimension.
[in]d1Topological dimension.

◆ create_entities()

bool create_entities ( int dim,
int num_threads = 1 )

Create entities of given topological dimension.

Note
Collective.
Parameters
[in]dimTopological dimension of entities to compute.
[in]num_threadsNumber of threads to use. Must be >= 1.
Returns
True if entities are created, false if entities already existed.

◆ create_entity_permutations()

void create_entity_permutations ( int dim,
int num_threads = 1 )

Compute entity permutations and reflections.

Note
Not collective. Unpacked from the cell permutations (computed if absent); creates no entities.

A permutation records how an entity is oriented as seen from a cell, relative to a low-to-high ordering of the entity's global vertex indices. It is passed to FFCx kernels as quadrature_permutation, so that cells sharing an entity agree on the order of the quadrature points on it. Which dimension is needed is a property of the integral, not of the element: an interior facet integral needs dim() - 1, a ridge integral dim() - 2.

Does nothing if the permutations for dim have already been computed.

Parameters
[in]dimTopological dimension of the entities, e.g. dim() - 1 for facets. Must satisfy 0 <= dim < dim(). Vertices have no orientation, so their permutations are empty.
[in]num_threadsNumber of threads to use. Must be >= 1.
See also
create_cell_permutations, which packs the orientations of all of a cell's sub-entities into one integer per cell, for correcting element DOFs rather than quadrature points.

◆ create_facet_orientations()

void create_facet_orientations ( )

Sign the facets on which two cells disagree on the normal.

On a manifold, the contravariant Piola map scales by the pseudo-determinant \(\sqrt{\det(J^T J)}\), which is positive, so each cell's normal is fixed by its vertex order. Elements mapped by it (e.g. Raviart-Thomas, Brezzi-Douglas-Marini) are conforming only across facets whose two cells agree on the normal, i.e. run the facet in opposite directions.

On each facet where they do not, one of the two cells negates its degrees-of-freedom there (see compute_facet_orientations). Only a facet's own basis functions have a non-zero normal trace on it, so nothing else changes. Cells are not reordered. As each facet is treated on its own, surfaces that cannot be oriented (e.g. a Möbius strip) work too, and no ghost cells are needed. Creates the edges.

A function space whose element needs the signs (see fem::FiniteElement::depends_on_facet_orientations) can only be created on a manifold after this call; Lagrange and Nédélec spaces do not need them. The signs are read with facet_orientations.

Warning
Changing the signs after creating spaces that depend on them invalidates existing Function data on those spaces.
Note
Collective.
Exceptions
std::invalid_argumentIf the topological dimension is not 2.
std::runtime_errorIf an edge is shared by more than two cells. On every process in Developer and Debug builds, otherwise only on the processes holding such an edge, while the others return.
std::out_of_rangeIf there is more than one cell type.

◆ entity_types()

const std::vector< CellType > & entity_types ( int dim) const

Entity types in the topology for a given dimension.

Parameters
[in]dimTopological dimension.
Returns
Entity types.

◆ facet_orientations()

std::vector< std::int8_t > facet_orientations ( ) const

Get the sign carried by each facet of each cell (see create_facet_orientations).

Note
Which of a facet's two cells carries the sign, and how many facets are signed, follow from the global numbering and so depend on the partitioning. The space they define does not.
Returns
For each owned and ghost cell and each of its facets, in cell-local facet order and flattened row-wise, -1 if the degrees-of-freedom on that facet are negated and 1 otherwise. All are 1 before create_facet_orientations has been called.
Exceptions
std::invalid_argumentIf the topological dimension is not 2.
std::runtime_errorIf create_cell_permutations has not been called.
std::out_of_rangeIf there is more than one cell type.

◆ get_cell_permutation_info()

const std::vector< std::uint32_t > & get_cell_permutation_info ( ) const

Get the cell permutation information.

Encodes, for each cell, how each of its sub-entities is reflected and rotated relative to the reference cell (see mesh::compute_cell_permutations for the bit layout). On a surface it also holds the facet signs (see facet_orientations).

Exceptions
std::runtime_errorIf create_cell_permutations has not been called.

◆ get_entity_permutations()

const std::vector< std::uint8_t > & get_entity_permutations ( int dim) const

Get the numbers that encode the permutation to apply to each cell-local entity of a given dimension.

The permutations are encoded so that:

  • n % 2 gives the number of reflections to apply
  • n // 2 gives the number of rotations to apply

The data is stored in a flattened 2D array, so that data[cell_index * entities_per_cell + entity_index] contains the permutation of the cell-local entity entity_index of cell with local index cell_index.

Parameters
[in]dimTopological dimension of the entities. Vertices have no orientation, so their permutations are empty.
Returns
The encoded permutation info.
Exceptions
std::runtime_errorIf create_entity_permutations has not been called for dim.
std::out_of_rangeIf there is more than one facet type (see Topology::index_map).

◆ has_facet_orientations()

bool has_facet_orientations ( ) const
noexcept

Check if the facet signs have been computed (see create_facet_orientations).

Function spaces whose basis depends on them can only be created once they have.

Returns
True if the facet signs have been computed.

◆ index_map()

std::shared_ptr< const common::IndexMap > index_map ( int dim) const

Get the IndexMap that describes the parallel distribution of the mesh entities.

Parameters
[in]dimTopological dimension
Returns
Index map for the entities of dimension dim.
Exceptions
std::out_of_rangeIf entities of dimension dim have not been created (call create_entities(dim) first), or if there is more than one entity type of dimension dim (call index_maps instead).

◆ index_maps()

std::vector< std::shared_ptr< const common::IndexMap > > index_maps ( int dim) const

Get the index maps that describe the parallel distribution of the mesh entities of a given topological dimension.

Parameters
[in]dimTopological dimension.
Returns
Index maps for entities of dimension dim. Entity types with no map are dropped, so the result is empty or has one entry per entity type in entity_types(dim) order; it is not indexable positionally by entity-type index if any map is missing.

◆ interprocess_facets() [1/2]

const std::vector< std::int32_t > & interprocess_facets ( ) const

List of inter-process facets.

"Inter-process" facets are facets that are connected (1) to a cell that is owned by the calling process (rank) and (2) to a cell that is owned by another process.

Precondition
Inter-process facets are available only if facet topology has been computed.

◆ interprocess_facets() [2/2]

const std::vector< std::int32_t > & interprocess_facets ( int index) const

List of inter-process facets of a given type.

"Inter-process" facets are facets that are connected (1) to a cell that is owned by the calling process (rank) and (2) to a cell that is owned by another process.

Facets must have been computed for inter-process facet data to be available.

Parameters
[in]indexIndex of facet type, following the order given by ::entity_types.
Returns
Indices of the inter-process facets.

The documentation for this class was generated from the following files: