DOLFIN
DOLFIN C++ interface
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 #include "MeshView.h"
32 
33 namespace dolfin
34 {
35 
46 
47 
48  // NOTE : Forward declaration not sufficient to use the mapping() function
49  // Need to include mesh view to use auto mapping = mesh.topology().mapping()
50  // class MeshView;
51 
52  class MeshTopology : public Variable
53  {
54  public:
55 
57  MeshTopology();
58 
60  MeshTopology(const MeshTopology& topology);
61 
63  ~MeshTopology();
64 
66  MeshTopology& operator= (const MeshTopology& topology);
67 
69  std::size_t dim() const;
70 
72  std::size_t size(std::size_t dim) const;
73 
75  std::size_t size_global(std::size_t dim) const;
76 
79  std::size_t ghost_offset(std::size_t dim) const;
80 
82  void clear();
83 
85  void clear(std::size_t d0, std::size_t d1);
86 
88  void init(std::size_t dim);
89 
92  void init(std::size_t dim, std::size_t local_size, std::size_t global_size);
93 
96  void init_global_indices(std::size_t dim, std::size_t size);
97 
99  void init_ghost(std::size_t dim, std::size_t index);
100 
103  void set_global_index(std::size_t dim, std::size_t local_index,
104  std::int64_t global_index)
105  {
106  dolfin_assert(dim < _global_indices.size());
107  dolfin_assert(local_index < _global_indices[dim].size());
108  _global_indices[dim][local_index] = global_index;
109  }
110 
113  const std::vector<std::int64_t>& global_indices(std::size_t d) const
114  {
115  dolfin_assert(d < _global_indices.size());
116  return _global_indices[d];
117  }
118 
121  bool have_global_indices(std::size_t dim) const
122  {
123  dolfin_assert(dim < _global_indices.size());
124  return !_global_indices[dim].empty();
125  }
126 
129  bool have_shared_entities(unsigned int dim) const
130  { return (_shared_entities.find(dim) != _shared_entities.end()); }
131 
134  std::map<std::int32_t, std::set<unsigned int> >&
135  shared_entities(unsigned int dim);
136 
139  const std::map<std::int32_t, std::set<unsigned int> >&
140  shared_entities(unsigned int dim) const;
141 
145  std::vector<unsigned int>& cell_owner()
146  { return _cell_owner; }
147 
151  const std::vector<unsigned int>& cell_owner() const
152  { return _cell_owner; }
153 
155  dolfin::MeshConnectivity& operator() (std::size_t d0, std::size_t d1);
156 
158  const dolfin::MeshConnectivity& operator() (std::size_t d0,
159  std::size_t d1) const;
160 
162  size_t hash() const;
163 
165  std::string str(bool verbose) const;
166 
175  // Developer note: std::vector is used in place of a MeshFunction
176  // to avoid circular dependencies in the header files
177  std::map<std::vector<std::size_t>,
178  std::pair<std::vector<std::size_t>,
179  std::vector<std::vector<std::size_t>>>> coloring;
180 
181  // Mappings to other Mesh objects, if any
182  std::map<unsigned, std::shared_ptr<MeshView>> mapping() const
183  { return _mapping; }
184 
185  void add_mapping(const std::pair<unsigned, std::shared_ptr<MeshView>> _pair)
186  { _mapping.emplace(_pair); }
187 
188  private:
189 
190  friend class MeshView;
191 
192  // Mappings to other Mesh objects, if any
193  std::map<unsigned, std::shared_ptr<MeshView>> _mapping;
194 
195  // Number of mesh entities for each topological dimension
196  std::vector<unsigned int> num_entities;
197 
198  // Number of ghost indices for each topological dimension
199  std::vector<std::size_t> ghost_offset_index;
200 
201  // Global number of mesh entities for each topological dimension
202  std::vector<std::size_t> global_num_entities;
203 
204  // Global indices for mesh entities (empty if not set)
205  std::vector<std::vector<std::int64_t> > _global_indices;
206 
207  // For entities of a given dimension d , maps each shared entity
208  // (local index) to a list of the processes sharing the vertex
209  std::map<unsigned int, std::map<std::int32_t, std::set<unsigned int>>>
210  _shared_entities;
211 
212  // For cells which are "ghosted", locate the owning process,
213  // using a vector rather than a map,
214  // since ghost cells are always at the end of the range.
215  std::vector<unsigned int> _cell_owner;
216 
217  // Connectivity for pairs of topological dimensions
218  std::vector<std::vector<MeshConnectivity> > connectivity;
219 
220  };
221 
222 }
223 
224 #endif
Definition: MeshConnectivity.h:40
Definition: MeshTopology.h:53
std::size_t size(std::size_t dim) const
Return number of entities for given dimension.
Definition: MeshTopology.cpp:79
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: MeshTopology.cpp:215
void clear()
Clear all data.
Definition: MeshTopology.cpp:106
const std::vector< unsigned int > & cell_owner() const
Definition: MeshTopology.h:151
~MeshTopology()
Destructor.
Definition: MeshTopology.cpp:51
void init_ghost(std::size_t dim, std::size_t index)
Initialise the offset index of ghost entities for this dimension.
Definition: MeshTopology.cpp:161
std::size_t dim() const
Return topological dimension.
Definition: MeshTopology.cpp:74
void init_global_indices(std::size_t dim, std::size_t size)
Definition: MeshTopology.cpp:167
bool have_shared_entities(unsigned int dim) const
Definition: MeshTopology.h:129
void set_global_index(std::size_t dim, std::size_t local_index, std::int64_t global_index)
Definition: MeshTopology.h:103
std::vector< unsigned int > & cell_owner()
Definition: MeshTopology.h:145
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:179
void init(std::size_t dim)
Initialize topology of given maximum dimension.
Definition: MeshTopology.cpp:126
size_t hash() const
Return hash based on the hash of cell-vertex connectivity.
Definition: MeshTopology.cpp:210
MeshTopology()
Create empty mesh topology.
Definition: MeshTopology.cpp:32
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
bool have_global_indices(std::size_t dim) const
Definition: MeshTopology.h:121
dolfin::MeshConnectivity & operator()(std::size_t d0, std::size_t d1)
Return connectivity for given pair of topological dimensions.
Definition: MeshTopology.cpp:174
std::map< std::int32_t, std::set< unsigned int > > & shared_entities(unsigned int dim)
Definition: MeshTopology.cpp:191
MeshTopology & operator=(const MeshTopology &topology)
Assignment.
Definition: MeshTopology.cpp:56
std::size_t size_global(std::size_t dim) const
Return global number of entities for given dimension.
Definition: MeshTopology.cpp:88
Common base class for DOLFIN variables.
Definition: Variable.h:36
Definition: adapt.h:30