From bc9fba251b57e8f546cf11ef62f77ab9ac6887bd Mon Sep 17 00:00:00 2001 From: Jean-Paul Pelteret Date: Tue, 3 Jul 2018 09:28:01 +0200 Subject: [PATCH] Add some MPI based tests for SolutionTransfer class --- tests/hp/solution_transfer_14.cc | 122 ++++++++++++++++++ ...sfer_14.with_trilinos=true.mpirun=2.output | 9 ++ ...tion_transfer_14.with_trilinos=true.output | 4 + tests/mpi/solution_transfer_02.cc | 120 +++++++++++++++++ ...sfer_02.with_trilinos=true.mpirun=2.output | 9 ++ ...tion_transfer_02.with_trilinos=true.output | 4 + 6 files changed, 268 insertions(+) create mode 100644 tests/hp/solution_transfer_14.cc create mode 100644 tests/hp/solution_transfer_14.with_trilinos=true.mpirun=2.output create mode 100644 tests/hp/solution_transfer_14.with_trilinos=true.output create mode 100644 tests/mpi/solution_transfer_02.cc create mode 100644 tests/mpi/solution_transfer_02.with_trilinos=true.mpirun=2.output create mode 100644 tests/mpi/solution_transfer_02.with_trilinos=true.output diff --git a/tests/hp/solution_transfer_14.cc b/tests/hp/solution_transfer_14.cc new file mode 100644 index 0000000000..5be629c0f3 --- /dev/null +++ b/tests/hp/solution_transfer_14.cc @@ -0,0 +1,122 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + +// Test to check if SolutionTransfer works in parallel. +// This tests is based off of solution_transfer_11.cc + +#include + +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include + +#include +#include + +#include "../tests.h" + + +template +void +transfer(const MPI_Comm &mpi_communicator) +{ + const unsigned int this_mpi_process = + Utilities::MPI::this_mpi_process(mpi_communicator); + + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + GridTools::partition_triangulation( + Utilities::MPI::n_mpi_processes(mpi_communicator), tria); + + hp::FECollection fe; + fe.push_back(FE_Q(1)); + fe.push_back(FE_Q(2)); + + hp::DoFHandler dof_handler(tria); + dof_handler.begin(0)->child(0)->set_active_fe_index(1); + + TrilinosWrappers::MPI::Vector solution; + + dof_handler.distribute_dofs(fe); + IndexSet locally_owned_dofs = + DoFTools::locally_owned_dofs_per_subdomain(dof_handler)[this_mpi_process]; + IndexSet locally_relevant_dofs = + DoFTools::locally_relevant_dofs_per_subdomain( + dof_handler)[this_mpi_process]; + solution.reinit(locally_owned_dofs, mpi_communicator); + + for (unsigned int i = 0; i < solution.size(); ++i) + if (locally_owned_dofs.is_element(i)) + solution(i) = i; + + SolutionTransfer> + soltrans(dof_handler); + + typename Triangulation::active_cell_iterator cell = tria.begin_active(), + endc = tria.end(); + ++cell; + ++cell; + for (; cell != endc; ++cell) + cell->set_refine_flag(); + + TrilinosWrappers::MPI::Vector old_solution; + old_solution.reinit(locally_owned_dofs, + locally_relevant_dofs, + mpi_communicator); + old_solution = solution; + + tria.prepare_coarsening_and_refinement(); + soltrans.prepare_for_pure_refinement(); + tria.execute_coarsening_and_refinement(); + dof_handler.distribute_dofs(fe); + locally_owned_dofs = + DoFTools::locally_owned_dofs_per_subdomain(dof_handler)[this_mpi_process]; + solution.reinit(locally_owned_dofs, mpi_communicator); + soltrans.refine_interpolate(old_solution, solution); +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + const MPI_Comm & mpi_communicator = MPI_COMM_WORLD; + + deallog << " 1D solution transfer" << std::endl; + transfer<1>(mpi_communicator); + + deallog << " 2D solution transfer" << std::endl; + transfer<2>(mpi_communicator); + + deallog << " 3D solution transfer" << std::endl; + transfer<3>(mpi_communicator); +} diff --git a/tests/hp/solution_transfer_14.with_trilinos=true.mpirun=2.output b/tests/hp/solution_transfer_14.with_trilinos=true.mpirun=2.output new file mode 100644 index 0000000000..d3343bcbd3 --- /dev/null +++ b/tests/hp/solution_transfer_14.with_trilinos=true.mpirun=2.output @@ -0,0 +1,9 @@ + +DEAL:0:: 1D solution transfer +DEAL:0:: 2D solution transfer +DEAL:0:: 3D solution transfer + +DEAL:1:: 1D solution transfer +DEAL:1:: 2D solution transfer +DEAL:1:: 3D solution transfer + diff --git a/tests/hp/solution_transfer_14.with_trilinos=true.output b/tests/hp/solution_transfer_14.with_trilinos=true.output new file mode 100644 index 0000000000..9764d32d2a --- /dev/null +++ b/tests/hp/solution_transfer_14.with_trilinos=true.output @@ -0,0 +1,4 @@ + +DEAL:0:: 1D solution transfer +DEAL:0:: 2D solution transfer +DEAL:0:: 3D solution transfer diff --git a/tests/mpi/solution_transfer_02.cc b/tests/mpi/solution_transfer_02.cc new file mode 100644 index 0000000000..49f8458416 --- /dev/null +++ b/tests/mpi/solution_transfer_02.cc @@ -0,0 +1,120 @@ +// --------------------------------------------------------------------- +// +// 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. +// +// --------------------------------------------------------------------- + + +// Test to check if SolutionTransfer works in parallel. +// This tests is based off of hp/solution_transfer_14.cc + +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include + +#include + +#include + +#include +#include + +#include "../tests.h" + + +template +void +transfer(const MPI_Comm &mpi_communicator) +{ + const unsigned int this_mpi_process = + Utilities::MPI::this_mpi_process(mpi_communicator); + + Triangulation tria; + GridGenerator::hyper_cube(tria); + tria.refine_global(1); + GridTools::partition_triangulation( + Utilities::MPI::n_mpi_processes(mpi_communicator), tria); + + const FE_Q fe(2); + + DoFHandler dof_handler(tria); + + TrilinosWrappers::MPI::Vector solution; + + dof_handler.distribute_dofs(fe); + IndexSet locally_owned_dofs = + DoFTools::locally_owned_dofs_per_subdomain(dof_handler)[this_mpi_process]; + IndexSet locally_relevant_dofs = + DoFTools::locally_relevant_dofs_per_subdomain( + dof_handler)[this_mpi_process]; + solution.reinit(locally_owned_dofs, mpi_communicator); + + for (unsigned int i = 0; i < solution.size(); ++i) + if (locally_owned_dofs.is_element(i)) + solution(i) = i; + + SolutionTransfer> + soltrans(dof_handler); + + typename Triangulation::active_cell_iterator cell = tria.begin_active(), + endc = tria.end(); + ++cell; + ++cell; + for (; cell != endc; ++cell) + cell->set_refine_flag(); + + TrilinosWrappers::MPI::Vector old_solution; + old_solution.reinit(locally_owned_dofs, + locally_relevant_dofs, + mpi_communicator); + old_solution = solution; + + tria.prepare_coarsening_and_refinement(); + soltrans.prepare_for_pure_refinement(); + tria.execute_coarsening_and_refinement(); + dof_handler.distribute_dofs(fe); + locally_owned_dofs = + DoFTools::locally_owned_dofs_per_subdomain(dof_handler)[this_mpi_process]; + locally_relevant_dofs = DoFTools::locally_relevant_dofs_per_subdomain( + dof_handler)[this_mpi_process]; + solution.reinit(locally_owned_dofs, mpi_communicator); + soltrans.refine_interpolate(old_solution, solution); +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + const MPI_Comm & mpi_communicator = MPI_COMM_WORLD; + + deallog << " 1D solution transfer" << std::endl; + transfer<1>(mpi_communicator); + + deallog << " 2D solution transfer" << std::endl; + transfer<2>(mpi_communicator); + + deallog << " 3D solution transfer" << std::endl; + transfer<3>(mpi_communicator); +} diff --git a/tests/mpi/solution_transfer_02.with_trilinos=true.mpirun=2.output b/tests/mpi/solution_transfer_02.with_trilinos=true.mpirun=2.output new file mode 100644 index 0000000000..d3343bcbd3 --- /dev/null +++ b/tests/mpi/solution_transfer_02.with_trilinos=true.mpirun=2.output @@ -0,0 +1,9 @@ + +DEAL:0:: 1D solution transfer +DEAL:0:: 2D solution transfer +DEAL:0:: 3D solution transfer + +DEAL:1:: 1D solution transfer +DEAL:1:: 2D solution transfer +DEAL:1:: 3D solution transfer + diff --git a/tests/mpi/solution_transfer_02.with_trilinos=true.output b/tests/mpi/solution_transfer_02.with_trilinos=true.output new file mode 100644 index 0000000000..9764d32d2a --- /dev/null +++ b/tests/mpi/solution_transfer_02.with_trilinos=true.output @@ -0,0 +1,4 @@ + +DEAL:0:: 1D solution transfer +DEAL:0:: 2D solution transfer +DEAL:0:: 3D solution transfer -- 2.39.5