/usr/include/dolfin/mesh/MeshEditor.h is in libdolfin-dev 2017.2.0.post0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | // Copyright (C) 2006-2012 Anders Logg
//
// This file is part of DOLFIN.
//
// DOLFIN is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// DOLFIN is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with DOLFIN. If not, see <http://www.gnu.org/licenses/>.
//
// First added: 2006-05-16
// Last changed: 2014-02-06
#ifndef __MESH_EDITOR_H
#define __MESH_EDITOR_H
#include <vector>
#include "CellType.h"
#include "Mesh.h"
namespace dolfin
{
class Point;
/// A simple mesh editor for creating simplicial meshes in 1D, 2D
/// and 3D.
class MeshEditor
{
public:
/// Constructor
MeshEditor();
/// Destructor
~MeshEditor();
/// Open mesh of given cell type, topological and geometrical dimension
///
/// @param mesh (_Mesh_)
/// The mesh to open.
/// @param type (CellType::Type)
/// Cell type.
/// @param tdim (std::size_t)
/// The topological dimension.
/// @param gdim (std::size_t)
/// The geometrical dimension.
/// @param degree (std::size_t)
/// The polynomial degree.
void open(Mesh& mesh, CellType::Type type, std::size_t tdim,
std::size_t gdim, std::size_t degree=1);
/// Open mesh of given cell type, topological and geometrical dimension
///
/// @param mesh (_Mesh_)
/// The mesh to open.
/// @param type (std::string)
/// Cell type.
/// @param tdim (std::size_t)
/// The topological dimension.
/// @param gdim (std::size_t)
/// The geometrical dimension.
/// @param degree (std::size_t)
/// The polynomial degree.
void open(Mesh& mesh, std::string type, std::size_t tdim,
std::size_t gdim, std::size_t degree=1);
/// Specify number of vertices (serial version)
///
/// @param num_vertices (std::size_t)
/// The number of vertices.
///
/// @code{.cpp}
///
/// Mesh mesh;
/// MeshEditor editor;
/// editor.open(mesh, 2, 2);
/// editor.init_vertices(9);
/// @endcode
void init_vertices(std::size_t num_vertices)
{ init_vertices_global(num_vertices, num_vertices); }
/// Initialise entities in MeshGeometry
///
/// Create required Edges and Faces for the current polynomial degree
/// in the mesh topology, so that points can be added for them.
/// In order to initialise entities, cells must all be added first.
///
void init_entities();
/// Specify number of vertices (distributed version)
///
/// @param num_local_vertices (std::size_t)
/// The number of vertices on this process.
/// @param num_global_vertices (std::size_t)
/// The number of vertices in distributed mesh.
///
/// @code{.cpp}
///
/// Mesh mesh;
/// MeshEditor editor;
/// editor.open(mesh, 2, 2);
/// editor.init_vertices(4, 8);
/// @endcode
void init_vertices_global(std::size_t num_local_vertices,
std::size_t num_global_vertices);
/// Specify number of cells (serial version)
///
/// @param num_cells (std::size_t)
/// The number of cells.
///
/// @code{.cpp}
///
/// Mesh mesh;
/// MeshEditor editor;
/// editor.open(mesh, 2, 2);
/// editor.init_cells(8);
/// @endcode
void init_cells(std::size_t num_cells)
{ init_cells_global(num_cells, num_cells); }
/// Specify number of cells (distributed version)
///
/// @param num_local_cells (std::size_t)
/// The number of local cells.
/// @param num_global_cells (std::size_t)
/// The number of cells in distributed mesh.
///
/// @code{.cpp}
///
/// Mesh mesh;
/// MeshEditor editor;
/// editor.open(mesh, 2, 2);
/// editor.init_cells(2, 6);
/// @endcode
void init_cells_global(std::size_t num_local_cells,
std::size_t num_global_cells);
/// Add vertex v at given point p
///
/// @param index (std::size_t)
/// The vertex (index).
/// @param p (_Point_)
/// The point.
void add_vertex(std::size_t index, const Point& p);
/// Add vertex v at given coordinate x
///
/// @param index (std::size_t)
/// The vertex (index).
/// @param x (std::vector<double>)
/// The x-coordinates.
void add_vertex(std::size_t index, const std::vector<double>& x);
/// Add vertex v at given point x (for a 1D mesh)
///
/// @param index (std::size_t)
/// The vertex (index).
/// @param x (double)
/// The x-coordinate.
void add_vertex(std::size_t index, double x);
/// Add vertex v at given point (x, y) (for a 2D mesh)
///
/// @param index (std::size_t)
/// The vertex (index).
/// @param x (double)
/// The x-coordinate.
/// @param y (double)
/// The y-coordinate.
void add_vertex(std::size_t index, double x, double y);
/// Add vertex v at given point (x, y, z) (for a 3D mesh)
///
/// @param index (std::size_t)
/// The vertex (index).
/// @param x (double)
/// The x-coordinate.
/// @param y (double)
/// The y-coordinate.
/// @param z (double)
/// The z-coordinate.
void add_vertex(std::size_t index, double x, double y, double z);
/// Add vertex v at given point p
///
/// @param local_index (std::size_t)
/// The vertex (local index).
/// @param global_index (std::size_t)
/// The vertex (global_index).
/// @param p (_Point_)
/// The point.
void add_vertex_global(std::size_t local_index, std::size_t global_index,
const Point& p);
/// Add vertex v at given coordinate x
///
/// @param local_index (std::size_t)
/// The vertex (local index).
/// @param global_index (std::size_t)
/// The vertex (global_index).
/// @param x (std::vector<double>)
/// The x-coordinates.
void add_vertex_global(std::size_t local_index, std::size_t global_index,
const std::vector<double>& x);
/// Add a point in a given entity of dimension entity_dim
void add_entity_point(std::size_t entity_dim, std::size_t order,
std::size_t index, const Point& p);
/// Add cell with given vertices (1D)
///
/// @param c (std::size_t)
/// The cell (index).
/// @param v0 (std::vector<std::size_t>)
/// The first vertex (local index).
/// @param v1 (std::vector<std::size_t>)
/// The second vertex (local index).
void add_cell(std::size_t c, std::size_t v0, std::size_t v1);
/// Add cell with given vertices (2D)
///
/// @param c (std::size_t)
/// The cell (index).
/// @param v0 (std::vector<std::size_t>)
/// The first vertex (local index).
/// @param v1 (std::vector<std::size_t>)
/// The second vertex (local index).
/// @param v2 (std::vector<std::size_t>)
/// The third vertex (local index).
void add_cell(std::size_t c, std::size_t v0, std::size_t v1,
std::size_t v2);
/// Add cell with given vertices (3D)
///
/// @param c (std::size_t)
/// The cell (index).
/// @param v0 (std::vector<std::size_t>)
/// The first vertex (local index).
/// @param v1 (std::vector<std::size_t>)
/// The second vertex (local index).
/// @param v2 (std::vector<std::size_t>)
/// The third vertex (local index).
/// @param v3 (std::vector<std::size_t>)
/// The fourth vertex (local index).
void add_cell(std::size_t c, std::size_t v0, std::size_t v1,
std::size_t v2, std::size_t v3);
/// Add cell with given vertices (non-templated version for Python
/// interface)
///
/// @param c (std::size_t)
/// The cell (index).
/// @param v (std::vector<std::size_t>)
/// The vertex indices (local indices)
void add_cell(std::size_t c, const std::vector<std::size_t>& v)
{ add_cell(c, c, v); }
/// Add cell with given vertices
///
/// @param c (std::size_t)
/// The cell (index).
/// @param v (typename T)
/// The vertex indices (local indices)
template<typename T>
void add_cell(std::size_t c, const T& v)
{ add_cell(c, c, v); }
/// Add cell with given vertices
///
/// @param local_index (std::size_t)
/// The cell (index).
/// @param global_index (std::size_t)
/// The global (user) cell index.
/// @param v (std::vector<std::size_t>)
/// The vertex indices (local indices)
template<typename T>
void add_cell(std::size_t local_index, std::size_t global_index,
const T& v)
{
// dolfin_assert(v.size() == _tdim + 1);
// Check vertices
check_vertices(v);
// Add cell
add_cell_common(local_index, _tdim);
// Set data
_mesh->_topology(_tdim, 0).set(local_index, v);
_mesh->_topology.set_global_index(_tdim, local_index, global_index);
}
/// Close mesh, finish editing, and order entities locally
///
/// @param order (bool)
/// Order entities locally if true. Default values is true.
///
/// @code{.cpp}
///
/// MeshEditor editor;
/// editor.open(mesh, 2, 2);
/// ...
/// editor.close()
/// @endcode
void close(bool order=true);
private:
// Friends
friend class TetrahedronCell;
// Add vertex, common part
void add_vertex_common(std::size_t v, std::size_t dim);
// Add cell, common part
void add_cell_common(std::size_t v, std::size_t dim);
// Compute boundary indicators (exterior facets)
void compute_boundary_indicators();
// Clear all data
void clear();
// Check that vertices are in range
template <typename T>
void check_vertices(const T& v) const
{
for (std::size_t i = 0; i < v.size(); ++i)
{
if (_num_vertices > 0 && v[i] >= _num_vertices)
{
dolfin_error("MeshEditor.cpp",
"add cell using mesh editor",
"Vertex index (%d) out of range [0, %d)", v[i],
_num_vertices);
}
}
}
// The mesh
Mesh* _mesh;
// Topological dimension
std::size_t _tdim;
// Geometrical (Euclidean) dimension
std::size_t _gdim;
// Number of vertices
std::size_t _num_vertices;
// Number of cells
std::size_t _num_cells;
// Next available vertex
std::size_t next_vertex;
// Next available cell
std::size_t next_cell;
// Temporary storage for local cell data
std::vector<std::size_t> _vertices;
};
}
#endif
|