From: Bruno Turcksin Date: Tue, 14 Sep 2021 18:18:17 +0000 (+0000) Subject: Add tests for FieldTransfer X-Git-Tag: v9.5.0-rc1~999^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=97f100c923b0839b7f0f4a97ca15feb3175885fb;p=dealii.git Add tests for FieldTransfer --- diff --git a/tests/hp/field_transfer_01.cc b/tests/hp/field_transfer_01.cc new file mode 100644 index 0000000000..c8f5cef27e --- /dev/null +++ b/tests/hp/field_transfer_01.cc @@ -0,0 +1,89 @@ +// --------------------------------------------------------------------- +// +// 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Check that we can use FieldTransfer when a cell is changed from FE_Nothing to +// FE_Q + +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + initlog(); + + parallel::distributed::Triangulation<2> triangulation(MPI_COMM_WORLD); + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global(1); + + hp::FECollection<2> fe_collection; + fe_collection.push_back(FE_Q<2>(1)); + fe_collection.push_back(FE_Nothing<2>()); + + DoFHandler<2> dof_handler(triangulation); + + // Assign FE_Nothing to the first cell + dof_handler.begin_active()->set_active_fe_index(1); + + dof_handler.distribute_dofs(fe_collection); + const unsigned int initial_n_dofs = dof_handler.n_dofs(); + + // Initialize solution + LinearAlgebra::distributed::Vector solution(initial_n_dofs); + const double old_value = 10.; + for (unsigned int i = 0; i < initial_n_dofs; ++i) + solution[i] = old_value; + + parallel::distributed::experimental:: + FieldTransfer<2, LinearAlgebra::distributed::Vector> + field_transfer(dof_handler); + // Assign FE_Q to the first cell + dof_handler.begin_active()->set_future_fe_index(0); + + triangulation.prepare_coarsening_and_refinement(); + + field_transfer.prepare_for_coarsening_and_refinement(solution, 1); + + triangulation.execute_coarsening_and_refinement(); + + dof_handler.distribute_dofs(fe_collection); + const unsigned int dofs_per_cell = + dof_handler.get_fe_collection().max_dofs_per_cell(); + + AffineConstraints affine_constraints; + const double new_value = -1.; + + const unsigned int final_n_dofs = dof_handler.n_dofs(); + LinearAlgebra::distributed::Vector new_solution(final_n_dofs); + field_transfer.interpolate(new_value, affine_constraints, new_solution); + + new_solution.print(deallog.get_file_stream()); +} diff --git a/tests/hp/field_transfer_01.with_p4est=true.output b/tests/hp/field_transfer_01.with_p4est=true.output new file mode 100644 index 0000000000..b2ca19b185 --- /dev/null +++ b/tests/hp/field_transfer_01.with_p4est=true.output @@ -0,0 +1,5 @@ + +Process #0 +Local range: [0, 9), global size: 9 +Vector data: +-1.000e+00 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 diff --git a/tests/hp/field_transfer_02.cc b/tests/hp/field_transfer_02.cc new file mode 100644 index 0000000000..9fe7ee90ef --- /dev/null +++ b/tests/hp/field_transfer_02.cc @@ -0,0 +1,124 @@ +// --------------------------------------------------------------------- +// +// 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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Check that we can use FieldTransfer when multiple cells are changed from +// FE_Nothing to FE_Q + +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + initlog(); + + parallel::distributed::Triangulation<2> triangulation(MPI_COMM_WORLD); + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global(2); + + hp::FECollection<2> fe_collection; + fe_collection.push_back(FE_Q<2>(1)); + fe_collection.push_back(FE_Nothing<2>()); + + DoFHandler<2> dof_handler(triangulation); + + // Assign FE_Nothing to half of the domain + for (auto cell : dof_handler.active_cell_iterators()) + { + if (cell->is_locally_owned()) + { + if (cell->center()[1] < 0.5) + { + cell->set_active_fe_index(0); + } + else + { + cell->set_active_fe_index(1); + } + } + } + + dof_handler.distribute_dofs(fe_collection); + + // Initialize solution + LinearAlgebra::distributed::Vector solution( + dof_handler.locally_owned_dofs(), MPI_COMM_WORLD); + const double old_value = 10.; + for (unsigned int i = 0; i < solution.local_size(); ++i) + solution.local_element(i) = old_value; + + parallel::distributed::experimental:: + FieldTransfer<2, LinearAlgebra::distributed::Vector> + field_transfer(dof_handler); + // Assgin FE_Q to all the cells + for (auto cell : dof_handler.active_cell_iterators()) + { + if (cell->is_locally_owned()) + { + cell->set_future_fe_index(0); + } + } + + triangulation.prepare_coarsening_and_refinement(); + + field_transfer.prepare_for_coarsening_and_refinement(solution, 1); + + triangulation.execute_coarsening_and_refinement(); + + dof_handler.distribute_dofs(fe_collection); + const unsigned int dofs_per_cell = + dof_handler.get_fe_collection().max_dofs_per_cell(); + + AffineConstraints affine_constraints; + const double new_value = 11.; + + LinearAlgebra::distributed::Vector new_solution( + dof_handler.locally_owned_dofs(), MPI_COMM_WORLD); + field_transfer.interpolate(new_value, affine_constraints, new_solution); + + // Check the new_solution + unsigned int myid = Utilities::MPI::this_mpi_process(MPI_COMM_WORLD); + if (myid == 0) + { + for (unsigned int i = 0; i < new_solution.local_size(); ++i) + AssertThrow(new_solution.local_element(i) == old_value, + ExcInternalError()); + } + else if (myid == 1) + { + for (unsigned int i = 0; i < new_solution.local_size(); ++i) + AssertThrow(new_solution.local_element(i) == new_value, + ExcInternalError()); + } + + if (myid == 0) + deallog << "OK" << std::endl; +} diff --git a/tests/hp/field_transfer_02.with_p4est=true.mpirun=2.output b/tests/hp/field_transfer_02.with_p4est=true.mpirun=2.output new file mode 100644 index 0000000000..0fd8fc12f0 --- /dev/null +++ b/tests/hp/field_transfer_02.with_p4est=true.mpirun=2.output @@ -0,0 +1,2 @@ + +DEAL::OK diff --git a/tests/hp/field_transfer_03.cc b/tests/hp/field_transfer_03.cc new file mode 100644 index 0000000000..f4ecde687e --- /dev/null +++ b/tests/hp/field_transfer_03.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.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + +// Check that we can use FieldTransfer when the coarsest cells are changed from +// FE_Nothing to FE_Q + + +#include + +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#include "../tests.h" + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + initlog(); + + parallel::distributed::Triangulation<2> triangulation(MPI_COMM_WORLD); + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global(1); + triangulation.execute_coarsening_and_refinement(); + + for (auto &cell : triangulation.active_cell_iterators()) + { + if (cell->center()[1] < 0.5) + cell->set_refine_flag(); + } + triangulation.execute_coarsening_and_refinement(); + + + hp::FECollection<2> fe_collection; + fe_collection.push_back(FE_Q<2>(2)); + fe_collection.push_back(FE_Nothing<2>()); + + DoFHandler<2> dof_handler(triangulation); + + // Assign FE_Nothing to the coarsest cells + for (auto &cell : dof_handler.active_cell_iterators()) + { + if (cell->center()[1] > 0.5) + cell->set_active_fe_index(1); + } + + dof_handler.distribute_dofs(fe_collection); + const unsigned int initial_n_dofs = dof_handler.n_dofs(); + + // Initialize solution + LinearAlgebra::distributed::Vector solution(initial_n_dofs); + const double old_value = 10.; + for (unsigned int i = 0; i < initial_n_dofs; ++i) + solution[i] = old_value; + + parallel::distributed::experimental:: + FieldTransfer<2, LinearAlgebra::distributed::Vector> + field_transfer(dof_handler); + // Assign FE_Q to all the cells + for (auto &cell : dof_handler.active_cell_iterators()) + { + cell->set_future_fe_index(0); + } + + triangulation.prepare_coarsening_and_refinement(); + + field_transfer.prepare_for_coarsening_and_refinement(solution, 1); + + triangulation.execute_coarsening_and_refinement(); + + dof_handler.distribute_dofs(fe_collection); + const unsigned int dofs_per_cell = + dof_handler.get_fe_collection().max_dofs_per_cell(); + + AffineConstraints affine_constraints; + DoFTools::make_hanging_node_constraints(dof_handler, affine_constraints); + affine_constraints.close(); + const double new_value = -1.; + + const unsigned int final_n_dofs = dof_handler.n_dofs(); + LinearAlgebra::distributed::Vector new_solution(final_n_dofs); + field_transfer.interpolate(new_value, affine_constraints, new_solution); + + affine_constraints.distribute(new_solution); + + new_solution.print(deallog.get_file_stream()); +} diff --git a/tests/hp/field_transfer_03.with_p4est=true.output b/tests/hp/field_transfer_03.with_p4est=true.output new file mode 100644 index 0000000000..50c822c5e3 --- /dev/null +++ b/tests/hp/field_transfer_03.with_p4est=true.output @@ -0,0 +1,5 @@ + +Process #0 +Local range: [0, 57), global size: 57 +Vector data: +1.000e+01 1.000e+01 -1.000e+00 -1.000e+00 -1.000e+00 -1.000e+00 1.000e+01 -1.000e+00 -1.000e+00 1.000e+01 -1.000e+00 -1.000e+00 1.000e+01 -1.000e+00 -1.000e+00 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01 1.000e+01