]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
fix refine_and_coarsen_fixed_fraction() refining more cells than necessary if indicat...
authorheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 11 Mar 2013 18:27:18 +0000 (18:27 +0000)
committerheister <heister@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 11 Mar 2013 18:27:18 +0000 (18:27 +0000)
git-svn-id: https://svn.dealii.org/trunk@28858 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/grid/grid_refinement.h
deal.II/source/grid/grid_refinement.cc
deal.II/source/grid/grid_refinement.inst.in

index 8b8efe3ebd264bfdbc1ffd0162c2daf63d3c5681..c5f9d6ec0b86dfa422a940afdaf0156677f9b765 100644 (file)
@@ -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 <int dim, class Vector, int spacedim>
   void refine (Triangulation<dim,spacedim> &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
index 1e2f5406bd166d6dbc862d642f17fd91958c3517..82c9684336851184c85a140ba35b433bec7a78be 100644 (file)
@@ -209,7 +209,8 @@ namespace
 template <int dim, class Vector, int spacedim>
 void GridRefinement::refine (Triangulation<dim,spacedim> &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<dim,spacedim> &tria,
           new_threshold=criteria(index);
     }
 
+  unsigned int marked=0;
   for (unsigned int index=0; index<n_cells; ++cell, ++index)
     if (std::fabs(criteria(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<dim,spacedim> &
 
   // 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);
index 6d6b688c280685cd50f452105373bccf02a49692..366c0f8324feb07234dff38b66c6829b022e73aa 100644 (file)
@@ -21,7 +21,8 @@ for (S : REAL_SCALARS; deal_II_dimension : DIMENSIONS)
   refine<deal_II_dimension,dealii::Vector<S>,deal_II_dimension>
          (Triangulation<deal_II_dimension> &,
           const dealii::Vector<S> &,
-          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,dealii::Vector<S>,deal_II_dimension+1>
          (Triangulation<deal_II_dimension,deal_II_dimension+1> &,
           const dealii::Vector<S> &,
-          const double);
+          const double,
+          const unsigned int);
 
   template
   void

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.