From: Ralf Hartmann Date: Thu, 4 Mar 1999 18:02:10 +0000 (+0000) Subject: Change the refine_and_coarsen_fixed_fraction (~number) functions such that they actua... X-Git-Tag: v8.0.0~22306 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=25a86ef079809c7515fa5bb7c9dc055b9132d502;p=dealii.git Change the refine_and_coarsen_fixed_fraction (~number) functions such that they actually do not coarse (or refine) if the bottom(top)_fraction is set to 0 git-svn-id: https://svn.dealii.org/trunk@952 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/grid/tria.cc b/deal.II/deal.II/source/grid/tria.cc index 473387905e..dec83179bc 100644 --- a/deal.II/deal.II/source/grid/tria.cc +++ b/deal.II/deal.II/source/grid/tria.cc @@ -3814,23 +3814,29 @@ Triangulation::refine_and_coarsen_fixed_number (const Vector &crite Assert ((top_fraction>=0) && (top_fraction<=1), ExcInvalidParameterValue()); Assert ((bottom_fraction>=0) && (bottom_fraction<=1), ExcInvalidParameterValue()); Assert (top_fraction+bottom_fraction <= 1, ExcInvalidParameterValue()); - // refine at least one cell; algorithmic - // simplification - const int refine_cells = max(static_cast(top_fraction*criteria.size()), - 1); - const int coarsen_cells = max(static_cast(bottom_fraction*criteria.size()), - 1); - - Vector tmp(criteria); - nth_element (tmp.begin(), tmp.begin()+refine_cells, - tmp.end(), - greater()); - refine (criteria, *(tmp.begin() + refine_cells)); - nth_element (tmp.begin(), tmp.begin()+tmp.size()-coarsen_cells, - tmp.end(), - greater()); - coarsen (criteria, *(tmp.begin() + tmp.size() - coarsen_cells)); + const int refine_cells=static_cast(top_fraction*criteria.size()); + const int coarsen_cells=static_cast(bottom_fraction*criteria.size()); + + if (refine_cells || coarsen_cells) + { + Vector tmp(criteria); + if (refine_cells) + { + nth_element (tmp.begin(), tmp.begin()+refine_cells, + tmp.end(), + greater()); + refine (criteria, *(tmp.begin() + refine_cells)); + } + + if (coarsen_cells) + { + nth_element (tmp.begin(), tmp.begin()+tmp.size()-coarsen_cells, + tmp.end(), + greater()); + coarsen (criteria, *(tmp.begin() + tmp.size() - coarsen_cells)); + } + } }; @@ -3904,8 +3910,10 @@ Triangulation::refine_and_coarsen_fixed_fraction (const Vector &cri bottom_threshold = 0.999*top_threshold; // actually flag cells - refine (criteria, top_threshold); - coarsen (criteria, bottom_threshold); + if (top_threshold < *max_element(criteria.begin(), criteria.end())) + refine (criteria, top_threshold); + if (bottom_threshold > *min_element(criteria.begin(), criteria.end())) + coarsen (criteria, bottom_threshold); };