35
35
SubMesh::SubMesh(const Mesh& mesh, const SubDomain& sub_domain)
37
37
// Create mesh function and mark sub domain
38
MeshFunction<uint> sub_domains(mesh, mesh.topology().dim());
38
MeshFunction<std::size_t> sub_domains(mesh, mesh.topology().dim());
40
40
sub_domain.mark(sub_domains, 1);
45
45
//-----------------------------------------------------------------------------
46
46
SubMesh::SubMesh(const Mesh& mesh,
47
const MeshFunction<uint>& sub_domains, uint sub_domain)
47
const MeshFunction<std::size_t>& sub_domains, std::size_t sub_domain)
50
50
init(mesh, sub_domains, sub_domain);
57
57
//-----------------------------------------------------------------------------
58
58
void SubMesh::init(const Mesh& mesh,
59
const MeshFunction<uint>& sub_domains, uint sub_domain)
59
const MeshFunction<std::size_t>& sub_domains, std::size_t sub_domain)
61
61
// Open mesh for editing
64
64
mesh.topology().dim(), mesh.geometry().dim());
67
std::set<std::size_t> cells;
68
68
for (CellIterator cell(mesh); !cell.end(); ++cell)
70
70
if (sub_domains[*cell] == sub_domain)
74
74
// Map to keep track of new local indices for vertices
75
std::map<uint, uint> local_vertex_indices;
75
std::map<std::size_t, std::size_t> local_vertex_indices;
78
78
editor.init_cells(cells.size());
79
uint current_cell = 0;
80
uint current_vertex = 0;
81
for (std::set<uint>::iterator cell_it = cells.begin();
79
std::size_t current_cell = 0;
80
std::size_t current_vertex = 0;
81
for (std::set<std::size_t>::iterator cell_it = cells.begin();
82
82
cell_it != cells.end(); ++cell_it)
84
std::vector<uint> cell_vertices;
84
std::vector<std::size_t> cell_vertices;
85
85
Cell cell(mesh, *cell_it);
86
86
for (VertexIterator vertex(cell); !vertex.end(); ++vertex)
88
const uint parent_vertex_index = vertex->index();
89
uint local_vertex_index = 0;
90
std::map<uint, uint>::iterator vertex_it
88
const std::size_t parent_vertex_index = vertex->index();
89
std::size_t local_vertex_index = 0;
90
std::map<std::size_t, std::size_t>::iterator vertex_it
91
91
= local_vertex_indices.find(parent_vertex_index);
92
92
if (vertex_it != local_vertex_indices.end())
94
93
local_vertex_index = vertex_it->second;
98
96
local_vertex_index = current_vertex++;
107
105
editor.init_vertices(local_vertex_indices.size());
108
for (std::map<uint, uint>::iterator it = local_vertex_indices.begin();
106
for (std::map<std::size_t, std::size_t>::iterator it = local_vertex_indices.begin();
109
107
it != local_vertex_indices.end(); ++it)
111
109
Vertex vertex(mesh, it->first);
112
110
if (MPI::num_processes() > 1)
113
111
error("SubMesh::init not working in parallel");
114
113
// FIXME: Get global vertex index
115
114
editor.add_vertex(it->second, vertex.point());
121
120
// Build local-to-parent mapping for vertices
122
boost::shared_ptr<MeshFunction<unsigned int> > parent_vertex_indices
121
boost::shared_ptr<MeshFunction<std::size_t> > parent_vertex_indices
123
122
= data().create_mesh_function("parent_vertex_indices", 0);
124
for (std::map<uint, uint>::iterator it = local_vertex_indices.begin();
123
for (std::map<std::size_t, std::size_t>::iterator it = local_vertex_indices.begin();
125
124
it != local_vertex_indices.end(); ++it)
126
126
(*parent_vertex_indices)[it->second] = it->first;
128
129
//-----------------------------------------------------------------------------