From a4610005890864c9d8dc4620d55862daf3e1a764 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Mon, 5 Mar 2018 04:41:06 +0100 Subject: [PATCH] Fix up GridTools::distort_random for p::s::Triangulation --- source/grid/grid_tools.cc | 8 ++- tests/mpi/distort_random_03.cc | 70 +++++++++++++++++++++ tests/mpi/distort_random_03.mpirun=3.output | 41 ++++++++++++ 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 tests/mpi/distort_random_03.cc create mode 100644 tests/mpi/distort_random_03.mpirun=3.output diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index a5df281fec..5318d8c146 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -882,10 +882,14 @@ namespace GridTools almost_infinite_length); // also note if a vertex is at the boundary - std::vector at_boundary (triangulation.n_vertices(), false); + std::vector at_boundary (keep_boundary ? triangulation.n_vertices() : 0, false); + // for parallel::shared::Triangulation we need to work on all vertices, + // not just the ones related to loacally owned cells; + const bool is_parallel_shared + = (dynamic_cast*> (&triangulation) != nullptr); for (typename Triangulation::active_cell_iterator cell=triangulation.begin_active(); cell!=triangulation.end(); ++cell) - if (cell->is_locally_owned()) + if (is_parallel_shared || cell->is_locally_owned()) { if (dim>1) { diff --git a/tests/mpi/distort_random_03.cc b/tests/mpi/distort_random_03.cc new file mode 100644 index 0000000000..ce412b7ca2 --- /dev/null +++ b/tests/mpi/distort_random_03.cc @@ -0,0 +1,70 @@ +// --------------------------------------------------------------------- +// +// 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 GridTools::distort_random for parallel::shared::Triangulation + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include + + + + +template +void test1 (const bool keep_boundary) +{ + const unsigned int my_id = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + parallel::shared::Triangulation tria (MPI_COMM_WORLD); + GridGenerator::hyper_cube(tria); + tria.refine_global(2); + GridTools::distort_random (0.1, tria, keep_boundary); + + deallog << "dim=" << dim << ", keep_boundary=" << keep_boundary << std::endl; + std::string filename; + if (keep_boundary) + filename = "keep_true-"; + else + filename = "keep_false-"; + filename += Utilities::int_to_string(dim); + + std::stringstream ss; + GridOut().write_gnuplot (tria, ss); + const std::string local_grid = ss.str(); + deallog << checksum(local_grid.begin(), local_grid.end()) << std::endl; + + deallog << "OK" << std::endl; +} + + + +int main (int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + MPILogInitAll log_all; + + test1<2> (true); + test1<2> (false); + test1<3> (true); + test1<3> (false); + + return 0; +} diff --git a/tests/mpi/distort_random_03.mpirun=3.output b/tests/mpi/distort_random_03.mpirun=3.output new file mode 100644 index 0000000000..090163e091 --- /dev/null +++ b/tests/mpi/distort_random_03.mpirun=3.output @@ -0,0 +1,41 @@ + +DEAL:0::dim=2, keep_boundary=1 +DEAL:0::561638746 +DEAL:0::OK +DEAL:0::dim=2, keep_boundary=0 +DEAL:0::1946764437 +DEAL:0::OK +DEAL:0::dim=3, keep_boundary=1 +DEAL:0::3893493253 +DEAL:0::OK +DEAL:0::dim=3, keep_boundary=0 +DEAL:0::2979128258 +DEAL:0::OK + +DEAL:1::dim=2, keep_boundary=1 +DEAL:1::561638746 +DEAL:1::OK +DEAL:1::dim=2, keep_boundary=0 +DEAL:1::1946764437 +DEAL:1::OK +DEAL:1::dim=3, keep_boundary=1 +DEAL:1::3893493253 +DEAL:1::OK +DEAL:1::dim=3, keep_boundary=0 +DEAL:1::2979128258 +DEAL:1::OK + + +DEAL:2::dim=2, keep_boundary=1 +DEAL:2::561638746 +DEAL:2::OK +DEAL:2::dim=2, keep_boundary=0 +DEAL:2::1946764437 +DEAL:2::OK +DEAL:2::dim=3, keep_boundary=1 +DEAL:2::3893493253 +DEAL:2::OK +DEAL:2::dim=3, keep_boundary=0 +DEAL:2::2979128258 +DEAL:2::OK + -- 2.39.5