DOLFIN
DOLFIN C++ interface
MeshEditor.h
1// Copyright (C) 2006-2012 Anders Logg
2//
3// This file is part of DOLFIN.
4//
5// DOLFIN is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// DOLFIN is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
17//
18// First added: 2006-05-16
19// Last changed: 2014-02-06
20
21#ifndef __MESH_EDITOR_H
22#define __MESH_EDITOR_H
23
24#include <vector>
25#include "CellType.h"
26#include "Mesh.h"
27
28namespace dolfin
29{
30
31 class Point;
32
35
37 {
38 public:
39
41 MeshEditor();
42
45
58 void open(Mesh& mesh, CellType::Type type, std::size_t tdim,
59 std::size_t gdim, std::size_t degree=1);
60
73 void open(Mesh& mesh, std::string type, std::size_t tdim,
74 std::size_t gdim, std::size_t degree=1);
75
88 void init_vertices(std::size_t num_vertices)
89 { init_vertices_global(num_vertices, num_vertices); }
90
97 void init_entities();
98
113 void init_vertices_global(std::size_t num_local_vertices,
114 std::size_t num_global_vertices);
115
128 void init_cells(std::size_t num_cells)
129 { init_cells_global(num_cells, num_cells); }
130
145 void init_cells_global(std::size_t num_local_cells,
146 std::size_t num_global_cells);
147
154 void add_vertex(std::size_t index, const Point& p);
155
162 void add_vertex(std::size_t index, const std::vector<double>& x);
163
170 void add_vertex(std::size_t index, double x);
171
180 void add_vertex(std::size_t index, double x, double y);
181
192 void add_vertex(std::size_t index, double x, double y, double z);
193
202 void add_vertex_global(std::size_t local_index, std::size_t global_index,
203 const Point& p);
204
213 void add_vertex_global(std::size_t local_index, std::size_t global_index,
214 const std::vector<double>& x);
215
217 void add_entity_point(std::size_t entity_dim, std::size_t order,
218 std::size_t index, const Point& p);
219
228 void add_cell(std::size_t c, std::size_t v0, std::size_t v1);
229
240 void add_cell(std::size_t c, std::size_t v0, std::size_t v1,
241 std::size_t v2);
242
255 void add_cell(std::size_t c, std::size_t v0, std::size_t v1,
256 std::size_t v2, std::size_t v3);
257
265 void add_cell(std::size_t c, const std::vector<std::size_t>& v)
266 { add_cell(c, c, v); }
267
274 template<typename T>
275 void add_cell(std::size_t c, const T& v)
276 { add_cell(c, c, v); }
277
286 template<typename T>
287 void add_cell(std::size_t local_index, std::size_t global_index,
288 const T& v)
289 {
290
291 // dolfin_assert(v.size() == _tdim + 1);
292
293 // Check vertices
294 check_vertices(v);
295
296 // Add cell
297 add_cell_common(local_index, _tdim);
298
299 // Set data
300 _mesh->_topology(_tdim, 0).set(local_index, v);
301 _mesh->_topology.set_global_index(_tdim, local_index, global_index);
302 }
303
316 void close(bool order=true);
317
318 private:
319
320 // Friends
321 friend class TetrahedronCell;
322
323 // Add vertex, common part
324 void add_vertex_common(std::size_t v, std::size_t dim);
325
326 // Add cell, common part
327 void add_cell_common(std::size_t v, std::size_t dim);
328
329 // Compute boundary indicators (exterior facets)
330 void compute_boundary_indicators();
331
332 // Clear all data
333 void clear();
334
335 // Check that vertices are in range
336 template <typename T>
337 void check_vertices(const T& v) const
338 {
339 for (std::size_t i = 0; i < v.size(); ++i)
340 {
341 if (_num_vertices > 0 && v[i] >= _num_vertices)
342 {
343 dolfin_error("MeshEditor.cpp",
344 "add cell using mesh editor",
345 "Vertex index (%d) out of range [0, %d)", v[i],
346 _num_vertices);
347 }
348 }
349 }
350
351 // The mesh
352 Mesh* _mesh;
353
354 // Topological dimension
355 std::size_t _tdim;
356
357 // Geometrical (Euclidean) dimension
358 std::size_t _gdim;
359
360 // Number of vertices
361 std::size_t _num_vertices;
362
363 // Number of cells
364 std::size_t _num_cells;
365
366 // Next available vertex
367 std::size_t next_vertex;
368
369 // Next available cell
370 std::size_t next_cell;
371
372 // Temporary storage for local cell data
373 std::vector<std::size_t> _vertices;
374
375 };
376
377}
378
379#endif
Type
Enum for different cell types.
Definition: CellType.h:51
Definition: MeshEditor.h:37
void init_cells(std::size_t num_cells)
Definition: MeshEditor.h:128
void add_vertex(std::size_t index, const Point &p)
Definition: MeshEditor.cpp:165
~MeshEditor()
Destructor.
Definition: MeshEditor.cpp:39
void init_vertices_global(std::size_t num_local_vertices, std::size_t num_global_vertices)
Definition: MeshEditor.cpp:99
void open(Mesh &mesh, CellType::Type type, std::size_t tdim, std::size_t gdim, std::size_t degree=1)
Definition: MeshEditor.cpp:44
void close(bool order=true)
Definition: MeshEditor.cpp:265
void init_entities()
Definition: MeshEditor.cpp:119
void init_vertices(std::size_t num_vertices)
Definition: MeshEditor.h:88
void add_vertex_global(std::size_t local_index, std::size_t global_index, const Point &p)
Definition: MeshEditor.cpp:202
void add_cell(std::size_t c, const T &v)
Definition: MeshEditor.h:275
void add_entity_point(std::size_t entity_dim, std::size_t order, std::size_t index, const Point &p)
Add a point in a given entity of dimension entity_dim.
Definition: MeshEditor.cpp:226
MeshEditor()
Constructor.
Definition: MeshEditor.cpp:33
void add_cell(std::size_t c, std::size_t v0, std::size_t v1)
Definition: MeshEditor.cpp:233
void add_cell(std::size_t local_index, std::size_t global_index, const T &v)
Definition: MeshEditor.h:287
void init_cells_global(std::size_t num_local_cells, std::size_t num_global_cells)
Definition: MeshEditor.cpp:145
void add_cell(std::size_t c, const std::vector< std::size_t > &v)
Definition: MeshEditor.h:265
void set_global_index(std::size_t dim, std::size_t local_index, std::int64_t global_index)
Definition: MeshTopology.h:103
Definition: Mesh.h:84
Definition: Point.h:41
This class implements functionality for tetrahedral cell meshes.
Definition: TetrahedronCell.h:41
Definition: adapt.h:30
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition: log.cpp:129