From b698da43ad1843291d68cc6efbb8c34c2732d068 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 16 Aug 2017 10:30:49 -0600 Subject: [PATCH] Add a whole bunch of tests for hp::DoFHandler on p::d::Triangulation. --- .../distributed_grids/hp_2d_dofhandler_01.cc | 92 +++++++++++ .../hp_2d_dofhandler_01.output | 6 + .../hp_count_dofs_per_block_01.cc | 142 +++++++++++++++++ .../hp_count_dofs_per_block_01.output | 21 +++ .../hp_count_dofs_per_component_01.cc | 108 +++++++++++++ .../hp_count_dofs_per_component_01.output | 9 ++ .../hp_dof_handler_number_cache.cc | 144 ++++++++++++++++++ .../hp_dof_handler_number_cache.output | 6 + 8 files changed, 528 insertions(+) create mode 100644 tests/distributed_grids/hp_2d_dofhandler_01.cc create mode 100644 tests/distributed_grids/hp_2d_dofhandler_01.output create mode 100644 tests/distributed_grids/hp_count_dofs_per_block_01.cc create mode 100644 tests/distributed_grids/hp_count_dofs_per_block_01.output create mode 100644 tests/distributed_grids/hp_count_dofs_per_component_01.cc create mode 100644 tests/distributed_grids/hp_count_dofs_per_component_01.output create mode 100644 tests/distributed_grids/hp_dof_handler_number_cache.cc create mode 100644 tests/distributed_grids/hp_dof_handler_number_cache.output diff --git a/tests/distributed_grids/hp_2d_dofhandler_01.cc b/tests/distributed_grids/hp_2d_dofhandler_01.cc new file mode 100644 index 0000000000..480e695238 --- /dev/null +++ b/tests/distributed_grids/hp_2d_dofhandler_01.cc @@ -0,0 +1,92 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2009 - 2015 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. +// +// --------------------------------------------------------------------- + + + +// create a parallel hp::DoFHandler on a single CPU +// +// like the test without the hp_ prefix, but for hp::DoFHandler + +#include "../tests.h" +#include "coarse_grid_common.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + + +template +void test(std::ostream & /*out*/) +{ + deallog << "hyper_cube" << std::endl; + + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + + GridGenerator::hyper_cube(tr); + tr.refine_global (1); + + hp::FECollection fe; + fe.push_back (FE_Q (2)); + hp::DoFHandler dofh(tr); + dofh.distribute_dofs (fe); + + typename + hp::DoFHandler::active_cell_iterator cell + = dofh.begin_active(); + + const unsigned int dofs_per_cell = dofh.get_fe()[0].dofs_per_cell; + std::vector local_dof_indices (dofs_per_cell); + + + + for (; cell != dofh.end(); ++cell) + { + cell->get_dof_indices (local_dof_indices); + + for (unsigned int i=0; i(logfile); + deallog.pop(); + + +} diff --git a/tests/distributed_grids/hp_2d_dofhandler_01.output b/tests/distributed_grids/hp_2d_dofhandler_01.output new file mode 100644 index 0000000000..43c245b2da --- /dev/null +++ b/tests/distributed_grids/hp_2d_dofhandler_01.output @@ -0,0 +1,6 @@ + +DEAL:2d::hyper_cube +DEAL:2d::0 1 2 3 4 5 6 7 8 +DEAL:2d::1 9 3 10 5 11 12 13 14 +DEAL:2d::2 3 15 16 17 18 7 19 20 +DEAL:2d::3 10 16 21 18 22 13 23 24 diff --git a/tests/distributed_grids/hp_count_dofs_per_block_01.cc b/tests/distributed_grids/hp_count_dofs_per_block_01.cc new file mode 100644 index 0000000000..928bb688f6 --- /dev/null +++ b/tests/distributed_grids/hp_count_dofs_per_block_01.cc @@ -0,0 +1,142 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2008 - 2015 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 DoFTools::count_dofs_per_block +// +// like the test without the hp_ prefix, but for hp::DoFHandler + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +template +void test() +{ + parallel::distributed::Triangulation + triangulation (MPI_COMM_WORLD, + Triangulation::limit_level_difference_at_vertices); + + hp::FECollection fe; + fe.push_back (FESystem (FE_Q(3),2, + FE_DGQ(1),1)); + + hp::DoFHandler dof_handler (triangulation); + + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global (2); + + const unsigned int n_refinements[] = { 0, 4, 3, 2 }; + for (unsigned int i=0; i flags (triangulation.n_active_cells(), false); + for (unsigned int k=0; k::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell, ++index) + if (flags[index]) + cell->set_refine_flag(); + AssertThrow (index == triangulation.n_active_cells(), ExcInternalError()); + + // flag all other cells for coarsening + // (this should ensure that at least + // some of them will actually be + // coarsened) + index=0; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell, ++index) + if (!flags[index]) + cell->set_coarsen_flag(); + + triangulation.execute_coarsening_and_refinement (); + dof_handler.distribute_dofs (fe); + + std::vector dofs_per_block (fe.n_components()); + DoFTools::count_dofs_per_block (dof_handler, dofs_per_block); + + AssertThrow (std::accumulate (dofs_per_block.begin(), dofs_per_block.end(), 0U) + == dof_handler.n_dofs(), + ExcInternalError()); + + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + if (myid == 0) + { + deallog << "Total number of dofs: " << dof_handler.n_dofs() << std::endl; + for (unsigned int i=0; i(); + deallog.pop(); + + deallog.push("3d"); + test<3>(); + deallog.pop(); + } + else + { + test<2>(); + test<3>(); + } + + +} diff --git a/tests/distributed_grids/hp_count_dofs_per_block_01.output b/tests/distributed_grids/hp_count_dofs_per_block_01.output new file mode 100644 index 0000000000..6d570526c3 --- /dev/null +++ b/tests/distributed_grids/hp_count_dofs_per_block_01.output @@ -0,0 +1,21 @@ + +DEAL:2d::Total number of dofs: 818 +DEAL:2d::Block 0 has 347 global dofs +DEAL:2d::Block 1 has 347 global dofs +DEAL:2d::Block 2 has 124 global dofs +DEAL:2d::Total number of dofs: 1874 +DEAL:2d::Block 0 has 791 global dofs +DEAL:2d::Block 1 has 791 global dofs +DEAL:2d::Block 2 has 292 global dofs +DEAL:2d::Total number of dofs: 2800 +DEAL:2d::Block 0 has 1182 global dofs +DEAL:2d::Block 1 has 1182 global dofs +DEAL:2d::Block 2 has 436 global dofs +DEAL:3d::Total number of dofs: 13282 +DEAL:3d::Block 0 has 6021 global dofs +DEAL:3d::Block 1 has 6021 global dofs +DEAL:3d::Block 2 has 1240 global dofs +DEAL:3d::Total number of dofs: 42960 +DEAL:3d::Block 0 has 19292 global dofs +DEAL:3d::Block 1 has 19292 global dofs +DEAL:3d::Block 2 has 4376 global dofs diff --git a/tests/distributed_grids/hp_count_dofs_per_component_01.cc b/tests/distributed_grids/hp_count_dofs_per_component_01.cc new file mode 100644 index 0000000000..e1bbdbdf5e --- /dev/null +++ b/tests/distributed_grids/hp_count_dofs_per_component_01.cc @@ -0,0 +1,108 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2008 - 2015 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 DoFTools::count_dofs_per_component +// +// like the test without the hp_ prefix, but for hp::DoFHandler + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + + +template +void test() +{ + parallel::distributed::Triangulation + triangulation (MPI_COMM_WORLD, + Triangulation::limit_level_difference_at_vertices); + + hp::FECollection fe; + fe.push_back (FESystem (FE_Q(3),2, + FE_DGQ(1),1)); + + hp::DoFHandler dof_handler (triangulation); + + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global (2); + dof_handler.distribute_dofs (fe); + + std::vector dofs_per_component (fe.n_components()); + DoFTools::count_dofs_per_component (dof_handler, dofs_per_component); + + Assert (std::accumulate (dofs_per_component.begin(), dofs_per_component.end(), 0U) + == dof_handler.n_dofs(), + ExcInternalError()); + + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + if (myid == 0) + { + deallog << "Total number of dofs: " << dof_handler.n_dofs() << std::endl; + for (unsigned int i=0; i(); + deallog.pop(); + + deallog.push("3d"); + test<3>(); + deallog.pop(); + } + else + { + test<2>(); + test<3>(); + } + + +} diff --git a/tests/distributed_grids/hp_count_dofs_per_component_01.output b/tests/distributed_grids/hp_count_dofs_per_component_01.output new file mode 100644 index 0000000000..40063fc779 --- /dev/null +++ b/tests/distributed_grids/hp_count_dofs_per_component_01.output @@ -0,0 +1,9 @@ + +DEAL:2d::Total number of dofs: 402 +DEAL:2d::Block 0 has 169 global dofs +DEAL:2d::Block 1 has 169 global dofs +DEAL:2d::Block 2 has 64 global dofs +DEAL:3d::Total number of dofs: 4906 +DEAL:3d::Block 0 has 2197 global dofs +DEAL:3d::Block 1 has 2197 global dofs +DEAL:3d::Block 2 has 512 global dofs diff --git a/tests/distributed_grids/hp_dof_handler_number_cache.cc b/tests/distributed_grids/hp_dof_handler_number_cache.cc new file mode 100644 index 0000000000..f5ae269504 --- /dev/null +++ b/tests/distributed_grids/hp_dof_handler_number_cache.cc @@ -0,0 +1,144 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2008 - 2015 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. +// +// --------------------------------------------------------------------- + + + +// like the same test in deal.II but this time use a +// parallel::distributed::Triangulation object. We still use only a +// single processor so the end result should be the same but we use +// entirely different code paths +// +// like the test without the hp_ prefix, but for hp::DoFHandler + + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + + +template +void test() +{ + parallel::distributed::Triangulation + triangulation (MPI_COMM_WORLD, + Triangulation::limit_level_difference_at_vertices); + + hp::FECollection fe; + fe.push_back (FESystem (FE_Q(3),2, + FE_DGQ(1),1)); + + hp::DoFHandler dof_handler (triangulation); + + GridGenerator::hyper_cube(triangulation); + triangulation.refine_global (2); + + const unsigned int n_refinements[] = { 0, 4, 3, 2 }; + for (unsigned int i=0; i flags (triangulation.n_active_cells(), false); + for (unsigned int k=0; k::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell, ++index) + if (flags[index]) + cell->set_refine_flag(); + AssertThrow (index == triangulation.n_active_cells(), ExcInternalError()); + + // flag all other cells for coarsening + // (this should ensure that at least + // some of them will actually be + // coarsened) + index=0; + for (typename Triangulation::active_cell_iterator + cell = triangulation.begin_active(); + cell != triangulation.end(); ++cell, ++index) + if (!flags[index]) + cell->set_coarsen_flag(); + + triangulation.execute_coarsening_and_refinement (); + dof_handler.distribute_dofs (fe); + + const unsigned int N = dof_handler.n_dofs(); + deallog << N << std::endl; + + IndexSet all (N); + all.add_range (0, N); + + AssertThrow (dof_handler.n_locally_owned_dofs() == N, + ExcInternalError()); + AssertThrow (dof_handler.locally_owned_dofs() == all, + ExcInternalError()); + AssertThrow (dof_handler.n_locally_owned_dofs_per_processor() == + std::vector (1,N), + ExcInternalError()); + AssertThrow (dof_handler.locally_owned_dofs_per_processor() == + std::vector(1,all), + ExcInternalError()); + } +} + + +int main(int argc, char *argv[]) +{ +#ifdef DEAL_II_WITH_MPI + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, 1); +#else + (void)argc; + (void)argv; +#endif + + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + if (myid == 0) + { + initlog(); + + deallog.push("2d"); + test<2>(); + deallog.pop(); + + deallog.push("3d"); + test<3>(); + deallog.pop(); + } + else + { + test<2>(); + test<3>(); + } + + +} diff --git a/tests/distributed_grids/hp_dof_handler_number_cache.output b/tests/distributed_grids/hp_dof_handler_number_cache.output new file mode 100644 index 0000000000..a3728cf6c2 --- /dev/null +++ b/tests/distributed_grids/hp_dof_handler_number_cache.output @@ -0,0 +1,6 @@ + +DEAL:2d::818 +DEAL:2d::1874 +DEAL:2d::2800 +DEAL:3d::13282 +DEAL:3d::42960 -- 2.39.5