DOLFIN-X
DOLFIN-X 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 "cell_types.h"
12 #include "utils.h"
13 #include <dolfinx/common/MPI.h>
14 #include <dolfinx/common/UniqueIdGenerator.h>
15 #include <dolfinx/common/array2d.h>
16 #include <string>
17 #include <utility>
18 
19 namespace dolfinx
20 {
21 
22 namespace fem
23 {
24 class CoordinateElement;
25 }
26 
27 namespace graph
28 {
29 template <typename T>
30 class AdjacencyList;
31 }
32 
33 namespace mesh
34 {
35 
41  = std::function<const dolfinx::graph::AdjacencyList<std::int32_t>(
42  MPI_Comm comm, int nparts, int tdim,
44  dolfinx::mesh::GhostMode ghost_mode)>;
45 
47 enum class GhostMode : int
48 {
49  none,
50  shared_facet,
51  shared_vertex
52 };
53 
56 class Mesh
57 {
58 public:
63  template <typename Topology, typename Geometry>
64  Mesh(MPI_Comm comm, Topology&& topology, Geometry&& geometry)
65  : _topology(std::forward<Topology>(topology)),
66  _geometry(std::forward<Geometry>(geometry)), _mpi_comm(comm)
67  {
68  // Do nothing
69  }
70 
73  Mesh(const Mesh& mesh) = default;
74 
77  Mesh(Mesh&& mesh) = default;
78 
80  ~Mesh() = default;
81 
82  // Assignment operator
83  Mesh& operator=(const Mesh& mesh) = delete;
84 
87  Mesh& operator=(Mesh&& mesh) = default;
88 
89  // TODO: Is there any use for this? In many situations one has to get the
90  // topology of a const Mesh, which is done by Mesh::topology_mutable. Note
91  // that the python interface (calls Mesh::topology()) may still rely on it.
94  Topology& topology();
95 
98  const Topology& topology() const;
99 
102  Topology& topology_mutable() const;
103 
106  Geometry& geometry();
107 
110  const Geometry& geometry() const;
111 
114  std::size_t id() const { return _unique_id; }
115 
118  MPI_Comm mpi_comm() const;
119 
121  std::string name = "mesh";
122 
123 private:
124  // Mesh topology:
125  // TODO: This is mutable because of the current memory management within
126  // mesh::Topology. It allows to obtain a non-const Topology from a
127  // const mesh (via Mesh::topology_mutable()).
128  //
129  mutable Topology _topology;
130 
131  // Mesh geometry
132  Geometry _geometry;
133 
134  // MPI communicator
135  dolfinx::MPI::Comm _mpi_comm;
136 
137  // Unique identifier
138  std::size_t _unique_id = common::UniqueIdGenerator::id();
139 };
140 
157 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
158  const fem::CoordinateElement& element,
159  const array2d<double>& x, GhostMode ghost_mode);
160 
162 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
163  const fem::CoordinateElement& element,
164  const array2d<double>& x, GhostMode ghost_mode,
165  const CellPartitionFunction& cell_partitioner);
166 
167 } // namespace mesh
168 } // namespace dolfinx
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:36
This class provides a dynamic 2-dimensional row-wise array data structure.
Definition: array2d.h:21
static std::size_t id()
Generate a unique ID.
Definition: UniqueIdGenerator.cpp:22
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:31
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:68
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:35
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:57
Topology & topology_mutable() const
Get mesh topology if one really needs the mutable version.
Definition: Mesh.cpp:120
Mesh(Mesh &&mesh)=default
Move constructor.
~Mesh()=default
Destructor.
Mesh(MPI_Comm comm, Topology &&topology, Geometry &&geometry)
Create a mesh.
Definition: Mesh.h:64
Mesh & operator=(Mesh &&mesh)=default
Assignment move operator.
std::string name
Name.
Definition: Mesh.h:121
MPI_Comm mpi_comm() const
Mesh MPI communicator.
Definition: Mesh.cpp:126
Geometry & geometry()
Get mesh geometry.
Definition: Mesh.cpp:122
std::size_t id() const
Get unique identifier for the mesh.
Definition: Mesh.h:114
Mesh(const Mesh &mesh)=default
Copy constructor.
Topology & topology()
Get mesh topology.
Definition: Mesh.cpp:116
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:57
Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &cells, const fem::CoordinateElement &element, const array2d< double > &x, GhostMode ghost_mode)
Create a mesh using the default partitioner. This function takes mesh input data that is distributed ...
Definition: Mesh.cpp:25
std::function< const 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
Definition: Mesh.h:44
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:48