Loading...
Searching...
No Matches
MeshEditor.h
// 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;
class MeshEditor
{
public:
MeshEditor();
~MeshEditor();
void open(Mesh& mesh, CellType::Type type, std::size_t tdim,
std::size_t gdim, std::size_t degree=1);
void open(Mesh& mesh, std::string type, std::size_t tdim,
std::size_t gdim, std::size_t degree=1);
void init_vertices(std::size_t num_vertices)
{ init_vertices_global(num_vertices, num_vertices); }
void init_entities();
void init_vertices_global(std::size_t num_local_vertices,
std::size_t num_global_vertices);
void init_cells(std::size_t num_cells)
{ init_cells_global(num_cells, num_cells); }
void init_cells_global(std::size_t num_local_cells,
std::size_t num_global_cells);
void add_vertex(std::size_t index, const Point& p);
void add_vertex(std::size_t index, const std::vector<double>& x);
void add_vertex(std::size_t index, double x);
void add_vertex(std::size_t index, double x, double y);
void add_vertex(std::size_t index, double x, double y, double z);
void add_vertex_global(std::size_t local_index, std::size_t global_index,
const Point& p);
void add_vertex_global(std::size_t local_index, std::size_t global_index,
const std::vector<double>& x);
void add_entity_point(std::size_t entity_dim, std::size_t order,
std::size_t index, const Point& p);
void add_cell(std::size_t c, std::size_t v0, std::size_t v1);
void add_cell(std::size_t c, std::size_t v0, std::size_t v1,
std::size_t v2);
void add_cell(std::size_t c, std::size_t v0, std::size_t v1,
std::size_t v2, std::size_t v3);
void add_cell(std::size_t c, const std::vector<std::size_t>& v)
{ add_cell(c, c, v); }
template<typename T>
void add_cell(std::size_t c, const T& v)
{ add_cell(c, c, v); }
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);
}
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
dolfin::CellType::Type
Type
Enum for different cell types.
Definition CellType.h:51
dolfin::MeshEditor::init_cells
void init_cells(std::size_t num_cells)
Definition MeshEditor.h:128
dolfin::MeshEditor::add_vertex
void add_vertex(std::size_t index, const Point &p)
Definition MeshEditor.cpp:165
dolfin::MeshEditor::~MeshEditor
~MeshEditor()
Destructor.
Definition MeshEditor.cpp:39
dolfin::MeshEditor::init_vertices_global
void init_vertices_global(std::size_t num_local_vertices, std::size_t num_global_vertices)
Definition MeshEditor.cpp:99
dolfin::MeshEditor::open
void open(Mesh &mesh, CellType::Type type, std::size_t tdim, std::size_t gdim, std::size_t degree=1)
Definition MeshEditor.cpp:44
dolfin::MeshEditor::close
void close(bool order=true)
Definition MeshEditor.cpp:265
dolfin::MeshEditor::init_entities
void init_entities()
Definition MeshEditor.cpp:119
dolfin::MeshEditor::init_vertices
void init_vertices(std::size_t num_vertices)
Definition MeshEditor.h:88
dolfin::MeshEditor::add_vertex_global
void add_vertex_global(std::size_t local_index, std::size_t global_index, const Point &p)
Definition MeshEditor.cpp:202
dolfin::MeshEditor::add_cell
void add_cell(std::size_t c, const T &v)
Definition MeshEditor.h:275
dolfin::MeshEditor::add_entity_point
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
dolfin::MeshEditor::MeshEditor
MeshEditor()
Constructor.
Definition MeshEditor.cpp:33
dolfin::MeshEditor::add_cell
void add_cell(std::size_t c, std::size_t v0, std::size_t v1)
Definition MeshEditor.cpp:233
dolfin::MeshEditor::add_cell
void add_cell(std::size_t local_index, std::size_t global_index, const T &v)
Definition MeshEditor.h:287
dolfin::MeshEditor::init_cells_global
void init_cells_global(std::size_t num_local_cells, std::size_t num_global_cells)
Definition MeshEditor.cpp:145
dolfin::MeshEditor::add_cell
void add_cell(std::size_t c, const std::vector< std::size_t > &v)
Definition MeshEditor.h:265
dolfin::Mesh
Definition Mesh.h:84
dolfin::Point
Definition Point.h:41
dolfin::TetrahedronCell
This class implements functionality for tetrahedral cell meshes.
Definition TetrahedronCell.h:41
dolfin
Definition adapt.h:30
dolfin::dolfin_error
void dolfin_error(std::string location, std::string task, std::string reason,...)
Definition log.cpp:129