From: heister Date: Mon, 11 Mar 2013 18:27:18 +0000 (+0000) Subject: fix refine_and_coarsen_fixed_fraction() refining more cells than necessary if indicat... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4a6dc01253cdb7600acbdf1b1fdaa0160d691fd;p=dealii-svn.git fix refine_and_coarsen_fixed_fraction() refining more cells than necessary if indicators are equal git-svn-id: https://svn.dealii.org/trunk@28858 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/grid/grid_refinement.h b/deal.II/include/deal.II/grid/grid_refinement.h index 8b8efe3ebd..c5f9d6ec0b 100644 --- a/deal.II/include/deal.II/grid/grid_refinement.h +++ b/deal.II/include/deal.II/grid/grid_refinement.h @@ -213,7 +213,7 @@ namespace GridRefinement /** * Flag all mesh cells for which the value in @p criteria exceeds @p - * threshold for refinement. + * threshold for refinement, but only flag up to @p max_to_mark cells. * * The vector @p criteria contains a nonnegative value for each active * cell, ordered in the canonical order of of @@ -229,7 +229,8 @@ namespace GridRefinement template void refine (Triangulation &tria, const Vector &criteria, - const double threshold); + const double threshold, + const unsigned int max_to_mark = numbers::invalid_unsigned_int); /** * Flag all mesh cells for which the value in @p criteria diff --git a/deal.II/source/grid/grid_refinement.cc b/deal.II/source/grid/grid_refinement.cc index 1e2f5406bd..82c9684336 100644 --- a/deal.II/source/grid/grid_refinement.cc +++ b/deal.II/source/grid/grid_refinement.cc @@ -209,7 +209,8 @@ namespace template void GridRefinement::refine (Triangulation &tria, const Vector &criteria, - const double threshold) + const double threshold, + const unsigned int max_to_mark) { Assert (criteria.size() == tria.n_active_cells(), ExcDimensionMismatch(criteria.size(), tria.n_active_cells())); @@ -239,9 +240,15 @@ void GridRefinement::refine (Triangulation &tria, new_threshold=criteria(index); } + unsigned int marked=0; for (unsigned int index=0; index= new_threshold) + { + if (max_to_mark!=numbers::invalid_unsigned_int && marked>=max_to_mark) + break; + marked++; cell->set_refine_flag(); + } } @@ -493,7 +500,7 @@ GridRefinement::refine_and_coarsen_fixed_fraction (Triangulation & // actually flag cells if (top_threshold < max_element(criteria)) - refine (tria, criteria, top_threshold); + refine (tria, criteria, top_threshold, pp - tmp.begin()); if (bottom_threshold > min_element(criteria)) coarsen (tria, criteria, bottom_threshold); diff --git a/deal.II/source/grid/grid_refinement.inst.in b/deal.II/source/grid/grid_refinement.inst.in index 6d6b688c28..366c0f8324 100644 --- a/deal.II/source/grid/grid_refinement.inst.in +++ b/deal.II/source/grid/grid_refinement.inst.in @@ -21,7 +21,8 @@ for (S : REAL_SCALARS; deal_II_dimension : DIMENSIONS) refine,deal_II_dimension> (Triangulation &, const dealii::Vector &, - const double); + const double, + const unsigned int); template void @@ -66,7 +67,8 @@ for (S : REAL_SCALARS; deal_II_dimension : DIMENSIONS) refine,deal_II_dimension+1> (Triangulation &, const dealii::Vector &, - const double); + const double, + const unsigned int); template void