From a7f248a5d1a4e00296c4adfa566537ef480e2413 Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Fri, 9 Jan 2015 15:41:07 +0100 Subject: [PATCH] Added copy boundary to manifold id function. --- doc/news/changes.h | 7 ++ include/deal.II/grid/grid_tools.h | 34 +++++++++ source/grid/grid_tools.cc | 19 +++++ source/grid/grid_tools.inst.in | 9 +++ .../copy_boundary_to_manifold_id_01.cc | 74 +++++++++++++++++++ .../copy_boundary_to_manifold_id_01.output | 60 +++++++++++++++ 6 files changed, 203 insertions(+) create mode 100644 tests/manifold/copy_boundary_to_manifold_id_01.cc create mode 100644 tests/manifold/copy_boundary_to_manifold_id_01.output diff --git a/doc/news/changes.h b/doc/news/changes.h index a75bd50a39..52be64b6d5 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -134,6 +134,13 @@ inconvenience this causes.

Specific improvements

    +
  1. New: GridTools::copy_boundary_to_manifold_id() copies + boundary_ids to manifold_ids for faces on the boundary. +
    + (Luca Heltai, 2015/01/09) +
  2. + +
  3. Fixed: Utilities::int_to_string() produced wrong results if the number of digits specified was ten or greater.
    diff --git a/include/deal.II/grid/grid_tools.h b/include/deal.II/grid/grid_tools.h index 7f83820c19..6208c6480b 100644 --- a/include/deal.II/grid/grid_tools.h +++ b/include/deal.II/grid/grid_tools.h @@ -1145,6 +1145,40 @@ namespace GridTools const FullMatrix &matrix = FullMatrix(), const std::vector &first_vector_components = std::vector()); + /*@}*/ + /** + * @name Dealing with boundary and manifold ids + */ + /*@{*/ + + /** + * Copy boundary ids to manifold ids. The default manifold_id for + * new Triangulation objects is numbers::invalid_manifold_id. When + * refinements occurs, the Triangulation asks where to locate new + * points to the underlying manifold, and if the manifold_id of a + * boundary face is set to numbers::invalid_manifold_id, then + * Triangulation reverts back boundary_id (this was the behavior of + * deal.II < 8.2). This function copies the boundary_ids of the + * boundary faces to the manifold_ids of the same faces, allowing + * the user to change the boundary_ids and use them for boundary + * conditions regardless of the geometry, which will use + * manifold_ids to create new points. Only active cells will be + * iterated over. This is a function you'd typically call when there + * is only one active level on your Triangulation. + * + * The optional parameter @p reset_boundary_ids, indicates wether + * this function should reset the boundary_ids of the Triangulation + * to its default value 0 after copying its value to the + * manifold_id. By default, boundary_ids are left untouched. + * + * @ingroup manifold + * @ingroup boundary + * + * @author Luca Heltai, 2015 + */ + template + void copy_boundary_to_manifold_id(Triangulation &tria, + bool reset_boundary_ids=false); /*@}*/ /** diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 0e7b739693..38b91b6504 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -2894,6 +2894,25 @@ next_cell: #endif } + template + void copy_boundary_to_manifold_id(Triangulation &tria, + bool reset_boundary_ids) + { + + typename Triangulation::active_cell_iterator + cell=tria.begin_active(), endc=tria.end(); + + for (; cell != endc; ++cell) + for (unsigned int f=0; f::faces_per_cell; ++f) + if (cell->face(f)->at_boundary()) + { + cell->face(f)->set_manifold_id + (static_cast(cell->face(f)->boundary_indicator())); + if (reset_boundary_ids == true) + cell->face(f)->set_boundary_indicator(0); + } + } + } /* namespace GridTools */ diff --git a/source/grid/grid_tools.inst.in b/source/grid/grid_tools.inst.in index d31b93d5ec..cef43b58c7 100644 --- a/source/grid/grid_tools.inst.in +++ b/source/grid/grid_tools.inst.in @@ -388,4 +388,13 @@ for (deal_II_dimension : DIMENSIONS ; deal_II_space_dimension : SPACE_DIMENSIONS #endif } +for (deal_II_dimension : DIMENSIONS ; deal_II_space_dimension : SPACE_DIMENSIONS) +{ +#if deal_II_space_dimension >= deal_II_dimension + namespace GridTools \{ + template void copy_boundary_to_manifold_id + (Triangulation &, bool); +\} +#endif +} diff --git a/tests/manifold/copy_boundary_to_manifold_id_01.cc b/tests/manifold/copy_boundary_to_manifold_id_01.cc new file mode 100644 index 0000000000..e45e7230b7 --- /dev/null +++ b/tests/manifold/copy_boundary_to_manifold_id_01.cc @@ -0,0 +1,74 @@ +//------------------------------------------------------------ +// Copyright (C) 2015, 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. +// +//------------------------------------------------------------ + + +// Copy from boundary ids to manifold ids + +#include "../tests.h" +#include +#include + + +// all include files you need here +#include +#include +#include +#include +#include +#include +#include + +template +void print_info(Triangulation &tria) { + typename Triangulation::active_cell_iterator cell; + + for (cell = tria.begin_active(); cell != tria.end(); ++cell) + { + for (unsigned int f=0; f::faces_per_cell; ++f) + if(cell->face(f)->at_boundary()) + deallog << "face: " << cell->face(f) + << ", boundary_id: " + << (int)cell->face(f)->boundary_indicator() + << ", manifold_id: " + << (int)cell->face(f)->manifold_id() << std::endl; + } +} + + +// Helper function +template +void test() +{ + deallog << "Testing dim=" << dim + << ", spacedim="<< spacedim << std::endl; + + Triangulation tria; + GridGenerator::hyper_cube (tria, 0., 1., true); + + print_info(tria); + GridTools::copy_boundary_to_manifold_id(tria); + print_info(tria); + GridTools::copy_boundary_to_manifold_id(tria, true); + print_info(tria); +} + +int main () +{ + initlog(true); + + test<1,1>(); + test<1,2>(); + test<2,2>(); + test<2,3>(); + test<3,3>(); + + return 0; +} + diff --git a/tests/manifold/copy_boundary_to_manifold_id_01.output b/tests/manifold/copy_boundary_to_manifold_id_01.output new file mode 100644 index 0000000000..c3b3c64149 --- /dev/null +++ b/tests/manifold/copy_boundary_to_manifold_id_01.output @@ -0,0 +1,60 @@ + +DEAL::Testing dim=1, spacedim=1 +DEAL::face: 0, boundary_id: 0, manifold_id: -1 +DEAL::face: 1, boundary_id: 1, manifold_id: -1 +DEAL::face: 0, boundary_id: 0, manifold_id: 0 +DEAL::face: 1, boundary_id: 1, manifold_id: 1 +DEAL::face: 0, boundary_id: 0, manifold_id: 0 +DEAL::face: 1, boundary_id: 0, manifold_id: 1 +DEAL::Testing dim=1, spacedim=2 +DEAL::face: 0, boundary_id: 0, manifold_id: -1 +DEAL::face: 1, boundary_id: 1, manifold_id: -1 +DEAL::face: 0, boundary_id: 0, manifold_id: 0 +DEAL::face: 1, boundary_id: 1, manifold_id: 1 +DEAL::face: 0, boundary_id: 0, manifold_id: 0 +DEAL::face: 1, boundary_id: 0, manifold_id: 1 +DEAL::Testing dim=2, spacedim=2 +DEAL::face: 1, boundary_id: 0, manifold_id: -1 +DEAL::face: 2, boundary_id: 1, manifold_id: -1 +DEAL::face: 0, boundary_id: 2, manifold_id: -1 +DEAL::face: 3, boundary_id: 3, manifold_id: -1 +DEAL::face: 1, boundary_id: 0, manifold_id: 0 +DEAL::face: 2, boundary_id: 1, manifold_id: 1 +DEAL::face: 0, boundary_id: 2, manifold_id: 2 +DEAL::face: 3, boundary_id: 3, manifold_id: 3 +DEAL::face: 1, boundary_id: 0, manifold_id: 0 +DEAL::face: 2, boundary_id: 0, manifold_id: 1 +DEAL::face: 0, boundary_id: 0, manifold_id: 2 +DEAL::face: 3, boundary_id: 0, manifold_id: 3 +DEAL::Testing dim=2, spacedim=3 +DEAL::face: 1, boundary_id: 0, manifold_id: -1 +DEAL::face: 2, boundary_id: 1, manifold_id: -1 +DEAL::face: 0, boundary_id: 2, manifold_id: -1 +DEAL::face: 3, boundary_id: 3, manifold_id: -1 +DEAL::face: 1, boundary_id: 0, manifold_id: 0 +DEAL::face: 2, boundary_id: 1, manifold_id: 1 +DEAL::face: 0, boundary_id: 2, manifold_id: 2 +DEAL::face: 3, boundary_id: 3, manifold_id: 3 +DEAL::face: 1, boundary_id: 0, manifold_id: 0 +DEAL::face: 2, boundary_id: 0, manifold_id: 1 +DEAL::face: 0, boundary_id: 0, manifold_id: 2 +DEAL::face: 3, boundary_id: 0, manifold_id: 3 +DEAL::Testing dim=3, spacedim=3 +DEAL::face: 2, boundary_id: 0, manifold_id: -1 +DEAL::face: 3, boundary_id: 1, manifold_id: -1 +DEAL::face: 0, boundary_id: 2, manifold_id: -1 +DEAL::face: 4, boundary_id: 3, manifold_id: -1 +DEAL::face: 1, boundary_id: 4, manifold_id: -1 +DEAL::face: 5, boundary_id: 5, manifold_id: -1 +DEAL::face: 2, boundary_id: 0, manifold_id: 0 +DEAL::face: 3, boundary_id: 1, manifold_id: 1 +DEAL::face: 0, boundary_id: 2, manifold_id: 2 +DEAL::face: 4, boundary_id: 3, manifold_id: 3 +DEAL::face: 1, boundary_id: 4, manifold_id: 4 +DEAL::face: 5, boundary_id: 5, manifold_id: 5 +DEAL::face: 2, boundary_id: 0, manifold_id: 0 +DEAL::face: 3, boundary_id: 0, manifold_id: 1 +DEAL::face: 0, boundary_id: 0, manifold_id: 2 +DEAL::face: 4, boundary_id: 0, manifold_id: 3 +DEAL::face: 1, boundary_id: 0, manifold_id: 4 +DEAL::face: 5, boundary_id: 0, manifold_id: 5 -- 2.39.5