Loading...
Searching...
No Matches
MeshConnectivity.h
// Copyright (C) 2006-2007 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// First added: 2006-05-09
// Last changed: 2010-11-28
#ifndef __MESH_CONNECTIVITY_H
#define __MESH_CONNECTIVITY_H
#include <vector>
#include <dolfin/log/log.h>
#include <cstdint>
namespace dolfin
{
class MeshConnectivity
{
public:
MeshConnectivity(std::size_t d0, std::size_t d1);
MeshConnectivity(const MeshConnectivity& connectivity);
~MeshConnectivity();
const MeshConnectivity& operator= (const MeshConnectivity& connectivity);
bool empty() const
{ return _connections.empty(); }
std::size_t size() const
{ return _connections.size(); }
std::size_t size(std::size_t entity) const
{
return (entity + 1) < index_to_position.size()
? index_to_position[entity + 1] - index_to_position[entity] : 0;
}
std::size_t size_global(std::size_t entity) const
{
if (_num_global_connections.empty())
return size(entity);
else
{
dolfin_assert(entity < _num_global_connections.size());
return _num_global_connections[entity];
}
}
const unsigned int* operator() (std::size_t entity) const
{
return (entity + 1) < index_to_position.size()
? &_connections[index_to_position[entity]] : 0;
}
const std::vector<unsigned int>& operator() () const
{ return _connections; }
void clear();
void init(std::size_t num_entities, std::size_t num_connections);
void init(std::vector<std::size_t>& num_connections);
void set(std::size_t entity, std::size_t connection, std::size_t pos);
template<typename T>
void set(std::size_t entity, const T& connections)
{
dolfin_assert((entity + 1) < index_to_position.size());
dolfin_assert(connections.size()
== index_to_position[entity + 1]-index_to_position[entity]);
// Copy data
std::copy(connections.begin(), connections.end(),
_connections.begin() + index_to_position[entity]);
}
void set(std::size_t entity, std::size_t* connections);
template <typename T>
void set(const T& connections)
{
// Clear old data if any
clear();
// Initialize offsets and compute total size
index_to_position.resize(connections.size() + 1);
std::int32_t size = 0;
for (std::size_t e = 0; e < connections.size(); e++)
{
index_to_position[e] = size;
size += connections[e].size();
}
index_to_position[connections.size()] = size;
// Initialize connections
_connections.reserve(size);
for (auto e = connections.begin(); e != connections.end(); ++e)
_connections.insert(_connections.end(), e->begin(), e->end());
_connections.shrink_to_fit();
}
void
set_global_size(const std::vector<unsigned int>& num_global_connections)
{
dolfin_assert(num_global_connections.size()
== index_to_position.size() - 1);
_num_global_connections = num_global_connections;
}
std::size_t hash() const;
std::string str(bool verbose) const;
private:
// Dimensions (only used for pretty-printing)
std::size_t _d0, _d1;
// Connections for all entities stored as a contiguous array
std::vector<unsigned int> _connections;
// Global number of connections for all entities (possibly not
// computed)
std::vector<unsigned int> _num_global_connections;
// Position of first connection for each entity (using local index)
std::vector<unsigned int> index_to_position;
};
}
#endif
dolfin::MeshConnectivity::size
std::size_t size() const
Return total number of connections.
Definition MeshConnectivity.h:62
dolfin::MeshConnectivity::operator()
const std::vector< unsigned int > & operator()() const
Return contiguous array of connections for all entities.
Definition MeshConnectivity.h:92
dolfin::MeshConnectivity::hash
std::size_t hash() const
Hash of connections.
Definition MeshConnectivity.cpp:128
dolfin::MeshConnectivity::set
void set(std::size_t entity, const T &connections)
Definition MeshConnectivity.h:112
dolfin::MeshConnectivity::empty
bool empty() const
Return true if the total number of connections is equal to zero.
Definition MeshConnectivity.h:58
dolfin::MeshConnectivity::set
void set(const T &connections)
Definition MeshConnectivity.h:130
dolfin::MeshConnectivity::clear
void clear()
Clear all data.
Definition MeshConnectivity.cpp:61
dolfin::MeshConnectivity::MeshConnectivity
MeshConnectivity(std::size_t d0, std::size_t d1)
Create empty connectivity between given dimensions (d0 – d1).
Definition MeshConnectivity.cpp:31
dolfin::MeshConnectivity::str
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition MeshConnectivity.cpp:135
dolfin::MeshConnectivity::set_global_size
void set_global_size(const std::vector< unsigned int > &num_global_connections)
Set global number of connections for all local entities.
Definition MeshConnectivity.h:155
dolfin::MeshConnectivity::size
std::size_t size(std::size_t entity) const
Return number of connections for given entity.
Definition MeshConnectivity.h:66
dolfin::MeshConnectivity::set
void set(std::size_t entity, std::size_t connection, std::size_t pos)
Set given connection for given entity.
Definition MeshConnectivity.cpp:107
dolfin::MeshConnectivity::operator=
const MeshConnectivity & operator=(const MeshConnectivity &connectivity)
Assignment.
Definition MeshConnectivity.cpp:49
dolfin::MeshConnectivity::~MeshConnectivity
~MeshConnectivity()
Destructor.
Definition MeshConnectivity.cpp:43
dolfin::MeshConnectivity::init
void init(std::size_t num_entities, std::size_t num_connections)
Definition MeshConnectivity.cpp:67
dolfin::MeshConnectivity::size_global
std::size_t size_global(std::size_t entity) const
Return global number of connections for given entity.
Definition MeshConnectivity.h:73
dolfin
Definition adapt.h:30