From 13288c73c412b7972d03fdf5663a0c545a8fc044 Mon Sep 17 00:00:00 2001 From: Giovanni Alzetta Date: Mon, 7 Jan 2019 12:09:28 +0100 Subject: [PATCH] Added tests and support for non-mpi to GridTools::build_global_tree --- source/grid/grid_tools.cc | 12 +- tests/grid/build_global_description_tree.cc | 124 ++++++++++++++++++ .../grid/build_global_description_tree.output | 3 + ...h_mpi=true.with_p4est=true.mpirun=2.output | 7 + 4 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 tests/grid/build_global_description_tree.cc create mode 100644 tests/grid/build_global_description_tree.output create mode 100644 tests/grid/build_global_description_tree.with_mpi=true.with_p4est=true.mpirun=2.output diff --git a/source/grid/grid_tools.cc b/source/grid/grid_tools.cc index 2da178fa23..caa15ded21 100644 --- a/source/grid/grid_tools.cc +++ b/source/grid/grid_tools.cc @@ -5088,12 +5088,14 @@ namespace GridTools MPI_Comm mpi_communicator) { #ifndef DEAL_II_WITH_MPI - (void)local_description; (void)mpi_communicator; - Assert(false, - ExcMessage( - "GridTools::build_global_description_tree() requires MPI.")); - return RTree, unsigned int>>{}; + // Building a tree with the only boxes available without MPI + std::vector, unsigned int>> boxes_index( + local_description.size()); + // Adding to each box the rank of the process owning it + for (unsigned int i = 0; i < local_description.size(); ++i) + boxes_index[i] = std::make_pair(local_description[i], 0u); + return pack_rtree(boxes_index); #else // Exchanging local bounding boxes std::vector>> global_bboxes; diff --git a/tests/grid/build_global_description_tree.cc b/tests/grid/build_global_description_tree.cc new file mode 100644 index 0000000000..3ece7f1828 --- /dev/null +++ b/tests/grid/build_global_description_tree.cc @@ -0,0 +1,124 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2018-2019 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Test GridTools::build_global_description_tree + + +#include +#include +#include +#include + +#include +#include + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "../tests.h" + +using namespace dealii; + +namespace bg = boost::geometry; +namespace bgi = boost::geometry::index; + + +template +void +test() +{ + unsigned int n_procs = Utilities::MPI::n_mpi_processes(MPI_COMM_WORLD); + unsigned int current_proc = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + unsigned int next_p = (current_proc + n_procs + 1) % n_procs; + + // For this test we actually set up a simple system of bounding boxes + // The triangulation is really used only to get the right mpi_communicator + Point p1; + Point p2; + for (unsigned int d = 1; d < spacedim; ++d) + { + p1[d] = current_proc; + p2[d] = current_proc + 1; + } + + BoundingBox box({p1, p2}); + + std::vector> local_description(1, box); + + auto built_tree = + GridTools::build_global_description_tree(local_description, MPI_COMM_WORLD); + + Point my_point; + Point point_inside_d_1; + Point outside_point; + + for (unsigned int d = 1; d < spacedim; ++d) + { + my_point[d] = current_proc + 0.1 + d / 4.2; + point_inside_d_1[d] = next_p + 0.25 + d / 5.1; + outside_point[d] = -current_proc - 2.6; + } + + std::vector, unsigned int>> test_results; + built_tree.query(bgi::intersects(outside_point), + std::back_inserter(test_results)); + if (test_results.size() != 0) + deallog + << "Point found inside a bounding box! It should be outside all of them!" + << std::endl; + + built_tree.query(bgi::intersects(my_point), std::back_inserter(test_results)); + if (std::get<1>(test_results[0]) != current_proc) + deallog << "Error: Point found inside wrong process: " + << std::get<1>(test_results[0]) << std::endl; + + built_tree.query(bgi::intersects(point_inside_d_1), + std::back_inserter(test_results)); + if (std::get<1>(test_results[1]) != next_p) + deallog << "Error: Point found inside wrong process: " + << std::get<1>(test_results[1]) << std::endl; +} + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); +#ifdef DEAL_II_WITH_MPI + MPILogInitAll log; +#else + initlog(); + deallog.push("0"); +#endif + + deallog << "Deal.II build_global_description_tree:" << std::endl; + + test<2, 2>(); + test<3, 3>(); + + deallog << "Test finished" << std::endl; + return 0; +} diff --git a/tests/grid/build_global_description_tree.output b/tests/grid/build_global_description_tree.output new file mode 100644 index 0000000000..7958569f40 --- /dev/null +++ b/tests/grid/build_global_description_tree.output @@ -0,0 +1,3 @@ + +DEAL:0::Deal.II build_global_description_tree: +DEAL:0::Test finished diff --git a/tests/grid/build_global_description_tree.with_mpi=true.with_p4est=true.mpirun=2.output b/tests/grid/build_global_description_tree.with_mpi=true.with_p4est=true.mpirun=2.output new file mode 100644 index 0000000000..b16cf2d3ab --- /dev/null +++ b/tests/grid/build_global_description_tree.with_mpi=true.with_p4est=true.mpirun=2.output @@ -0,0 +1,7 @@ + +DEAL:0::Deal.II build_global_description_tree: +DEAL:0::Test finished + +DEAL:1::Deal.II build_global_description_tree: +DEAL:1::Test finished + -- 2.39.5