From f146c939bed59f322bec95aba7a2b021e9ca3f5d Mon Sep 17 00:00:00 2001 From: Luca Heltai Date: Fri, 6 Apr 2018 15:35:39 +0200 Subject: [PATCH] Make tria use std::unique_ptr > --- include/deal.II/grid/tria.h | 3 +- source/grid/tria.cc | 11 ++---- tests/manifold/manifold_clone_01.cc | 48 +++++++++++++++++++++++ tests/manifold/manifold_clone_01.output | 52 +++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 tests/manifold/manifold_clone_01.cc create mode 100644 tests/manifold/manifold_clone_01.output diff --git a/include/deal.II/grid/tria.h b/include/deal.II/grid/tria.h index 12cc8d88ba..2879e2c2c1 100644 --- a/include/deal.II/grid/tria.h +++ b/include/deal.II/grid/tria.h @@ -3538,8 +3538,7 @@ private: * Collection of manifold objects. We store only objects, which are not of * type FlatManifold. */ - std::map, Triangulation > > manifold; - + std::map > > manifold; /** * Flag indicating whether anisotropic refinement took place. diff --git a/source/grid/tria.cc b/source/grid/tria.cc index ba59ead4e5..dd31de1966 100644 --- a/source/grid/tria.cc +++ b/source/grid/tria.cc @@ -8958,7 +8958,7 @@ Triangulation::set_manifold (const types::manifold_id m_number, Assert(m_number < numbers::invalid_manifold_id, ExcIndexRange(m_number,0,numbers::invalid_manifold_id)); - manifold[m_number] = &manifold_object; + manifold[m_number] = manifold_object.clone(); } @@ -9069,8 +9069,7 @@ Triangulation::get_manifold (const types::manifold_id m_number) c { //look, if there is a manifold stored at //manifold_id number. - typename std::map, Triangulation > >::const_iterator it - = manifold.find(m_number); + const auto it = manifold.find(m_number); if (it != manifold.end()) { @@ -9167,11 +9166,9 @@ copy_triangulation (const Triangulation &other_tria) if (dim > 1) faces = std_cxx14::make_unique> (*other_tria.faces); - typename std::map, Triangulation > >::const_iterator - bdry_iterator = other_tria.manifold.begin(); + auto bdry_iterator = other_tria.manifold.begin(); for (; bdry_iterator != other_tria.manifold.end() ; ++bdry_iterator) - manifold[bdry_iterator->first] = bdry_iterator->second; + manifold[bdry_iterator->first] = bdry_iterator->second->clone(); levels.reserve (other_tria.levels.size()); diff --git a/tests/manifold/manifold_clone_01.cc b/tests/manifold/manifold_clone_01.cc new file mode 100644 index 0000000000..f441837c9d --- /dev/null +++ b/tests/manifold/manifold_clone_01.cc @@ -0,0 +1,48 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018 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. +// +// --------------------------------------------------------------------- + +// Check that now it is possible to build a mesh and a manifold in the +// "wrong" order. + +#include "../tests.h" + +#include +#include +#include +#include +#include + +int main() +{ + initlog(); + + // We intentionally create the tria before the manifold, to make sure + // that now it is possible to do so, since manifold is cloned internally + // in the Triangulation + + Triangulation<2> tria; + + Point<2> center(1.0, 2.0); + const SphericalManifold<2,2> manifold(center); + + GridGenerator::hyper_ball(tria, center); + GridTools::copy_boundary_to_manifold_id(tria); + + tria.set_manifold(0, manifold); + tria.refine_global(1); + + GridOut go; + go.write_msh(tria, deallog.get_file_stream()); +} diff --git a/tests/manifold/manifold_clone_01.output b/tests/manifold/manifold_clone_01.output new file mode 100644 index 0000000000..4ede1f68e9 --- /dev/null +++ b/tests/manifold/manifold_clone_01.output @@ -0,0 +1,52 @@ + +$NOD +25 +1 0.292893 1.29289 0 +2 1.70711 1.29289 0 +3 0.707107 1.70711 0 +4 1.29289 1.70711 0 +5 0.707107 2.29289 0 +6 1.29289 2.29289 0 +7 0.292893 2.70711 0 +8 1.70711 2.70711 0 +9 1.00000 1.00000 0 +10 0.500000 1.50000 0 +11 1.11022e-16 2.00000 0 +12 1.50000 1.50000 0 +13 2.00000 2.00000 0 +14 1.00000 1.70711 0 +15 0.707107 2.00000 0 +16 1.29289 2.00000 0 +17 1.00000 2.29289 0 +18 0.500000 2.50000 0 +19 1.00000 3.00000 0 +20 1.50000 2.50000 0 +21 1.00000 1.35355 0 +22 0.353553 2.00000 0 +23 1.00000 2.00000 0 +24 1.64645 2.00000 0 +25 1.00000 2.64645 0 +$ENDNOD +$ELM +20 +1 3 0 0 4 1 9 21 10 +2 3 0 0 4 9 2 12 21 +3 3 0 0 4 10 21 14 3 +4 3 0 0 4 21 12 4 14 +5 3 0 0 4 1 10 22 11 +6 3 0 0 4 10 3 15 22 +7 3 0 0 4 11 22 18 7 +8 3 0 0 4 22 15 5 18 +9 3 0 0 4 3 14 23 15 +10 3 0 0 4 14 4 16 23 +11 3 0 0 4 15 23 17 5 +12 3 0 0 4 23 16 6 17 +13 3 0 0 4 2 13 24 12 +14 3 0 0 4 13 8 20 24 +15 3 0 0 4 12 24 16 4 +16 3 0 0 4 24 20 6 16 +17 3 0 0 4 7 18 25 19 +18 3 0 0 4 18 5 17 25 +19 3 0 0 4 19 25 20 8 +20 3 0 0 4 25 17 6 20 +$ENDELM -- 2.39.5