Loading...
Searching...
No Matches
MeshEntity.h
// Copyright (C) 2006-2011 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/>.
//
// Modified by Andre Massing, 2009.
// Modified by Garth N. Wells, 2012.
//
// First added: 2006-05-11
// Last changed: 2014-07-02
#ifndef __MESH_ENTITY_H
#define __MESH_ENTITY_H
#include <cmath>
#include <iostream>
#include <dolfin/geometry/Point.h>
#include "Mesh.h"
namespace dolfin
{
//class Mesh;
class Point;
class MeshEntity
{
public:
MeshEntity() : _mesh(0), _dim(0), _local_index(0) {}
MeshEntity(const Mesh& mesh, std::size_t dim, std::size_t index);
virtual ~MeshEntity();
void init(const Mesh& mesh, std::size_t dim, std::size_t index);
bool operator==(const MeshEntity& e) const
{
return (_mesh == e._mesh && _dim == e._dim
&& _local_index == e._local_index);
}
bool operator!=(const MeshEntity& e) const
{ return !operator==(e); }
const Mesh& mesh() const
{ return *_mesh; }
std::size_t dim() const
{ return _dim; }
std::size_t index() const
{ return _local_index; }
std::int64_t global_index() const
{
const std::vector<std::int64_t>& global_indices
= _mesh->topology().global_indices(_dim);
if (global_indices.empty())
return -1;
return global_indices[_local_index];
}
std::size_t num_entities(std::size_t dim) const
{ return _mesh->topology()(_dim, dim).size(_local_index); }
std::size_t num_global_entities(std::size_t dim) const
{ return _mesh->topology()(_dim, dim).size_global(_local_index); }
const unsigned int* entities(std::size_t dim) const
{
const unsigned int* initialized_mesh_entities
= _mesh->topology()(_dim, dim)(_local_index);
dolfin_assert(initialized_mesh_entities);
return initialized_mesh_entities;
}
std::size_t mesh_id() const
{ return _mesh->id(); }
bool incident(const MeshEntity& entity) const;
std::size_t index(const MeshEntity& entity) const;
Point midpoint() const;
bool is_ghost() const
{ return (_local_index >= _mesh->topology().ghost_offset(_dim)); }
std::set<unsigned int> sharing_processes() const
{
const std::map<std::int32_t, std::set<unsigned int>>& sharing_map
= _mesh->topology().shared_entities(_dim);
const auto map_it = sharing_map.find(_local_index);
if (map_it == sharing_map.end())
return std::set<unsigned int>();
else
return map_it->second;
}
bool is_shared() const
{
if (_mesh->topology().have_shared_entities(_dim))
{
const std::map<std::int32_t, std::set<unsigned int>>& sharing_map
= _mesh->topology().shared_entities(_dim);
return (sharing_map.find(_local_index) != sharing_map.end());
}
return false;
}
unsigned int owner() const;
// Note: Not a subclass of Variable for efficiency!
std::string str(bool verbose) const;
protected:
// Friends
friend class MeshEntityIterator;
template<typename T> friend class MeshEntityIteratorBase;
friend class SubsetIterator;
// The mesh
Mesh const * _mesh;
// Topological dimension
std::size_t _dim;
// Local index of entity within topological dimension
std::size_t _local_index;
};
}
#endif
dolfin::MeshEntityIteratorBase
Base class for MeshEntityIterators.
Definition MeshEntityIteratorBase.h:37
dolfin::MeshEntityIterator
Definition MeshEntityIterator.h:65
dolfin::MeshEntity
Definition MeshEntity.h:43
dolfin::MeshEntity::sharing_processes
std::set< unsigned int > sharing_processes() const
Definition MeshEntity.h:213
dolfin::MeshEntity::incident
bool incident(const MeshEntity &entity) const
Definition MeshEntity.cpp:69
dolfin::MeshEntity::mesh
const Mesh & mesh() const
Definition MeshEntity.h:99
dolfin::MeshEntity::init
void init(const Mesh &mesh, std::size_t dim, std::size_t index)
Definition MeshEntity.cpp:39
dolfin::MeshEntity::midpoint
Point midpoint() const
Definition MeshEntity.cpp:115
dolfin::MeshEntity::is_shared
bool is_shared() const
Definition MeshEntity.h:227
dolfin::MeshEntity::entities
const unsigned int * entities(std::size_t dim) const
Definition MeshEntity.h:163
dolfin::MeshEntity::dim
std::size_t dim() const
Definition MeshEntity.h:106
dolfin::MeshEntity::MeshEntity
MeshEntity()
Default Constructor.
Definition MeshEntity.h:47
dolfin::MeshEntity::index
std::size_t index() const
Definition MeshEntity.h:113
dolfin::MeshEntity::owner
unsigned int owner() const
Definition MeshEntity.cpp:146
dolfin::MeshEntity::is_ghost
bool is_ghost() const
Definition MeshEntity.h:207
dolfin::MeshEntity::~MeshEntity
virtual ~MeshEntity()
Destructor.
Definition MeshEntity.cpp:64
dolfin::MeshEntity::num_entities
std::size_t num_entities(std::size_t dim) const
Definition MeshEntity.h:140
dolfin::MeshEntity::str
std::string str(bool verbose) const
Definition MeshEntity.cpp:162
dolfin::MeshEntity::num_global_entities
std::size_t num_global_entities(std::size_t dim) const
Definition MeshEntity.h:152
dolfin::MeshEntity::mesh_id
std::size_t mesh_id() const
Definition MeshEntity.h:175
dolfin::MeshEntity::operator==
bool operator==(const MeshEntity &e) const
Definition MeshEntity.h:79
dolfin::MeshEntity::operator!=
bool operator!=(const MeshEntity &e) const
Definition MeshEntity.h:92
dolfin::MeshEntity::global_index
std::int64_t global_index() const
Definition MeshEntity.h:122
dolfin::Mesh
Definition Mesh.h:84
dolfin::Point
Definition Point.h:41
dolfin::SubsetIterator
Definition SubsetIterator.h:42
dolfin
Definition adapt.h:30