DOLFIN
DOLFIN C++ interface
Loading...
Searching...
No Matches
MeshTopology.h
1// Copyright (C) 2006-2009 Anders Logg
2//
3// This file is part of DOLFIN.
4//
5// DOLFIN is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// DOLFIN is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17//
18// First added: 2006-05-08
19// Last changed: 2014-07-02
20
21#ifndef __MESH_TOPOLOGY_H
22#define __MESH_TOPOLOGY_H
23
24#include <cstdint>
25#include <map>
26#include <utility>
27#include <vector>
28
29#include <dolfin/common/Variable.h>
30#include "MeshConnectivity.h"
31
32namespace dolfin
33{
34
45
46 class MeshTopology : public Variable
47 {
48 public:
49
52
54 MeshTopology(const MeshTopology& topology);
55
58
60 MeshTopology& operator= (const MeshTopology& topology);
61
63 std::size_t dim() const;
64
66 std::size_t size(std::size_t dim) const;
67
69 std::size_t size_global(std::size_t dim) const;
70
73 std::size_t ghost_offset(std::size_t dim) const;
74
76 void clear();
77
79 void clear(std::size_t d0, std::size_t d1);
80
82 void init(std::size_t dim);
83
86 void init(std::size_t dim, std::size_t local_size, std::size_t global_size);
87
90 void init_global_indices(std::size_t dim, std::size_t size);
91
93 void init_ghost(std::size_t dim, std::size_t index);
94
97 void set_global_index(std::size_t dim, std::size_t local_index,
98 std::int64_t global_index)
99 {
100 dolfin_assert(dim < _global_indices.size());
101 dolfin_assert(local_index < _global_indices[dim].size());
102 _global_indices[dim][local_index] = global_index;
103 }
104
107 const std::vector<std::int64_t>& global_indices(std::size_t d) const
108 {
109 dolfin_assert(d < _global_indices.size());
110 return _global_indices[d];
111 }
112
115 bool have_global_indices(std::size_t dim) const
116 {
117 dolfin_assert(dim < _global_indices.size());
118 return !_global_indices[dim].empty();
119 }
120
123 bool have_shared_entities(unsigned int dim) const
124 { return (_shared_entities.find(dim) != _shared_entities.end()); }
125
128 std::map<std::int32_t, std::set<unsigned int> >&
129 shared_entities(unsigned int dim);
130
133 const std::map<std::int32_t, std::set<unsigned int> >&
134 shared_entities(unsigned int dim) const;
135
139 std::vector<unsigned int>& cell_owner()
140 { return _cell_owner; }
141
145 const std::vector<unsigned int>& cell_owner() const
146 { return _cell_owner; }
147
149 dolfin::MeshConnectivity& operator() (std::size_t d0, std::size_t d1);
150
152 const dolfin::MeshConnectivity& operator() (std::size_t d0,
153 std::size_t d1) const;
154
156 size_t hash() const;
157
159 std::string str(bool verbose) const;
160
169 // Developer note: std::vector is used in place of a MeshFunction
170 // to avoid circular dependencies in the header files
171 std::map<std::vector<std::size_t>,
172 std::pair<std::vector<std::size_t>,
173 std::vector<std::vector<std::size_t>>>> coloring;
174
175 private:
176
177 // Number of mesh entities for each topological dimension
178 std::vector<unsigned int> num_entities;
179
180 // Number of ghost indices for each topological dimension
181 std::vector<std::size_t> ghost_offset_index;
182
183 // Global number of mesh entities for each topological dimension
184 std::vector<std::size_t> global_num_entities;
185
186 // Global indices for mesh entities (empty if not set)
187 std::vector<std::vector<std::int64_t> > _global_indices;
188
189 // For entities of a given dimension d , maps each shared entity
190 // (local index) to a list of the processes sharing the vertex
191 std::map<unsigned int, std::map<std::int32_t, std::set<unsigned int>>>
192 _shared_entities;
193
194 // For cells which are "ghosted", locate the owning process,
195 // using a vector rather than a map,
196 // since ghost cells are always at the end of the range.
197 std::vector<unsigned int> _cell_owner;
198
199 // Connectivity for pairs of topological dimensions
200 std::vector<std::vector<MeshConnectivity> > connectivity;
201
202 };
203
204}
205
206#endif
Definition MeshConnectivity.h:40
std::size_t size(std::size_t dim) const
Return number of entities for given dimension.
Definition MeshTopology.cpp:75
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition MeshTopology.cpp:210
void clear()
Clear all data.
Definition MeshTopology.cpp:102
~MeshTopology()
Destructor.
Definition MeshTopology.cpp:48
void init_ghost(std::size_t dim, std::size_t index)
Initialise the offset index of ghost entities for this dimension.
Definition MeshTopology.cpp:156
std::size_t dim() const
Return topological dimension.
Definition MeshTopology.cpp:70
void init_global_indices(std::size_t dim, std::size_t size)
Definition MeshTopology.cpp:162
std::vector< unsigned int > & cell_owner()
Definition MeshTopology.h:139
bool have_shared_entities(unsigned int dim) const
Definition MeshTopology.h:123
void set_global_index(std::size_t dim, std::size_t local_index, std::int64_t global_index)
Definition MeshTopology.h:97
std::map< std::vector< std::size_t >, std::pair< std::vector< std::size_t >, std::vector< std::vector< std::size_t > > > > coloring
Definition MeshTopology.h:173
void init(std::size_t dim)
Initialize topology of given maximum dimension.
Definition MeshTopology.cpp:121
size_t hash() const
Return hash based on the hash of cell-vertex connectivity.
Definition MeshTopology.cpp:205
MeshTopology()
Create empty mesh topology.
Definition MeshTopology.cpp:31
const std::vector< unsigned int > & cell_owner() const
Definition MeshTopology.h:145
std::size_t ghost_offset(std::size_t dim) const
Definition MeshTopology.cpp:93
bool have_global_indices(std::size_t dim) const
Definition MeshTopology.h:115
const std::vector< std::int64_t > & global_indices(std::size_t d) const
Definition MeshTopology.h:107
dolfin::MeshConnectivity & operator()(std::size_t d0, std::size_t d1)
Return connectivity for given pair of topological dimensions.
Definition MeshTopology.cpp:169
std::map< std::int32_t, std::set< unsigned int > > & shared_entities(unsigned int dim)
Definition MeshTopology.cpp:186
MeshTopology & operator=(const MeshTopology &topology)
Assignment.
Definition MeshTopology.cpp:53
std::size_t size_global(std::size_t dim) const
Return global number of entities for given dimension.
Definition MeshTopology.cpp:84
Variable()
Create unnamed variable.
Definition Variable.cpp:31
Definition adapt.h:30