DOLFINx 0.9.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
32 template <typename V>
33 requires std::is_convertible_v<std::remove_cvref_t<V>, Geometry<T>>
34 Mesh(MPI_Comm comm, std::shared_ptr<Topology> topology, V&& geometry)
35 : _topology(topology), _geometry(std::forward<V>(geometry)), _comm(comm)
36 {
37 // Do nothing
38 }
39
42 Mesh(const Mesh& mesh) = default;
43
46 Mesh(Mesh&& mesh) = default;
47
49 ~Mesh() = default;
50
51 // Assignment operator
52 Mesh& operator=(const Mesh& mesh) = delete;
53
56 Mesh& operator=(Mesh&& mesh) = default;
57
58 // TODO: Is there any use for this? In many situations one has to get
59 // the topology of a const Mesh, which is done by
60 // Mesh::topology_mutable. Note that the python interface (calls
61 // Mesh::topology()) may still rely on it.
64 std::shared_ptr<Topology> topology() { return _topology; }
65
68 std::shared_ptr<const Topology> topology() const { return _topology; }
69
72 std::shared_ptr<Topology> topology_mutable() const { return _topology; }
73
76 Geometry<T>& geometry() { return _geometry; }
77
80 const Geometry<T>& geometry() const { return _geometry; }
81
84 MPI_Comm comm() const { return _comm.comm(); }
85
87 std::string name = "mesh";
88
89private:
90 // Mesh topology
91 // Note: This is mutable because of the current memory management
92 // within mesh::Topology. It allows to obtain a non-const Topology
93 // from a const mesh (via Mesh::topology_mutable()).
94 std::shared_ptr<Topology> _topology;
95
96 // Mesh geometry
97 Geometry<T> _geometry;
98
99 // MPI communicator
100 dolfinx::MPI::Comm _comm;
101};
102
105template <typename V>
106Mesh(MPI_Comm, std::shared_ptr<Topology>,
109
110} // namespace dolfinx::mesh
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
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
Definition Mesh.h:72
const Geometry< T > & geometry() const
Get mesh geometry (const version)
Definition Mesh.h:80
std::shared_ptr< Topology > topology()
Get mesh topology.
Definition Mesh.h:64
Mesh & operator=(Mesh &&mesh)=default
Mesh(const Mesh &mesh)=default
Geometry< T > & geometry()
Get mesh geometry.
Definition Mesh.h:76
Mesh(MPI_Comm comm, std::shared_ptr< Topology > topology, V &&geometry)
Create a mesh.
Definition Mesh.h:34
Mesh(Mesh &&mesh)=default
std::string name
Name.
Definition Mesh.h:87
~Mesh()=default
Destructor.
MPI_Comm comm() const
Mesh MPI communicator.
Definition Mesh.h:84
std::shared_ptr< const Topology > topology() const
Definition Mesh.h:68
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32