]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Change the refine_and_coarsen_fixed_fraction (~number) functions such that they actua...
authorhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 4 Mar 1999 18:02:10 +0000 (18:02 +0000)
committerhartmann <hartmann@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 4 Mar 1999 18:02:10 +0000 (18:02 +0000)
git-svn-id: https://svn.dealii.org/trunk@952 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/source/grid/tria.cc

index 473387905ee79df8123a85640a7941b72581eefd..dec83179bc0d936853ad937b31e902e059d50fd6 100644 (file)
@@ -3814,23 +3814,29 @@ Triangulation<dim>::refine_and_coarsen_fixed_number (const Vector<number> &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<int>(top_fraction*criteria.size()),
-                              1);
-  const int coarsen_cells = max(static_cast<int>(bottom_fraction*criteria.size()),
-                               1);
-  
-  Vector<number> tmp(criteria);  
-  nth_element (tmp.begin(), tmp.begin()+refine_cells,
-              tmp.end(),
-              greater<double>());
-  refine (criteria, *(tmp.begin() + refine_cells));
 
-  nth_element (tmp.begin(), tmp.begin()+tmp.size()-coarsen_cells,
-              tmp.end(),
-              greater<double>());
-  coarsen (criteria, *(tmp.begin() + tmp.size() - coarsen_cells));
+  const int refine_cells=static_cast<int>(top_fraction*criteria.size());
+  const int coarsen_cells=static_cast<int>(bottom_fraction*criteria.size());
+
+  if (refine_cells || coarsen_cells)
+    {
+      Vector<number> tmp(criteria);
+      if (refine_cells)
+       {
+         nth_element (tmp.begin(), tmp.begin()+refine_cells,
+                      tmp.end(),
+                      greater<double>());
+         refine (criteria, *(tmp.begin() + refine_cells));
+       }
+
+      if (coarsen_cells)
+       {
+         nth_element (tmp.begin(), tmp.begin()+tmp.size()-coarsen_cells,
+                      tmp.end(),
+                      greater<double>());
+         coarsen (criteria, *(tmp.begin() + tmp.size() - coarsen_cells));
+       }
+    }
 };
 
 
@@ -3904,8 +3910,10 @@ Triangulation<dim>::refine_and_coarsen_fixed_fraction (const Vector<number> &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);
 };
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.