Loading...
Searching...
No Matches
DofMap.h
Go to the documentation of this file.
// Copyright (C) 2007-2020 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 "ElementDofLayout.h"
#include <basix/mdspan.hpp>
#include <concepts>
#include <cstdlib>
#include <dolfinx/common/MPI.h>
#include <dolfinx/graph/AdjacencyList.h>
#include <dolfinx/graph/ordering.h>
#include <functional>
#include <memory>
#include <mpi.h>
#include <span>
#include <utility>
#include <vector>
namespace dolfinx::common
{
class IndexMap;
}
namespace dolfinx::mesh
{
class Topology;
}
namespace dolfinx::fem
{
graph::AdjacencyList<std::int32_t> transpose_dofmap(
md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>> dofmap,
std::int32_t num_cells);
class DofMap
{
public:
template <typename E, typename U>
requires std::is_convertible_v<std::remove_cvref_t<E>,
fem::ElementDofLayout>
and std::is_convertible_v<std::remove_cvref_t<U>,
std::vector<std::int32_t>>
DofMap(E&& element, std::shared_ptr<const common::IndexMap> index_map,
int index_map_bs, U&& dofmap, int bs)
: index_map(std::move(index_map)), _index_map_bs(index_map_bs),
_element_dof_layout(std::forward<E>(element)),
_dofmap(std::forward<U>(dofmap)), _bs(bs),
_shape1(_element_dof_layout.num_dofs()
* _element_dof_layout.block_size() / _bs)
{
// Do nothing
}
// Copy constructor
DofMap(const DofMap& dofmap) = delete;
DofMap(DofMap&& dofmap) = default;
// Destructor
~DofMap() = default;
// Copy assignment
DofMap& operator=(const DofMap& dofmap) = delete;
DofMap& operator=(DofMap&& dofmap) = default;
bool operator==(const DofMap& map) const;
std::span<const std::int32_t> cell_dofs(std::int32_t c) const
{
return std::span<const std::int32_t>(_dofmap.data() + _shape1 * c, _shape1);
}
int bs() const noexcept;
DofMap extract_sub_dofmap(std::span<const int> component) const;
std::pair<DofMap, std::vector<std::int32_t>>
collapse(MPI_Comm comm, const mesh::Topology& topology,
std::function<std::vector<int>(
const graph::AdjacencyList<std::int32_t>&)>&& reorder_fn
= nullptr) const;
md::mdspan<const std::int32_t, md::dextents<std::size_t, 2>> map() const;
const ElementDofLayout& element_dof_layout() const
{
return _element_dof_layout;
}
std::shared_ptr<const common::IndexMap> index_map;
int index_map_bs() const;
private:
// Block size for the IndexMap
int _index_map_bs = -1;
// Layout of dofs on a cell
ElementDofLayout _element_dof_layout;
// Cell local-to-dof map
std::vector<std::int32_t> _dofmap;
// Block size for the dofmap
int _bs = -1;
// Number of columns in _dofmap
int _shape1 = -1;
};
} // namespace dolfinx::fem
dolfinx::common::IndexMap
Definition IndexMap.h:97
dolfinx::fem::DofMap
Degree-of-freedom map.
Definition DofMap.h:73
dolfinx::fem::DofMap::DofMap
DofMap(DofMap &&dofmap)=default
Move constructor.
dolfinx::fem::DofMap::operator=
DofMap & operator=(DofMap &&dofmap)=default
Move assignment.
dolfinx::fem::DofMap::index_map
std::shared_ptr< const common::IndexMap > index_map
Index map that describes the parallel distribution of the dofmap.
Definition DofMap.h:164
dolfinx::fem::DofMap::extract_sub_dofmap
DofMap extract_sub_dofmap(std::span< const int > component) const
Extract subdofmap component.
Definition DofMap.cpp:170
dolfinx::fem::DofMap::DofMap
DofMap(E &&element, std::shared_ptr< const common::IndexMap > index_map, int index_map_bs, U &&dofmap, int bs)
Create a DofMap from the layout of dofs on a reference element, an IndexMap defining the distribution...
Definition DofMap.h:93
dolfinx::fem::DofMap::collapse
std::pair< DofMap, std::vector< std::int32_t > > collapse(MPI_Comm comm, const mesh::Topology &topology, std::function< std::vector< int >(const graph::AdjacencyList< std::int32_t > &)> &&reorder_fn=nullptr) const
Create a "collapsed" dofmap (collapses a sub-dofmap).
Definition DofMap.cpp:204
dolfinx::fem::DofMap::cell_dofs
std::span< const std::int32_t > cell_dofs(std::int32_t c) const
Local-to-global mapping of dofs on a cell.
Definition DofMap.h:127
dolfinx::fem::DofMap::element_dof_layout
const ElementDofLayout & element_dof_layout() const
Layout of dofs on an element.
Definition DofMap.h:157
dolfinx::fem::DofMap::map
md::mdspan< const std::int32_t, md::dextents< std::size_t, 2 > > map() const
Get dofmap data.
Definition DofMap.cpp:270
dolfinx::fem::DofMap::index_map_bs
int index_map_bs() const
Block size associated with the index_map.
Definition DofMap.cpp:276
dolfinx::fem::DofMap::operator==
bool operator==(const DofMap &map) const
Equality operator.
Definition DofMap.cpp:162
dolfinx::fem::DofMap::bs
int bs() const noexcept
Return the block size for the dofmap.
Definition DofMap.cpp:168
dolfinx::fem::ElementDofLayout
Definition ElementDofLayout.h:31
dolfinx::graph::AdjacencyList
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
dolfinx::mesh::Topology
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition Topology.h:41
dolfinx::common
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
dolfinx::fem
Finite element method functionality.
Definition assemble_expression_impl.h:23
dolfinx::fem::transpose_dofmap
graph::AdjacencyList< std::int32_t > transpose_dofmap(md::mdspan< const std::int32_t, md::dextents< std::size_t, 2 > > dofmap, std::int32_t num_cells)
Create an adjacency list that maps a global index (process-wise) to the 'unassembled' cell-wise contr...
Definition DofMap.cpp:118
dolfinx::graph
Graph data structures and algorithms.
Definition AdjacencyList.h:20
dolfinx::mesh
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32