From: Lei Qiao Date: Mon, 1 Jun 2015 18:21:24 +0000 (-0500) Subject: add tests for maximal cell number limit of parallel refine_and_coarsen_fixed_number X-Git-Tag: v8.3.0-rc1~124^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c85b1629f222d52b44756115cc28ead834311c20;p=dealii.git add tests for maximal cell number limit of parallel refine_and_coarsen_fixed_number --- diff --git a/tests/mpi/refine_and_coarsen_fixed_number_07.cc b/tests/mpi/refine_and_coarsen_fixed_number_07.cc new file mode 100644 index 0000000000..ac6f1cbeb4 --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_07.cc @@ -0,0 +1,177 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 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. +// +// --------------------------------------------------------------------- + + + +// derived from _02, but with maximal cell number limit + +#include "../tests.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +#include + + +void test(const unsigned int max_n_cell) +{ + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + + parallel::distributed::Triangulation<2> tr(MPI_COMM_WORLD); + + std::vector sub(2); + sub[0] = 5*Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD); + sub[1] = 1; + GridGenerator::subdivided_hyper_rectangle(static_cast&>(tr), + sub, Point<2>(0,0), Point<2>(1,1)); + tr.refine_global (1); + + Vector indicators (tr.dealii::Triangulation<2>::n_active_cells()); + { + unsigned int cell_index = 0; + unsigned int my_cell_index = 0; + for (Triangulation<2>::active_cell_iterator + cell = tr.begin_active(); cell != tr.end(); ++cell, ++cell_index) + if (cell->subdomain_id() == myid) + { + ++my_cell_index; + indicators(cell_index) = std::pow (10, (float)my_cell_index); + } + } + + parallel::distributed::GridRefinement + ::refine_and_coarsen_fixed_number (tr, indicators, 0.2, 0.2, max_n_cell); + + // now count number of cells + // flagged for refinement and + // coarsening. we have to + // accumulate over all processors + unsigned int my_refined = 0, + my_coarsened = 0; + for (Triangulation<2>::active_cell_iterator + cell = tr.begin_active(); cell != tr.end(); ++cell) + if (cell->refine_flag_set()) + ++my_refined; + else if (cell->coarsen_flag_set()) + ++my_coarsened; + + unsigned int n_refined = 0, + n_coarsened = 0; + MPI_Reduce (&my_refined, &n_refined, 1, MPI_UNSIGNED, MPI_SUM, 0, + MPI_COMM_WORLD); + MPI_Reduce (&my_coarsened, &n_coarsened, 1, MPI_UNSIGNED, MPI_SUM, 0, + MPI_COMM_WORLD); + + // make sure we have indeed flagged + // exactly 20% of cells + if (myid == 0) + { + deallog << "total active cells = " + << tr.n_global_active_cells() << std::endl; + deallog << "n_refined = " << n_refined << std::endl; + deallog << "n_coarsened = " << n_coarsened << std::endl; + } + + tr.execute_coarsening_and_refinement (); + if (myid == 0) + { + deallog << "total active cells = " + << tr.n_global_active_cells() << std::endl; + deallog << "cell number upper limit = " + << max_n_cell << std::endl; + } +} + + +int main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + + unsigned int myid = Utilities::MPI::this_mpi_process (MPI_COMM_WORLD); + + + deallog.push(Utilities::int_to_string(myid)); + + +// test effective maximal cell number limit + { + const unsigned int max_n_cell = static_cast + (1.1 + * 4 // corresponds to tr.refine_global (1) in 2d + * 5*Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD) // corresponds to definition in function test + + 0.5 // avoid truncation + ); + if (myid == 0) + { + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test(max_n_cell); + } + else + test(max_n_cell); + } + MPI_Barrier(MPI_COMM_WORLD); + + +// cell number already exceeded maximal cell number limit + { + const unsigned int max_n_cell = static_cast + (0.8 * 4 * 5*Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD)); + if (myid == 0) + { + std::ofstream logfile("output", std::ofstream::app); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test(max_n_cell); + } + else + test(max_n_cell); + } + MPI_Barrier(MPI_COMM_WORLD); + + +// test non-effective maximal cell number limit + { + const unsigned int max_n_cell = static_cast + (100.0 * 4 * 5*Utilities::MPI::n_mpi_processes (MPI_COMM_WORLD)); + if (myid == 0) + { + std::ofstream logfile("output", std::ofstream::app); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + test(max_n_cell); + } + else + test(max_n_cell); + } + + return (0); +} diff --git a/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=1.output b/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=1.output new file mode 100644 index 0000000000..6ff81d403f --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=1.output @@ -0,0 +1,18 @@ + +DEAL:0::total active cells = 20 +DEAL:0::n_refined = 1 +DEAL:0::n_coarsened = 2 +DEAL:0::total active cells = 23 +DEAL:0::cell number upper limit = 22 + +DEAL:0::total active cells = 20 +DEAL:0::n_refined = 0 +DEAL:0::n_coarsened = 6 +DEAL:0::total active cells = 17 +DEAL:0::cell number upper limit = 16 + +DEAL:0::total active cells = 20 +DEAL:0::n_refined = 4 +DEAL:0::n_coarsened = 4 +DEAL:0::total active cells = 29 +DEAL:0::cell number upper limit = 2000 diff --git a/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=10.output b/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=10.output new file mode 100644 index 0000000000..8e60c16a21 --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=10.output @@ -0,0 +1,18 @@ + +DEAL:0::total active cells = 200 +DEAL:0::n_refined = 10 +DEAL:0::n_coarsened = 20 +DEAL:0::total active cells = 230 +DEAL:0::cell number upper limit = 220 + +DEAL:0::total active cells = 200 +DEAL:0::n_refined = 0 +DEAL:0::n_coarsened = 50 +DEAL:0::total active cells = 170 +DEAL:0::cell number upper limit = 160 + +DEAL:0::total active cells = 200 +DEAL:0::n_refined = 40 +DEAL:0::n_coarsened = 40 +DEAL:0::total active cells = 317 +DEAL:0::cell number upper limit = 20000 diff --git a/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=4.output b/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=4.output new file mode 100644 index 0000000000..a611f23de4 --- /dev/null +++ b/tests/mpi/refine_and_coarsen_fixed_number_07.mpirun=4.output @@ -0,0 +1,18 @@ + +DEAL:0::total active cells = 80 +DEAL:0::n_refined = 4 +DEAL:0::n_coarsened = 8 +DEAL:0::total active cells = 92 +DEAL:0::cell number upper limit = 88 + +DEAL:0::total active cells = 80 +DEAL:0::n_refined = 0 +DEAL:0::n_coarsened = 20 +DEAL:0::total active cells = 68 +DEAL:0::cell number upper limit = 64 + +DEAL:0::total active cells = 80 +DEAL:0::n_refined = 16 +DEAL:0::n_coarsened = 16 +DEAL:0::total active cells = 125 +DEAL:0::cell number upper limit = 8000