/usr/include/dolfin/mesh/Cell.h is in libdolfin-dev 2016.2.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | // Copyright (C) 2006-2015 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 Johan Hoffman 2006.
// Modified by Andre Massing 2009.
// Modified by Garth N. Wells 2010.
// Modified by Jan Blechta 2013
// Modified by Martin Alnaes, 2015
#ifndef __CELL_H
#define __CELL_H
#include <memory>
#include <dolfin/geometry/Point.h>
#include "CellType.h"
#include "Mesh.h"
#include "MeshEntity.h"
#include "MeshEntityIteratorBase.h"
#include "MeshFunction.h"
#include <dolfin/geometry/CollisionDetection.h>
#include <dolfin/geometry/IntersectionTriangulation.h>
namespace dolfin
{
/// A Cell is a _MeshEntity_ of topological codimension 0.
class Cell : public MeshEntity
{
public:
/// Create empty cell
Cell() : MeshEntity() {}
/// Create cell on given mesh with given index
///
/// *Arguments*
/// mesh (_Mesh_)
/// The mesh.
/// index (std::size_t)
/// The index.
Cell(const Mesh& mesh, std::size_t index)
: MeshEntity(mesh, mesh.topology().dim(), index) {}
/// Destructor
~Cell() {}
/// Return type of cell
CellType::Type type() const
{ return _mesh->type().cell_type(); }
/// Return number of vertices of cell
std::size_t num_vertices() const
{ return _mesh->type().num_vertices(); }
/// Compute orientation of cell
///
/// *Returns*
/// std::size_t
/// Orientation of the cell (0 is 'up'/'right', 1 is 'down'/'left')
std::size_t orientation() const
{ return _mesh->type().orientation(*this); }
/// Compute orientation of cell relative to given 'up' direction
///
/// *Arguments*
/// up (_Point_)
/// The direction defined as 'up'
///
/// *Returns*
/// std::size_t
/// Orientation of the cell (0 is 'same', 1 is 'opposite')
std::size_t orientation(const Point& up) const
{ return _mesh->type().orientation(*this, up); }
/// Compute (generalized) volume of cell
///
/// *Returns*
/// double
/// The volume of the cell.
///
/// *Example*
/// .. code-block:: c++
///
/// UnitSquare mesh(1, 1);
/// Cell cell(mesh, 0);
/// info("%g", cell.volume());
///
/// output::
///
/// 0.5
double volume() const
{ return _mesh->type().volume(*this); }
/// Compute greatest distance between any two vertices
///
/// *Returns*
/// double
/// The greatest distance between any two vertices of the cell.
///
/// *Example*
/// .. code-block:: c++
///
/// UnitSquareMesh mesh(1, 1);
/// Cell cell(mesh, 0);
/// info("%g", cell.h());
///
/// output::
///
/// 1.41421
double h() const
{ return _mesh->type().h(*this); }
/// Compute circumradius of cell
///
/// *Returns*
/// double
/// The circumradius of the cell.
///
/// *Example*
/// .. code-block:: c++
///
/// UnitSquareMesh mesh(1, 1);
/// Cell cell(mesh, 0);
/// info("%g", cell.circumradius());
///
/// output::
///
/// 0.707106
double circumradius() const
{ return _mesh->type().circumradius(*this); }
/// Compute inradius of cell
///
/// *Returns*
/// double
/// Radius of the sphere inscribed in the cell.
///
/// *Example*
/// .. code-block:: c++
///
/// UnitSquareMesh mesh(1, 1);
/// Cell cell(mesh, 0);
/// info("%g", cell.inradius());
///
/// output::
///
/// 0.29289
double inradius() const
{
// We would need facet areas
_mesh->init(_mesh->type().dim() - 1);
return _mesh->type().inradius(*this);
}
/// Compute ratio of inradius to circumradius times dim for cell.
/// Useful as cell quality measure. Returns 1. for equilateral
/// and 0. for degenerate cell.
/// See Jonathan Richard Shewchuk: What Is a Good Linear Finite Element?,
/// online: http://www.cs.berkeley.edu/~jrs/papers/elemj.pdf
///
/// *Returns*
/// double
/// topological_dimension * inradius / circumradius
///
/// *Example*
/// .. code-block:: c++
///
/// UnitSquareMesh mesh(1, 1);
/// Cell cell(mesh, 0);
/// info("%g", cell.radius_ratio());
///
/// output::
///
/// 0.828427
double radius_ratio() const
{
// We would need facet areas
_mesh->init(_mesh->type().dim() - 1);
return _mesh->type().radius_ratio(*this);
}
/// Compute squared distance to given point.
///
/// *Arguments*
/// point (_Point_)
/// The point.
/// *Returns*
/// double
/// The squared distance to the point.
double squared_distance(const Point& point) const
{ return _mesh->type().squared_distance(*this, point); }
/// Compute distance to given point.
///
/// *Arguments*
/// point (_Point_)
/// The point.
/// *Returns*
/// double
/// The distance to the point.
double distance(const Point& point) const
{
return sqrt(squared_distance(point));
}
/// Compute component i of normal of given facet with respect to the cell
///
/// *Arguments*
/// facet (std::size_t)
/// Index of facet.
/// i (std::size_t)
/// Component.
///
/// *Returns*
/// double
/// Component i of the normal of the facet.
double normal(std::size_t facet, std::size_t i) const
{ return _mesh->type().normal(*this, facet, i); }
/// Compute normal of given facet with respect to the cell
///
/// *Arguments*
/// facet (std::size_t)
/// Index of facet.
///
/// *Returns*
/// _Point_
/// Normal of the facet.
Point normal(std::size_t facet) const
{ return _mesh->type().normal(*this, facet); }
/// Compute normal to cell itself (viewed as embedded in 3D)
///
/// *Returns*
/// _Point_
/// Normal of the cell
Point cell_normal() const
{ return _mesh->type().cell_normal(*this); }
/// Compute the area/length of given facet with respect to the cell
///
/// *Arguments*
/// facet (std::size_t)
/// Index of the facet.
///
/// *Returns*
/// double
/// Area/length of the facet.
double facet_area(std::size_t facet) const
{ return _mesh->type().facet_area(*this, facet); }
/// Order entities locally
///
/// *Arguments*
/// global_vertex_indices (_std::vector<std::int64_t>_)
/// The global vertex indices.
void order(const std::vector<std::int64_t>& local_to_global_vertex_indices)
{ _mesh->type().order(*this, local_to_global_vertex_indices); }
/// Check if entities are ordered
///
/// *Arguments*
/// global_vertex_indices (_std::vector<std::size_t>)
/// The global vertex indices.
///
/// *Returns*
/// bool
/// True iff ordered.
bool ordered(const std::vector<std::int64_t>& local_to_global_vertex_indices) const
{ return _mesh->type().ordered(*this, local_to_global_vertex_indices); }
/// Check whether given point is contained in cell. This function is
/// identical to the function collides(point).
///
/// *Arguments*
/// point (_Point_)
/// The point to be checked.
///
/// *Returns*
/// bool
/// True iff point is contained in cell.
bool contains(const Point& point) const
{ return CollisionDetection::collides(*this, point); }
/// Check whether given point collides with cell
///
/// *Arguments*
/// point (_Point_)
/// The point to be checked.
///
/// *Returns*
/// bool
/// True iff point collides with cell.
bool collides(const Point& point) const
{ return CollisionDetection::collides(*this, point); }
/// Check whether given entity collides with cell
///
/// *Arguments*
/// entity (_MeshEntity_)
/// The cell to be checked.
///
/// *Returns*
/// bool
/// True iff entity collides with cell.
bool collides(const MeshEntity& entity) const
{ return CollisionDetection::collides(*this, entity); }
/// Compute triangulation of intersection with given entity
///
/// *Arguments*
/// entity (_MeshEntity_)
/// The entity with which to intersect.
///
/// *Returns*
/// std::vector<double>
/// A flattened array of simplices of dimension
/// num_simplices x num_vertices x gdim =
/// num_simplices x (tdim + 1) x gdim
std::vector<double>
triangulate_intersection(const MeshEntity& entity) const
{ return IntersectionTriangulation::triangulate_intersection(*this, entity); }
// FIXME: This function is part of a UFC transition
/// Get cell coordinate dofs (not vertex coordinates)
void get_coordinate_dofs(std::vector<double>& coordinates) const
{
const MeshGeometry& geom = _mesh->geometry();
const std::size_t gdim = geom.dim();
const std::size_t geom_degree = geom.degree();
const std::size_t num_vertices = this->num_vertices();
const unsigned int* vertices = this->entities(0);
if (geom_degree == 1)
{
coordinates.resize(num_vertices*gdim);
for (std::size_t i = 0; i < num_vertices; ++i)
for (std::size_t j = 0; j < gdim; ++j)
coordinates[i*gdim + j] = geom.x(vertices[i])[j];
}
else if (geom_degree == 2)
{
const std::size_t tdim = _mesh->topology().dim();
const std::size_t num_edges = this->num_entities(1);
const unsigned int* edges = this->entities(1);
coordinates.resize((num_vertices + num_edges)*gdim);
for (std::size_t i = 0; i < num_vertices; ++i)
for (std::size_t j = 0; j < gdim; j++)
coordinates[i*gdim + j] = geom.x(vertices[i])[j];
for (std::size_t i = 0; i < num_edges; ++i)
{
const std::size_t entity_index
= (tdim == 1) ? index() : edges[i];
const std::size_t point_index
= geom.get_entity_index(1, 0, entity_index);
for (std::size_t j = 0; j < gdim; ++j)
coordinates[(i + num_vertices)*gdim + j] = geom.x(point_index)[j];
}
}
else
{
dolfin_error("Cell.h", "get coordinate_dofs", "Unsupported mesh degree");
}
}
// FIXME: This function is part of a UFC transition
/// Get cell vertex coordinates (not coordinate dofs)
void get_vertex_coordinates(std::vector<double>& coordinates) const
{
const std::size_t gdim = _mesh->geometry().dim();
const std::size_t num_vertices = this->num_vertices();
const unsigned int* vertices = this->entities(0);
coordinates.resize(num_vertices*gdim);
for (std::size_t i = 0; i < num_vertices; i++)
for (std::size_t j = 0; j < gdim; j++)
coordinates[i*gdim + j] = _mesh->geometry().x(vertices[i])[j];
}
// FIXME: This function is part of a UFC transition
/// Fill UFC cell with miscellaneous data
void get_cell_data(ufc::cell& ufc_cell, int local_facet=-1) const
{
ufc_cell.geometric_dimension = _mesh->geometry().dim();
ufc_cell.local_facet = local_facet;
if (_mesh->cell_orientations().empty())
ufc_cell.orientation = -1;
else
{
dolfin_assert(index() < _mesh->cell_orientations().size());
ufc_cell.orientation = _mesh->cell_orientations()[index()];
}
ufc_cell.mesh_identifier = mesh_id();
ufc_cell.index = index();
}
// FIXME: This function is part of a UFC transition
/// Fill UFC cell with topology data
void get_cell_topology(ufc::cell& ufc_cell) const
{
const MeshTopology& topology = _mesh->topology();
const std::size_t tdim = topology.dim();
ufc_cell.topological_dimension = tdim;
if (_mesh->cell_orientations().empty())
ufc_cell.orientation = -1;
else
{
dolfin_assert(index() < _mesh->cell_orientations().size());
ufc_cell.orientation = _mesh->cell_orientations()[index()];
}
ufc_cell.entity_indices.resize(tdim + 1);
for (std::size_t d = 0; d < tdim; d++)
{
ufc_cell.entity_indices[d].resize(num_entities(d));
if (topology.have_global_indices(d))
{
const std::vector<std::int64_t>& global_indices
= topology.global_indices(d);
for (std::size_t i = 0; i < num_entities(d); ++i)
ufc_cell.entity_indices[d][i] = global_indices[entities(d)[i]];
}
else
{
for (std::size_t i = 0; i < num_entities(d); ++i)
ufc_cell.entity_indices[d][i] = entities(d)[i];
}
}
ufc_cell.entity_indices[tdim].resize(1);
if (topology.have_global_indices(tdim))
ufc_cell.entity_indices[tdim][0] = global_index();
else
ufc_cell.entity_indices[tdim][0] = index();
// FIXME: Using the local cell index is inconsistent with UFC, but
// necessary to make DOLFIN run
// Local cell index
ufc_cell.index = ufc_cell.entity_indices[tdim][0];
}
};
/// A CellIterator is a MeshEntityIterator of topological codimension 0.
typedef MeshEntityIteratorBase<Cell> CellIterator;
/// A CellFunction is a MeshFunction of topological codimension 0.
template <typename T> class CellFunction : public MeshFunction<T>
{
public:
CellFunction(std::shared_ptr<const Mesh> mesh)
: MeshFunction<T>(mesh, mesh->topology().dim()) {}
CellFunction(std::shared_ptr<const Mesh> mesh, const T& value)
: MeshFunction<T>(mesh, mesh->topology().dim(), value) {}
};
}
#endif
|