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