From 1c93e9062b2ee949cfb05583705031a65ed4c0fb Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 1 Jul 2023 20:13:55 -0600 Subject: [PATCH] Add test. --- tests/petsc/solution_transfer_01.cc | 100 ++++++++++++++++++++++++ tests/petsc/solution_transfer_01.output | 3 + tests/petsc/solution_transfer_02.cc | 100 ++++++++++++++++++++++++ tests/petsc/solution_transfer_02.output | 3 + 4 files changed, 206 insertions(+) create mode 100644 tests/petsc/solution_transfer_01.cc create mode 100644 tests/petsc/solution_transfer_01.output create mode 100644 tests/petsc/solution_transfer_02.cc create mode 100644 tests/petsc/solution_transfer_02.output diff --git a/tests/petsc/solution_transfer_01.cc b/tests/petsc/solution_transfer_01.cc new file mode 100644 index 0000000000..5c0b92d428 --- /dev/null +++ b/tests/petsc/solution_transfer_01.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2023 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. +// +// --------------------------------------------------------------------- + + + +// SolutionTransfer writes into vectors, but used to forget to +// compress the resulting vectors appropriately. This didn't matter +// most of the time because the (sequential) SolutionTransfer was +// apparently used only with our own vector types, for which +// compress() is a no-op. But it failed with PETSc vectors. +// +// This variation of the function deals with the +// SolutionTransfer::interpolate() variant that takes multiple vectors +// to transfer. + + +#include +#include + +#include + +#include +#include + +#include + +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + Triangulation triangulation; + + GridGenerator::hyper_cube(triangulation, 0, 1); + triangulation.refine_global(2); + + FE_Q fe(1); + DoFHandler dof_handler(triangulation); + dof_handler.distribute_dofs(fe); + + + PETScWrappers::MPI::Vector solution; + solution.reinit(dof_handler.locally_owned_dofs(), MPI_COMM_SELF); + + // Do a fake transfer + SolutionTransfer solution_trans(dof_handler); + + PETScWrappers::MPI::Vector previous_solution; + previous_solution = solution; + triangulation.prepare_coarsening_and_refinement(); + solution_trans.prepare_for_coarsening_and_refinement(previous_solution); + + triangulation.execute_coarsening_and_refinement(); + + solution_trans.interpolate(previous_solution, solution); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + mpi_initlog(); + deallog << std::setprecision(2); + + { + deallog.push("2d"); + test<2>(); + deallog.pop(); + } + + { + deallog.push("3d"); + test<3>(); + deallog.pop(); + } +} diff --git a/tests/petsc/solution_transfer_01.output b/tests/petsc/solution_transfer_01.output new file mode 100644 index 0000000000..25966e9bd0 --- /dev/null +++ b/tests/petsc/solution_transfer_01.output @@ -0,0 +1,3 @@ + +DEAL:2d::OK +DEAL:3d::OK diff --git a/tests/petsc/solution_transfer_02.cc b/tests/petsc/solution_transfer_02.cc new file mode 100644 index 0000000000..5c0b92d428 --- /dev/null +++ b/tests/petsc/solution_transfer_02.cc @@ -0,0 +1,100 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2023 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. +// +// --------------------------------------------------------------------- + + + +// SolutionTransfer writes into vectors, but used to forget to +// compress the resulting vectors appropriately. This didn't matter +// most of the time because the (sequential) SolutionTransfer was +// apparently used only with our own vector types, for which +// compress() is a no-op. But it failed with PETSc vectors. +// +// This variation of the function deals with the +// SolutionTransfer::interpolate() variant that takes multiple vectors +// to transfer. + + +#include +#include + +#include + +#include +#include + +#include + +#include + +#include + +#include "../tests.h" + + +template +void +test() +{ + Triangulation triangulation; + + GridGenerator::hyper_cube(triangulation, 0, 1); + triangulation.refine_global(2); + + FE_Q fe(1); + DoFHandler dof_handler(triangulation); + dof_handler.distribute_dofs(fe); + + + PETScWrappers::MPI::Vector solution; + solution.reinit(dof_handler.locally_owned_dofs(), MPI_COMM_SELF); + + // Do a fake transfer + SolutionTransfer solution_trans(dof_handler); + + PETScWrappers::MPI::Vector previous_solution; + previous_solution = solution; + triangulation.prepare_coarsening_and_refinement(); + solution_trans.prepare_for_coarsening_and_refinement(previous_solution); + + triangulation.execute_coarsening_and_refinement(); + + solution_trans.interpolate(previous_solution, solution); + + deallog << "OK" << std::endl; +} + + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization( + argc, argv, testing_max_num_threads()); + + mpi_initlog(); + deallog << std::setprecision(2); + + { + deallog.push("2d"); + test<2>(); + deallog.pop(); + } + + { + deallog.push("3d"); + test<3>(); + deallog.pop(); + } +} diff --git a/tests/petsc/solution_transfer_02.output b/tests/petsc/solution_transfer_02.output new file mode 100644 index 0000000000..25966e9bd0 --- /dev/null +++ b/tests/petsc/solution_transfer_02.output @@ -0,0 +1,3 @@ + +DEAL:2d::OK +DEAL:3d::OK -- 2.39.5