From: Peter Munch Date: Sun, 10 Jan 2021 21:44:15 +0000 (+0100) Subject: Enabling mixed meshes in GridIn::read_vkt() amd read_msh() X-Git-Tag: v9.3.0-rc1~653^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F11501%2Fhead;p=dealii.git Enabling mixed meshes in GridIn::read_vkt() amd read_msh() --- diff --git a/source/grid/grid_in.cc b/source/grid/grid_in.cc index 50d432be0f..2eec0e3195 100644 --- a/source/grid/grid_in.cc +++ b/source/grid/grid_in.cc @@ -529,17 +529,12 @@ GridIn::read_vtk(std::istream &in) Assert(subcelldata.check_consistency(dim), ExcInternalError()); - // make sure that only either simplex or hypercube cells are available - // // TODO: the functions below (GridTools::delete_unused_vertices(), // GridTools::invert_all_cells_of_negative_grid(), - // GridReordering::reorder_cells(), - // Triangulation::create_triangulation_compatibility()) need to be - // revisited for simplex meshes - AssertThrow(dim == 1 || (is_tria_or_tet_mesh ^ is_quad_or_hex_mesh), - ExcNotImplemented()); + // GridReordering::reorder_cells()) need to be + // revisited for simplex/mixed meshes - if (dim == 1 || is_quad_or_hex_mesh) + if (dim == 1 || (is_quad_or_hex_mesh && !is_tria_or_tet_mesh)) { GridTools::delete_unused_vertices(vertices, cells, subcelldata); @@ -556,7 +551,10 @@ GridIn::read_vtk(std::istream &in) } else { - tria->create_triangulation(vertices, cells, subcelldata); + // simplex or mixed mesh + tria->create_triangulation_compatibility(vertices, + cells, + subcelldata); } } else @@ -2150,17 +2148,12 @@ GridIn::read_msh(std::istream &in) // check that we actually read some cells. AssertThrow(cells.size() > 0, ExcGmshNoCellInformation()); - // make sure that only either simplex or hypercube cells are available - // // TODO: the functions below (GridTools::delete_unused_vertices(), // GridTools::invert_all_cells_of_negative_grid(), - // GridReordering::reorder_cells(), - // Triangulation::create_triangulation_compatibility()) need to be revisited - // for simplex meshes - AssertThrow(dim == 1 || (is_tria_or_tet_mesh ^ is_quad_or_hex_mesh), - ExcNotImplemented()); + // GridReordering::reorder_cells()) need to be revisited + // for simplex/mixed meshes - if (dim == 1 || is_quad_or_hex_mesh) + if (dim == 1 || (is_quad_or_hex_mesh && !is_tria_or_tet_mesh)) { // do some clean-up on vertices... GridTools::delete_unused_vertices(vertices, cells, subcelldata); @@ -2173,7 +2166,8 @@ GridIn::read_msh(std::istream &in) } else { - tria->create_triangulation(vertices, cells, subcelldata); + // simplex or mixed mesh + tria->create_triangulation_compatibility(vertices, cells, subcelldata); } // in 1d, we also have to attach boundary ids to vertices, which does not diff --git a/source/grid/tria.cc b/source/grid/tria.cc index 964bb3b598..dc48caea96 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -481,7 +481,8 @@ namespace const SubCellData &) { for (auto &cell : cells) - std::swap(cell.vertices[2], cell.vertices[3]); + if (cell.vertices.size() == GeometryInfo<2>::vertices_per_cell) + std::swap(cell.vertices[2], cell.vertices[3]); } @@ -490,21 +491,18 @@ namespace { unsigned int tmp[GeometryInfo<3>::vertices_per_cell]; for (auto &cell : cells) - { - for (const unsigned int i : GeometryInfo<3>::vertex_indices()) - tmp[i] = cell.vertices[i]; - for (const unsigned int i : GeometryInfo<3>::vertex_indices()) - cell.vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i]; - } + if (cell.vertices.size() == GeometryInfo<3>::vertices_per_cell) + { + for (const unsigned int i : GeometryInfo<3>::vertex_indices()) + tmp[i] = cell.vertices[i]; + for (const unsigned int i : GeometryInfo<3>::vertex_indices()) + cell.vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i]; + } // now points in boundary quads - std::vector>::iterator boundary_quad = - subcelldata.boundary_quads.begin(); - std::vector>::iterator end_quad = - subcelldata.boundary_quads.end(); - for (unsigned int quad_no = 0; boundary_quad != end_quad; - ++boundary_quad, ++quad_no) - std::swap(boundary_quad->vertices[2], boundary_quad->vertices[3]); + for (auto &boundary_quad : subcelldata.boundary_quads) + if (boundary_quad.vertices.size() == GeometryInfo<2>::vertices_per_cell) + std::swap(boundary_quad.vertices[2], boundary_quad.vertices[3]); }