From: Timo Heister Date: Wed, 26 Feb 2020 13:13:52 +0000 (-0500) Subject: fix 64bit overflow in refine_and_coarsen_fixed_number X-Git-Tag: v9.2.0-rc1~500^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F9568%2Fhead;p=dealii.git fix 64bit overflow in refine_and_coarsen_fixed_number The argument max_n_cells (that probably nobody uses) was declared as an unsigned int, meaning that we can not refine over 4 billion cells with this function. This is now fixed. --- diff --git a/include/deal.II/distributed/grid_refinement.h b/include/deal.II/distributed/grid_refinement.h index 4f96a88bc2..6b4358ec89 100644 --- a/include/deal.II/distributed/grid_refinement.h +++ b/include/deal.II/distributed/grid_refinement.h @@ -131,10 +131,10 @@ namespace parallel refine_and_coarsen_fixed_number( parallel::distributed::Triangulation &tria, const dealii::Vector & criteria, - const double top_fraction_of_cells, - const double bottom_fraction_of_cells, - const unsigned int max_n_cells = - std::numeric_limits::max()); + const double top_fraction_of_cells, + const double bottom_fraction_of_cells, + const types::global_dof_index max_n_cells = + std::numeric_limits::max()); /** * Like dealii::GridRefinement::refine_and_coarsen_fixed_fraction, but diff --git a/include/deal.II/grid/grid_refinement.h b/include/deal.II/grid/grid_refinement.h index 52a6fdaf7e..3ec8e03862 100644 --- a/include/deal.II/grid/grid_refinement.h +++ b/include/deal.II/grid/grid_refinement.h @@ -87,10 +87,10 @@ namespace GridRefinement template std::pair adjust_refine_and_coarsen_number_fraction( - const unsigned int current_n_cells, - const unsigned int max_n_cells, - const double top_fraction_of_cells, - const double bottom_fraction_of_cells); + const types::global_dof_index current_n_cells, + const types::global_dof_index max_n_cells, + const double top_fraction_of_cells, + const double bottom_fraction_of_cells); /** * This function provides a strategy to mark cells for refinement and diff --git a/source/distributed/grid_refinement.cc b/source/distributed/grid_refinement.cc index a1625db018..fc45b9f954 100644 --- a/source/distributed/grid_refinement.cc +++ b/source/distributed/grid_refinement.cc @@ -434,9 +434,9 @@ namespace parallel refine_and_coarsen_fixed_number( parallel::distributed::Triangulation &tria, const dealii::Vector & criteria, - const double top_fraction_of_cells, - const double bottom_fraction_of_cells, - const unsigned int max_n_cells) + const double top_fraction_of_cells, + const double bottom_fraction_of_cells, + const types::global_dof_index max_n_cells) { Assert(criteria.size() == tria.n_active_cells(), ExcDimensionMismatch(criteria.size(), tria.n_active_cells())); diff --git a/source/distributed/grid_refinement.inst.in b/source/distributed/grid_refinement.inst.in index 3e4477074f..688294715d 100644 --- a/source/distributed/grid_refinement.inst.in +++ b/source/distributed/grid_refinement.inst.in @@ -69,7 +69,7 @@ for (S : REAL_SCALARS; deal_II_dimension : DIMENSIONS) const dealii::Vector &, const double, const double, - const unsigned int); + const types::global_dof_index); template void refine_and_coarsen_fixed_fraction &, const double, const double, - const unsigned int); + const types::global_dof_index); template void refine_and_coarsen_fixed_fraction &tria, template std::pair GridRefinement::adjust_refine_and_coarsen_number_fraction( - const unsigned int current_n_cells, - const unsigned int max_n_cells, - const double top_fraction, - const double bottom_fraction) + const types::global_dof_index current_n_cells, + const types::global_dof_index max_n_cells, + const double top_fraction, + const double bottom_fraction) { Assert(top_fraction >= 0, ExcInvalidParameterValue()); Assert(top_fraction <= 1, ExcInvalidParameterValue()); @@ -166,7 +166,7 @@ GridRefinement::adjust_refine_and_coarsen_number_fraction( // again, this is true for isotropically // refined cells. we take this as an // approximation of a mixed refinement. - else if (static_cast( + else if (static_cast( current_n_cells + refine_cells * cell_increase_on_refine - coarsen_cells * cell_decrease_on_coarsen) > max_n_cells) { diff --git a/source/grid/grid_refinement.inst.in b/source/grid/grid_refinement.inst.in index e173c988cf..8bda2e72e1 100644 --- a/source/grid/grid_refinement.inst.in +++ b/source/grid/grid_refinement.inst.in @@ -97,7 +97,10 @@ for (S : REAL_SCALARS; deal_II_dimension : DIMENSIONS) for (deal_II_dimension : DIMENSIONS) { - template std::pair GridRefinement:: - adjust_refine_and_coarsen_number_fraction( - const unsigned int, const unsigned int, const double, const double); + template std::pair + GridRefinement::adjust_refine_and_coarsen_number_fraction< + deal_II_dimension>(const types::global_dof_index, + const types::global_dof_index, + const double, + const double); }