5
5
// Modified by Ola Skavhaug 2006.
7
7
// First added: 2006-06-21
8
// Last changed: 2008-04-21
8
// Last changed: 2008-05-28
10
10
#include <dolfin/log/dolfin_log.h>
11
11
#include <dolfin/common/Array.h>
24
25
//-----------------------------------------------------------------------------
25
26
void BoundaryComputation::computeBoundary(Mesh& mesh, BoundaryMesh& boundary)
27
computeBoundaryCommon(mesh, boundary, 0, 0);
29
//-----------------------------------------------------------------------------
30
void BoundaryComputation::computeBoundary(Mesh& mesh, BoundaryMesh& boundary,
31
MeshFunction<uint>& vertex_map)
33
computeBoundaryCommon(mesh, boundary, &vertex_map, 0);
35
//-----------------------------------------------------------------------------
36
void BoundaryComputation::computeBoundary(Mesh& mesh, BoundaryMesh& boundary,
37
MeshFunction<uint>& vertex_map,
38
MeshFunction<uint>& cell_map)
40
computeBoundaryCommon(mesh, boundary, &vertex_map, &cell_map);
42
//-----------------------------------------------------------------------------
43
void BoundaryComputation::computeBoundaryCommon(Mesh& mesh,
44
BoundaryMesh& boundary,
45
MeshFunction<uint>* vertex_map,
46
MeshFunction<uint>* cell_map)
48
28
// We iterate over all facets in the mesh and check if they are on
49
29
// the boundary. A facet is on the boundary if it is connected to
50
30
// exactly one cell.
52
32
message(1, "Computing boundary mesh.");
54
34
// Open boundary mesh for editing
35
const uint D = mesh.topology().dim();
56
37
editor.open(boundary, mesh.type().facetType(),
57
mesh.topology().dim() - 1, mesh.geometry().dim());
38
D - 1, mesh.geometry().dim());
59
40
// Generate facet - cell connectivity if not generated
60
mesh.init(mesh.topology().dim() - 1, mesh.topology().dim());
62
43
// Temporary array for assignment of indices to vertices on the boundary
63
44
const uint num_vertices = mesh.numVertices();
70
51
for (FacetIterator f(mesh); !f.end(); ++f)
72
53
// Boundary facets are connected to exactly one cell
73
if (f->numEntities(mesh.topology().dim()) == 1)
54
if (f->numEntities(D) == 1)
75
56
// Count boundary vertices and assign indices
76
57
for (VertexIterator v(*f); !v.end(); ++v)
89
70
editor.initVertices(num_boundary_vertices);
90
71
editor.initCells(num_boundary_cells);
92
// Initialize the mappings from boundary to mesh if requested
94
vertex_map->init(boundary, 0, num_boundary_vertices);
96
cell_map->init(boundary, mesh.topology().dim() - 1, num_boundary_cells);
73
// Initialize the mappings from boundary to mesh
74
MeshFunction<uint>* vertex_map = boundary.data().createMeshFunction("vertex map", 0);
75
MeshFunction<uint>* cell_map = boundary.data().createMeshFunction("cell map", D - 1);
76
dolfin_assert(vertex_map);
77
dolfin_assert(cell_map);
78
vertex_map->init(boundary, 0, num_boundary_vertices);
79
cell_map->init(boundary, D - 1, num_boundary_cells);
99
82
for (VertexIterator v(mesh); !v.end(); ++v)
116
99
for (FacetIterator f(mesh); !f.end(); ++f)
118
101
// Boundary facets are connected to exactly one cell
119
if (f->numEntities(mesh.topology().dim()) == 1)
102
if (f->numEntities(D) == 1)
121
104
// Compute new vertex numbers for cell
122
105
uint* vertices = f->entities(0);