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 <Eigen/Dense>
13 #include <dolfinx/common/MPI.h>
14 #include <dolfinx/common/UniqueIdGenerator.h>
15 #include <string>
16 #include <utility>
17 
18 namespace dolfinx
19 {
20 
21 namespace fem
22 {
23 class CoordinateElement;
24 }
25 
26 namespace graph
27 {
28 template <typename T>
29 class AdjacencyList;
30 }
31 
32 namespace mesh
33 {
34 
36 enum class GhostMode : int
37 {
38  none,
39  shared_facet,
40  shared_vertex
41 };
42 
45 
46 class Mesh
47 {
48 public:
53  template <typename Topology, typename Geometry>
54  Mesh(MPI_Comm comm, Topology&& topology, Geometry&& geometry)
55  : _topology(std::forward<Topology>(topology)),
56  _geometry(std::forward<Geometry>(geometry)), _mpi_comm(comm)
57  {
58  // Do nothing
59  }
60 
63  Mesh(const Mesh& mesh) = default;
64 
67  Mesh(Mesh&& mesh) = default;
68 
70  ~Mesh() = default;
71 
72  // Assignment operator
73  Mesh& operator=(const Mesh& mesh) = delete;
74 
77  Mesh& operator=(Mesh&& mesh) = default;
78 
79  // TODO: Is there any use for this? In many situations one has to get the
80  // topology of a const Mesh, which is done by Mesh::topology_mutable. Note
81  // that the python interface (calls Mesh::topology()) may still rely on it.
84  Topology& topology();
85 
88  const Topology& topology() const;
89 
92  Topology& topology_mutable() const;
93 
96  Geometry& geometry();
97 
100  const Geometry& geometry() const;
101 
106  double hmin() const;
107 
112  double hmax() const;
113 
116  double rmin() const;
117 
120  double rmax() const;
121 
126  std::size_t hash() const;
127 
130  std::size_t id() const { return _unique_id; }
131 
134  MPI_Comm mpi_comm() const;
135 
137  std::string name = "mesh";
138 
139 private:
140  // Mesh topology:
141  // TODO: This is mutable because of the current memory management within
142  // mesh::Topology. It allows to obtain a non-const Topology from a
143  // const mesh (via Mesh::topology_mutable()).
144  //
145  mutable Topology _topology;
146 
147  // Mesh geometry
148  Geometry _geometry;
149 
150  // MPI communicator
151  dolfinx::MPI::Comm _mpi_comm;
152 
153  // Unique identifier
154  std::size_t _unique_id = common::UniqueIdGenerator::id();
155 };
156 
158 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
159  const fem::CoordinateElement& element,
160  const Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic,
161  Eigen::RowMajor>& x,
162  GhostMode ghost_mode);
163 
164 } // namespace mesh
165 } // namespace dolfinx
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:36
static std::size_t id()
Generate a unique ID.
Definition: UniqueIdGenerator.cpp:22
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:24
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:28
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:39
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:47
double rmax() const
Compute maximum cell inradius.
Definition: Mesh.cpp:157
Topology & topology_mutable() const
Get mesh topology if one really needs the mutable version.
Definition: Mesh.cpp:145
std::size_t hash() const
Compute hash of mesh, currently based on the has of the mesh geometry and mesh topology.
Definition: Mesh.cpp:159
Mesh(Mesh &&mesh)=default
Move constructor.
~Mesh()=default
Destructor.
Mesh(MPI_Comm comm, Topology &&topology, Geometry &&geometry)
Create a mesh.
Definition: Mesh.h:54
Mesh & operator=(Mesh &&mesh)=default
Assignment move operator.
std::string name
Name.
Definition: Mesh.h:137
double rmin() const
Compute minimum cell inradius.
Definition: Mesh.cpp:155
MPI_Comm mpi_comm() const
Mesh MPI communicator.
Definition: Mesh.cpp:173
Geometry & geometry()
Get mesh geometry.
Definition: Mesh.cpp:147
std::size_t id() const
Get unique identifier for the mesh.
Definition: Mesh.h:130
Mesh(const Mesh &mesh)=default
Copy constructor.
Topology & topology()
Get mesh topology.
Definition: Mesh.cpp:141
double hmax() const
Compute maximum cell size in mesh, measured greatest distance between any two vertices of a cell.
Definition: Mesh.cpp:153
double hmin() const
Compute minimum cell size in mesh, measured greatest distance between any two vertices of a cell.
Definition: Mesh.cpp:151
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:58
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:37
Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &cells, const fem::CoordinateElement &element, const Eigen::Array< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > &x, GhostMode ghost_mode)
Create a mesh.
Definition: Mesh.cpp:64