From faf0bc65be34cd103519ac7e6d94eba981d43a3a Mon Sep 17 00:00:00 2001 From: Lei Qiao Date: Sat, 30 May 2015 11:39:50 -0500 Subject: [PATCH] add maximal cell number limit to parallel version of refine_and_coarsen_fixed_number --- include/deal.II/distributed/grid_refinement.h | 5 +++-- source/distributed/grid_refinement.cc | 20 +++++++++++++------ source/distributed/grid_refinement.inst.in | 6 ++++-- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/include/deal.II/distributed/grid_refinement.h b/include/deal.II/distributed/grid_refinement.h index 42e82af1a1..862ba4af84 100644 --- a/include/deal.II/distributed/grid_refinement.h +++ b/include/deal.II/distributed/grid_refinement.h @@ -70,8 +70,9 @@ namespace parallel refine_and_coarsen_fixed_number ( parallel::distributed::Triangulation &tria, const Vector &criteria, - const double top_fraction_of_cells, - const double bottom_fraction_of_cells); + const double top_fraction_of_cells, + const double bottom_fraction_of_cells, + const unsigned int max_n_cells = std::numeric_limits::max()); /** * Like dealii::GridRefinement::refine_and_coarsen_fixed_fraction, but diff --git a/source/distributed/grid_refinement.cc b/source/distributed/grid_refinement.cc index 731f505a38..1ee88da7df 100644 --- a/source/distributed/grid_refinement.cc +++ b/source/distributed/grid_refinement.cc @@ -543,8 +543,9 @@ namespace parallel refine_and_coarsen_fixed_number ( parallel::distributed::Triangulation &tria, const Vector &criteria, - const double top_fraction_of_cells, - const double bottom_fraction_of_cells) + const double top_fraction_of_cells, + const double bottom_fraction_of_cells, + const unsigned int max_n_cells) { Assert ((top_fraction_of_cells>=0) && (top_fraction_of_cells<=1), dealii::GridRefinement::ExcInvalidParameterValue()); @@ -555,6 +556,13 @@ namespace parallel Assert (criteria.is_non_negative (), dealii::GridRefinement::ExcNegativeCriteria()); + const std::pair adjusted_fractions = + dealii::GridRefinement::adjust_refine_and_coarsen_number_fraction ( + tria.n_global_active_cells(), + max_n_cells, + top_fraction_of_cells, + bottom_fraction_of_cells); + // first extract from the // vector of indicators the // ones that correspond to @@ -590,7 +598,7 @@ namespace parallel master_compute_threshold (locally_owned_indicators, global_min_and_max, static_cast - (top_fraction_of_cells * + (adjusted_fractions.first * tria.n_global_active_cells()), mpi_communicator); @@ -600,14 +608,14 @@ namespace parallel // use a threshold lower // than the smallest // value we have locally - if (bottom_fraction_of_cells > 0) + if (adjusted_fractions.second > 0) bottom_threshold = RefineAndCoarsenFixedNumber:: master_compute_threshold (locally_owned_indicators, global_min_and_max, static_cast - ((1-bottom_fraction_of_cells) * + ((1-adjusted_fractions.second) * tria.n_global_active_cells()), mpi_communicator); else @@ -629,7 +637,7 @@ namespace parallel // compute bottom // threshold only if // necessary - if (bottom_fraction_of_cells > 0) + if (adjusted_fractions.second > 0) bottom_threshold = RefineAndCoarsenFixedNumber:: diff --git a/source/distributed/grid_refinement.inst.in b/source/distributed/grid_refinement.inst.in index c9527a2b49..f2fddc5b13 100644 --- a/source/distributed/grid_refinement.inst.in +++ b/source/distributed/grid_refinement.inst.in @@ -31,7 +31,8 @@ namespace parallel (parallel::distributed::Triangulation &, const dealii::Vector &, const double, - const double); + const double, + const unsigned int); template void @@ -60,7 +61,8 @@ namespace parallel (parallel::distributed::Triangulation &, const dealii::Vector &, const double, - const double); + const double, + const unsigned int); template void -- 2.39.5