21 #ifndef __MESH_CONNECTIVITY_H 22 #define __MESH_CONNECTIVITY_H 25 #include <dolfin/log/log.h> 57 {
return _connections.empty(); }
61 {
return _connections.size(); }
64 std::size_t
size(std::size_t entity)
const 66 return (entity + 1) < index_to_position.size()
67 ? index_to_position[entity + 1] - index_to_position[entity] : 0;
73 if (_num_global_connections.empty())
77 dolfin_assert(entity < _num_global_connections.size());
78 return _num_global_connections[entity];
83 const unsigned int*
operator() (std::size_t entity)
const 85 return (entity + 1) < index_to_position.size()
86 ? &_connections[index_to_position[entity]] : 0;
91 {
return _connections; }
98 void init(std::size_t num_entities, std::size_t num_connections);
102 void init(std::vector<std::size_t>& num_connections);
105 void set(std::size_t entity, std::size_t connection, std::size_t pos);
110 void set(std::size_t entity,
const T& connections)
112 dolfin_assert((entity + 1) < index_to_position.size());
113 dolfin_assert(connections.size()
114 == index_to_position[entity + 1]-index_to_position[entity]);
117 std::copy(connections.begin(), connections.end(),
118 _connections.begin() + index_to_position[entity]);
122 void set(std::size_t entity, std::size_t* connections);
127 template <
typename T>
128 void set(
const T& connections)
134 index_to_position.resize(connections.size() + 1);
135 std::int32_t
size = 0;
136 for (std::size_t e = 0; e < connections.size(); e++)
138 index_to_position[e] =
size;
139 size += connections[e].size();
141 index_to_position[connections.size()] =
size;
144 _connections.reserve(size);
145 for (
auto e = connections.begin(); e != connections.end(); ++e)
146 _connections.insert(_connections.end(), e->begin(), e->end());
148 _connections.shrink_to_fit();
155 dolfin_assert(num_global_connections.size()
156 == index_to_position.size() - 1);
157 _num_global_connections = num_global_connections;
161 std::size_t
hash()
const;
164 std::string
str(
bool verbose)
const;
169 std::size_t _d0, _d1;
172 std::vector<unsigned int> _connections;
176 std::vector<unsigned int> _num_global_connections;
179 std::vector<unsigned int> index_to_position;
const MeshConnectivity & operator=(const MeshConnectivity &connectivity)
Assignment.
Definition: MeshConnectivity.cpp:49
std::size_t size() const
Return total number of connections.
Definition: MeshConnectivity.h:60
std::size_t size(std::size_t entity) const
Return number of connections for given entity.
Definition: MeshConnectivity.h:64
std::size_t size_global(std::size_t entity) const
Return global number of connections for given entity.
Definition: MeshConnectivity.h:71
void set_global_size(const std::vector< unsigned int > &num_global_connections)
Set global number of connections for all local entities.
Definition: MeshConnectivity.h:153
void clear()
Clear all data.
Definition: MeshConnectivity.cpp:61
Definition: MeshConnectivity.h:39
std::size_t hash() const
Hash of connections.
Definition: MeshConnectivity.cpp:128
MeshConnectivity(std::size_t d0, std::size_t d1)
Create empty connectivity between given dimensions (d0 – d1)
Definition: MeshConnectivity.cpp:31
~MeshConnectivity()
Destructor.
Definition: MeshConnectivity.cpp:43
bool empty() const
Return true if the total number of connections is equal to zero.
Definition: MeshConnectivity.h:56
const std::vector< unsigned int > & operator()() const
Return contiguous array of connections for all entities.
Definition: MeshConnectivity.h:90
std::string str(bool verbose) const
Return informal string representation (pretty-print)
Definition: MeshConnectivity.cpp:135
void init(std::size_t num_entities, std::size_t num_connections)
Definition: MeshConnectivity.cpp:67