Loading...
Searching...
No Matches
EntityMap.h
// Copyright (C) 2025 Jørgen S. Dokken and Joseph P. Dean
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include "Topology.h"
#include <concepts>
#include <dolfinx/common/IndexMap.h>
#include <span>
#include <vector>
namespace dolfinx::mesh
{
class EntityMap
{
public:
template <typename U>
requires std::is_convertible_v<std::remove_cvref_t<U>,
std::vector<std::int32_t>>
EntityMap(std::shared_ptr<const Topology> topology,
std::shared_ptr<const Topology> sub_topology, int dim,
U&& sub_topology_to_topology)
: _dim(dim), _topology(topology),
_sub_topology_to_topology(std::forward<U>(sub_topology_to_topology)),
_sub_topology(sub_topology)
{
auto e_imap = sub_topology->index_map(_dim);
if (!e_imap)
{
throw std::runtime_error(
"No index map for entities, call `Topology::create_entities("
+ std::to_string(_dim) + ")");
}
std::size_t num_ents = e_imap->size_local() + e_imap->num_ghosts();
if (num_ents != _sub_topology_to_topology.size())
{
throw std::runtime_error(
"Size mismatch between `sub_topology_to_topology` and index map.");
}
}
EntityMap(const EntityMap& map) = default;
EntityMap(EntityMap&& map) = default;
// Destructor
~EntityMap() = default;
std::size_t dim() const;
std::shared_ptr<const Topology> topology() const;
std::shared_ptr<const Topology> sub_topology() const;
std::vector<std::int32_t>
sub_topology_to_topology(std::span<const std::int32_t> entities,
bool inverse) const;
private:
// Dimension of the entities
std::size_t _dim;
// A topology
std::shared_ptr<const Topology> _topology;
// A list of `_dim`-dimensional entities in _topology, where
// `_sub_topology_to_topology[i]` is the index in `_topology` of the
// `i`th entity in `_sub_topology`
std::vector<std::int32_t> _sub_topology_to_topology;
// A second topology, consisting of a subset of entities in
// `_topology`
std::shared_ptr<const Topology> _sub_topology;
};
} // namespace dolfinx::mesh
dolfinx::mesh::EntityMap::sub_topology_to_topology
std::vector< std::int32_t > sub_topology_to_topology(std::span< const std::int32_t > entities, bool inverse) const
Map entities between the sub-topology and the parent topology.
Definition EntityMap.cpp:30
dolfinx::mesh::EntityMap::EntityMap
EntityMap(EntityMap &&map)=default
Move constructor.
dolfinx::mesh::EntityMap::dim
std::size_t dim() const
Get the topological dimension of the entities related by this EntityMap.
Definition EntityMap.cpp:17
dolfinx::mesh::EntityMap::EntityMap
EntityMap(std::shared_ptr< const Topology > topology, std::shared_ptr< const Topology > sub_topology, int dim, U &&sub_topology_to_topology)
Constructor of a bidirectional map relating entities of dimension dim in topology and sub_topology.
Definition EntityMap.h:37
dolfinx::mesh::EntityMap::EntityMap
EntityMap(const EntityMap &map)=default
Copy constructor.
dolfinx::mesh::EntityMap::sub_topology
std::shared_ptr< const Topology > sub_topology() const
Get the sub-topology.
Definition EntityMap.cpp:24
dolfinx::mesh::EntityMap::topology
std::shared_ptr< const Topology > topology() const
Get the (parent) topology.
Definition EntityMap.cpp:19
dolfinx::mesh
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32