From: Martin Kronbichler Date: Wed, 26 Jun 2024 20:14:06 +0000 (+0200) Subject: New test cases X-Git-Tag: v9.6.0-rc1~52^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=83bba6993a5aeaa8480a5b55b578d224ca5baf38;p=dealii.git New test cases --- diff --git a/tests/multigrid-global-coarsening/mg_transfer_p_08.cc b/tests/multigrid-global-coarsening/mg_transfer_p_08.cc new file mode 100644 index 0000000000..27ca7c4788 --- /dev/null +++ b/tests/multigrid-global-coarsening/mg_transfer_p_08.cc @@ -0,0 +1,174 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +/** + * Test MGTwoLevelTransfer set up with MatrixFree objects by comparing against + * MGTwoLevelTransfer set up from DoFHandler for restriction and prolongation + */ + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +template +void +do_test(const FiniteElement &fe_fine, + const FiniteElement &fe_coarse, + const Triangulation &tria) +{ + deallog << "Testing " << fe_fine.get_name() << " <-> " << fe_coarse.get_name() + << std::endl; + // setup dof-handlers + DoFHandler dof_handler_fine(tria); + dof_handler_fine.distribute_dofs(fe_fine); + + DoFHandler dof_handler_coarse(tria); + dof_handler_coarse.distribute_dofs(fe_coarse); + + AffineConstraints constraints_coarse( + dof_handler_coarse.locally_owned_dofs(), + DoFTools::extract_locally_relevant_dofs(dof_handler_coarse)); + DoFTools::make_hanging_node_constraints(dof_handler_coarse, + constraints_coarse); + constraints_coarse.close(); + + AffineConstraints constraints_fine( + dof_handler_fine.locally_owned_dofs(), + DoFTools::extract_locally_relevant_dofs(dof_handler_fine)); + DoFTools::make_hanging_node_constraints(dof_handler_fine, constraints_fine); + constraints_fine.close(); + + // setup transfer operator + MGTwoLevelTransfer> + transfer_ref; + transfer_ref.reinit(dof_handler_fine, + dof_handler_coarse, + constraints_fine, + constraints_coarse); + + MappingQ1 mapping; + MatrixFree mf_coarse, mf_fine; + mf_coarse.reinit(mapping, + dof_handler_coarse, + constraints_coarse, + QGauss(1), + typename MatrixFree::AdditionalData()); + mf_fine.reinit(mapping, + dof_handler_fine, + constraints_fine, + QGauss(1), + typename MatrixFree::AdditionalData()); + MGTwoLevelTransfer> transfer; + transfer.reinit(mf_fine, 0, mf_coarse, 0); + + LinearAlgebra::distributed::Vector vec_fine_0, vec_fine_1, + vec_coarse_0, vec_coarse_1; + mf_fine.initialize_dof_vector(vec_fine_0); + mf_fine.initialize_dof_vector(vec_fine_1); + mf_coarse.initialize_dof_vector(vec_coarse_0); + mf_coarse.initialize_dof_vector(vec_coarse_1); + + // prolongate + for (auto &d : vec_coarse_0) + d = random_value(); + transfer_ref.prolongate_and_add(vec_fine_0, vec_coarse_0); + transfer.prolongate_and_add(vec_fine_1, vec_coarse_0); + deallog << "Prolongate: " << vec_fine_0.l2_norm() << " " + << vec_fine_1.l2_norm() << " "; + vec_fine_1 -= vec_fine_0; + deallog << vec_fine_1.l2_norm() << std::endl; + + vec_coarse_0 = 0; + transfer_ref.restrict_and_add(vec_coarse_0, vec_fine_0); + vec_coarse_1 = 0; + transfer.restrict_and_add(vec_coarse_1, vec_fine_0); + deallog << "Restrict: " << vec_coarse_0.l2_norm() << " " + << vec_coarse_1.l2_norm() << " "; + vec_coarse_1 -= vec_coarse_0; + deallog << vec_coarse_1.l2_norm() << std::endl << std::endl; +} + + + +template +void +test(int fe_degree_fine, int fe_degree_coarse) +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, -1., 1.); + tria.refine_global(5 - dim); + + deallog << "Uniform grid" << std::endl << std::endl; + do_test(FE_Q(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_DGQ(fe_degree_coarse), + tria); + + for (const auto &cell : tria.active_cell_iterators()) + if (cell->center()[0] < 0 || cell->center()[1] < 0 || + cell->center()[dim - 1] < 0) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + deallog << "Adaptively refined grid" << std::endl << std::endl; + do_test(FE_Q(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_DGQ(fe_degree_coarse), + tria); +} + + + +int +main() +{ + initlog(); + + MultithreadInfo::set_thread_limit(1); + + deallog.precision(8); + + test<2, double>(2, 1); + test<2, double>(3, 1); + test<2, double>(1, 1); + test<3, double>(2, 1); +} diff --git a/tests/multigrid-global-coarsening/mg_transfer_p_08.output b/tests/multigrid-global-coarsening/mg_transfer_p_08.output new file mode 100644 index 0000000000..1b4553385a --- /dev/null +++ b/tests/multigrid-global-coarsening/mg_transfer_p_08.output @@ -0,0 +1,113 @@ + +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 9.7594177 9.7594177 2.5928168e-16 +DEAL::Restrict: 18.243332 18.243332 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 13.681075 13.681075 0.0000000 +DEAL::Restrict: 37.528777 37.528777 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 13.410468 13.410468 0.0000000 +DEAL::Restrict: 19.646997 19.646997 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 17.050353 17.050353 4.2576778e-16 +DEAL::Restrict: 32.785109 32.785109 1.0175362e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 22.993594 22.993594 0.0000000 +DEAL::Restrict: 64.734329 64.734329 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 23.896733 23.896733 0.0000000 +DEAL::Restrict: 34.979593 34.979593 0.0000000 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 13.970341 13.970341 3.7649495e-16 +DEAL::Restrict: 38.921055 38.921055 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 17.897493 17.897493 0.0000000 +DEAL::Restrict: 64.733634 64.733634 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 17.040442 17.040442 0.0000000 +DEAL::Restrict: 33.069406 33.069406 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 23.995505 23.995505 4.5543677e-16 +DEAL::Restrict: 68.683227 68.683227 1.2560740e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 32.232248 32.232248 0.0000000 +DEAL::Restrict: 121.85053 121.85053 1.7763568e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 31.288447 31.288447 0.0000000 +DEAL::Restrict: 60.922879 60.922879 0.0000000 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 5.8705925 5.8705925 1.3718318e-15 +DEAL::Restrict: 5.8705925 5.8705925 1.3925930e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 8.5900766 8.5900766 0.0000000 +DEAL::Restrict: 16.161051 16.161051 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 9.2810677 9.2810677 2.7336622e-15 +DEAL::Restrict: 9.2810677 9.2810677 2.3902658e-15 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 8.5554966 8.5554966 2.2520986e-15 +DEAL::Restrict: 8.5554966 8.5554966 2.2061413e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 16.938147 16.938147 0.0000000 +DEAL::Restrict: 33.240500 33.240500 6.6613381e-16 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 16.701303 16.701303 4.9116575e-15 +DEAL::Restrict: 16.701303 16.701303 4.2433973e-15 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 14.568060 14.568060 3.3947435e-16 +DEAL::Restrict: 34.906413 34.906413 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 24.761956 24.761956 0.0000000 +DEAL::Restrict: 104.38633 104.38633 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_DGQ<3>(1) +DEAL::Prolongate: 22.941814 22.941814 0.0000000 +DEAL::Restrict: 40.931761 40.931761 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 33.426138 33.426138 9.3934916e-16 +DEAL::Restrict: 86.786371 86.786371 5.3842955e-15 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 60.273111 60.273111 0.0000000 +DEAL::Restrict: 283.65311 283.65311 1.7874246e-14 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_DGQ<3>(1) +DEAL::Prolongate: 59.789542 59.789542 0.0000000 +DEAL::Restrict: 106.61081 106.61081 0.0000000 +DEAL:: diff --git a/tests/multigrid-global-coarsening/mg_transfer_p_09.cc b/tests/multigrid-global-coarsening/mg_transfer_p_09.cc new file mode 100644 index 0000000000..4d82350fb4 --- /dev/null +++ b/tests/multigrid-global-coarsening/mg_transfer_p_09.cc @@ -0,0 +1,176 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +/** + * Test MGTwoLevelTransfer set up via MatrixFree objects in parallel, using a + * similar test as mg_transfer_p_08 + */ + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +template +void +do_test(const FiniteElement &fe_fine, + const FiniteElement &fe_coarse, + const Triangulation &tria) +{ + deallog << "Testing " << fe_fine.get_name() << " <-> " << fe_coarse.get_name() + << std::endl; + // setup dof-handlers + DoFHandler dof_handler_fine(tria); + dof_handler_fine.distribute_dofs(fe_fine); + + DoFHandler dof_handler_coarse(tria); + dof_handler_coarse.distribute_dofs(fe_coarse); + + AffineConstraints constraints_coarse( + dof_handler_coarse.locally_owned_dofs(), + DoFTools::extract_locally_relevant_dofs(dof_handler_coarse)); + DoFTools::make_hanging_node_constraints(dof_handler_coarse, + constraints_coarse); + constraints_coarse.close(); + + AffineConstraints constraints_fine( + dof_handler_fine.locally_owned_dofs(), + DoFTools::extract_locally_relevant_dofs(dof_handler_fine)); + DoFTools::make_hanging_node_constraints(dof_handler_fine, constraints_fine); + constraints_fine.close(); + + // setup transfer operator + MGTwoLevelTransfer> + transfer_ref; + transfer_ref.reinit(dof_handler_fine, + dof_handler_coarse, + constraints_fine, + constraints_coarse); + + MappingQ1 mapping; + MatrixFree mf_coarse, mf_fine; + mf_coarse.reinit(mapping, + dof_handler_coarse, + constraints_coarse, + QGauss(1), + typename MatrixFree::AdditionalData()); + mf_fine.reinit(mapping, + dof_handler_fine, + constraints_fine, + QGauss(1), + typename MatrixFree::AdditionalData()); + MGTwoLevelTransfer> transfer; + transfer.reinit(mf_fine, 0, mf_coarse, 0); + + LinearAlgebra::distributed::Vector vec_fine_0, vec_fine_1, + vec_coarse_0, vec_coarse_1; + mf_fine.initialize_dof_vector(vec_fine_0); + mf_fine.initialize_dof_vector(vec_fine_1); + mf_coarse.initialize_dof_vector(vec_coarse_0); + mf_coarse.initialize_dof_vector(vec_coarse_1); + + // prolongate + for (auto &d : vec_coarse_0) + d = random_value(); + transfer_ref.prolongate_and_add(vec_fine_0, vec_coarse_0); + transfer.prolongate_and_add(vec_fine_1, vec_coarse_0); + deallog << "Prolongate: " << vec_fine_0.l2_norm() << " " + << vec_fine_1.l2_norm() << " "; + vec_fine_1 -= vec_fine_0; + deallog << vec_fine_1.l2_norm() << std::endl; + + vec_coarse_0 = 0; + transfer_ref.restrict_and_add(vec_coarse_0, vec_fine_0); + transfer.restrict_and_add(vec_coarse_1, vec_fine_0); + deallog << "Restrict: " << vec_coarse_0.l2_norm() << " " + << vec_coarse_1.l2_norm() << " "; + vec_coarse_1 -= vec_coarse_0; + deallog << vec_coarse_1.l2_norm() << std::endl << std::endl; +} + + + +template +void +test(int fe_degree_fine, int fe_degree_coarse) +{ + parallel::distributed::Triangulation tria(MPI_COMM_WORLD); + GridGenerator::hyper_cube(tria, -1., 1.); + tria.refine_global(5 - dim); + + deallog << "Uniform grid" << std::endl << std::endl; + do_test(FE_Q(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_DGQ(fe_degree_coarse), + tria); + + for (const auto &cell : tria.active_cell_iterators()) + if (cell->center()[0] < 0 || cell->center()[1] < 0 || + cell->center()[dim - 1] < 0) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + deallog << "Adaptively refined grid" << std::endl << std::endl; + do_test(FE_Q(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_DGQ(fe_degree_coarse), + tria); +} + + + +int +main(int argc, char **argv) +{ + mpi_initlog(); + + Utilities::MPI::MPI_InitFinalize mpi(argc, argv, 1); + + deallog.precision(8); + + test<2, double>(2, 1); + test<2, double>(3, 1); + test<2, double>(1, 1); + test<3, double>(2, 1); +} diff --git a/tests/multigrid-global-coarsening/mg_transfer_p_09.with_p4est=true.mpirun=2.output b/tests/multigrid-global-coarsening/mg_transfer_p_09.with_p4est=true.mpirun=2.output new file mode 100644 index 0000000000..21c888149d --- /dev/null +++ b/tests/multigrid-global-coarsening/mg_transfer_p_09.with_p4est=true.mpirun=2.output @@ -0,0 +1,113 @@ + +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 9.4483815 9.4483815 1.9629222e-16 +DEAL::Restrict: 17.465797 17.465797 2.2204460e-16 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 13.546334 13.546334 0.0000000 +DEAL::Restrict: 36.608314 36.608314 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 14.159491 14.159491 0.0000000 +DEAL::Restrict: 20.766381 20.766381 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 16.577860 16.577860 4.3885418e-16 +DEAL::Restrict: 31.875804 31.875804 1.2161884e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 22.856584 22.856584 0.0000000 +DEAL::Restrict: 65.425562 65.425562 2.5510983e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 24.280557 24.280557 0.0000000 +DEAL::Restrict: 35.583303 35.583303 0.0000000 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 13.383701 13.383701 2.9110293e-16 +DEAL::Restrict: 37.265683 37.265683 9.9301366e-16 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 17.363047 17.363047 0.0000000 +DEAL::Restrict: 63.747617 63.747617 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 17.487769 17.487769 0.0000000 +DEAL::Restrict: 34.033630 34.033630 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 23.874363 23.874363 5.1796240e-16 +DEAL::Restrict: 67.651419 67.651419 1.6616297e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 30.992134 30.992134 0.0000000 +DEAL::Restrict: 118.86886 118.86886 5.1021966e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 31.965373 31.965373 0.0000000 +DEAL::Restrict: 62.378601 62.378601 0.0000000 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 5.0670626 5.0670626 1.3638424e-15 +DEAL::Restrict: 5.0670626 5.0670626 1.2276255e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 8.9499952 8.9499952 0.0000000 +DEAL::Restrict: 16.296827 16.296827 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 9.1815144 9.1815144 2.7689839e-15 +DEAL::Restrict: 9.1815144 9.1815144 2.3686740e-15 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 8.7026201 8.7026201 2.2275997e-15 +DEAL::Restrict: 8.7026201 8.7026201 2.1437547e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 16.322042 16.322042 0.0000000 +DEAL::Restrict: 31.769324 31.769324 8.0059321e-16 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 16.784284 16.784284 5.0508063e-15 +DEAL::Restrict: 16.784284 16.784284 4.3041266e-15 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 14.283655 14.283655 4.2389770e-16 +DEAL::Restrict: 34.659345 34.659345 1.3322676e-15 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 21.684421 21.684421 0.0000000 +DEAL::Restrict: 86.718276 86.718276 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_DGQ<3>(1) +DEAL::Prolongate: 21.869381 21.869381 0.0000000 +DEAL::Restrict: 38.878744 38.878744 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 35.376142 35.376142 1.0337658e-15 +DEAL::Restrict: 91.441559 91.441559 4.7881385e-15 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 58.985203 58.985203 0.0000000 +DEAL::Restrict: 277.38156 277.38156 1.0658141e-14 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_DGQ<3>(1) +DEAL::Prolongate: 60.890816 60.890816 0.0000000 +DEAL::Restrict: 108.70426 108.70426 0.0000000 +DEAL:: diff --git a/tests/multigrid-global-coarsening/mg_transfer_p_10.cc b/tests/multigrid-global-coarsening/mg_transfer_p_10.cc new file mode 100644 index 0000000000..794c817151 --- /dev/null +++ b/tests/multigrid-global-coarsening/mg_transfer_p_10.cc @@ -0,0 +1,189 @@ +// ------------------------------------------------------------------------ +// +// SPDX-License-Identifier: LGPL-2.1-or-later +// Copyright (C) 2024 by the deal.II authors +// +// This file is part of the deal.II library. +// +// Part of the source code is dual licensed under Apache-2.0 WITH +// LLVM-exception OR LGPL-2.1-or-later. Detailed license information +// governing the source code and code contributions can be found in +// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II. +// +// ------------------------------------------------------------------------ + + +/** + * Test MGTwoLevelTransfer set up with MatrixFree objects with multiple + * DoFHandler objects + */ + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include + +#include + +#include + +#include "../tests.h" + +using namespace dealii; + +template +void +do_test(const FiniteElement &fe_fine, + const FiniteElement &fe_coarse, + const Triangulation &tria) +{ + deallog << "Testing " << fe_fine.get_name() << " <-> " << fe_coarse.get_name() + << std::endl; + // setup dof-handlers + DoFHandler dof_handler_fine(tria); + dof_handler_fine.distribute_dofs(fe_fine); + + DoFHandler dof_handler_coarse(tria); + dof_handler_coarse.distribute_dofs(fe_coarse); + + FE_DGQ fe_dummy(0); + DoFHandler dof_handler_dummy(tria); + dof_handler_dummy.distribute_dofs(fe_dummy); + AffineConstraints constraints_dummy; + constraints_dummy.close(); + + AffineConstraints constraints_coarse( + dof_handler_coarse.locally_owned_dofs(), + DoFTools::extract_locally_relevant_dofs(dof_handler_coarse)); + DoFTools::make_hanging_node_constraints(dof_handler_coarse, + constraints_coarse); + constraints_coarse.close(); + + AffineConstraints constraints_fine( + dof_handler_fine.locally_owned_dofs(), + DoFTools::extract_locally_relevant_dofs(dof_handler_fine)); + DoFTools::make_hanging_node_constraints(dof_handler_fine, constraints_fine); + constraints_fine.close(); + + // setup transfer operator + MGTwoLevelTransfer> + transfer_ref; + transfer_ref.reinit(dof_handler_fine, + dof_handler_coarse, + constraints_fine, + constraints_coarse); + + MappingQ1 mapping; + MatrixFree mf_coarse, mf_fine; + mf_coarse.reinit(mapping, + std::vector *>{ + {&dof_handler_dummy, &dof_handler_coarse}}, + std::vector *>{ + {&constraints_dummy, &constraints_coarse}}, + std::vector>{{QGauss<1>(1)}}, + typename MatrixFree::AdditionalData()); + mf_fine.reinit(mapping, + std::vector *>{{&dof_handler_coarse, + &dof_handler_dummy, + &dof_handler_fine, + &dof_handler_dummy}}, + std::vector *>{ + {&constraints_coarse, + &constraints_dummy, + &constraints_fine, + &constraints_dummy}}, + std::vector>{{QGauss<1>(1)}}, + typename MatrixFree::AdditionalData()); + MGTwoLevelTransfer> transfer; + transfer.reinit(mf_fine, 2, mf_coarse, 1); + + LinearAlgebra::distributed::Vector vec_fine_0, vec_fine_1, + vec_coarse_0, vec_coarse_1; + mf_fine.initialize_dof_vector(vec_fine_0, 2); + mf_fine.initialize_dof_vector(vec_fine_1, 2); + mf_coarse.initialize_dof_vector(vec_coarse_0, 1); + mf_coarse.initialize_dof_vector(vec_coarse_1, 1); + + // prolongate + for (auto &d : vec_coarse_0) + d = random_value(); + transfer_ref.prolongate_and_add(vec_fine_0, vec_coarse_0); + transfer.prolongate_and_add(vec_fine_1, vec_coarse_0); + deallog << "Prolongate: " << vec_fine_0.l2_norm() << " " + << vec_fine_1.l2_norm() << " "; + vec_fine_1 -= vec_fine_0; + deallog << vec_fine_1.l2_norm() << std::endl; + + vec_coarse_0 = 0; + transfer_ref.restrict_and_add(vec_coarse_0, vec_fine_0); + vec_coarse_1 = 0; + transfer.restrict_and_add(vec_coarse_1, vec_fine_0); + deallog << "Restrict: " << vec_coarse_0.l2_norm() << " " + << vec_coarse_1.l2_norm() << " "; + vec_coarse_1 -= vec_coarse_0; + deallog << vec_coarse_1.l2_norm() << std::endl << std::endl; +} + + + +template +void +test(int fe_degree_fine, int fe_degree_coarse) +{ + Triangulation tria; + GridGenerator::hyper_cube(tria, -1., 1.); + tria.refine_global(5 - dim); + + deallog << "Uniform grid" << std::endl << std::endl; + do_test(FE_Q(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_DGQ(fe_degree_coarse), + tria); + + for (const auto &cell : tria.active_cell_iterators()) + if (cell->center()[0] < 0 || cell->center()[1] < 0 || + cell->center()[dim - 1] < 0) + cell->set_refine_flag(); + tria.execute_coarsening_and_refinement(); + + deallog << "Adaptively refined grid" << std::endl << std::endl; + do_test(FE_Q(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_Q(fe_degree_coarse), + tria); + do_test(FE_DGQ(fe_degree_fine), + FE_DGQ(fe_degree_coarse), + tria); +} + + + +int +main() +{ + initlog(); + + MultithreadInfo::set_thread_limit(1); + + deallog.precision(8); + + test<2, double>(2, 1); + test<2, double>(3, 1); + test<2, double>(1, 1); + test<3, double>(2, 1); +} diff --git a/tests/multigrid-global-coarsening/mg_transfer_p_10.output b/tests/multigrid-global-coarsening/mg_transfer_p_10.output new file mode 100644 index 0000000000..1b4553385a --- /dev/null +++ b/tests/multigrid-global-coarsening/mg_transfer_p_10.output @@ -0,0 +1,113 @@ + +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 9.7594177 9.7594177 2.5928168e-16 +DEAL::Restrict: 18.243332 18.243332 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 13.681075 13.681075 0.0000000 +DEAL::Restrict: 37.528777 37.528777 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 13.410468 13.410468 0.0000000 +DEAL::Restrict: 19.646997 19.646997 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 17.050353 17.050353 4.2576778e-16 +DEAL::Restrict: 32.785109 32.785109 1.0175362e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_Q<2>(1) +DEAL::Prolongate: 22.993594 22.993594 0.0000000 +DEAL::Restrict: 64.734329 64.734329 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(2) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 23.896733 23.896733 0.0000000 +DEAL::Restrict: 34.979593 34.979593 0.0000000 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 13.970341 13.970341 3.7649495e-16 +DEAL::Restrict: 38.921055 38.921055 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 17.897493 17.897493 0.0000000 +DEAL::Restrict: 64.733634 64.733634 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 17.040442 17.040442 0.0000000 +DEAL::Restrict: 33.069406 33.069406 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 23.995505 23.995505 4.5543677e-16 +DEAL::Restrict: 68.683227 68.683227 1.2560740e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_Q<2>(1) +DEAL::Prolongate: 32.232248 32.232248 0.0000000 +DEAL::Restrict: 121.85053 121.85053 1.7763568e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(3) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 31.288447 31.288447 0.0000000 +DEAL::Restrict: 60.922879 60.922879 0.0000000 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 5.8705925 5.8705925 1.3718318e-15 +DEAL::Restrict: 5.8705925 5.8705925 1.3925930e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 8.5900766 8.5900766 0.0000000 +DEAL::Restrict: 16.161051 16.161051 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 9.2810677 9.2810677 2.7336622e-15 +DEAL::Restrict: 9.2810677 9.2810677 2.3902658e-15 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 8.5554966 8.5554966 2.2520986e-15 +DEAL::Restrict: 8.5554966 8.5554966 2.2061413e-15 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_Q<2>(1) +DEAL::Prolongate: 16.938147 16.938147 0.0000000 +DEAL::Restrict: 33.240500 33.240500 6.6613381e-16 +DEAL:: +DEAL::Testing FE_DGQ<2>(1) <-> FE_DGQ<2>(1) +DEAL::Prolongate: 16.701303 16.701303 4.9116575e-15 +DEAL::Restrict: 16.701303 16.701303 4.2433973e-15 +DEAL:: +DEAL::Uniform grid +DEAL:: +DEAL::Testing FE_Q<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 14.568060 14.568060 3.3947435e-16 +DEAL::Restrict: 34.906413 34.906413 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 24.761956 24.761956 0.0000000 +DEAL::Restrict: 104.38633 104.38633 0.0000000 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_DGQ<3>(1) +DEAL::Prolongate: 22.941814 22.941814 0.0000000 +DEAL::Restrict: 40.931761 40.931761 0.0000000 +DEAL:: +DEAL::Adaptively refined grid +DEAL:: +DEAL::Testing FE_Q<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 33.426138 33.426138 9.3934916e-16 +DEAL::Restrict: 86.786371 86.786371 5.3842955e-15 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_Q<3>(1) +DEAL::Prolongate: 60.273111 60.273111 0.0000000 +DEAL::Restrict: 283.65311 283.65311 1.7874246e-14 +DEAL:: +DEAL::Testing FE_DGQ<3>(2) <-> FE_DGQ<3>(1) +DEAL::Prolongate: 59.789542 59.789542 0.0000000 +DEAL::Restrict: 106.61081 106.61081 0.0000000 +DEAL::