15
15
// You should have received a copy of the GNU Lesser General Public License
16
16
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
18
// Modified by Benjamin Kehlet, 2012
18
20
// First added: 2006-05-16
19
// Last changed: 2012-09-27
21
// Last changed: 2012-10-30
21
23
#include <dolfin/log/dolfin_log.h>
22
24
#include <dolfin/parameter/dolfin_parameter.h>
65
67
//-----------------------------------------------------------------------------
66
void MeshEditor::open(Mesh& mesh, CellType::Type type, uint tdim, uint gdim)
68
void MeshEditor::open(Mesh& mesh, CellType::Type type, std::size_t tdim, std::size_t gdim)
68
70
// Clear old mesh data
84
86
mesh._domains.init(tdim);
86
88
// Initialize temporary storage for local cell data
87
vertices.resize(mesh.type().num_vertices(tdim));
88
std::fill(vertices.begin(), vertices.end(), 0);
89
vertices = std::vector<std::size_t>(mesh.type().num_vertices(tdim), 0);
90
91
//-----------------------------------------------------------------------------
91
void MeshEditor::open(Mesh& mesh, std::string type, uint tdim, uint gdim)
92
void MeshEditor::open(Mesh& mesh, std::string type, std::size_t tdim, std::size_t gdim)
93
94
if (type == "point")
94
95
open(mesh, CellType::point, tdim, gdim);
140
141
mesh->_topology(tdim, 0).init(num_cells, mesh->type().num_vertices(tdim));
142
143
//-----------------------------------------------------------------------------
143
void MeshEditor::add_vertex(uint index, const Point& p)
144
void MeshEditor::add_vertex(std::size_t index, const Point& p)
145
146
add_vertex_global(index, index, p);
147
148
//-----------------------------------------------------------------------------
148
void MeshEditor::add_vertex(uint index, const std::vector<double>& x)
149
void MeshEditor::add_vertex(std::size_t index, const std::vector<double>& x)
150
151
add_vertex_global(index, index, x);
152
153
//-----------------------------------------------------------------------------
153
void MeshEditor::add_vertex(uint index, double x)
154
void MeshEditor::add_vertex(std::size_t index, double x)
155
156
dolfin_assert(gdim == 1);
156
157
std::vector<double> p(1);
158
159
add_vertex(index, p);
160
161
//-----------------------------------------------------------------------------
161
void MeshEditor::add_vertex(uint index, double x, double y)
162
void MeshEditor::add_vertex(std::size_t index, double x, double y)
163
164
dolfin_assert(gdim == 2);
164
165
std::vector<double> p(2);
167
168
add_vertex(index, p);
169
170
//-----------------------------------------------------------------------------
170
void MeshEditor::add_vertex(uint index, double x, double y, double z)
171
void MeshEditor::add_vertex(std::size_t index, double x, double y, double z)
172
173
dolfin_assert(gdim == 3);
173
174
std::vector<double> p(3);
177
178
add_vertex(index, p);
179
180
//-----------------------------------------------------------------------------
180
void MeshEditor::add_vertex_global(uint local_index, uint global_index,
181
void MeshEditor::add_vertex_global(std::size_t local_index,
182
std::size_t global_index,
183
185
// Geometric dimension
184
const uint gdim = mesh->geometry().dim();
186
const std::size_t gdim = mesh->geometry().dim();
187
189
add_vertex_common(local_index, gdim);
192
194
mesh->_topology.set_global_index(0, local_index, global_index);
194
196
//-----------------------------------------------------------------------------
195
void MeshEditor::add_vertex_global(uint local_index, uint global_index,
197
void MeshEditor::add_vertex_global(std::size_t local_index,
198
std::size_t global_index,
196
199
const std::vector<double>& x)
203
206
mesh->_topology.set_global_index(0, local_index, global_index);
205
208
//-----------------------------------------------------------------------------
206
void MeshEditor::add_cell(uint c, uint v0, uint v1)
209
void MeshEditor::add_cell(std::size_t c, std::size_t v0, std::size_t v1)
208
211
dolfin_assert(tdim == 1);
209
std::vector<uint> vertices(2);
212
std::vector<std::size_t> vertices(2);
210
213
vertices[0] = v0;
211
214
vertices[1] = v1;
212
215
add_cell(c, c, vertices);
214
217
//-----------------------------------------------------------------------------
215
void MeshEditor::add_cell(uint c, uint v0, uint v1, uint v2)
218
void MeshEditor::add_cell(std::size_t c, std::size_t v0, std::size_t v1,
217
221
dolfin_assert(tdim == 2);
218
std::vector<uint> vertices(3);
222
std::vector<std::size_t> vertices(3);
219
223
vertices[0] = v0;
220
224
vertices[1] = v1;
221
225
vertices[2] = v2;
222
226
add_cell(c, c, vertices);
224
228
//-----------------------------------------------------------------------------
225
void MeshEditor::add_cell(uint c, uint v0, uint v1, uint v2, uint v3)
229
void MeshEditor::add_cell(std::size_t c, std::size_t v0, std::size_t v1,
230
std::size_t v2, std::size_t v3)
227
232
dolfin_assert(tdim == 3);
228
std::vector<uint> vertices(4);
233
std::vector<std::size_t> vertices(4);
229
234
vertices[0] = v0;
230
235
vertices[1] = v1;
231
236
vertices[2] = v2;
233
238
add_cell(c, c, vertices);
235
240
//-----------------------------------------------------------------------------
236
void MeshEditor::add_cell(uint c, const std::vector<uint>& v)
241
void MeshEditor::add_cell(std::size_t c, const std::vector<std::size_t>& v)
238
243
add_cell(c, c, v);
240
245
//-----------------------------------------------------------------------------
241
void MeshEditor::add_cell(uint local_index, uint global_index,
242
const std::vector<uint>& v)
246
void MeshEditor::add_cell(std::size_t local_index, std::size_t global_index,
247
const std::vector<std::size_t>& v)
244
249
dolfin_assert(v.size() == tdim + 1);
358
363
vertices.clear();
360
365
//-----------------------------------------------------------------------------
361
void MeshEditor::check_vertices(const std::vector<uint>& v) const
366
void MeshEditor::check_vertices(const std::vector<std::size_t>& v) const
363
for (uint i = 0; i < v.size(); ++i)
368
for (std::size_t i = 0; i < v.size(); ++i)
365
370
if (num_vertices > 0 && v[i] >= num_vertices)