DOLFINx 0.10.0.0
DOLFINx C++ interface
Loading...
Searching...
No Matches
Mesh.h
1// Copyright (C) 2006-2023 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 <concepts>
11#include <dolfinx/common/MPI.h>
12#include <string>
13
14namespace dolfinx::mesh
15{
16class Topology;
17
21template <std::floating_point T>
22class Mesh
23{
24public:
27
36 template <typename V>
37 requires std::is_convertible_v<std::remove_cvref_t<V>, Geometry<T>>
38 Mesh(MPI_Comm comm, std::shared_ptr<Topology> topology, V&& geometry)
39 : _topology(topology), _geometry(std::forward<V>(geometry)), _comm(comm)
40 {
41 // Do nothing
42 }
43
46 Mesh(const Mesh& mesh) = default;
47
50 Mesh(Mesh&& mesh) = default;
51
53 ~Mesh() = default;
54
55 // Assignment operator
56 Mesh& operator=(const Mesh& mesh) = delete;
57
60 Mesh& operator=(Mesh&& mesh) = default;
61
62 // TODO: Is there any use for this? In many situations one has to get
63 // the topology of a const Mesh, which is done by
64 // Mesh::topology_mutable. Note that the python interface (calls
65 // Mesh::topology()) may still rely on it.
68 std::shared_ptr<Topology> topology() { return _topology; }
69
72 std::shared_ptr<const Topology> topology() const { return _topology; }
73
76 std::shared_ptr<Topology> topology_mutable() const { return _topology; }
77
80 Geometry<T>& geometry() { return _geometry; }
81
84 const Geometry<T>& geometry() const { return _geometry; }
85
88 MPI_Comm comm() const { return _comm.comm(); }
89
91 std::string name = "mesh";
92
93private:
94 // Mesh topology
95 // Note: This is non-const because of the current memory management
96 // within mesh::Topology. It allows to obtain a non-const Topology
97 // from a const mesh (via Mesh::topology_mutable()).
98 std::shared_ptr<Topology> _topology;
99
100 // Mesh geometry
101 Geometry<T> _geometry;
102
103 // MPI communicator
104 dolfinx::MPI::Comm _comm;
105};
106
109template <typename V>
110Mesh(MPI_Comm, std::shared_ptr<Topology>, V)
113
114} // namespace dolfinx::mesh
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:44
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:34
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
std::shared_ptr< Topology > topology_mutable() const
Get mesh topology if one really needs the mutable version.
Definition Mesh.h:76
const Geometry< T > & geometry() const
Get mesh geometry (const version).
Definition Mesh.h:84
std::shared_ptr< Topology > topology()
Get mesh topology.
Definition Mesh.h:68
Mesh & operator=(Mesh &&mesh)=default
Mesh(const Mesh &mesh)=default
Geometry< T > & geometry()
Get mesh geometry.
Definition Mesh.h:80
Mesh(MPI_Comm comm, std::shared_ptr< Topology > topology, V &&geometry)
Create a Mesh.
Definition Mesh.h:38
Mesh(Mesh &&mesh)=default
std::string name
Name.
Definition Mesh.h:91
~Mesh()=default
Destructor.
MPI_Comm comm() const
Mesh MPI communicator.
Definition Mesh.h:88
std::shared_ptr< const Topology > topology() const
Get mesh topology (const version).
Definition Mesh.h:72
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32