]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Simplify nested if/for clauses to avoid -Wdangling-else warnings 813/head
authorMatthias Maier <matthias.maier@iwr.uni-heidelberg.de>
Thu, 16 Apr 2015 15:32:25 +0000 (17:32 +0200)
committerMatthias Maier <matthias.maier@iwr.uni-heidelberg.de>
Thu, 16 Apr 2015 15:32:25 +0000 (17:32 +0200)
include/deal.II/lac/constraint_matrix.templates.h
source/dofs/dof_tools_constraints.cc
source/grid/tria_accessor.cc

index 2fe7edc31b271da73a790e068b5f855e0a631af4..835988e11d13d68120509577db27db12a2bacd5d 100644 (file)
@@ -1,6 +1,6 @@
 // ---------------------------------------------------------------------
 //
-// Copyright (C) 1999 - 2014 by the deal.II authors
+// Copyright (C) 1999 - 2015 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -636,33 +636,37 @@ distribute_local_to_global (const Vector<double>            &local_vector,
         const ConstraintLine *position =
           lines_cache.size() <= line_index ? 0 : &lines[lines_cache[line_index]];
 
-        // Gauss elimination of the matrix columns
-        // with the inhomogeneity. Go through them one
-        // by one and again check whether they are
+        // Gauss elimination of the matrix columns with the inhomogeneity.
+        // Go through them one by one and again check whether they are
         // constrained. If so, distribute the constraint
         const double val = position->inhomogeneity;
         if (val != 0)
           for (size_type j=0; j<n_local_dofs; ++j)
-            if (is_constrained(local_dof_indices[j]) == false)
-              global_vector(local_dof_indices[j]) -= val * local_matrix(j,i);
-            else
-              {
-                const double matrix_entry = local_matrix(j,i);
-                if (matrix_entry == 0)
+            {
+              if (is_constrained(local_dof_indices[j]) == false)
+                {
+                  global_vector(local_dof_indices[j]) -= val * local_matrix(j,i);
                   continue;
+                }
 
-                const ConstraintLine &position_j =
-                  lines[lines_cache[calculate_line_index(local_dof_indices[j])]];
-                for (size_type q=0; q<position_j.entries.size(); ++q)
-                  {
-                    Assert (!(!local_lines.size()
-                              || local_lines.is_element(position_j.entries[q].first))
-                            || is_constrained(position_j.entries[q].first) == false,
-                            ExcMessage ("Tried to distribute to a fixed dof."));
-                    global_vector(position_j.entries[q].first)
-                    -= val * position_j.entries[q].second * matrix_entry;
-                  }
-              }
+              const double matrix_entry = local_matrix(j,i);
+
+              if (matrix_entry == 0)
+                continue;
+
+              const ConstraintLine &position_j =
+                lines[lines_cache[calculate_line_index(local_dof_indices[j])]];
+
+              for (size_type q=0; q<position_j.entries.size(); ++q)
+                {
+                  Assert (!(!local_lines.size()
+                            || local_lines.is_element(position_j.entries[q].first))
+                          || is_constrained(position_j.entries[q].first) == false,
+                          ExcMessage ("Tried to distribute to a fixed dof."));
+                  global_vector(position_j.entries[q].first)
+                  -= val * position_j.entries[q].second * matrix_entry;
+                }
+            }
 
         // now distribute the constraint,
         // but make sure we don't touch
index f3f2e78164b73906cfb2593fd16808e435d2e885..68adca2558d5c6e0997b1c10f508cb21c36a7ed5 100644 (file)
@@ -752,9 +752,12 @@ namespace DoFTools
       typename DH::active_cell_iterator cell = dof_handler.begin_active(),
                                         endc = dof_handler.end();
       for (; cell!=endc; ++cell)
-        // artificial cells can at best neighbor ghost cells, but we're not
-        // interested in these interfaces
-        if (!cell->is_artificial ())
+        {
+          // artificial cells can at best neighbor ghost cells, but we're not
+          // interested in these interfaces
+          if (cell->is_artificial ())
+            continue;
+
           for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
             if (cell->face(face)->has_children())
               {
@@ -857,6 +860,7 @@ namespace DoFTools
                             ExcInternalError());
                   }
               }
+        }
     }
 
 
@@ -884,9 +888,12 @@ namespace DoFTools
       typename DH::active_cell_iterator cell = dof_handler.begin_active(),
                                         endc = dof_handler.end();
       for (; cell!=endc; ++cell)
-        // artificial cells can at best neighbor ghost cells, but we're not
-        // interested in these interfaces
-        if (!cell->is_artificial ())
+        {
+          // artificial cells can at best neighbor ghost cells, but we're not
+          // interested in these interfaces
+          if (cell->is_artificial ())
+            continue;
+
           for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
             if (cell->face(face)->has_children())
               {
@@ -1073,6 +1080,7 @@ namespace DoFTools
                             ExcInternalError());
                   }
               }
+        }
     }
 
 
@@ -1137,9 +1145,12 @@ namespace DoFTools
       typename DH::active_cell_iterator cell = dof_handler.begin_active(),
                                         endc = dof_handler.end();
       for (; cell!=endc; ++cell)
-        // artificial cells can at best neighbor ghost cells, but we're not
-        // interested in these interfaces
-        if (!cell->is_artificial ())
+        {
+          // artificial cells can at best neighbor ghost cells, but we're not
+          // interested in these interfaces
+          if (cell->is_artificial ())
+            continue;
+
           for (unsigned int face=0; face<GeometryInfo<dim>::faces_per_cell; ++face)
             if (cell->face(face)->has_children())
               {
@@ -1594,6 +1605,7 @@ namespace DoFTools
                       }
                   }
               }
+        }
     }
   }
 
index 2fc78e1fc41e3ada749926fb07b7f88b86261c35..11551eae908a0094dc6d80552a4b847b8310908c 100644 (file)
@@ -1830,39 +1830,39 @@ CellAccessor<dim, spacedim>::neighbor_of_coarser_neighbor (const unsigned int ne
 
 
 
-      // if the guess was false, then
-      // we need to loop over all faces
-      // and subfaces and find the
-      // number the hard way
+      // if the guess was false, then we need to loop over all faces and
+      // subfaces and find the number the hard way
       for (unsigned int face_no=0; face_no<GeometryInfo<3>::faces_per_cell; ++face_no)
         {
-          if (face_no!=face_no_guess)
+          if (face_no==face_no_guess)
+            continue;
+
+          const TriaIterator<TriaAccessor<3-1, 3, spacedim> > face
+            =neighbor_cell->face(face_no);
+
+          if (!face->has_children())
+            continue;
+
+          for (unsigned int subface_no=0; subface_no<face->n_children(); ++subface_no)
             {
-              const TriaIterator<TriaAccessor<3-1, 3, spacedim> > face
-                =neighbor_cell->face(face_no);
-              if (face->has_children())
-                for (unsigned int subface_no=0; subface_no<face->n_children(); ++subface_no)
-                  if (face->child_index(subface_no)==this_face_index)
-                    // call a helper function, that
-                    // translates the current subface
-                    // number to a subface number for
-                    // the current FaceRefineCase
-                    return std::make_pair (face_no, translate_subface_no(face, subface_no));
-                  else if (face->child(subface_no)->has_children())
-                    for (unsigned int subsub_no=0; subsub_no<face->child(subface_no)->n_children(); ++subsub_no)
-                      if (face->child(subface_no)->child_index(subsub_no)==this_face_index)
-                        // call a helper function, that
-                        // translates the current subface
-                        // number and subsubface number to
-                        // a subface number for the current
-                        // FaceRefineCase
-                        return std::make_pair (face_no, translate_subface_no(face, subface_no, subsub_no));
+              if (face->child_index(subface_no)==this_face_index)
+                // call a helper function, that translates the current
+                // subface number to a subface number for the current
+                // FaceRefineCase
+                return std::make_pair (face_no, translate_subface_no(face, subface_no));
+
+              if (face->child(subface_no)->has_children())
+                for (unsigned int subsub_no=0; subsub_no<face->child(subface_no)->n_children(); ++subsub_no)
+                  if (face->child(subface_no)->child_index(subsub_no)==this_face_index)
+                    // call a helper function, that translates the current
+                    // subface number and subsubface number to a subface
+                    // number for the current FaceRefineCase
+                    return std::make_pair (face_no, translate_subface_no(face, subface_no, subsub_no));
             }
         }
 
-      // we should never get here,
-      // since then we did not find
-      // our way back...
+      // we should never get here, since then we did not find our way
+      // back...
       Assert (false, ExcInternalError());
       return std::make_pair (numbers::invalid_unsigned_int,
                              numbers::invalid_unsigned_int);

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.