DOLFIN
DOLFIN C++ interface
MeshEntity.h
1// Copyright (C) 2006-2011 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// Modified by Andre Massing, 2009.
19// Modified by Garth N. Wells, 2012.
20//
21// First added: 2006-05-11
22// Last changed: 2014-07-02
23
24#ifndef __MESH_ENTITY_H
25#define __MESH_ENTITY_H
26
27#include <cmath>
28#include <iostream>
29
30#include <dolfin/geometry/Point.h>
31#include "Mesh.h"
32
33namespace dolfin
34{
35
36 //class Mesh;
37 class Point;
38
41
43 {
44 public:
45
47 MeshEntity() : _mesh(0), _dim(0), _local_index(0) {}
48
57 MeshEntity(const Mesh& mesh, std::size_t dim, std::size_t index);
58
60 virtual ~MeshEntity();
61
70 void init(const Mesh& mesh, std::size_t dim, std::size_t index);
71
79 bool operator==(const MeshEntity& e) const
80 {
81 return (_mesh == e._mesh && _dim == e._dim
82 && _local_index == e._local_index);
83 }
84
92 bool operator!=(const MeshEntity& e) const
93 { return !operator==(e); }
94
99 const Mesh& mesh() const
100 { return *_mesh; }
101
106 std::size_t dim() const
107 { return _dim; }
108
113 std::size_t index() const
114 { return _local_index; }
115
122 std::int64_t global_index() const
123 {
124 const std::vector<std::int64_t>& global_indices
125 = _mesh->topology().global_indices(_dim);
126 if (global_indices.empty())
127 return -1;
128 return global_indices[_local_index];
129 }
130
140 std::size_t num_entities(std::size_t dim) const
141 { return _mesh->topology()(_dim, dim).size(_local_index); }
142
152 std::size_t num_global_entities(std::size_t dim) const
153 { return _mesh->topology()(_dim, dim).size_global(_local_index); }
154
163 const unsigned int* entities(std::size_t dim) const
164 {
165 const unsigned int* initialized_mesh_entities
166 = _mesh->topology()(_dim, dim)(_local_index);
167 dolfin_assert(initialized_mesh_entities);
168 return initialized_mesh_entities;
169 }
170
175 std::size_t mesh_id() const
176 { return _mesh->id(); }
177
185 bool incident(const MeshEntity& entity) const;
186
195 std::size_t index(const MeshEntity& entity) const;
196
201 Point midpoint() const;
202
207 bool is_ghost() const
208 { return (_local_index >= _mesh->topology().ghost_offset(_dim)); }
209
213 std::set<unsigned int> sharing_processes() const
214 {
215 const std::map<std::int32_t, std::set<unsigned int>>& sharing_map
216 = _mesh->topology().shared_entities(_dim);
217 const auto map_it = sharing_map.find(_local_index);
218 if (map_it == sharing_map.end())
219 return std::set<unsigned int>();
220 else
221 return map_it->second;
222 }
223
227 bool is_shared() const
228 {
229 if (_mesh->topology().have_shared_entities(_dim))
230 {
231 const std::map<std::int32_t, std::set<unsigned int>>& sharing_map
232 = _mesh->topology().shared_entities(_dim);
233 return (sharing_map.find(_local_index) != sharing_map.end());
234 }
235 return false;
236 }
237
241 unsigned int owner() const;
242
243 // Note: Not a subclass of Variable for efficiency!
251 std::string str(bool verbose) const;
252
253 protected:
254
255 // Friends
256 friend class MeshEntityIterator;
257 template<typename T> friend class MeshEntityIteratorBase;
258 friend class SubsetIterator;
259
260 // The mesh
261 Mesh const * _mesh;
262
263 // Topological dimension
264 std::size_t _dim;
265
266 // Local index of entity within topological dimension
267 std::size_t _local_index;
268
269 };
270
271}
272
273#endif
Base class for MeshEntityIterators.
Definition: MeshEntityIteratorBase.h:37
Definition: MeshEntityIterator.h:65
Definition: MeshEntity.h:43
std::set< unsigned int > sharing_processes() const
Definition: MeshEntity.h:213
bool incident(const MeshEntity &entity) const
Definition: MeshEntity.cpp:69
const Mesh & mesh() const
Definition: MeshEntity.h:99
void init(const Mesh &mesh, std::size_t dim, std::size_t index)
Definition: MeshEntity.cpp:39
Point midpoint() const
Definition: MeshEntity.cpp:115
bool is_shared() const
Definition: MeshEntity.h:227
const unsigned int * entities(std::size_t dim) const
Definition: MeshEntity.h:163
std::size_t dim() const
Definition: MeshEntity.h:106
MeshEntity()
Default Constructor.
Definition: MeshEntity.h:47
std::size_t index() const
Definition: MeshEntity.h:113
unsigned int owner() const
Definition: MeshEntity.cpp:146
bool is_ghost() const
Definition: MeshEntity.h:207
virtual ~MeshEntity()
Destructor.
Definition: MeshEntity.cpp:64
std::size_t num_entities(std::size_t dim) const
Definition: MeshEntity.h:140
std::string str(bool verbose) const
Definition: MeshEntity.cpp:162
std::size_t num_global_entities(std::size_t dim) const
Definition: MeshEntity.h:152
std::size_t mesh_id() const
Definition: MeshEntity.h:175
bool operator==(const MeshEntity &e) const
Definition: MeshEntity.h:79
bool operator!=(const MeshEntity &e) const
Definition: MeshEntity.h:92
std::int64_t global_index() const
Definition: MeshEntity.h:122
bool have_shared_entities(unsigned int dim) const
Definition: MeshTopology.h:129
std::size_t ghost_offset(std::size_t dim) const
Definition: MeshTopology.cpp:97
const std::vector< std::int64_t > & global_indices(std::size_t d) const
Definition: MeshTopology.h:113
std::map< std::int32_t, std::set< unsigned int > > & shared_entities(unsigned int dim)
Definition: MeshTopology.cpp:191
Definition: Mesh.h:84
MeshTopology & topology()
Definition: Mesh.h:220
Definition: Point.h:41
Definition: SubsetIterator.h:42
std::size_t id() const
Definition: Variable.h:68
Definition: adapt.h:30