Loading...
Searching...
No Matches
MeshTopology.h
// Copyright (C) 2006-2009 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-08
// Last changed: 2014-07-02
#ifndef __MESH_TOPOLOGY_H
#define __MESH_TOPOLOGY_H
#include <cstdint>
#include <map>
#include <utility>
#include <vector>
#include <dolfin/common/Variable.h>
#include "MeshConnectivity.h"
#include "MeshView.h"
namespace dolfin
{
// NOTE : Forward declaration not sufficient to use the mapping() function
// Need to include mesh view to use auto mapping = mesh.topology().mapping()
// class MeshView;
class MeshTopology : public Variable
{
public:
MeshTopology();
MeshTopology(const MeshTopology& topology);
~MeshTopology();
MeshTopology& operator= (const MeshTopology& topology);
std::size_t dim() const;
std::size_t size(std::size_t dim) const;
std::size_t size_global(std::size_t dim) const;
std::size_t ghost_offset(std::size_t dim) const;
void clear();
void clear(std::size_t d0, std::size_t d1);
void init(std::size_t dim);
void init(std::size_t dim, std::size_t local_size, std::size_t global_size);
void init_global_indices(std::size_t dim, std::size_t size);
void init_ghost(std::size_t dim, std::size_t index);
void set_global_index(std::size_t dim, std::size_t local_index,
std::int64_t global_index)
{
dolfin_assert(dim < _global_indices.size());
dolfin_assert(local_index < _global_indices[dim].size());
_global_indices[dim][local_index] = global_index;
}
const std::vector<std::int64_t>& global_indices(std::size_t d) const
{
dolfin_assert(d < _global_indices.size());
return _global_indices[d];
}
bool have_global_indices(std::size_t dim) const
{
dolfin_assert(dim < _global_indices.size());
return !_global_indices[dim].empty();
}
bool have_shared_entities(unsigned int dim) const
{ return (_shared_entities.find(dim) != _shared_entities.end()); }
std::map<std::int32_t, std::set<unsigned int> >&
shared_entities(unsigned int dim);
const std::map<std::int32_t, std::set<unsigned int> >&
shared_entities(unsigned int dim) const;
std::vector<unsigned int>& cell_owner()
{ return _cell_owner; }
const std::vector<unsigned int>& cell_owner() const
{ return _cell_owner; }
dolfin::MeshConnectivity& operator() (std::size_t d0, std::size_t d1);
const dolfin::MeshConnectivity& operator() (std::size_t d0,
std::size_t d1) const;
size_t hash() const;
std::string str(bool verbose) const;
// Developer note: std::vector is used in place of a MeshFunction
// to avoid circular dependencies in the header files
std::map<std::vector<std::size_t>,
std::pair<std::vector<std::size_t>,
std::vector<std::vector<std::size_t>>>> coloring;
// Mappings to other Mesh objects, if any
std::map<unsigned, std::shared_ptr<MeshView>> mapping() const
{ return _mapping; }
void add_mapping(const std::pair<unsigned, std::shared_ptr<MeshView>> _pair)
{ _mapping.emplace(_pair); }
private:
friend class MeshView;
// Mappings to other Mesh objects, if any
std::map<unsigned, std::shared_ptr<MeshView>> _mapping;
// Number of mesh entities for each topological dimension
std::vector<unsigned int> num_entities;
// Number of ghost indices for each topological dimension
std::vector<std::size_t> ghost_offset_index;
// Global number of mesh entities for each topological dimension
std::vector<std::size_t> global_num_entities;
// Global indices for mesh entities (empty if not set)
std::vector<std::vector<std::int64_t> > _global_indices;
// For entities of a given dimension d , maps each shared entity
// (local index) to a list of the processes sharing the vertex
std::map<unsigned int, std::map<std::int32_t, std::set<unsigned int>>>
_shared_entities;
// For cells which are "ghosted", locate the owning process,
// using a vector rather than a map,
// since ghost cells are always at the end of the range.
std::vector<unsigned int> _cell_owner;
// Connectivity for pairs of topological dimensions
std::vector<std::vector<MeshConnectivity> > connectivity;
};
}
#endif
dolfin::MeshConnectivity
Definition MeshConnectivity.h:42
dolfin::MeshTopology::size
std::size_t size(std::size_t dim) const
Return number of entities for given dimension.
Definition MeshTopology.cpp:79
dolfin::MeshTopology::str
std::string str(bool verbose) const
Return informal string representation (pretty-print).
Definition MeshTopology.cpp:215
dolfin::MeshTopology::clear
void clear()
Clear all data.
Definition MeshTopology.cpp:106
dolfin::MeshTopology::~MeshTopology
~MeshTopology()
Destructor.
Definition MeshTopology.cpp:51
dolfin::MeshTopology::init_ghost
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
dolfin::MeshTopology::dim
std::size_t dim() const
Return topological dimension.
Definition MeshTopology.cpp:74
dolfin::MeshTopology::init_global_indices
void init_global_indices(std::size_t dim, std::size_t size)
Definition MeshTopology.cpp:167
dolfin::MeshTopology::cell_owner
std::vector< unsigned int > & cell_owner()
Definition MeshTopology.h:145
dolfin::MeshTopology::have_shared_entities
bool have_shared_entities(unsigned int dim) const
Definition MeshTopology.h:129
dolfin::MeshTopology::set_global_index
void set_global_index(std::size_t dim, std::size_t local_index, std::int64_t global_index)
Definition MeshTopology.h:103
dolfin::MeshTopology::coloring
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
dolfin::MeshTopology::init
void init(std::size_t dim)
Initialize topology of given maximum dimension.
Definition MeshTopology.cpp:126
dolfin::MeshTopology::hash
size_t hash() const
Return hash based on the hash of cell-vertex connectivity.
Definition MeshTopology.cpp:210
dolfin::MeshTopology::MeshTopology
MeshTopology()
Create empty mesh topology.
Definition MeshTopology.cpp:32
dolfin::MeshTopology::cell_owner
const std::vector< unsigned int > & cell_owner() const
Definition MeshTopology.h:151
dolfin::MeshTopology::ghost_offset
std::size_t ghost_offset(std::size_t dim) const
Definition MeshTopology.cpp:97
dolfin::MeshTopology::have_global_indices
bool have_global_indices(std::size_t dim) const
Definition MeshTopology.h:121
dolfin::MeshTopology::global_indices
const std::vector< std::int64_t > & global_indices(std::size_t d) const
Definition MeshTopology.h:113
dolfin::MeshTopology::operator()
dolfin::MeshConnectivity & operator()(std::size_t d0, std::size_t d1)
Return connectivity for given pair of topological dimensions.
Definition MeshTopology.cpp:174
dolfin::MeshTopology::shared_entities
std::map< std::int32_t, std::set< unsigned int > > & shared_entities(unsigned int dim)
Definition MeshTopology.cpp:191
dolfin::MeshTopology::operator=
MeshTopology & operator=(const MeshTopology &topology)
Assignment.
Definition MeshTopology.cpp:56
dolfin::MeshTopology::size_global
std::size_t size_global(std::size_t dim) const
Return global number of entities for given dimension.
Definition MeshTopology.cpp:88
dolfin::Variable::Variable
Variable()
Create unnamed variable.
Definition Variable.cpp:31
dolfin
Definition adapt.h:30