Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.2.0a0/v0.9.0/cpp
DOLFINx  0.2.0
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 "cell_types.h"
12 #include "utils.h"
13 #include <dolfinx/common/MPI.h>
14 #include <dolfinx/common/UniqueIdGenerator.h>
15 #include <string>
16 #include <utility>
17 
18 namespace dolfinx::fem
19 {
20 class CoordinateElement;
21 }
22 
23 namespace dolfinx::graph
24 {
25 template <typename T>
26 class AdjacencyList;
27 }
28 
29 namespace dolfinx::mesh
30 {
31 
37  = std::function<const dolfinx::graph::AdjacencyList<std::int32_t>(
38  MPI_Comm comm, int nparts, int tdim,
41 
43 enum class GhostMode : int
44 {
45  none,
46  shared_facet,
47  shared_vertex
48 };
49 
52 class Mesh
53 {
54 public:
59  template <typename Topology, typename Geometry>
60  Mesh(MPI_Comm comm, Topology&& topology, Geometry&& geometry)
61  : _topology(std::forward<Topology>(topology)),
62  _geometry(std::forward<Geometry>(geometry)), _mpi_comm(comm)
63  {
64  // Do nothing
65  }
66 
69  Mesh(const Mesh& mesh) = default;
70 
73  Mesh(Mesh&& mesh) = default;
74 
76  ~Mesh() = default;
77 
78  // Assignment operator
79  Mesh& operator=(const Mesh& mesh) = delete;
80 
83  Mesh& operator=(Mesh&& mesh) = default;
84 
85  // TODO: Is there any use for this? In many situations one has to get the
86  // topology of a const Mesh, which is done by Mesh::topology_mutable. Note
87  // that the python interface (calls Mesh::topology()) may still rely on it.
90  Topology& topology();
91 
94  const Topology& topology() const;
95 
98  Topology& topology_mutable() const;
99 
102  Geometry& geometry();
103 
106  const Geometry& geometry() const;
107 
110  std::size_t id() const { return _unique_id; }
111 
114  MPI_Comm mpi_comm() const;
115 
117  std::string name = "mesh";
118 
119 private:
120  // Mesh topology:
121  // TODO: This is mutable because of the current memory management within
122  // mesh::Topology. It allows to obtain a non-const Topology from a
123  // const mesh (via Mesh::topology_mutable()).
124  //
125  mutable Topology _topology;
126 
127  // Mesh geometry
128  Geometry _geometry;
129 
130  // MPI communicator
131  dolfinx::MPI::Comm _mpi_comm;
132 
133  // Unique identifier
134  std::size_t _unique_id = common::UniqueIdGenerator::id();
135 };
136 
153 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
154  const fem::CoordinateElement& element,
155  const xt::xtensor<double, 2>& x, GhostMode ghost_mode);
156 
158 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
159  const fem::CoordinateElement& element,
160  const xt::xtensor<double, 2>& x, GhostMode ghost_mode,
161  const CellPartitionFunction& cell_partitioner);
162 
163 } // namespace dolfinx::mesh
dolfinx::mesh
Mesh data structures and algorithms on meshes.
Definition: DirichletBC.h:19
dolfinx::mesh::Mesh::topology_mutable
Topology & topology_mutable() const
Get mesh topology if one really needs the mutable version.
Definition: Mesh.cpp:177
dolfinx::graph
Graph data structures and algorithms.
Definition: AdjacencyList.h:18
dolfinx::mesh::CellPartitionFunction
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:40
dolfinx::mesh::Mesh::id
std::size_t id() const
Get unique identifier for the mesh.
Definition: Mesh.h:110
dolfinx::graph::AdjacencyList
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:46
dolfinx::mesh::GhostMode
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:43
dolfinx::mesh::Mesh::topology
Topology & topology()
Get mesh topology.
Definition: Mesh.cpp:173
dolfinx::mesh::Mesh::Mesh
Mesh(MPI_Comm comm, Topology &&topology, Geometry &&geometry)
Create a mesh.
Definition: Mesh.h:60
dolfinx::mesh::Mesh
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:52
dolfinx::mesh::create_mesh
Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &cells, const fem::CoordinateElement &element, const xt::xtensor< double, 2 > &x, GhostMode ghost_mode)
Create a mesh using the default partitioner. This function takes mesh input data that is distributed ...
Definition: Mesh.cpp:55
dolfinx::mesh::Mesh::~Mesh
~Mesh()=default
Destructor.
dolfinx::MPI::Comm
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:31
dolfinx::mesh::Mesh::name
std::string name
Name.
Definition: Mesh.h:117
dolfinx::fem
Finite element method functionality.
Definition: assemble_matrix_impl.h:22
dolfinx::mesh::Topology
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:55
dolfinx::mesh::Mesh::geometry
Geometry & geometry()
Get mesh geometry.
Definition: Mesh.cpp:179
dolfinx::mesh::Mesh::mpi_comm
MPI_Comm mpi_comm() const
Mesh MPI communicator.
Definition: Mesh.cpp:183
dolfinx::mesh::Geometry
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:36
dolfinx::common::UniqueIdGenerator::id
static std::size_t id()
Generate a unique ID.
Definition: UniqueIdGenerator.cpp:22
dolfinx::fem::CoordinateElement
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:28