From b7d0e9ac0ed18e8c0b733cd39ec26f0a2c066e78 Mon Sep 17 00:00:00 2001
From: hartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Date: Mon, 26 Nov 2001 16:20:56 +0000
Subject: [PATCH] Make the GridRefinement::refine function work also when the
 threshold happens to be zero.

git-svn-id: https://svn.dealii.org/trunk@5271 0785d39b-7218-0410-832d-ea1e28bc413d
---
 .../deal.II/source/grid/grid_refinement.cc    | 23 +++++++++++--------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/deal.II/deal.II/source/grid/grid_refinement.cc b/deal.II/deal.II/source/grid/grid_refinement.cc
index ab1518c9f3..0f7c109390 100644
--- a/deal.II/deal.II/source/grid/grid_refinement.cc
+++ b/deal.II/deal.II/source/grid/grid_refinement.cc
@@ -81,21 +81,24 @@ void GridRefinement::refine (Triangulation<dim>   &tria,
   Assert (criteria.size() == tria.n_active_cells(),
 	  ExcInvalidVectorSize(criteria.size(), tria.n_active_cells()));
   Assert (*std::min_element(criteria.begin(), criteria.end()) >= 0,
-	  ExcInvalidParameterValue());  
-
-				   // nothing to do; especially we
-				   // do not want to flag with zero
-				   // error since then we may get
-				   // into conflict with coarsening
-				   // in some cases
-  if (threshold==0)
-    return;
+	  ExcInvalidParameterValue());
   
   typename Triangulation<dim>::active_cell_iterator cell = tria.begin_active();
   const unsigned int n_cells = criteria.size();
+
+  double new_threshold=threshold;
+				   // when threshold==0 find the
+				   // smallest value in criteria
+				   // greater 0
+  if (new_threshold==0)
+    for (unsigned int index=0; index<n_cells; ++index)
+      if (criteria(index)>0
+	  && (criteria(index)<new_threshold
+	      || new_threshold==0))
+	new_threshold=criteria(index);
   
   for (unsigned int index=0; index<n_cells; ++cell, ++index)
-    if (std::fabs(criteria(index)) >= threshold)
+    if (std::fabs(criteria(index)) >= new_threshold)
       cell->set_refine_flag();
 };
 
-- 
2.39.5