From 70e6ddbe5943e5a07d7b06cfc7320698610e842e Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Tue, 17 Apr 2018 10:21:34 +0200 Subject: [PATCH] Disentagle Manifold and Boundary ids. Co-authored-by: Jean-Paul Pelteret --- .../deal.II/grid/tria_accessor.templates.h | 16 +- tests/manifold/tria_boundary_id_01.cc | 160 ++++++++++++++ tests/manifold/tria_boundary_id_01.output | 200 ++++++++++++++++++ 3 files changed, 361 insertions(+), 15 deletions(-) create mode 100644 tests/manifold/tria_boundary_id_01.cc create mode 100644 tests/manifold/tria_boundary_id_01.output diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index 49fbefe3fb..1ad679cc06 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -2026,21 +2026,7 @@ const Manifold & TriaAccessor::get_manifold () const { Assert (this->used(), TriaAccessorExceptions::ExcCellNotUsed()); - - // Get the default (manifold_id) - const types::manifold_id mi = this->objects().manifold_id[this->present_index]; - - // In case this is not valid, check - // the boundary id, after having - // casted it to a manifold id - if (mi == numbers::invalid_manifold_id) - return this->tria->get_manifold(structdim < dim ? - this->objects().boundary_or_material_id[this->present_index].boundary_id: - dim < spacedim ? - this->objects().boundary_or_material_id[this->present_index].material_id: - numbers::invalid_manifold_id); - else - return this->tria->get_manifold(mi); + return this->tria->get_manifold(this->manifold_id()); } diff --git a/tests/manifold/tria_boundary_id_01.cc b/tests/manifold/tria_boundary_id_01.cc new file mode 100644 index 0000000000..a47d9aaa98 --- /dev/null +++ b/tests/manifold/tria_boundary_id_01.cc @@ -0,0 +1,160 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2003 - 2017 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, 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 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +// Test that an overlap in boundary and manifold IDs does not lead to +// the boundary being treated as a (curved) manifold upon refinement. + +#include "../tests.h" + + +#include +#include +#include +#include + +#include + +using namespace dealii; + +template +void print_triangulation_data(Stream &stream, + const Triangulation &triangulation) +{ +// Boundary id count + std::map boundary_id_count; + std::map manifold_id_count; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell!=triangulation.end(); ++cell) + { + for (unsigned int face=0; face::faces_per_cell; ++face) + { + if (cell->face(face)->at_boundary()) + { + boundary_id_count[cell->face(face)->boundary_id()]++; + manifold_id_count[cell->face(face)->manifold_id()]++; + } + else + { + // Prevent double-accounting when face is shared + if (cell->neighbor_level(face) == cell->level()) + { + if (cell->id() < cell->neighbor(face)->id()) + manifold_id_count[cell->face(face)->manifold_id()]++; + } + else + manifold_id_count[cell->face(face)->manifold_id()]++; + + } + } + } + + for (typename std::map::const_iterator + it = boundary_id_count.begin(); + it != boundary_id_count.end(); ++it) + { + stream + << " Boundary: " << it->first + << " ;" + << " Number of faces: " << it->second + << "\n"; + } + for (typename std::map::const_iterator + it = manifold_id_count.begin(); + it != manifold_id_count.end(); ++it) + { + stream + << " Manifold: " << it->first + << " ;" + << " Number of faces: " << it->second + << "\n"; + } + + stream << std::endl; +} + +int main (int argc, char *argv[]) +{ + initlog(); + + const int dim = 2; + const unsigned int n_global_refinements = 1; + + // Create a geometry with flat and curved boundaries + const double inner_radius = 0.25; + const double outer_radius = 0.5; + const double tol = 1e-6; + Triangulation tria; + GridGenerator::hyper_cube_with_cylindrical_hole (tria,inner_radius,outer_radius); + tria.reset_all_manifolds(); + + // Enumerate the flat boundaries and the curved one + // separately. Also provide a manifold ID to the curved + // surface. Note that the manifold ID coincides with + // one of the boundary IDs. This is the root cause of the + // issue... + const types::manifold_id curved_manifold_id = 1; + for (typename Triangulation::active_cell_iterator + cell = tria.begin_active(); + cell != tria.end(); ++cell) + { + for (unsigned int face=0; face::faces_per_cell; ++face) + { + if (cell->face(face)->at_boundary()) + { + const Point pt_centre = cell->face(face)->center(); + + for (unsigned int vertex=0; vertex::vertices_per_face; ++vertex) + { + const Point pt_vertex = cell->face(face)->vertex(vertex); + + if (std::abs(pt_vertex.norm() - inner_radius) < tol) + { + cell->face(face)->set_manifold_id(curved_manifold_id); + cell->face(face)->set_boundary_id(5); + } + else + { + if (std::abs(pt_centre[0] - outer_radius) < tol) + cell->face(face)->set_boundary_id(1); + else if (std::abs(pt_centre[0] + outer_radius) < tol) + cell->face(face)->set_boundary_id(2); + else if (std::abs(pt_centre[1] - outer_radius) < tol) + cell->face(face)->set_boundary_id(3); + else if (std::abs(pt_centre[1] + outer_radius) < tol) + cell->face(face)->set_boundary_id(4); + } + } + } + } + } + + static const SphericalManifold sphere; + tria.set_manifold(curved_manifold_id, sphere); + tria.refine_global(n_global_refinements); + + deallog << "Boundary / manifold information" << std::endl; + print_triangulation_data(deallog, tria); + + deallog << "Output grid: " << std::endl; + std::ofstream file_gridout ("grid.vtu"); + GridOut().write_vtu(tria, file_gridout); + GridOut().write_vtk(tria, deallog.get_file_stream()); + + deallog << "OK" << std::endl; + + return 0; +} diff --git a/tests/manifold/tria_boundary_id_01.output b/tests/manifold/tria_boundary_id_01.output new file mode 100644 index 0000000000..e2b4b7d32c --- /dev/null +++ b/tests/manifold/tria_boundary_id_01.output @@ -0,0 +1,200 @@ + +DEAL::Boundary / manifold information +DEAL:: Boundary: 1 ; Number of faces: 4 + Boundary: 2 ; Number of faces: 4 + Boundary: 3 ; Number of faces: 4 + Boundary: 4 ; Number of faces: 4 + Boundary: 5 ; Number of faces: 16 + Manifold: -1 ; Number of faces: 48 + Manifold: 0 ; Number of faces: 16 + Manifold: 1 ; Number of faces: 16 + +DEAL::Output grid: +# vtk DataFile Version 3.0 +#This file was generated +ASCII +DATASET UNSTRUCTURED_GRID + +POINTS 128 double +0.500000 0.00000 0 +0.500000 0.250000 0 +0.375000 0.00000 0 +0.365485 0.172835 0 +0.500000 0.250000 0 +0.500000 0.500000 0 +0.365485 0.172835 0 +0.338388 0.338388 0 +0.375000 0.00000 0 +0.365485 0.172835 0 +0.250000 0.00000 0 +0.230970 0.0956709 0 +0.365485 0.172835 0 +0.338388 0.338388 0 +0.230970 0.0956709 0 +0.176777 0.176777 0 +0.500000 0.500000 0 +0.250000 0.500000 0 +0.338388 0.338388 0 +0.172835 0.365485 0 +0.250000 0.500000 0 +3.06162e-17 0.500000 0 +0.172835 0.365485 0 +2.29621e-17 0.375000 0 +0.338388 0.338388 0 +0.172835 0.365485 0 +0.176777 0.176777 0 +0.0956709 0.230970 0 +0.172835 0.365485 0 +2.29621e-17 0.375000 0 +0.0956709 0.230970 0 +1.53081e-17 0.250000 0 +3.06162e-17 0.500000 0 +-0.250000 0.500000 0 +2.29621e-17 0.375000 0 +-0.172835 0.365485 0 +-0.250000 0.500000 0 +-0.500000 0.500000 0 +-0.172835 0.365485 0 +-0.338388 0.338388 0 +2.29621e-17 0.375000 0 +-0.172835 0.365485 0 +1.53081e-17 0.250000 0 +-0.0956709 0.230970 0 +-0.172835 0.365485 0 +-0.338388 0.338388 0 +-0.0956709 0.230970 0 +-0.176777 0.176777 0 +-0.500000 0.500000 0 +-0.500000 0.250000 0 +-0.338388 0.338388 0 +-0.365485 0.172835 0 +-0.500000 0.250000 0 +-0.500000 6.12323e-17 0 +-0.365485 0.172835 0 +-0.375000 4.59243e-17 0 +-0.338388 0.338388 0 +-0.365485 0.172835 0 +-0.176777 0.176777 0 +-0.230970 0.0956709 0 +-0.365485 0.172835 0 +-0.375000 4.59243e-17 0 +-0.230970 0.0956709 0 +-0.250000 3.06162e-17 0 +-0.500000 6.12323e-17 0 +-0.500000 -0.250000 0 +-0.375000 4.59243e-17 0 +-0.365485 -0.172835 0 +-0.500000 -0.250000 0 +-0.500000 -0.500000 0 +-0.365485 -0.172835 0 +-0.338388 -0.338388 0 +-0.375000 4.59243e-17 0 +-0.365485 -0.172835 0 +-0.250000 3.06162e-17 0 +-0.230970 -0.0956709 0 +-0.365485 -0.172835 0 +-0.338388 -0.338388 0 +-0.230970 -0.0956709 0 +-0.176777 -0.176777 0 +-0.500000 -0.500000 0 +-0.250000 -0.500000 0 +-0.338388 -0.338388 0 +-0.172835 -0.365485 0 +-0.250000 -0.500000 0 +-9.18485e-17 -0.500000 0 +-0.172835 -0.365485 0 +-6.88864e-17 -0.375000 0 +-0.338388 -0.338388 0 +-0.172835 -0.365485 0 +-0.176777 -0.176777 0 +-0.0956709 -0.230970 0 +-0.172835 -0.365485 0 +-6.88864e-17 -0.375000 0 +-0.0956709 -0.230970 0 +-4.59243e-17 -0.250000 0 +-9.18485e-17 -0.500000 0 +0.250000 -0.500000 0 +-6.88864e-17 -0.375000 0 +0.172835 -0.365485 0 +0.250000 -0.500000 0 +0.500000 -0.500000 0 +0.172835 -0.365485 0 +0.338388 -0.338388 0 +-6.88864e-17 -0.375000 0 +0.172835 -0.365485 0 +-4.59243e-17 -0.250000 0 +0.0956709 -0.230970 0 +0.172835 -0.365485 0 +0.338388 -0.338388 0 +0.0956709 -0.230970 0 +0.176777 -0.176777 0 +0.500000 -0.500000 0 +0.500000 -0.250000 0 +0.338388 -0.338388 0 +0.365485 -0.172835 0 +0.500000 -0.250000 0 +0.500000 0.00000 0 +0.365485 -0.172835 0 +0.375000 0.00000 0 +0.338388 -0.338388 0 +0.365485 -0.172835 0 +0.176777 -0.176777 0 +0.230970 -0.0956709 0 +0.365485 -0.172835 0 +0.375000 0.00000 0 +0.230970 -0.0956709 0 +0.250000 0.00000 0 + +CELLS 32 160 +4 0 1 3 2 +4 4 5 7 6 +4 8 9 11 10 +4 12 13 15 14 +4 16 17 19 18 +4 20 21 23 22 +4 24 25 27 26 +4 28 29 31 30 +4 32 33 35 34 +4 36 37 39 38 +4 40 41 43 42 +4 44 45 47 46 +4 48 49 51 50 +4 52 53 55 54 +4 56 57 59 58 +4 60 61 63 62 +4 64 65 67 66 +4 68 69 71 70 +4 72 73 75 74 +4 76 77 79 78 +4 80 81 83 82 +4 84 85 87 86 +4 88 89 91 90 +4 92 93 95 94 +4 96 97 99 98 +4 100 101 103 102 +4 104 105 107 106 +4 108 109 111 110 +4 112 113 115 114 +4 116 117 119 118 +4 120 121 123 122 +4 124 125 127 126 + +CELL_TYPES 32 + 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 +POINT_DATA 128 +SCALARS level double 1 +LOOKUP_TABLE default +1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 1.00000 +SCALARS manifold double 1 +LOOKUP_TABLE default +-1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 -1.00000 +SCALARS material double 1 +LOOKUP_TABLE default +0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 +SCALARS subdomain double 1 +LOOKUP_TABLE default +0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 +SCALARS level_subdomain double 1 +LOOKUP_TABLE default +0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 +DEAL::OK -- 2.39.5