]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Use cell->active_cell_index() instead of the double-indexed loop. 1989/head
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 17 Dec 2015 06:18:15 +0000 (00:18 -0600)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Thu, 17 Dec 2015 06:57:22 +0000 (00:57 -0600)
examples/step-14/step-14.cc
examples/step-18/step-18.cc
examples/step-27/step-27.cc
examples/step-28/step-28.cc
examples/step-46/step-46.cc

index 8ce57a67b5a0628e5afbbcfcfb23b44c8ba3a3da..079f0b8ddf71bc943274e262f09b478727b278e1 100644 (file)
@@ -1008,8 +1008,8 @@ namespace Step14
     RefinementWeightedKelly<dim>::refine_grid ()
     {
       // First compute some residual based error indicators for all cells by a
-      // method already implemented in the library. What exactly is computed
-      // can be read in the documentation of that class.
+      // method already implemented in the library. What exactly we compute
+      // here is described in more detail in the documentation of that class.
       Vector<float> estimated_error_per_cell (this->triangulation->n_active_cells());
       KellyErrorEstimator<dim>::estimate (this->dof_handler,
                                           *this->face_quadrature,
@@ -1017,13 +1017,20 @@ namespace Step14
                                           this->solution,
                                           estimated_error_per_cell);
 
-      // Now we are going to weight these indicators by the value of the
-      // function given to the constructor:
+      // Next weigh each entry in the vector of indicators by the value of the
+      // function given to the constructor, evaluated at the cell center. We need
+      // to write the result into the vector entry that corresponds to the current
+      // cell, which we can obtain by asking the cell what its index among all
+      // active cells is using CellAccessor::active_cell_index(). (In reality,
+      // this index is zero for the first cell we handle in the loop, one for the
+      // second cell, etc., and we could as well just keep track of this index
+      // using an integer counter; but using CellAccessor::active_cell_index()
+      // makes this more explicit.)
       typename DoFHandler<dim>::active_cell_iterator
       cell = this->dof_handler.begin_active(),
       endc = this->dof_handler.end();
-      for (unsigned int cell_index=0; cell!=endc; ++cell, ++cell_index)
-        estimated_error_per_cell(cell_index)
+      for (; cell!=endc; ++cell)
+        estimated_error_per_cell(cell->active_cell_index())
         *= weighting_function->value (cell->center());
 
       GridRefinement::refine_and_coarsen_fixed_number (*this->triangulation,
index 6330b9f00bf09dbc021fbc371adf9a2f63dc647c..321f5a22c4bf17f78572a3dc425546c08b682f1c 100644 (file)
@@ -1301,7 +1301,7 @@ namespace Step18
       typename Triangulation<dim>::active_cell_iterator
       cell = triangulation.begin_active(),
       endc = triangulation.end();
-      for (unsigned int index=0; cell!=endc; ++cell, ++index)
+      for (; cell!=endc; ++cell)
         if (cell->is_locally_owned() )
           {
             // On these cells, add up the stresses over all quadrature
@@ -1315,7 +1315,7 @@ namespace Step18
                 .old_stress;
 
             // ...then write the norm of the average to their destination:
-            norm_of_stress(index)
+            norm_of_stress(cell->active_cell_index())
               = (accumulated_stress /
                  quadrature_formula.size()).norm();
           }
@@ -1326,7 +1326,7 @@ namespace Step18
       // elements would not appear in the output file, that we would find out
       // by looking at the graphical output:
         else
-          norm_of_stress(index) = -1e+20;
+          norm_of_stress(cell->active_cell_index()) = -1e+20;
     }
     // Finally attach this vector as well to be treated for output:
     data_out.add_data_vector (norm_of_stress, "norm_of_stress");
index 5ca341ca46dede3994bf41a707dbdfe49a716630..0adfe4283adc03658cf5233ddb3cf571d6136b7d 100644 (file)
@@ -382,8 +382,8 @@ namespace Step27
         typename hp::DoFHandler<dim>::active_cell_iterator
         cell = dof_handler.begin_active(),
         endc = dof_handler.end();
-        for (unsigned int index=0; cell!=endc; ++cell, ++index)
-          fe_degrees(index)
+        for (; cell!=endc; ++cell)
+          fe_degrees(cell->active_cell_index())
             = fe_collection[cell->active_fe_index()].degree;
       }
 
@@ -443,13 +443,13 @@ namespace Step27
         typename hp::DoFHandler<dim>::active_cell_iterator
         cell = dof_handler.begin_active(),
         endc = dof_handler.end();
-        for (unsigned int index=0; cell!=endc; ++cell, ++index)
+        for (; cell!=endc; ++cell)
           if (cell->refine_flag_set())
             {
               max_smoothness = std::max (max_smoothness,
-                                         smoothness_indicators(index));
+                                         smoothness_indicators(cell->active_cell_index()));
               min_smoothness = std::min (min_smoothness,
-                                         smoothness_indicators(index));
+                                         smoothness_indicators(cell->active_cell_index()));
             }
       }
       const float threshold_smoothness = (max_smoothness + min_smoothness) / 2;
@@ -466,10 +466,10 @@ namespace Step27
         typename hp::DoFHandler<dim>::active_cell_iterator
         cell = dof_handler.begin_active(),
         endc = dof_handler.end();
-        for (unsigned int index=0; cell!=endc; ++cell, ++index)
+        for (; cell!=endc; ++cell)
           if (cell->refine_flag_set()
               &&
-              (smoothness_indicators(index) > threshold_smoothness)
+              (smoothness_indicators(cell->active_cell_index()) > threshold_smoothness)
               &&
               (cell->active_fe_index()+1 < fe_collection.size()))
             {
@@ -753,7 +753,7 @@ namespace Step27
     typename hp::DoFHandler<dim>::active_cell_iterator
     cell = dof_handler.begin_active(),
     endc = dof_handler.end();
-    for (unsigned int index=0; cell!=endc; ++cell, ++index)
+    for (; cell!=endc; ++cell)
       {
         // Inside the loop, we first need to get the values of the local
         // degrees of freedom (which we put into the
@@ -829,7 +829,7 @@ namespace Step27
 
         // The final step is to compute the Sobolev index $s=\mu-\frac d2$ and
         // store it in the vector of estimated values for each cell:
-        smoothness_indicators(index) = mu - 1.*dim/2;
+        smoothness_indicators(cell->active_cell_index()) = mu - 1.*dim/2;
       }
   }
 }
index dd1ae6b440d40d586d0c8487f470626df71b4c82..b73f9070de3553027732aeee698d555812f3ca1c 100644 (file)
@@ -1093,10 +1093,10 @@ namespace Step28
     cell = triangulation.begin_active(),
     endc = triangulation.end();
 
-    for (unsigned int cell_index=0; cell!=endc; ++cell, ++cell_index)
-      if (error_indicators(cell_index) > refine_threshold)
+    for (; cell!=endc; ++cell)
+      if (error_indicators(cell->active_cell_index()) > refine_threshold)
         cell->set_refine_flag ();
-      else if (error_indicators(cell_index) < coarsen_threshold)
+      else if (error_indicators(cell->active_cell_index()) < coarsen_threshold)
         cell->set_coarsen_flag ();
 
     SolutionTransfer<dim> soltrans(dof_handler);
index 46f6d4971480b8201d1a11327ccd7d25857f407a..d5f1602430adcf24383d1ea7c3e0a5a1a8e7a7de 100644 (file)
@@ -994,59 +994,56 @@ namespace Step46
     // more. The structure of these nested conditions is much the same as we
     // encountered when assembling interface terms in
     // <code>assemble_system</code>.
-    {
-      unsigned int cell_index = 0;
-      for (typename hp::DoFHandler<dim>::active_cell_iterator
-           cell = dof_handler.begin_active();
-           cell != dof_handler.end(); ++cell, ++cell_index)
-        for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
-          if (cell_is_in_solid_domain (cell))
-            {
-              if ((cell->at_boundary(f) == false)
+    for (typename hp::DoFHandler<dim>::active_cell_iterator
+         cell = dof_handler.begin_active();
+         cell != dof_handler.end(); ++cell)
+      for (unsigned int f=0; f<GeometryInfo<dim>::faces_per_cell; ++f)
+        if (cell_is_in_solid_domain (cell))
+          {
+            if ((cell->at_boundary(f) == false)
+                &&
+                (((cell->neighbor(f)->level() == cell->level())
                   &&
-                  (((cell->neighbor(f)->level() == cell->level())
-                    &&
-                    (cell->neighbor(f)->has_children() == false)
-                    &&
-                    cell_is_in_fluid_domain (cell->neighbor(f)))
-                   ||
-                   ((cell->neighbor(f)->level() == cell->level())
-                    &&
-                    (cell->neighbor(f)->has_children() == true)
-                    &&
-                    (cell_is_in_fluid_domain (cell->neighbor_child_on_subface
-                                              (f, 0))))
-                   ||
-                   (cell->neighbor_is_coarser(f)
-                    &&
-                    cell_is_in_fluid_domain(cell->neighbor(f)))
-                  ))
-                estimated_error_per_cell(cell_index) = 0;
-            }
-          else
-            {
-              if ((cell->at_boundary(f) == false)
+                  (cell->neighbor(f)->has_children() == false)
                   &&
-                  (((cell->neighbor(f)->level() == cell->level())
-                    &&
-                    (cell->neighbor(f)->has_children() == false)
-                    &&
-                    cell_is_in_solid_domain (cell->neighbor(f)))
-                   ||
-                   ((cell->neighbor(f)->level() == cell->level())
-                    &&
-                    (cell->neighbor(f)->has_children() == true)
-                    &&
-                    (cell_is_in_solid_domain (cell->neighbor_child_on_subface
-                                              (f, 0))))
-                   ||
-                   (cell->neighbor_is_coarser(f)
-                    &&
-                    cell_is_in_solid_domain(cell->neighbor(f)))
-                  ))
-                estimated_error_per_cell(cell_index) = 0;
-            }
-    }
+                  cell_is_in_fluid_domain (cell->neighbor(f)))
+                 ||
+                 ((cell->neighbor(f)->level() == cell->level())
+                  &&
+                  (cell->neighbor(f)->has_children() == true)
+                  &&
+                  (cell_is_in_fluid_domain (cell->neighbor_child_on_subface
+                                            (f, 0))))
+                 ||
+                 (cell->neighbor_is_coarser(f)
+                  &&
+                  cell_is_in_fluid_domain(cell->neighbor(f)))
+                ))
+              estimated_error_per_cell(cell->active_cell_index()) = 0;
+          }
+        else
+          {
+            if ((cell->at_boundary(f) == false)
+                &&
+                (((cell->neighbor(f)->level() == cell->level())
+                  &&
+                  (cell->neighbor(f)->has_children() == false)
+                  &&
+                  cell_is_in_solid_domain (cell->neighbor(f)))
+                 ||
+                 ((cell->neighbor(f)->level() == cell->level())
+                  &&
+                  (cell->neighbor(f)->has_children() == true)
+                  &&
+                  (cell_is_in_solid_domain (cell->neighbor_child_on_subface
+                                            (f, 0))))
+                 ||
+                 (cell->neighbor_is_coarser(f)
+                  &&
+                  cell_is_in_solid_domain(cell->neighbor(f)))
+                ))
+              estimated_error_per_cell(cell->active_cell_index()) = 0;
+          }
 
     GridRefinement::refine_and_coarsen_fixed_number (triangulation,
                                                      estimated_error_per_cell,

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.