Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.1.0/v0.9.0/cpp
DOLFINx  0.1.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
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 
40  = std::function<const dolfinx::graph::AdjacencyList<std::int32_t>(
41  MPI_Comm comm, int nparts, int tdim,
44 
46 enum class GhostMode : int
47 {
48  none,
49  shared_facet,
50  shared_vertex
51 };
52 
55 class Mesh
56 {
57 public:
62  template <typename Topology, typename Geometry>
63  Mesh(MPI_Comm comm, Topology&& topology, Geometry&& geometry)
64  : _topology(std::forward<Topology>(topology)),
65  _geometry(std::forward<Geometry>(geometry)), _mpi_comm(comm)
66  {
67  // Do nothing
68  }
69 
72  Mesh(const Mesh& mesh) = default;
73 
76  Mesh(Mesh&& mesh) = default;
77 
79  ~Mesh() = default;
80 
81  // Assignment operator
82  Mesh& operator=(const Mesh& mesh) = delete;
83 
86  Mesh& operator=(Mesh&& mesh) = default;
87 
88  // TODO: Is there any use for this? In many situations one has to get the
89  // topology of a const Mesh, which is done by Mesh::topology_mutable. Note
90  // that the python interface (calls Mesh::topology()) may still rely on it.
93  Topology& topology();
94 
97  const Topology& topology() const;
98 
101  Topology& topology_mutable() const;
102 
105  Geometry& geometry();
106 
109  const Geometry& geometry() const;
110 
113  std::size_t id() const { return _unique_id; }
114 
117  MPI_Comm mpi_comm() const;
118 
120  std::string name = "mesh";
121 
122 private:
123  // Mesh topology:
124  // TODO: This is mutable because of the current memory management within
125  // mesh::Topology. It allows to obtain a non-const Topology from a
126  // const mesh (via Mesh::topology_mutable()).
127  //
128  mutable Topology _topology;
129 
130  // Mesh geometry
131  Geometry _geometry;
132 
133  // MPI communicator
134  dolfinx::MPI::Comm _mpi_comm;
135 
136  // Unique identifier
137  std::size_t _unique_id = common::UniqueIdGenerator::id();
138 };
139 
156 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
157  const fem::CoordinateElement& element,
158  const xt::xtensor<double, 2>& x, GhostMode ghost_mode);
159 
161 Mesh create_mesh(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& cells,
162  const fem::CoordinateElement& element,
163  const xt::xtensor<double, 2>& x, GhostMode ghost_mode,
164  const CellPartitionFunction& cell_partitioner);
165 
166 } // namespace mesh
167 } // namespace dolfinx
dolfinx::mesh::Mesh::topology_mutable
Topology & topology_mutable() const
Get mesh topology if one really needs the mutable version.
Definition: Mesh.cpp:122
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:43
dolfinx::mesh::Mesh::id
std::size_t id() const
Get unique identifier for the mesh.
Definition: Mesh.h:113
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:46
dolfinx::mesh::Mesh::topology
Topology & topology()
Get mesh topology.
Definition: Mesh.cpp:118
dolfinx::mesh::Mesh::Mesh
Mesh(MPI_Comm comm, Topology &&topology, Geometry &&geometry)
Create a mesh.
Definition: Mesh.h:63
dolfinx::mesh::Mesh
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:55
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:25
dolfinx::mesh::Mesh::~Mesh
~Mesh()=default
Destructor.
dolfinx::MPI::Comm
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:35
dolfinx::mesh::Mesh::name
std::string name
Name.
Definition: Mesh.h:120
dolfinx::mesh::Topology
Topology stores the topology of a mesh, consisting of mesh entities and connectivity (incidence relat...
Definition: Topology.h:56
dolfinx::mesh::Mesh::geometry
Geometry & geometry()
Get mesh geometry.
Definition: Mesh.cpp:124
dolfinx::mesh::Mesh::mpi_comm
MPI_Comm mpi_comm() const
Mesh MPI communicator.
Definition: Mesh.cpp:128
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:30