Loading...
Searching...
No Matches
Topology.h
// Copyright (C) 2006-2024 Anders Logg and Garth N. Wells
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include <array>
#include <cstdint>
#include <dolfinx/common/MPI.h>
#include <dolfinx/graph/AdjacencyList.h>
#include <map>
#include <memory>
#include <optional>
#include <span>
#include <tuple>
#include <utility>
#include <vector>
namespace dolfinx::common
{
class IndexMap;
}
namespace dolfinx::mesh
{
enum class CellType : std::int8_t;
class Topology
{
public:
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);
Topology(const Topology& topology) = default;
Topology(Topology&& topology) = default;
~Topology() = default;
Topology& operator=(const Topology& topology) = delete;
Topology& operator=(Topology&& topology) = default;
int dim() const noexcept;
const std::vector<CellType>& entity_types(int dim) const;
CellType cell_type() const;
std::vector<std::shared_ptr<const common::IndexMap>>
index_maps(int dim) const;
std::shared_ptr<const common::IndexMap> index_map(int dim) const;
std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
connectivity(std::array<int, 2> d0, std::array<int, 2> d1) const;
std::shared_ptr<const graph::AdjacencyList<std::int32_t>>
connectivity(int d0, int d1) const;
const std::vector<std::uint32_t>& get_cell_permutation_info() const;
const std::vector<std::uint8_t>& get_facet_permutations() const;
std::vector<CellType> cell_types() const;
const std::vector<std::int32_t>& interprocess_facets(int index) const;
const std::vector<std::int32_t>& interprocess_facets() const;
bool create_entities(int dim);
void create_connectivity(int d0, int d1);
void create_entity_permutations();
std::vector<std::vector<std::int64_t>> original_cell_index;
MPI_Comm comm() const;
private:
// Cell types for entities in Topology, where _entity_types_new[d][i]
// is the ith entity type of dimension d
std::vector<std::vector<CellType>> _entity_types;
// Parallel layout of entities for each dimension and cell type
// flattened in the same layout as _entity_types above.
// std::vector<std::shared_ptr<const common::IndexMap>> _index_map;
// _index_maps[(d, i) is the index map for the ith entity type of
// dimension d
std::map<std::array<int, 2>, std::shared_ptr<const common::IndexMap>>
_index_maps;
// Connectivity between cell types _connectivity_new[(dim0, i0),
// (dim1, i1)] is the connection from (dim0, i0) -> (dim1, i1),
// where dim0 and dim1 are topological dimensions and i0 and i1
// are the indices of cell types (following the order in _entity_types).
std::map<std::pair<std::array<int, 2>, std::array<int, 2>>,
std::shared_ptr<graph::AdjacencyList<std::int32_t>>>
_connectivity;
// The facet permutations (local facet, cell))
// [cell0_0, cell0_1, ,cell0_2, cell1_0, cell1_1, ,cell1_2, ...,
// celln_0, celln_1, ,celln_2,]
std::vector<std::uint8_t> _facet_permutations;
// Cell permutation info. See the documentation for
// get_cell_permutation_info for documentation of how this is encoded.
std::vector<std::uint32_t> _cell_permutations;
// List of facets that are on the inter-process boundary for each
// facet type. _interprocess_facets[i] is the inter-process facets of
// facet type i.
std::vector<std::vector<std::int32_t>> _interprocess_facets;
};
Topology
create_topology(MPI_Comm comm, const std::vector<CellType>& cell_types,
std::vector<std::span<const std::int64_t>> cells,
std::vector<std::span<const std::int64_t>> original_cell_index,
std::vector<std::span<const int>> ghost_owners,
std::span<const std::int64_t> boundary_vertices);
Topology create_topology(MPI_Comm comm, std::span<const std::int64_t> cells,
std::span<const std::int64_t> original_cell_index,
std::span<const int> ghost_owners, CellType cell_type,
std::span<const std::int64_t> boundary_vertices);
std::tuple<Topology, std::vector<int32_t>, std::vector<int32_t>>
create_subtopology(const Topology& topology, int dim,
std::span<const std::int32_t> entities);
std::vector<std::int32_t>
entities_to_index(const Topology& topology, int dim,
std::span<const std::int32_t> entities);
std::vector<std::vector<std::int32_t>>
compute_mixed_cell_pairs(const Topology& topology, mesh::CellType facet_type);
} // namespace dolfinx::mesh
dolfinx::common::IndexMap
Definition IndexMap.h:97
dolfinx::graph::AdjacencyList
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
dolfinx::mesh::Topology::index_map
std::shared_ptr< const common::IndexMap > index_map(int dim) const
Get the IndexMap that described the parallel distribution of the mesh entities.
Definition Topology.cpp:824
dolfinx::mesh::Topology::create_connectivity
void create_connectivity(int d0, int d1)
Create connectivity between given pair of dimensions, d0 -> d1.
Definition Topology.cpp:958
dolfinx::mesh::Topology::original_cell_index
std::vector< std::vector< std::int64_t > > original_cell_index
Original cell index for each cell type.
Definition Topology.h:206
dolfinx::mesh::Topology::create_entity_permutations
void create_entity_permutations()
Compute entity permutations and reflections.
Definition Topology.cpp:998
dolfinx::mesh::Topology::get_cell_permutation_info
const std::vector< std::uint32_t > & get_cell_permutation_info() const
Returns the permutation information.
Definition Topology.cpp:860
dolfinx::mesh::Topology::connectivity
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.
Definition Topology.cpp:840
dolfinx::mesh::Topology::get_facet_permutations
const std::vector< std::uint8_t > & get_facet_permutations() const
Get the numbers that encode the number of permutations to apply to facets.
Definition Topology.cpp:875
dolfinx::mesh::Topology::Topology
Topology(const Topology &topology)=default
Copy constructor.
dolfinx::mesh::Topology::~Topology
~Topology()=default
Destructor.
dolfinx::mesh::Topology::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)
Create a mesh topology.
Definition Topology.cpp:742
dolfinx::mesh::Topology::entity_types
const std::vector< CellType > & entity_types(int dim) const
Entity types in the topology for a given dimension.
Definition Topology.cpp:791
dolfinx::mesh::Topology::dim
int dim() const noexcept
Topological dimension of the mesh.
Definition Topology.cpp:786
dolfinx::mesh::Topology::interprocess_facets
const std::vector< std::int32_t > & interprocess_facets(int index) const
List of inter-process facets of a given type.
Definition Topology.cpp:889
dolfinx::mesh::Topology::Topology
Topology(Topology &&topology)=default
Move constructor.
dolfinx::mesh::Topology::cell_types
std::vector< CellType > cell_types() const
Get the types of cells in the topology.
Definition Topology.cpp:806
dolfinx::mesh::Topology::operator=
Topology & operator=(const Topology &topology)=delete
Assignment.
dolfinx::mesh::Topology::comm
MPI_Comm comm() const
Mesh MPI communicator.
Definition Topology.cpp:1018
dolfinx::mesh::Topology::cell_type
CellType cell_type() const
Cell type.
Definition Topology.cpp:796
dolfinx::mesh::Topology::create_entities
bool create_entities(int dim)
Create entities of given topological dimension.
Definition Topology.cpp:901
dolfinx::mesh::Topology::operator=
Topology & operator=(Topology &&topology)=default
Assignment.
dolfinx::mesh::Topology::index_maps
std::vector< std::shared_ptr< const common::IndexMap > > index_maps(int dim) const
Get the index maps that described the parallel distribution of the mesh entities of a given topologic...
Definition Topology.cpp:812
dolfinx::common
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
dolfinx::graph
Graph data structures and algorithms.
Definition AdjacencyList.h:20
dolfinx::mesh
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
dolfinx::mesh::create_topology
Topology create_topology(MPI_Comm comm, const std::vector< CellType > &cell_types, std::vector< std::span< const std::int64_t > > cells, std::vector< std::span< const std::int64_t > > original_cell_index, std::vector< std::span< const int > > ghost_owners, std::span< const std::int64_t > boundary_vertices)
Create a mesh topology.
Definition Topology.cpp:1025
dolfinx::mesh::create_subtopology
std::tuple< Topology, std::vector< int32_t >, std::vector< int32_t > > create_subtopology(const Topology &topology, int dim, std::span< const std::int32_t > entities)
Create a topology for a subset of entities of a given topological dimension.
Definition Topology.cpp:1313
dolfinx::mesh::CellType
CellType
Cell type identifier.
Definition cell_types.h:22
dolfinx::mesh::compute_mixed_cell_pairs
std::vector< std::vector< std::int32_t > > compute_mixed_cell_pairs(const Topology &topology, mesh::CellType facet_type)
Compute a list of cell-cell connections for each possible combination in the topology which have the ...
Definition Topology.cpp:1454
dolfinx::mesh::entities_to_index
std::vector< std::int32_t > entities_to_index(const Topology &topology, int dim, std::span< const std::int32_t > entities)
Get entity indices for entities defined by their vertices.
Definition Topology.cpp:1396