From 474068f0bcd363c9752cd6637c9447a8092ee8c2 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 6 Sep 2018 14:58:30 -0600 Subject: [PATCH] Add tests. --- tests/mpi/renumber_z_order_05.cc | 119 +++++++++++++++++ ...z_order_05.with_p4est=true.mpirun=4.output | 31 +++++ tests/mpi/renumber_z_order_06.cc | 123 ++++++++++++++++++ ...z_order_06.with_p4est=true.mpirun=4.output | 31 +++++ 4 files changed, 304 insertions(+) create mode 100644 tests/mpi/renumber_z_order_05.cc create mode 100644 tests/mpi/renumber_z_order_05.with_p4est=true.mpirun=4.output create mode 100644 tests/mpi/renumber_z_order_06.cc create mode 100644 tests/mpi/renumber_z_order_06.with_p4est=true.mpirun=4.output diff --git a/tests/mpi/renumber_z_order_05.cc b/tests/mpi/renumber_z_order_05.cc new file mode 100644 index 0000000000..27fd2a3c10 --- /dev/null +++ b/tests/mpi/renumber_z_order_05.cc @@ -0,0 +1,119 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Test that DofRenumbering::hierarchical() gives the same DoF numbers +// independent of their previous ordering. This was broken before where +// the hierarchical numbering on each processor re-used the indices +// the processor previously owned. This worked just fine with the +// original ordering used by default by DoFHandler, but not if there +// was another reordering step in between. +// +// This test is like the _04 test, but for dim!=spacedim + + +#include +#include + +#include + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include "../tests.h" + + +void +test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + + parallel::distributed::Triangulation<2, 3> tr(MPI_COMM_WORLD); + GridGenerator::subdivided_hyper_rectangle(tr, + std::vector{{2, 2}}, + Point<2>(), + Point<2>(2, 2)); + + const FE_Q<2, 3> fe(1); + + for (unsigned int test = 0; test < 2; ++test) + { + DoFHandler<2, 3> dof_handler(tr); + dof_handler.distribute_dofs(fe); + + // in the second test run, revert the global order of DoF + // indices. the point is to make sure that processors do not + // have strictly increasing, contiguous groups of DoF indices. + if (test == 1) + { + IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs(); + std::vector new_numbers( + locally_owned_dofs.n_elements()); + for (auto i : locally_owned_dofs) + new_numbers[locally_owned_dofs.index_within_set(i)] = + dof_handler.n_dofs() - i - 1; + dof_handler.renumber_dofs(new_numbers); + } + + // next, let the hierarchical numbering work on it. the + // important aspect is that the result of hierarchical + // renumbering should not depend on the *previous* numbering. so + // we should be getting the same output as in the first run + DoFRenumbering::hierarchical(dof_handler); + + // output DoF indices + deallog << (test == 0 ? "Without " : "With ") + << "prior reordering:" << std::endl; + const unsigned int dofs_per_cell = fe.dofs_per_cell; + std::vector local_dof_indices(dofs_per_cell); + DoFHandler<2, 3>::active_cell_iterator cell = dof_handler.begin_active(), + endc = dof_handler.end(); + for (; cell != endc; ++cell) + if (cell->subdomain_id() == tr.locally_owned_subdomain()) + { + deallog << "Cell=" << cell << std::endl; + cell->get_dof_indices(local_dof_indices); + for (auto i : local_dof_indices) + deallog << i << ' '; + deallog << std::endl; + } + } +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + + test(); +} diff --git a/tests/mpi/renumber_z_order_05.with_p4est=true.mpirun=4.output b/tests/mpi/renumber_z_order_05.with_p4est=true.mpirun=4.output new file mode 100644 index 0000000000..e917cb3595 --- /dev/null +++ b/tests/mpi/renumber_z_order_05.with_p4est=true.mpirun=4.output @@ -0,0 +1,31 @@ + +DEAL:0::Without prior reordering: +DEAL:0::Cell=0.0 +DEAL:0::0 1 2 3 +DEAL:0::With prior reordering: +DEAL:0::Cell=0.0 +DEAL:0::0 1 2 3 + +DEAL:1::Without prior reordering: +DEAL:1::Cell=0.1 +DEAL:1::1 4 3 5 +DEAL:1::With prior reordering: +DEAL:1::Cell=0.1 +DEAL:1::1 4 3 5 + + +DEAL:2::Without prior reordering: +DEAL:2::Cell=0.2 +DEAL:2::2 3 6 7 +DEAL:2::With prior reordering: +DEAL:2::Cell=0.2 +DEAL:2::2 3 6 7 + + +DEAL:3::Without prior reordering: +DEAL:3::Cell=0.3 +DEAL:3::3 5 7 8 +DEAL:3::With prior reordering: +DEAL:3::Cell=0.3 +DEAL:3::3 5 7 8 + diff --git a/tests/mpi/renumber_z_order_06.cc b/tests/mpi/renumber_z_order_06.cc new file mode 100644 index 0000000000..a9e866164f --- /dev/null +++ b/tests/mpi/renumber_z_order_06.cc @@ -0,0 +1,123 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 - 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Test that DofRenumbering::hierarchical() gives the same DoF numbers +// independent of their previous ordering. This was broken before where +// the hierarchical numbering on each processor re-used the indices +// the processor previously owned. This worked just fine with the +// original ordering used by default by DoFHandler, but not if there +// was another reordering step in between. +// +// This test is like the _04 test, but for dim!=spacedim and using an +// hp::DoFHandler with a single element. + + +#include +#include + +#include + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include "../tests.h" + + +void +test() +{ + unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + + parallel::distributed::Triangulation<2, 3> tr(MPI_COMM_WORLD); + GridGenerator::subdivided_hyper_rectangle(tr, + std::vector{{2, 2}}, + Point<2>(), + Point<2>(2, 2)); + + hp::FECollection<2, 3> fe; + fe.push_back(FE_Q<2, 3>(1)); + + for (unsigned int test = 0; test < 2; ++test) + { + hp::DoFHandler<2, 3> dof_handler(tr); + dof_handler.distribute_dofs(fe); + + // in the second test run, revert the global order of DoF + // indices. the point is to make sure that processors do not + // have strictly increasing, contiguous groups of DoF indices. + if (test == 1) + { + IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs(); + std::vector new_numbers( + locally_owned_dofs.n_elements()); + for (auto i : locally_owned_dofs) + new_numbers[locally_owned_dofs.index_within_set(i)] = + dof_handler.n_dofs() - i - 1; + dof_handler.renumber_dofs(new_numbers); + } + + // next, let the hierarchical numbering work on it. the + // important aspect is that the result of hierarchical + // renumbering should not depend on the *previous* numbering. so + // we should be getting the same output as in the first run + DoFRenumbering::hierarchical(dof_handler); + + // output DoF indices + deallog << (test == 0 ? "Without " : "With ") + << "prior reordering:" << std::endl; + const unsigned int dofs_per_cell = fe[0].dofs_per_cell; + std::vector local_dof_indices(dofs_per_cell); + hp::DoFHandler<2, 3>::active_cell_iterator cell = + dof_handler.begin_active(), + endc = dof_handler.end(); + for (; cell != endc; ++cell) + if (cell->subdomain_id() == tr.locally_owned_subdomain()) + { + deallog << "Cell=" << cell << std::endl; + cell->get_dof_indices(local_dof_indices); + for (auto i : local_dof_indices) + deallog << i << ' '; + deallog << std::endl; + } + } +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + + test(); +} diff --git a/tests/mpi/renumber_z_order_06.with_p4est=true.mpirun=4.output b/tests/mpi/renumber_z_order_06.with_p4est=true.mpirun=4.output new file mode 100644 index 0000000000..e917cb3595 --- /dev/null +++ b/tests/mpi/renumber_z_order_06.with_p4est=true.mpirun=4.output @@ -0,0 +1,31 @@ + +DEAL:0::Without prior reordering: +DEAL:0::Cell=0.0 +DEAL:0::0 1 2 3 +DEAL:0::With prior reordering: +DEAL:0::Cell=0.0 +DEAL:0::0 1 2 3 + +DEAL:1::Without prior reordering: +DEAL:1::Cell=0.1 +DEAL:1::1 4 3 5 +DEAL:1::With prior reordering: +DEAL:1::Cell=0.1 +DEAL:1::1 4 3 5 + + +DEAL:2::Without prior reordering: +DEAL:2::Cell=0.2 +DEAL:2::2 3 6 7 +DEAL:2::With prior reordering: +DEAL:2::Cell=0.2 +DEAL:2::2 3 6 7 + + +DEAL:3::Without prior reordering: +DEAL:3::Cell=0.3 +DEAL:3::3 5 7 8 +DEAL:3::With prior reordering: +DEAL:3::Cell=0.3 +DEAL:3::3 5 7 8 + -- 2.39.5