DOLFINx
DOLFINx C++ interface
Mesh.h
1// Copyright (C) 2006-2020 Anders Logg, Chris Richardson and Garth N. Wells
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "Geometry.h"
10#include "Topology.h"
11#include "utils.h"
12#include <dolfinx/common/MPI.h>
13#include <string>
14#include <utility>
15
16namespace dolfinx::fem
17{
18class CoordinateElement;
19}
20
21namespace dolfinx::graph
22{
23template <typename T>
24class AdjacencyList;
25}
26
27namespace dolfinx::mesh
28{
29
32class Mesh
33{
34public:
39 template <typename Topology, typename Geometry>
41 : _topology(std::forward<Topology>(topology)),
42 _geometry(std::forward<Geometry>(geometry)), _comm(comm)
43 {
44 // Do nothing
45 }
46
49 Mesh(const Mesh& mesh) = default;
50
53 Mesh(Mesh&& mesh) = default;
54
56 ~Mesh() = default;
57
58 // Assignment operator
59 Mesh& operator=(const Mesh& mesh) = delete;
60
63 Mesh& operator=(Mesh&& mesh) = default;
64
65 // TODO: Is there any use for this? In many situations one has to get the
66 // topology of a const Mesh, which is done by Mesh::topology_mutable. Note
67 // that the python interface (calls Mesh::topology()) may still rely on it.
71
74 const Topology& topology() const;
75
79
83
86 const Geometry& geometry() const;
87
90 MPI_Comm comm() const;
91
93 std::string name = "mesh";
94
95private:
96 // Mesh topology:
97 // TODO: This is mutable because of the current memory management within
98 // mesh::Topology. It allows to obtain a non-const Topology from a
99 // const mesh (via Mesh::topology_mutable()).
100 //
101 mutable Topology _topology;
102
103 // Mesh geometry
104 Geometry _geometry;
105
106 // MPI communicator
107 dolfinx::MPI::Comm _comm;
108};
109
129Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
130 const fem::CoordinateElement& element,
131 std::span<const double> x, std::array<std::size_t, 2> xshape,
132 GhostMode ghost_mode);
133
135Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
136 const fem::CoordinateElement& element,
137 std::span<const double> x, std::array<std::size_t, 2> xshape,
138 GhostMode ghost_mode,
139 const CellPartitionFunction& cell_partitioner);
140
148std::tuple<Mesh, std::vector<std::int32_t>, std::vector<std::int32_t>,
149 std::vector<std::int32_t>>
150create_submesh(const Mesh& mesh, int dim,
151 const std::span<const std::int32_t>& entities);
152
153} // namespace dolfinx::mesh
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:42
A CoordinateElement manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:32
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:26
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:28
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:33
Mesh & operator=(Mesh &&mesh)=default
Assignment move operator.
Mesh(const Mesh &mesh)=default
Copy constructor.
Mesh(Mesh &&mesh)=default
Move constructor.
std::string name
Name.
Definition: Mesh.h:93
~Mesh()=default
Destructor.
MPI_Comm comm() const
Mesh MPI communicator.
Definition: Mesh.cpp:454
Mesh(MPI_Comm comm, Topology &&topology, Geometry &&geometry)
Create a mesh.
Definition: Mesh.h:40
Geometry & geometry()
Get mesh geometry.
Definition: Mesh.cpp:450
Topology & topology()
Get mesh topology.
Definition: Mesh.cpp:444
Topology & topology_mutable() const
Get mesh topology if one really needs the mutable version.
Definition: Mesh.cpp:448
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:44
Finite element method functionality.
Definition: assemble_matrix_impl.h:25
Graph data structures and algorithms.
Definition: dofmapbuilder.h:25
Mesh data structures and algorithms on meshes.
Definition: DofMap.h:30
std::tuple< Mesh, std::vector< std::int32_t >, std::vector< std::int32_t >, std::vector< std::int32_t > > create_submesh(const Mesh &mesh, int dim, const std::span< const std::int32_t > &entities)
Create a new mesh consisting of a subset of entities in a mesh.
Definition: Mesh.cpp:208
GhostMode
Enum for different partitioning ghost modes.
Definition: utils.h:29
Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &cells, const fem::CoordinateElement &element, std::span< const double > x, std::array< std::size_t, 2 > xshape, GhostMode ghost_mode)
Create a mesh using the default partitioner.
Definition: Mesh.cpp:60
std::function< dolfinx::graph::AdjacencyList< std::int32_t >(MPI_Comm comm, int nparts, int tdim, const dolfinx::graph::AdjacencyList< std::int64_t > &cells, dolfinx::mesh::GhostMode ghost_mode)> CellPartitionFunction
Signature for the cell partitioning function. The function should compute the destination rank for ce...
Definition: utils.h:54