本文整理汇总了C++中MeshEditor::init_vertices_global方法的典型用法代码示例。如果您正苦于以下问题:C++ MeshEditor::init_vertices_global方法的具体用法?C++ MeshEditor::init_vertices_global怎么用?C++ MeshEditor::init_vertices_global使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MeshEditor
的用法示例。
在下文中一共展示了MeshEditor::init_vertices_global方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: p_refine
//-----------------------------------------------------------------------------
void dolfin::p_refine(Mesh& refined_mesh, const Mesh& mesh)
{
MeshEditor editor;
if (mesh.geometry().degree() != 1)
{
dolfin_error("refine.cpp",
"increase polynomial degree of mesh",
"Currently only linear -> quadratic is supported");
}
const CellType::Type cell_type = mesh.type().cell_type();
if (cell_type != CellType::Type::triangle
and cell_type != CellType::Type::tetrahedron
and cell_type != CellType::Type::interval)
{
dolfin_error("refine.cpp",
"increase polynomial degree of mesh",
"Unsupported cell type");
}
const std::size_t tdim = mesh.topology().dim();
const std::size_t gdim = mesh.geometry().dim();
editor.open(refined_mesh, cell_type, tdim, gdim, 2);
// Copy over mesh
editor.init_vertices_global(mesh.num_entities(0), mesh.num_entities_global(0));
for (VertexIterator v(mesh); !v.end(); ++v)
editor.add_vertex(v->index(), v->point());
editor.init_cells_global(mesh.num_entities(tdim), mesh.num_entities_global(tdim));
std::vector<std::size_t> verts(tdim + 1);
for (CellIterator c(mesh); !c.end(); ++c)
{
std::copy(c->entities(0), c->entities(0) + tdim + 1, verts.begin());
editor.add_cell(c->index(), verts);
}
// Initialise edges
editor.init_entities();
// Add points at centres of edges
for (EdgeIterator e(refined_mesh); !e.end(); ++e)
editor.add_entity_point(1, 0, e->index(), e->midpoint());
editor.close();
}
示例2: Mesh
//-----------------------------------------------------------------------------
UnitTriangleMesh::UnitTriangleMesh() : Mesh()
{
// Receive mesh according to parallel policy
if (MPI::is_receiver(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
}
// Open mesh for editing
MeshEditor editor;
editor.open(*this, CellType::triangle, 2, 2);
// Create vertices
editor.init_vertices_global(3, 3);
std::vector<double> x(2);
x[0] = 0.0; x[1] = 0.0;
editor.add_vertex(0, x);
x[0] = 1.0; x[1] = 0.0;
editor.add_vertex(1, x);
x[0] = 0.0; x[1] = 1.0;
editor.add_vertex(2, x);
// Create cells
editor.init_cells_global(1, 1);
std::vector<std::size_t> cell_data(3);
cell_data[0] = 0; cell_data[1] = 1; cell_data[2] = 2;
editor.add_cell(0, cell_data);
// Close mesh editor
editor.close();
// Broadcast mesh according to parallel policy
if (MPI::is_broadcaster(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
}
}
示例3: Mesh
//-----------------------------------------------------------------------------
UnitDiscMesh::UnitDiscMesh(MPI_Comm comm, std::size_t n,
std::size_t degree, std::size_t gdim)
: Mesh(comm)
{
dolfin_assert(n > 0);
dolfin_assert(gdim == 2 or gdim == 3);
dolfin_assert(degree == 1 or degree == 2);
MeshEditor editor;
editor.open(*this, 2, gdim, degree);
editor.init_vertices_global(1 + 3*n*(n + 1),
1 + 3*n*(n + 1));
std::size_t c = 0;
editor.add_vertex(c, Point(0,0,0));
++c;
for (std::size_t i = 1; i <= n; ++i)
for (std::size_t j = 0; j < 6*i; ++j)
{
double r = (double)i/(double)n;
double th = 2*M_PI*(double)j/(double)(6*i);
double x = r*cos(th);
double y = r*sin(th);
editor.add_vertex(c, Point(x, y, 0));
++c;
}
editor.init_cells(6*n*n);
c = 0;
std::size_t base_i = 0;
std::size_t row_i = 1;
for (std::size_t i = 1; i <= n; ++i)
{
std::size_t base_m = base_i;
base_i = 1 + 3*i*(i - 1);
std::size_t row_m = row_i;
row_i = 6*i;
for (std::size_t k = 0; k != 6; ++k)
for (std::size_t j = 0; j < (i*2 - 1); ++j)
{
std::size_t i0, i1, i2;
if (j%2 == 0)
{
i0 = base_i + (k*i + j/2)%row_i;
i1 = base_i + (k*i + j/2 + 1)%row_i;
i2 = base_m + (k*(i-1) + j/2)%row_m;
}
else
{
i0 = base_m + (k*(i-1) + j/2)%row_m;
i1 = base_m + (k*(i-1) + j/2 + 1)%row_m;
i2 = base_i + (k*i + j/2 + 1)%row_i;
}
editor.add_cell(c, i0, i1, i2);
++c;
}
}
// Initialise entities required for this degree polynomial mesh
// and allocate space for the point coordinate data
if (degree == 2)
{
editor.init_entities();
for (EdgeIterator e(*this); !e.end(); ++e)
{
Point v0 = Vertex(*this, e->entities(0)[0]).point();
Point v1 = Vertex(*this, e->entities(0)[1]).point();
Point pt = e->midpoint();
if (std::abs(v0.norm() - 1.0) < 1e-6 and
std::abs(v1.norm() - 1.0) < 1e-6)
pt *= v0.norm()/pt.norm();
// Add Edge-based point
editor.add_entity_point(1, 0, e->index(), pt);
}
}
editor.close();
}
示例4: compute_boundary
//.........这里部分代码省略.........
boundary.topology().shared_entities(0)[local_boundary_index]
= other_processes;
// FIXME: More sophisticated ownership determination
if (min_process < owner)
owner = min_process;
}
const std::size_t global_mesh_index
= mesh.topology().global_indices(0)[local_mesh_index];
global_index_owner[global_mesh_index] = owner;
// Update counts
if (owner == my_rank)
num_owned_vertices++;
num_boundary_vertices++;
}
}
// Count boundary cells (facets of the mesh)
num_boundary_cells++;
}
}
}
// Initiate boundary topology
/*
boundary.topology().init(0, num_boundary_vertices,
MPI::sum(mesh.mpi_comm(), num_owned_vertices));
boundary.topology().init(D - 1, num_boundary_cells,
MPI::sum(mesh.mpi_comm(), num_boundary_cells));
*/
// Specify number of vertices and cells
editor.init_vertices_global(num_boundary_vertices,
MPI::sum(mesh.mpi_comm(), num_owned_vertices));
editor.init_cells_global(num_boundary_cells, MPI::sum(mesh.mpi_comm(),
num_boundary_cells));
// Write vertex map
MeshFunction<std::size_t>& vertex_map = boundary.entity_map(0);
if (num_boundary_vertices > 0)
{
vertex_map.init(reference_to_no_delete_pointer(boundary), 0,
num_boundary_vertices);
}
std::map<std::size_t, std::size_t>::const_iterator it;
for (it = boundary_vertices.begin(); it != boundary_vertices.end(); ++it)
vertex_map[it->second] = it->first;
// Get vertex ownership distribution, and find index to start global
// numbering from
std::vector<std::size_t> ownership_distribution(num_processes);
MPI::all_gather(mesh.mpi_comm(), num_owned_vertices, ownership_distribution);
std::size_t start_index = 0;
for (std::size_t j = 0; j < my_rank; j++)
start_index += ownership_distribution[j];
// Set global indices of owned vertices, request global indices for
// vertices owned elsewhere
std::map<std::size_t, std::size_t> global_indices;
std::vector<std::vector<std::size_t>> request_global_indices(num_processes);
std::size_t current_index = start_index;
for (std::size_t local_boundary_index = 0;
local_boundary_index<num_boundary_vertices; local_boundary_index++)
{
示例5: coarsen_cell
//.........这里部分代码省略.........
vert2remove_idx = edge_vertex[1];
}
else
{
// No vertices to remove, cannot coarsen
cout << "all vertices forbidden" << endl;
editor.close();
return false;
}
Vertex vertex_to_remove(mesh, vert2remove_idx);
// Remove cells around edge
num_cells_to_remove = 0;
for (CellIterator cn(shortest_edge); !cn.end(); ++cn)
{
cell_to_remove[cn->index()] = true;
num_cells_to_remove++;
// Update cell map
old2new_cell[cn->index()] = -1;
}
// Regenerate cells around vertex
for (CellIterator cn(vertex_to_remove); !cn.end(); ++cn)
{
cell_to_regenerate[cn->index()] = true;
// Update cell map (will be filled in with correct index)
old2new_cell[cn->index()] = -1;
}
// Specify number of vertices and cells
editor.init_vertices_global(num_vertices - 1, num_vertices - 1);
editor.init_cells_global(num_cells - num_cells_to_remove,
num_cells - num_cells_to_remove);
cout << "Number of cells in old mesh: " << num_cells << "; to remove: " <<
num_cells_to_remove << endl;
// Add old vertices
std::size_t vertex = 0;
for(VertexIterator v(mesh); !v.end(); ++v)
{
if(vertex_to_remove.index() == v->index())
old2new_vertex[v->index()] = -1;
else
{
//cout << "adding old vertex at: " << v->point() << endl;
old2new_vertex[v->index()] = vertex;
editor.add_vertex(vertex, v->point());
vertex++;
}
}
// Add old unrefined cells
std::size_t cv_idx;
std::size_t current_cell = 0;
std::vector<std::size_t> cell_vertices(cell_type.num_entities(0));
for (CellIterator c(mesh); !c.end(); ++c)
{
if (cell_to_remove[*c] == false && cell_to_regenerate[*c] == false)
{
cv_idx = 0;
for (VertexIterator v(*c); !v.end(); ++v)
cell_vertices[cv_idx++] = old2new_vertex[v->index()];
示例6: refine
//-----------------------------------------------------------------------------
void UniformMeshRefinement::refine(Mesh& refined_mesh,
const Mesh& mesh)
{
not_working_in_parallel("UniformMeshRefinement::refine");
log(TRACE, "Refining simplicial mesh uniformly.");
// Check that refined_mesh and mesh are not the same
if (&refined_mesh == &mesh)
{
dolfin_error("UniformMeshRefinement.cpp",
"refine mesh",
"Refined_mesh and mesh point to the same object");
}
// Generate cell - edge connectivity if not generated
mesh.init(mesh.topology().dim(), 1);
// Generate edge - vertex connectivity if not generated
mesh.init(1, 0);
// Mesh needs to be ordered (so we can pick right combination of vertices/edges)
if (!mesh.ordered())
dolfin_error("UniformMeshRefinement.cpp",
"refine mesh",
"Mesh is not ordered according to the UFC numbering convention, consider calling mesh.order()");
// Get cell type
const CellType& cell_type = mesh.type();
// Open new mesh for editing
MeshEditor editor;
editor.open(refined_mesh, cell_type.cell_type(),
mesh.topology().dim(), mesh.geometry().dim());
// Get size of mesh
const std::size_t num_vertices = mesh.size(0);
const std::size_t num_edges = mesh.size(1);
const std::size_t num_cells = mesh.size(mesh.topology().dim());
// Specify number of vertices and cells
editor.init_vertices_global(num_vertices + num_edges, num_vertices + num_edges);
editor.init_cells_global(ipow(2, mesh.topology().dim())*num_cells,
ipow(2, mesh.topology().dim())*num_cells);
// Add old vertices
std::size_t vertex = 0;
for (VertexIterator v(mesh); !v.end(); ++v)
{
editor.add_vertex(vertex, v->point());
vertex++;
}
// Add new vertices
for (EdgeIterator e(mesh); !e.end(); ++e)
{
editor.add_vertex(vertex, e->midpoint());
vertex++;
}
// Add cells
std::size_t current_cell = 0;
for (CellIterator c(mesh); !c.end(); ++c)
cell_type.refine_cell(*c, editor, current_cell);
// Close editor
editor.close();
// Make sure that mesh is ordered after refinement
//refined_mesh.order();
}
示例7: build
//-----------------------------------------------------------------------------
void IntervalMesh::build(std::size_t nx, double a, double b)
{
// Receive mesh according to parallel policy
if (MPI::is_receiver(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
}
if (std::abs(a - b) < DOLFIN_EPS)
{
dolfin_error("Interval.cpp",
"create interval",
"Length of interval is zero. Consider checking your dimensions");
}
if (b < a)
{
dolfin_error("Interval.cpp",
"create interval",
"Length of interval is negative. Consider checking the order of your arguments");
}
if (nx < 1)
{
dolfin_error("Interval.cpp",
"create interval",
"Number of points on interval is (%d), it must be at least 1", nx);
}
rename("mesh", "Mesh of the interval (a, b)");
// Open mesh for editing
MeshEditor editor;
editor.open(*this, CellType::interval, 1, 1);
// Create vertices and cells:
editor.init_vertices_global((nx+1), (nx+1));
editor.init_cells_global(nx, nx);
// Create main vertices:
for (std::size_t ix = 0; ix <= nx; ix++)
{
const std::vector<double>
x(1, a + (static_cast<double>(ix)*(b - a)/static_cast<double>(nx)));
editor.add_vertex(ix, x);
}
// Create intervals
for (std::size_t ix = 0; ix < nx; ix++)
{
std::vector<std::size_t> cell(2);
cell[0] = ix; cell[1] = ix + 1;
editor.add_cell(ix, cell);
}
// Close mesh editor
editor.close();
// Broadcast mesh according to parallel policy
if (MPI::is_broadcaster(this->mpi_comm()))
{
std::cout << "Building mesh (dist 0a)" << std::endl;
MeshPartitioning::build_distributed_mesh(*this);
std::cout << "Building mesh (dist 1a)" << std::endl;
return;
}
}
示例8: Mesh
//-----------------------------------------------------------------------------
UnitHexMesh::UnitHexMesh(MPI_Comm comm, std::size_t nx, std::size_t ny,
std::size_t nz) : Mesh(comm)
{
// Receive mesh according to parallel policy
if (MPI::is_receiver(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
}
MeshEditor editor;
editor.open(*this, CellType::hexahedron, 3, 3);
// Create vertices and cells:
editor.init_vertices_global((nx + 1)*(ny + 1)*(nz + 1),
(nx + 1)*(ny + 1)*(nz + 1));
editor.init_cells_global(nx*ny*nz, nx*ny*nz);
// Storage for vertices
std::vector<double> x(3);
const double a = 0.0;
const double b = 1.0;
const double c = 0.0;
const double d = 1.0;
const double e = 0.0;
const double f = 1.0;
// Create main vertices:
std::size_t vertex = 0;
for (std::size_t iz = 0; iz <= nz; iz++)
{
x[2] = e + ((static_cast<double>(iz))*(f - e)/static_cast<double>(nz));
for (std::size_t iy = 0; iy <= ny; iy++)
{
x[1] = c + ((static_cast<double>(iy))*(d - c)/static_cast<double>(ny));
for (std::size_t ix = 0; ix <= nx; ix++)
{
x[0] = a + ((static_cast<double>(ix))*(b - a)/static_cast<double>(nx));
editor.add_vertex(vertex, x);
vertex++;
}
}
}
// Create cuboids
std::size_t cell = 0;
std::vector<std::size_t> v(8);
for (std::size_t iz = 0; iz < nz; iz++)
for (std::size_t iy = 0; iy < ny; iy++)
for (std::size_t ix = 0; ix < nx; ix++)
{
v[0] = (iz*(ny + 1) + iy)*(nx + 1) + ix;
v[1] = v[0] + 1;
v[2] = v[0] + (nx + 1);
v[3] = v[1] + (nx + 1);
v[4] = v[0] + (nx + 1)*(ny + 1);
v[5] = v[1] + (nx + 1)*(ny + 1);
v[6] = v[2] + (nx + 1)*(ny + 1);
v[7] = v[3] + (nx + 1)*(ny + 1);
editor.add_cell(cell, v);
++cell;
}
// Close mesh editor
editor.close();
// Broadcast mesh according to parallel policy
if (MPI::is_broadcaster(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
}
}
示例9: read_mesh
//-----------------------------------------------------------------------------
void XMLMesh::read_mesh(Mesh& mesh, const pugi::xml_node mesh_node)
{
// Get cell type and geometric dimension
const std::string cell_type_str = mesh_node.attribute("celltype").value();
const std::size_t gdim = mesh_node.attribute("dim").as_uint();
// Get topological dimension
boost::scoped_ptr<CellType> cell_type(CellType::create(cell_type_str));
const std::size_t tdim = cell_type->dim();
// Create mesh for editing
MeshEditor editor;
editor.open(mesh, cell_type_str, tdim, gdim);
// Get vertices xml node
pugi::xml_node xml_vertices = mesh_node.child("vertices");
dolfin_assert(xml_vertices);
// Get number of vertices and init editor
const std::size_t num_vertices = xml_vertices.attribute("size").as_uint();
editor.init_vertices_global(num_vertices, num_vertices);
// Iterate over vertices and add to mesh
Point p;
for (pugi::xml_node_iterator it = xml_vertices.begin();
it != xml_vertices.end(); ++it)
{
const std::size_t index = it->attribute("index").as_uint();
p[0] = it->attribute("x").as_double();
p[1] = it->attribute("y").as_double();
p[2] = it->attribute("z").as_double();
editor.add_vertex(index, p);
}
// Get cells node
pugi::xml_node xml_cells = mesh_node.child("cells");
dolfin_assert(xml_cells);
// Get number of cells and init editor
const std::size_t num_cells = xml_cells.attribute("size").as_uint();
editor.init_cells_global(num_cells, num_cells);
// Create list of vertex index attribute names
const unsigned int num_vertices_per_cell = cell_type->num_vertices(tdim);
std::vector<std::string> v_str(num_vertices_per_cell);
for (std::size_t i = 0; i < num_vertices_per_cell; ++i)
v_str[i] = "v" + boost::lexical_cast<std::string, unsigned int>(i);
// Iterate over cells and add to mesh
std::vector<std::size_t> v(num_vertices_per_cell);
for (pugi::xml_node_iterator it = xml_cells.begin(); it != xml_cells.end();
++it)
{
const std::size_t index = it->attribute("index").as_uint();
for (unsigned int i = 0; i < num_vertices_per_cell; ++i)
v[i] = it->attribute(v_str[i].c_str()).as_uint();
editor.add_cell(index, v);
}
// Close mesh editor
editor.close();
}
示例10: renumber_by_color
//-----------------------------------------------------------------------------
dolfin::Mesh MeshRenumbering::renumber_by_color(const Mesh& mesh,
const std::vector<std::size_t> coloring_type)
{
// Start timer
Timer timer("Renumber mesh by color");
// Get some some mesh
const std::size_t tdim = mesh.topology().dim();
const std::size_t gdim = mesh.geometry().dim();
const std::size_t num_local_vertices = mesh.size(0);
const std::size_t num_global_vertices = mesh.size_global(0);
const std::size_t num_local_cells = mesh.size(tdim);
const std::size_t num_global_cells = mesh.size_global(tdim);
// Check that requested coloring is a cell coloring
if (coloring_type[0] != tdim)
{
dolfin_error("MeshRenumbering.cpp",
"renumber mesh by color",
"Coloring is not a cell coloring: only cell colorings are supported");
}
// Compute renumbering
std::vector<double> new_coordinates;
std::vector<std::size_t> new_connections;
MeshRenumbering::compute_renumbering(mesh, coloring_type, new_coordinates,
new_connections);
// Create new mesh
Mesh new_mesh;
// Create mesh editor
MeshEditor editor;
editor.open(new_mesh, mesh.type().cell_type(), tdim, gdim);
editor.init_cells_global(num_local_cells, num_global_cells);
editor.init_vertices_global(num_local_vertices, num_global_vertices);
// Add vertices
dolfin_assert(new_coordinates.size() == num_local_vertices*gdim);
for (std::size_t i = 0; i < num_local_vertices; ++i)
{
std::vector<double> x(gdim);
for (std::size_t j = 0; j < gdim; ++j)
x[j] = new_coordinates[i*gdim + j];
editor.add_vertex(i, x);
}
cout << "Done adding vertices" << endl;
// Add cells
dolfin_assert(new_coordinates.size() == num_local_vertices*gdim);
const std::size_t vertices_per_cell = mesh.type().num_entities(0);
for (std::size_t i = 0; i < num_local_cells; ++i)
{
std::vector<std::size_t> c(vertices_per_cell);
std::copy(new_connections.begin() + i*vertices_per_cell,
new_connections.begin() + i*vertices_per_cell + vertices_per_cell,
c.begin());
editor.add_cell(i, c);
}
editor.close();
cout << "Close editor" << endl;
// Initialise coloring data
typedef std::map<std::vector<std::size_t>, std::pair<std::vector<std::size_t>,
std::vector<std::vector<std::size_t>>>>::const_iterator
ConstMeshColoringData;
// Get old coloring
ConstMeshColoringData mesh_coloring
= mesh.topology().coloring.find(coloring_type);
if (mesh_coloring == mesh.topology().coloring.end())
{
dolfin_error("MeshRenumbering.cpp",
"renumber mesh by color",
"Requested mesh coloring has not been computed");
}
// Get old coloring data
const std::vector<std::size_t>& colors = mesh_coloring->second.first;
const std::vector<std::vector<std::size_t>>&
entities_of_color = mesh_coloring->second.second;
dolfin_assert(colors.size() == num_local_cells);
dolfin_assert(!entities_of_color.empty());
const std::size_t num_colors = entities_of_color.size();
// New coloring data
dolfin_assert(new_mesh.topology().coloring.empty());
std::vector<std::size_t> new_colors(colors.size());
std::vector<std::vector<std::size_t>> new_entities_of_color(num_colors);
std::size_t current_cell = 0;
for (std::size_t color = 0; color < num_colors; color++)
{
// Get the array of cell indices of current color
const std::vector<std::size_t>& colored_cells = entities_of_color[color];
std::vector<std::size_t>& new_colored_cells = new_entities_of_color[color];
//.........这里部分代码省略.........
示例11: build
//-----------------------------------------------------------------------------
void RectangleMesh::build(const Point& p0, const Point& p1,
std::size_t nx, std::size_t ny,
std::string diagonal)
{
// Receive mesh according to parallel policy
if (MPI::is_receiver(this->mpi_comm()))
{
MeshPartitioning::build_distributed_mesh(*this);
return;
}
// Check options
if (diagonal != "left" && diagonal != "right" && diagonal != "right/left"
&& diagonal != "left/right" && diagonal != "crossed")
{
dolfin_error("RectangleMesh.cpp",
"create rectangle",
"Unknown mesh diagonal definition: allowed options are \"left\", \"right\", \"left/right\", \"right/left\" and \"crossed\"");
}
// Extract minimum and maximum coordinates
const double x0 = std::min(p0.x(), p1.x());
const double x1 = std::max(p0.x(), p1.x());
const double y0 = std::min(p0.y(), p1.y());
const double y1 = std::max(p0.y(), p1.y());
const double a = x0;
const double b = x1;
const double c = y0;
const double d = y1;
if (std::abs(x0 - x1) < DOLFIN_EPS || std::abs(y0 - y1) < DOLFIN_EPS)
{
dolfin_error("Rectangle.cpp",
"create rectangle",
"Rectangle seems to have zero width, height or depth. Consider checking your dimensions");
}
if (nx < 1 || ny < 1)
{
dolfin_error("RectangleMesh.cpp",
"create rectangle",
"Rectangle has non-positive number of vertices in some dimension: number of vertices must be at least 1 in each dimension");
}
rename("mesh", "Mesh of the unit square (a,b) x (c,d)");
// Open mesh for editing
MeshEditor editor;
editor.open(*this, CellType::triangle, 2, 2);
// Create vertices and cells:
if (diagonal == "crossed")
{
editor.init_vertices_global((nx + 1)*(ny + 1) + nx*ny,
(nx + 1)*(ny + 1) + nx*ny);
editor.init_cells_global(4*nx*ny, 4*nx*ny);
}
else
{
editor.init_vertices_global((nx + 1)*(ny + 1), (nx + 1)*(ny + 1));
editor.init_cells_global(2*nx*ny, 2*nx*ny);
}
// Storage for vertices
std::vector<double> x(2);
// Create main vertices:
std::size_t vertex = 0;
for (std::size_t iy = 0; iy <= ny; iy++)
{
x[1] = c + ((static_cast<double>(iy))*(d - c)/static_cast<double>(ny));
for (std::size_t ix = 0; ix <= nx; ix++)
{
x[0] = a + ((static_cast<double>(ix))*(b - a)/static_cast<double>(nx));
editor.add_vertex(vertex, x);
vertex++;
}
}
// Create midpoint vertices if the mesh type is crossed
if (diagonal == "crossed")
{
for (std::size_t iy = 0; iy < ny; iy++)
{
x[1] = c +(static_cast<double>(iy) + 0.5)*(d - c)/static_cast<double>(ny);
for (std::size_t ix = 0; ix < nx; ix++)
{
x[0] = a + (static_cast<double>(ix) + 0.5)*(b - a)/static_cast<double>(nx);
editor.add_vertex(vertex, x);
vertex++;
}
}
}
// Create triangles
std::size_t cell = 0;
if (diagonal == "crossed")
{
boost::multi_array<std::size_t, 2> cells(boost::extents[4][3]);
//.........这里部分代码省略.........
示例12: init
//-----------------------------------------------------------------------------
void SubMesh::init(const Mesh& mesh,
const std::vector<std::size_t>& sub_domains,
std::size_t sub_domain)
{
// Open mesh for editing
MeshEditor editor;
const std::size_t D = mesh.topology().dim();
editor.open(*this, mesh.type().cell_type(), D,
mesh.geometry().dim());
// Build set of cells that are in sub-mesh
std::vector<bool> parent_cell_in_subdomain(mesh.num_cells(), false);
std::set<std::size_t> submesh_cells;
for (CellIterator cell(mesh); !cell.end(); ++cell)
{
if (sub_domains[cell->index()] == sub_domain)
{
parent_cell_in_subdomain[cell->index()] = true;
submesh_cells.insert(cell->index());
}
}
// Map from parent vertex index to submesh vertex index
std::map<std::size_t, std::size_t> parent_to_submesh_vertex_indices;
// Map from submesh cell to parent cell
std::vector<std::size_t> submesh_cell_parent_indices;
submesh_cell_parent_indices.reserve(submesh_cells.size());
// Vector from parent cell index to submesh cell index
std::vector<std::size_t> parent_to_submesh_cell_indices(mesh.num_cells(), 0);
// Add sub-mesh cells
editor.init_cells_global(submesh_cells.size(), submesh_cells.size());
std::size_t current_cell = 0;
std::size_t current_vertex = 0;
for (std::set<std::size_t>::iterator cell_it = submesh_cells.begin();
cell_it != submesh_cells.end(); ++cell_it)
{
// Data structure to hold new vertex indices for cell
std::vector<std::size_t> cell_vertices;
// Create cell
Cell cell(mesh, *cell_it);
// Iterate over cell vertices
for (VertexIterator vertex(cell); !vertex.end(); ++vertex)
{
const std::size_t parent_vertex_index = vertex->index();
// Look for parent vertex in map
std::map<std::size_t, std::size_t>::iterator vertex_it
= parent_to_submesh_vertex_indices.find(parent_vertex_index);
// If vertex has been inserted, get new index, otherwise
// increment and insert
std::size_t submesh_vertex_index = 0;
if (vertex_it != parent_to_submesh_vertex_indices.end())
submesh_vertex_index = vertex_it->second;
else
{
submesh_vertex_index = current_vertex++;
parent_to_submesh_vertex_indices[parent_vertex_index]
= submesh_vertex_index;
}
// Add vertex to list of cell vertices (new indexing)
cell_vertices.push_back(submesh_vertex_index);
}
// Add parent cell index to list
submesh_cell_parent_indices.push_back(cell.index());
// Store parent cell -> submesh cell indices
parent_to_submesh_cell_indices[cell.index()] = current_cell;
// Add cell to mesh
editor.add_cell(current_cell++, cell_vertices);
}
// Vector to hold submesh vertex -> parent vertex
std::vector<std::size_t> parent_vertex_indices;
parent_vertex_indices.resize(parent_to_submesh_vertex_indices.size());
// Initialise mesh editor
editor.init_vertices_global(parent_to_submesh_vertex_indices.size(),
parent_to_submesh_vertex_indices.size());
// Add vertices
for (std::map<std::size_t, std::size_t>::iterator it
= parent_to_submesh_vertex_indices.begin();
it != parent_to_submesh_vertex_indices.end(); ++it)
{
Vertex vertex(mesh, it->first);
if (MPI::size(mesh.mpi_comm()) > 1)
error("SubMesh::init not working in parallel");
// FIXME: Get global vertex index
editor.add_vertex(it->second, vertex.point());
//.........这里部分代码省略.........