From: Marc Fehling Date: Thu, 14 May 2020 18:44:41 +0000 (+0200) Subject: Added tests with different compositions of criteria vectors for fixed number refinement. X-Git-Tag: v9.3.0-rc1~1632^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9969%2Fhead;p=dealii.git Added tests with different compositions of criteria vectors for fixed number refinement. --- diff --git a/tests/grid/refine_and_coarsen_fixed_number_03.cc b/tests/grid/refine_and_coarsen_fixed_number_03.cc new file mode 100644 index 0000000000..96c22dc71e --- /dev/null +++ b/tests/grid/refine_and_coarsen_fixed_number_03.cc @@ -0,0 +1,116 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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. +// +// --------------------------------------------------------------------- + + +// verify the binary search algorithm in different compositions of +// criteria and refinement and coarsening fractions for +// GridRefinement::refine_and_coarsen_fixed_number(). + + +#include +#include +#include + +#include + +#include "../tests.h" + + +template +void +verify(Triangulation & tr, + const Vector &criteria, + const float refinement_fraction, + const float coarsening_fraction) +{ + GridRefinement::refine_and_coarsen_fixed_number(tr, + criteria, + refinement_fraction, + coarsening_fraction); + + unsigned int n_refine_flags = 0, n_coarsen_flags = 0; + for (const auto &cell : tr.active_cell_iterators()) + { + if (cell->refine_flag_set()) + { + ++n_refine_flags; + cell->clear_refine_flag(); + } + if (cell->coarsen_flag_set()) + { + ++n_coarsen_flags; + cell->clear_coarsen_flag(); + } + } + + deallog << " refinement_fraction:" << refinement_fraction + << " coarsening_fraction:" << coarsening_fraction << std::endl + << " n_refine_flags:" << n_refine_flags + << " n_coarsen_flags:" << n_coarsen_flags << std::endl; +} + + +template +void +test() +{ + const unsigned int n_cells = 100; + const float refinement_fraction = 0.1, coarsening_fraction = 0.1; + + Triangulation tr; + std::vector rep(dim, 1); + rep[0] = n_cells; + Point p1, p2; + for (unsigned int d = 0; d < dim; ++d) + { + p1[d] = 0; + p2[d] = (d == 0) ? n_cells : 1; + } + GridGenerator::subdivided_hyper_rectangle(tr, rep, p1, p2); + + deallog << "n_cells:" << n_cells << std::endl; + Vector criteria(n_cells); + { + deallog << "criteria:[b>0,e>0]" << std::endl; + + std::iota(criteria.begin(), criteria.end(), 1); + Assert(criteria(0) > 0. && criteria(n_cells - 1) > 0., ExcInternalError()); + + verify(tr, criteria, refinement_fraction, coarsening_fraction); + verify(tr, criteria, refinement_fraction, 0.); + verify(tr, criteria, 0., coarsening_fraction); + } + + { + deallog << "criteria:[b=0,e>0]" << std::endl; + + std::iota(criteria.begin(), criteria.end(), 0); + Assert(criteria(0) == 0. && criteria(n_cells - 1) > 0., ExcInternalError()); + + verify(tr, criteria, refinement_fraction, coarsening_fraction); + verify(tr, criteria, refinement_fraction, 0.); + verify(tr, criteria, 0., coarsening_fraction); + } +} + + +int +main(int argc, char *argv[]) +{ + initlog(); + deallog << std::setprecision(1); + + test<2>(); +} diff --git a/tests/grid/refine_and_coarsen_fixed_number_03.output b/tests/grid/refine_and_coarsen_fixed_number_03.output new file mode 100644 index 0000000000..a3562425c0 --- /dev/null +++ b/tests/grid/refine_and_coarsen_fixed_number_03.output @@ -0,0 +1,16 @@ + +DEAL::n_cells:100 +DEAL::criteria:[b>0,e>0] +DEAL:: refinement_fraction:0.1 coarsening_fraction:0.1 +DEAL:: n_refine_flags:10 n_coarsen_flags:10 +DEAL:: refinement_fraction:0.1 coarsening_fraction:0. +DEAL:: n_refine_flags:10 n_coarsen_flags:0 +DEAL:: refinement_fraction:0. coarsening_fraction:0.1 +DEAL:: n_refine_flags:0 n_coarsen_flags:10 +DEAL::criteria:[b=0,e>0] +DEAL:: refinement_fraction:0.1 coarsening_fraction:0.1 +DEAL:: n_refine_flags:10 n_coarsen_flags:10 +DEAL:: refinement_fraction:0.1 coarsening_fraction:0. +DEAL:: n_refine_flags:10 n_coarsen_flags:0 +DEAL:: refinement_fraction:0. coarsening_fraction:0.1 +DEAL:: n_refine_flags:0 n_coarsen_flags:10 diff --git a/tests/mpi/refine_and_coarsen_fixed_number_08.cc b/tests/mpi/refine_and_coarsen_fixed_number_08.cc new file mode 100644 index 0000000000..a949957ce4 --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_08.cc @@ -0,0 +1,125 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2020 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. +// +// --------------------------------------------------------------------- + + +// verify the binary search algorithm in different compositions of +// criteria and refinement and coarsening fractions for +// parallel::distributed::GridRefinement::refine_and_coarsen_fixed_number(). + +#include +#include + +#include + +#include + +#include "../tests.h" + + +template +void +verify(parallel::distributed::Triangulation &tr, + const Vector & criteria, + const float refinement_fraction, + const float coarsening_fraction) +{ + parallel::distributed::GridRefinement::refine_and_coarsen_fixed_number( + tr, criteria, refinement_fraction, coarsening_fraction); + + unsigned int n_refine_flags = 0, n_coarsen_flags = 0; + for (const auto &cell : tr.active_cell_iterators()) + if (cell->is_locally_owned()) + { + if (cell->refine_flag_set()) + { + ++n_refine_flags; + cell->clear_refine_flag(); + } + if (cell->coarsen_flag_set()) + { + ++n_coarsen_flags; + cell->clear_coarsen_flag(); + } + } + + const unsigned int n_global_refine_flags = + Utilities::MPI::sum(n_refine_flags, MPI_COMM_WORLD), + n_global_coarsen_flags = + Utilities::MPI::sum(n_coarsen_flags, MPI_COMM_WORLD); + + deallog << " refinement_fraction:" << refinement_fraction + << " coarsening_fraction:" << coarsening_fraction << std::endl + << " n_refine_flags:" << n_global_refine_flags + << " n_coarsen_flags:" << n_global_coarsen_flags << std::endl; +} + + +template +void +test() +{ + const unsigned int n_cells = 100; + const float refinement_fraction = 0.1, coarsening_fraction = 0.1; + + parallel::distributed::Triangulation tr(MPI_COMM_WORLD); + std::vector rep(dim, 1); + rep[0] = n_cells; + Point p1, p2; + for (unsigned int d = 0; d < dim; ++d) + { + p1[d] = 0; + p2[d] = (d == 0) ? n_cells : 1; + } + GridGenerator::subdivided_hyper_rectangle(tr, rep, p1, p2); + + deallog << "n_cells:" << n_cells << std::endl; + Vector criteria(n_cells); + { + deallog << "criteria:[b>0,e>0]" << std::endl; + + std::iota(criteria.begin(), criteria.end(), 1); + Assert(criteria(0) > 0. && criteria(n_cells - 1) > 0., ExcInternalError()); + + verify(tr, criteria, refinement_fraction, coarsening_fraction); + verify(tr, criteria, refinement_fraction, 0.); + verify(tr, criteria, 0., coarsening_fraction); + } + + { + deallog << "criteria:[b=0,e>0]" << std::endl; + + std::iota(criteria.begin(), criteria.end(), 0); + Assert(criteria(0) == 0. && criteria(n_cells - 1) > 0., ExcInternalError()); + + verify(tr, criteria, refinement_fraction, coarsening_fraction); + verify(tr, criteria, refinement_fraction, 0.); + verify(tr, criteria, 0., coarsening_fraction); + } +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + if (Utilities::MPI::this_mpi_process(MPI_COMM_WORLD) == 0) + { + initlog(); + deallog << std::setprecision(1); + } + + test<2>(); +} diff --git a/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=1.with_p4est=true.output b/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=1.with_p4est=true.output new file mode 100644 index 0000000000..a3562425c0 --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=1.with_p4est=true.output @@ -0,0 +1,16 @@ + +DEAL::n_cells:100 +DEAL::criteria:[b>0,e>0] +DEAL:: refinement_fraction:0.1 coarsening_fraction:0.1 +DEAL:: n_refine_flags:10 n_coarsen_flags:10 +DEAL:: refinement_fraction:0.1 coarsening_fraction:0. +DEAL:: n_refine_flags:10 n_coarsen_flags:0 +DEAL:: refinement_fraction:0. coarsening_fraction:0.1 +DEAL:: n_refine_flags:0 n_coarsen_flags:10 +DEAL::criteria:[b=0,e>0] +DEAL:: refinement_fraction:0.1 coarsening_fraction:0.1 +DEAL:: n_refine_flags:10 n_coarsen_flags:10 +DEAL:: refinement_fraction:0.1 coarsening_fraction:0. +DEAL:: n_refine_flags:10 n_coarsen_flags:0 +DEAL:: refinement_fraction:0. coarsening_fraction:0.1 +DEAL:: n_refine_flags:0 n_coarsen_flags:10 diff --git a/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=4.with_p4est=true.output b/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=4.with_p4est=true.output new file mode 100644 index 0000000000..a3562425c0 --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_08.mpirun=4.with_p4est=true.output @@ -0,0 +1,16 @@ + +DEAL::n_cells:100 +DEAL::criteria:[b>0,e>0] +DEAL:: refinement_fraction:0.1 coarsening_fraction:0.1 +DEAL:: n_refine_flags:10 n_coarsen_flags:10 +DEAL:: refinement_fraction:0.1 coarsening_fraction:0. +DEAL:: n_refine_flags:10 n_coarsen_flags:0 +DEAL:: refinement_fraction:0. coarsening_fraction:0.1 +DEAL:: n_refine_flags:0 n_coarsen_flags:10 +DEAL::criteria:[b=0,e>0] +DEAL:: refinement_fraction:0.1 coarsening_fraction:0.1 +DEAL:: n_refine_flags:10 n_coarsen_flags:10 +DEAL:: refinement_fraction:0.1 coarsening_fraction:0. +DEAL:: n_refine_flags:10 n_coarsen_flags:0 +DEAL:: refinement_fraction:0. coarsening_fraction:0.1 +DEAL:: n_refine_flags:0 n_coarsen_flags:10