From 7bb6e45ac86118e24e216821a1b0b439bc16e390 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Mon, 8 Feb 2021 17:21:35 -0700 Subject: [PATCH] Added tests for ::SolutionTransfer on p::s::Triangulations with artificial cells. --- tests/mpi/solution_transfer_07.cc | 92 +++++++++++++++ ..._transfer_07.with_mpi=true.mpirun=2.output | 15 +++ tests/mpi/solution_transfer_08.cc | 92 +++++++++++++++ ..._transfer_08.with_mpi=true.mpirun=2.output | 15 +++ tests/mpi/solution_transfer_09.cc | 110 ++++++++++++++++++ ..._transfer_09.with_mpi=true.mpirun=2.output | 9 ++ tests/mpi/solution_transfer_10.cc | 110 ++++++++++++++++++ ..._transfer_10.with_mpi=true.mpirun=2.output | 9 ++ 8 files changed, 452 insertions(+) create mode 100644 tests/mpi/solution_transfer_07.cc create mode 100644 tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output create mode 100644 tests/mpi/solution_transfer_08.cc create mode 100644 tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output create mode 100644 tests/mpi/solution_transfer_09.cc create mode 100644 tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output create mode 100644 tests/mpi/solution_transfer_10.cc create mode 100644 tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output diff --git a/tests/mpi/solution_transfer_07.cc b/tests/mpi/solution_transfer_07.cc new file mode 100644 index 0000000000..b3be482dd2 --- /dev/null +++ b/tests/mpi/solution_transfer_07.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 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. +// +// --------------------------------------------------------------------- + + + +// Verify that SolutionTransfer works on parallel shared Triangulation +// objects with or without artificial cells. +// +// Test 'coarsening_and_refinement'. + + +#include + +#include + +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +test(const bool allow_artificial_cells) +{ + parallel::shared::Triangulation tria(MPI_COMM_WORLD, + Triangulation::none, + allow_artificial_cells); + GridGenerator::subdivided_hyper_cube(tria, 2); + + FE_Q fe(1); + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + tria.begin_active()->set_refine_flag(); + tria.prepare_coarsening_and_refinement(); + + Vector sol_old(dh.n_dofs()); + sol_old = 1.; + + SolutionTransfer soltrans(dh); + soltrans.prepare_for_coarsening_and_refinement(sol_old); + + tria.execute_coarsening_and_refinement(); + dh.distribute_dofs(fe); + + Vector sol_new(dh.n_dofs()); + soltrans.interpolate(sol_old, sol_new); + for (unsigned int i = 0; i < sol_new.size(); ++i) + AssertThrow(sol_new[i] == 1., ExcInternalError()); + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + + deallog.push("1d"); + test<1>(false); + test<1>(true); + deallog.pop(); + deallog.push("2d"); + test<2>(false); + test<2>(true); + deallog.pop(); + deallog.push("3d"); + test<3>(false); + test<3>(true); + deallog.pop(); +} diff --git a/tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output new file mode 100644 index 0000000000..1f211b7ae7 --- /dev/null +++ b/tests/mpi/solution_transfer_07.with_mpi=true.mpirun=2.output @@ -0,0 +1,15 @@ + +DEAL:0:1d::OK +DEAL:0:1d::OK +DEAL:0:2d::OK +DEAL:0:2d::OK +DEAL:0:3d::OK +DEAL:0:3d::OK + +DEAL:1:1d::OK +DEAL:1:1d::OK +DEAL:1:2d::OK +DEAL:1:2d::OK +DEAL:1:3d::OK +DEAL:1:3d::OK + diff --git a/tests/mpi/solution_transfer_08.cc b/tests/mpi/solution_transfer_08.cc new file mode 100644 index 0000000000..09471e6387 --- /dev/null +++ b/tests/mpi/solution_transfer_08.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 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. +// +// --------------------------------------------------------------------- + + + +// Verify that SolutionTransfer works on parallel shared Triangulation +// objects with or without artificial cells. +// +// Test 'pure_refinement'. + + +#include + +#include + +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +test(const bool allow_artificial_cells) +{ + parallel::shared::Triangulation tria(MPI_COMM_WORLD, + Triangulation::none, + allow_artificial_cells); + GridGenerator::subdivided_hyper_cube(tria, 2); + + FE_Q fe(1); + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + tria.begin_active()->set_refine_flag(); + tria.prepare_coarsening_and_refinement(); + + Vector sol_old(dh.n_dofs()); + sol_old = 1.; + + SolutionTransfer soltrans(dh); + soltrans.prepare_for_pure_refinement(); + + tria.execute_coarsening_and_refinement(); + dh.distribute_dofs(fe); + + Vector sol_new(dh.n_dofs()); + soltrans.refine_interpolate(sol_old, sol_new); + for (unsigned int i = 0; i < sol_new.size(); ++i) + AssertThrow(sol_new[i] == 1., ExcInternalError()); + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + + deallog.push("1d"); + test<1>(false); + test<1>(true); + deallog.pop(); + deallog.push("2d"); + test<2>(false); + test<2>(true); + deallog.pop(); + deallog.push("3d"); + test<3>(false); + test<3>(true); + deallog.pop(); +} diff --git a/tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output new file mode 100644 index 0000000000..1f211b7ae7 --- /dev/null +++ b/tests/mpi/solution_transfer_08.with_mpi=true.mpirun=2.output @@ -0,0 +1,15 @@ + +DEAL:0:1d::OK +DEAL:0:1d::OK +DEAL:0:2d::OK +DEAL:0:2d::OK +DEAL:0:3d::OK +DEAL:0:3d::OK + +DEAL:1:1d::OK +DEAL:1:1d::OK +DEAL:1:2d::OK +DEAL:1:2d::OK +DEAL:1:3d::OK +DEAL:1:3d::OK + diff --git a/tests/mpi/solution_transfer_09.cc b/tests/mpi/solution_transfer_09.cc new file mode 100644 index 0000000000..a1ee7371d5 --- /dev/null +++ b/tests/mpi/solution_transfer_09.cc @@ -0,0 +1,110 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 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. +// +// --------------------------------------------------------------------- + + + +// Verify that SolutionTransfer yields the same result on parallel +// shared Triangulation objects with and without artificial cells. +// +// Test 'coarsening_and_refinement'. + + +#include +#include + +#include + +#include + +#include + +#include +#include + +#include + +#include +#include + +#include "../tests.h" + + +template +Vector +refine_and_transfer(const Function &function, Triangulation &tria) +{ + FE_Q fe(1); + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + tria.begin_active()->set_refine_flag(); + tria.prepare_coarsening_and_refinement(); + + Vector sol_old(dh.n_dofs()); + VectorTools::interpolate(MappingQGeneric(1), dh, function, sol_old); + + SolutionTransfer soltrans(dh); + soltrans.prepare_for_coarsening_and_refinement(sol_old); + + tria.execute_coarsening_and_refinement(); + dh.distribute_dofs(fe); + + Vector sol_new(dh.n_dofs()); + soltrans.interpolate(sol_old, sol_new); + + return sol_new; +} + + +template +void +test(const Function &function) +{ + parallel::shared::Triangulation tria(MPI_COMM_WORLD, + Triangulation::none, + false); + parallel::shared::Triangulation tria_artificial(MPI_COMM_WORLD, + Triangulation::none, + true); + GridGenerator::subdivided_hyper_cube(tria, 2); + GridGenerator::subdivided_hyper_cube(tria_artificial, 2); + + Vector sol = refine_and_transfer(function, tria); + Vector sol_artificial = + refine_and_transfer(function, tria_artificial); + + AssertDimension(sol.size(), sol_artificial.size()); + AssertThrow(sol == sol_artificial, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + + deallog.push("1d"); + test<1>(Functions::CosineFunction<1>()); + deallog.pop(); + deallog.push("2d"); + test<2>(Functions::CosineFunction<2>()); + deallog.pop(); + deallog.push("3d"); + test<3>(Functions::CosineFunction<3>()); + deallog.pop(); +} diff --git a/tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output new file mode 100644 index 0000000000..1b4e669b90 --- /dev/null +++ b/tests/mpi/solution_transfer_09.with_mpi=true.mpirun=2.output @@ -0,0 +1,9 @@ + +DEAL:0:1d::OK +DEAL:0:2d::OK +DEAL:0:3d::OK + +DEAL:1:1d::OK +DEAL:1:2d::OK +DEAL:1:3d::OK + diff --git a/tests/mpi/solution_transfer_10.cc b/tests/mpi/solution_transfer_10.cc new file mode 100644 index 0000000000..be62e2fb61 --- /dev/null +++ b/tests/mpi/solution_transfer_10.cc @@ -0,0 +1,110 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2021 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. +// +// --------------------------------------------------------------------- + + + +// Verify that SolutionTransfer yields the same result on parallel +// shared Triangulation objects with and without artificial cells. +// +// Test 'pure_refinement'. + + +#include +#include + +#include + +#include + +#include + +#include +#include + +#include + +#include +#include + +#include "../tests.h" + + +template +Vector +refine_and_transfer(const Function &function, Triangulation &tria) +{ + FE_Q fe(1); + DoFHandler dh(tria); + dh.distribute_dofs(fe); + + tria.begin_active()->set_refine_flag(); + tria.prepare_coarsening_and_refinement(); + + Vector sol_old(dh.n_dofs()); + VectorTools::interpolate(MappingQGeneric(1), dh, function, sol_old); + + SolutionTransfer soltrans(dh); + soltrans.prepare_for_pure_refinement(); + + tria.execute_coarsening_and_refinement(); + dh.distribute_dofs(fe); + + Vector sol_new(dh.n_dofs()); + soltrans.refine_interpolate(sol_old, sol_new); + + return sol_new; +} + + +template +void +test(const Function &function) +{ + parallel::shared::Triangulation tria(MPI_COMM_WORLD, + Triangulation::none, + false); + parallel::shared::Triangulation tria_artificial(MPI_COMM_WORLD, + Triangulation::none, + true); + GridGenerator::subdivided_hyper_cube(tria, 2); + GridGenerator::subdivided_hyper_cube(tria_artificial, 2); + + Vector sol = refine_and_transfer(function, tria); + Vector sol_artificial = + refine_and_transfer(function, tria_artificial); + + AssertDimension(sol.size(), sol_artificial.size()); + AssertThrow(sol == sol_artificial, ExcInternalError()); + + deallog << "OK" << std::endl; +} + + +int +main(int argc, char **argv) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll log; + + deallog.push("1d"); + test<1>(Functions::CosineFunction<1>()); + deallog.pop(); + deallog.push("2d"); + test<2>(Functions::CosineFunction<2>()); + deallog.pop(); + deallog.push("3d"); + test<3>(Functions::CosineFunction<3>()); + deallog.pop(); +} diff --git a/tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output b/tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output new file mode 100644 index 0000000000..1b4e669b90 --- /dev/null +++ b/tests/mpi/solution_transfer_10.with_mpi=true.mpirun=2.output @@ -0,0 +1,9 @@ + +DEAL:0:1d::OK +DEAL:0:2d::OK +DEAL:0:3d::OK + +DEAL:1:1d::OK +DEAL:1:2d::OK +DEAL:1:3d::OK + -- 2.39.5