From: Luca Heltai Date: Fri, 13 Apr 2018 18:25:38 +0000 (+0200) Subject: Added map_boundary_to_manifold_ids. X-Git-Tag: v9.0.0-rc1~176^2~3 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ad922e91b2261f5841384f624c0c2f09acadbfa;p=dealii.git Added map_boundary_to_manifold_ids. --- diff --git a/doc/news/changes/minor/20180413LucaHeltai b/doc/news/changes/minor/20180413LucaHeltai new file mode 100644 index 0000000000..88a9e75085 --- /dev/null +++ b/doc/news/changes/minor/20180413LucaHeltai @@ -0,0 +1,5 @@ +New: GridTools::map_boundary_to_manifold_ids() allows you to set manifold ids on the +boundary according to a given map of boundary to manifold ids. +
+(Luca Heltai, 2018/04/13) + diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index c6d19deb4b..ee6722b4b1 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -2269,6 +2269,35 @@ namespace GridTools void copy_boundary_to_manifold_id(Triangulation &tria, const bool reset_boundary_ids=false); + /** + * Map the given boundary ids to the given manifold ids on faces and + * edges at the boundary. + * + * This function copies the boundary_ids of the boundary faces and + * edges that are present in the parameter @p src_boundary_ids to + * the corresponding manifold_id in @p dst_manifold_ids, of the same + * faces and edges. + * + * If the optional parameter @p reset_boundary_ids is non empty, + * each boundary id in @p src_boundary_ids, is replaced with the + * corresponding boudnary id in @p reset_boundary_ids. + * + * An exception is thrown if the size of the input vectors do not + * match. If a boundary id indicated in @p src_boundary_ids is not + * present in the triangulation, it is simply ignored during the + * process. + * + * @ingroup manifold + * @relatesalso boundary + * + * @author Luca Heltai, 2018 + */ + template + void map_boundary_to_manifold_ids(const std::vector &src_boundary_ids, + const std::vector &dst_manifold_ids, + Triangulation &tria, + const std::vector &reset_boundary_ids= {}); + /** * Copy material ids to manifold ids. The default manifold_id for new * Triangulation objects is numbers::invalid_manifold_id. When refinements diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 803ab44fd7..55d4267fb2 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -3236,6 +3236,33 @@ next_cell: void copy_boundary_to_manifold_id(Triangulation &tria, const bool reset_boundary_ids) { + const auto src_boundary_ids = tria.get_boundary_ids(); + std::vector dst_manifold_ids(src_boundary_ids.size()); + auto m_it = dst_manifold_ids.begin(); + for (auto b : src_boundary_ids) + { + *m_it = static_cast(b); + ++m_it; + } + const std::vector reset_boundary_id = + reset_boundary_ids ? + std::vector(src_boundary_ids.size(), 0) : src_boundary_ids; + map_boundary_to_manifold_ids(src_boundary_ids, dst_manifold_ids, tria, reset_boundary_id); + } + + + + template + void map_boundary_to_manifold_ids(const std::vector &src_boundary_ids, + const std::vector &dst_manifold_ids, + Triangulation &tria, + const std::vector &reset_boundary_ids_) + { + AssertDimension(src_boundary_ids.size(), dst_manifold_ids.size()); + const auto reset_boundary_ids = reset_boundary_ids_.size() ? + reset_boundary_ids_ : src_boundary_ids; + AssertDimension(reset_boundary_ids.size(), src_boundary_ids.size()); + // in 3d, we not only have to copy boundary ids of faces, but also of edges // because we see them twice (once from each adjacent boundary face), // we cannot immediately reset their boundary ids. thus, copy first @@ -3247,8 +3274,13 @@ next_cell: for (unsigned int f=0; f::faces_per_cell; ++f) if (cell->face(f)->at_boundary()) for (signed int e=0; e(GeometryInfo::lines_per_face); ++e) - cell->face(f)->line(e)->set_manifold_id - (static_cast(cell->face(f)->line(e)->boundary_id())); + { + auto bid = cell->face(f)->line(e)->boundary_id(); + auto ind = std::find(src_boundary_ids.begin(), src_boundary_ids.end(), bid)- + src_boundary_ids.begin(); + if ((unsigned int)ind < src_boundary_ids.size()) + cell->face(f)->line(e)->set_manifold_id(dst_manifold_ids[ind]); + } // now do cells for (typename Triangulation::active_cell_iterator @@ -3257,24 +3289,31 @@ next_cell: for (unsigned int f=0; f::faces_per_cell; ++f) if (cell->face(f)->at_boundary()) { - // copy boundary to manifold ids - cell->face(f)->set_manifold_id - (static_cast(cell->face(f)->boundary_id())); + auto bid = cell->face(f)->boundary_id(); + auto ind = std::find(src_boundary_ids.begin(), src_boundary_ids.end(), bid)- + src_boundary_ids.begin(); - // then reset boundary ids if so desired, and in 3d also that - // of edges - if (reset_boundary_ids == true) + if ((unsigned int)ind < src_boundary_ids.size()) { - cell->face(f)->set_boundary_id(0); - if (dim >= 3) - for (signed int e=0; e(GeometryInfo::lines_per_face); ++e) - cell->face(f)->line(e)->set_boundary_id(0); + // assign the manifold id + cell->face(f)->set_manifold_id(dst_manifold_ids[ind]); + // then reset boundary id + cell->face(f)->set_boundary_id(reset_boundary_ids[ind]); } + + if (dim >= 3) + for (signed int e=0; e(GeometryInfo::lines_per_face); ++e) + { + auto bid = cell->face(f)->line(e)->boundary_id(); + auto ind = std::find(src_boundary_ids.begin(), src_boundary_ids.end(), bid)- + src_boundary_ids.begin(); + if ((unsigned int)ind < src_boundary_ids.size()) + cell->face(f)->line(e)->set_boundary_id(reset_boundary_ids[ind]); + } } } - template void copy_material_to_manifold_id(Triangulation &tria, const bool compute_face_ids) diff --git a/source/grid/grid_tools.inst.in b/source/grid/grid_tools.inst.in index 53248ff85b..5268a15fd7 100644 --- a/source/grid/grid_tools.inst.in +++ b/source/grid/grid_tools.inst.in @@ -284,9 +284,16 @@ for (deal_II_dimension : DIMENSIONS ; deal_II_space_dimension : SPACE_DIMENSIONS namespace GridTools \{ template void copy_boundary_to_manifold_id (Triangulation &, const bool); + template void copy_material_to_manifold_id (Triangulation &, const bool); + template void map_boundary_to_manifold_ids + (const std::vector &, + const std::vector &, + Triangulation &, + const std::vector &); + template void regularize_corner_cells (Triangulation &, double); diff --git a/tests/manifold/map_boundary_to_manifold_id_01.cc b/tests/manifold/map_boundary_to_manifold_id_01.cc new file mode 100644 index 0000000000..314b2e3a9d --- /dev/null +++ b/tests/manifold/map_boundary_to_manifold_id_01.cc @@ -0,0 +1,84 @@ +//---------------------------- manifold_id_02.cc --------------------------- +// Copyright (C) 2018 by the deal.II authors +// +// This file is subject to LGPL and may not be distributed +// without copyright and license information. Please refer +// to the file deal.II/doc/license.html for the text and +// further information on this license. +// +//---------------------------- manifold_id_02.cc --------------------------- + + +// Test the function map_boundary_to_manifold_ids + +#include "../tests.h" + + +// all include files you need here +#include +#include +#include +#include +#include +#include + +template +void print_info(const Triangulation &tria) +{ + for (auto cell = tria.begin_active(); cell != tria.end(); ++cell) + { + deallog << "C: " << cell + << ", manifold id: " << (int)cell->manifold_id() << std::endl; + for (unsigned int f=0; f::faces_per_cell; ++f) + { + deallog << "f: " << cell->face(f) + << ", boundary id: " << (int)cell->face(f)->boundary_id() + << ", manifold id: " << (int)cell->face(f)->manifold_id() << std::endl; + if (dim >=3) + for (signed int e=0; e(GeometryInfo::lines_per_face); ++e) + deallog << "e: " << cell->face(f)->line(e) + << ", boundary id: " << (int)cell->face(f)->line(e)->boundary_id() + << ", manifold id: " << (int)cell->face(f)->line(e)->manifold_id() << std::endl; + } + } +} + +// Helper function +template +void test() +{ + deallog << "Testing dim=" << dim + << ", spacedim="<< spacedim << std::endl; + + deallog << "Default" << std::endl; + Triangulation tria; + GridGenerator::hyper_cube (tria, 0, 1, true); + print_info(tria); + + // Test setting all manifold ids to 0 + deallog << "All manifold ids to 0" << std::endl; + auto bids = tria.get_boundary_ids(); + std::vector mids(bids.size(), 0); + GridTools::map_boundary_to_manifold_ids(bids, mids, tria); + print_info(tria); + + // Test resetting all boundary ids to 1, and all manifold ids to 2 + mids = std::vector(bids.size(), 2); + std::vector rbids(bids.size(), 1); + GridTools::map_boundary_to_manifold_ids(bids, mids, tria, rbids); + print_info(tria); +} + +int main () +{ + initlog(); + test<1,1>(); + test<1,2>(); + test<1,3>(); + test<2,2>(); + test<2,3>(); + test<3,3>(); + + return 0; +} + diff --git a/tests/manifold/map_boundary_to_manifold_id_01.output b/tests/manifold/map_boundary_to_manifold_id_01.output new file mode 100644 index 0000000000..e6509af513 --- /dev/null +++ b/tests/manifold/map_boundary_to_manifold_id_01.output @@ -0,0 +1,169 @@ + +DEAL::Testing dim=1, spacedim=1 +DEAL::Default +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 0, manifold id: -1 +DEAL::f: 1, boundary id: 1, manifold id: -1 +DEAL::All manifold ids to 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 0, manifold id: 0 +DEAL::f: 1, boundary id: 1, manifold id: 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 1, manifold id: 2 +DEAL::f: 1, boundary id: 1, manifold id: 2 +DEAL::Testing dim=1, spacedim=2 +DEAL::Default +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 0, manifold id: -1 +DEAL::f: 1, boundary id: 1, manifold id: -1 +DEAL::All manifold ids to 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 0, manifold id: 0 +DEAL::f: 1, boundary id: 1, manifold id: 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 1, manifold id: 2 +DEAL::f: 1, boundary id: 1, manifold id: 2 +DEAL::Testing dim=1, spacedim=3 +DEAL::Default +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 0, manifold id: -1 +DEAL::f: 1, boundary id: 1, manifold id: -1 +DEAL::All manifold ids to 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 0, manifold id: 0 +DEAL::f: 1, boundary id: 1, manifold id: 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 0, boundary id: 1, manifold id: 2 +DEAL::f: 1, boundary id: 1, manifold id: 2 +DEAL::Testing dim=2, spacedim=2 +DEAL::Default +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 1, boundary id: 0, manifold id: -1 +DEAL::f: 2, boundary id: 1, manifold id: -1 +DEAL::f: 0, boundary id: 2, manifold id: -1 +DEAL::f: 3, boundary id: 3, manifold id: -1 +DEAL::All manifold ids to 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 1, boundary id: 0, manifold id: 0 +DEAL::f: 2, boundary id: 1, manifold id: 0 +DEAL::f: 0, boundary id: 2, manifold id: 0 +DEAL::f: 3, boundary id: 3, manifold id: 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 1, boundary id: 1, manifold id: 2 +DEAL::f: 2, boundary id: 1, manifold id: 2 +DEAL::f: 0, boundary id: 1, manifold id: 2 +DEAL::f: 3, boundary id: 1, manifold id: 2 +DEAL::Testing dim=2, spacedim=3 +DEAL::Default +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 1, boundary id: 0, manifold id: -1 +DEAL::f: 2, boundary id: 1, manifold id: -1 +DEAL::f: 0, boundary id: 2, manifold id: -1 +DEAL::f: 3, boundary id: 3, manifold id: -1 +DEAL::All manifold ids to 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 1, boundary id: 0, manifold id: 0 +DEAL::f: 2, boundary id: 1, manifold id: 0 +DEAL::f: 0, boundary id: 2, manifold id: 0 +DEAL::f: 3, boundary id: 3, manifold id: 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 1, boundary id: 1, manifold id: 2 +DEAL::f: 2, boundary id: 1, manifold id: 2 +DEAL::f: 0, boundary id: 1, manifold id: 2 +DEAL::f: 3, boundary id: 1, manifold id: 2 +DEAL::Testing dim=3, spacedim=3 +DEAL::Default +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 2, boundary id: 0, manifold id: -1 +DEAL::e: 2, boundary id: 0, manifold id: -1 +DEAL::e: 6, boundary id: 0, manifold id: -1 +DEAL::e: 1, boundary id: 0, manifold id: -1 +DEAL::e: 9, boundary id: 0, manifold id: -1 +DEAL::f: 3, boundary id: 1, manifold id: -1 +DEAL::e: 4, boundary id: 0, manifold id: -1 +DEAL::e: 7, boundary id: 0, manifold id: -1 +DEAL::e: 3, boundary id: 0, manifold id: -1 +DEAL::e: 10, boundary id: 0, manifold id: -1 +DEAL::f: 0, boundary id: 2, manifold id: -1 +DEAL::e: 0, boundary id: 0, manifold id: -1 +DEAL::e: 8, boundary id: 0, manifold id: -1 +DEAL::e: 2, boundary id: 0, manifold id: -1 +DEAL::e: 4, boundary id: 0, manifold id: -1 +DEAL::f: 4, boundary id: 3, manifold id: -1 +DEAL::e: 5, boundary id: 0, manifold id: -1 +DEAL::e: 11, boundary id: 0, manifold id: -1 +DEAL::e: 6, boundary id: 0, manifold id: -1 +DEAL::e: 7, boundary id: 0, manifold id: -1 +DEAL::f: 1, boundary id: 4, manifold id: -1 +DEAL::e: 1, boundary id: 0, manifold id: -1 +DEAL::e: 3, boundary id: 0, manifold id: -1 +DEAL::e: 0, boundary id: 0, manifold id: -1 +DEAL::e: 5, boundary id: 0, manifold id: -1 +DEAL::f: 5, boundary id: 5, manifold id: -1 +DEAL::e: 9, boundary id: 0, manifold id: -1 +DEAL::e: 10, boundary id: 0, manifold id: -1 +DEAL::e: 8, boundary id: 0, manifold id: -1 +DEAL::e: 11, boundary id: 0, manifold id: -1 +DEAL::All manifold ids to 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 2, boundary id: 0, manifold id: 0 +DEAL::e: 2, boundary id: 0, manifold id: 0 +DEAL::e: 6, boundary id: 0, manifold id: 0 +DEAL::e: 1, boundary id: 0, manifold id: 0 +DEAL::e: 9, boundary id: 0, manifold id: 0 +DEAL::f: 3, boundary id: 1, manifold id: 0 +DEAL::e: 4, boundary id: 0, manifold id: 0 +DEAL::e: 7, boundary id: 0, manifold id: 0 +DEAL::e: 3, boundary id: 0, manifold id: 0 +DEAL::e: 10, boundary id: 0, manifold id: 0 +DEAL::f: 0, boundary id: 2, manifold id: 0 +DEAL::e: 0, boundary id: 0, manifold id: 0 +DEAL::e: 8, boundary id: 0, manifold id: 0 +DEAL::e: 2, boundary id: 0, manifold id: 0 +DEAL::e: 4, boundary id: 0, manifold id: 0 +DEAL::f: 4, boundary id: 3, manifold id: 0 +DEAL::e: 5, boundary id: 0, manifold id: 0 +DEAL::e: 11, boundary id: 0, manifold id: 0 +DEAL::e: 6, boundary id: 0, manifold id: 0 +DEAL::e: 7, boundary id: 0, manifold id: 0 +DEAL::f: 1, boundary id: 4, manifold id: 0 +DEAL::e: 1, boundary id: 0, manifold id: 0 +DEAL::e: 3, boundary id: 0, manifold id: 0 +DEAL::e: 0, boundary id: 0, manifold id: 0 +DEAL::e: 5, boundary id: 0, manifold id: 0 +DEAL::f: 5, boundary id: 5, manifold id: 0 +DEAL::e: 9, boundary id: 0, manifold id: 0 +DEAL::e: 10, boundary id: 0, manifold id: 0 +DEAL::e: 8, boundary id: 0, manifold id: 0 +DEAL::e: 11, boundary id: 0, manifold id: 0 +DEAL::C: 0.0, manifold id: -1 +DEAL::f: 2, boundary id: 1, manifold id: 2 +DEAL::e: 2, boundary id: 1, manifold id: 2 +DEAL::e: 6, boundary id: 1, manifold id: 2 +DEAL::e: 1, boundary id: 1, manifold id: 2 +DEAL::e: 9, boundary id: 1, manifold id: 2 +DEAL::f: 3, boundary id: 1, manifold id: 2 +DEAL::e: 4, boundary id: 1, manifold id: 2 +DEAL::e: 7, boundary id: 1, manifold id: 2 +DEAL::e: 3, boundary id: 1, manifold id: 2 +DEAL::e: 10, boundary id: 1, manifold id: 2 +DEAL::f: 0, boundary id: 1, manifold id: 2 +DEAL::e: 0, boundary id: 1, manifold id: 2 +DEAL::e: 8, boundary id: 1, manifold id: 2 +DEAL::e: 2, boundary id: 1, manifold id: 2 +DEAL::e: 4, boundary id: 1, manifold id: 2 +DEAL::f: 4, boundary id: 1, manifold id: 2 +DEAL::e: 5, boundary id: 1, manifold id: 2 +DEAL::e: 11, boundary id: 1, manifold id: 2 +DEAL::e: 6, boundary id: 1, manifold id: 2 +DEAL::e: 7, boundary id: 1, manifold id: 2 +DEAL::f: 1, boundary id: 1, manifold id: 2 +DEAL::e: 1, boundary id: 1, manifold id: 2 +DEAL::e: 3, boundary id: 1, manifold id: 2 +DEAL::e: 0, boundary id: 1, manifold id: 2 +DEAL::e: 5, boundary id: 1, manifold id: 2 +DEAL::f: 5, boundary id: 1, manifold id: 2 +DEAL::e: 9, boundary id: 1, manifold id: 2 +DEAL::e: 10, boundary id: 1, manifold id: 2 +DEAL::e: 8, boundary id: 1, manifold id: 2 +DEAL::e: 11, boundary id: 1, manifold id: 2