]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Wrote an internal find_constraint function so that the implementation gets a bit...
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 17 Sep 2009 16:38:20 +0000 (16:38 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 17 Sep 2009 16:38:20 +0000 (16:38 +0000)
git-svn-id: https://svn.dealii.org/trunk@19469 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/constraint_matrix.h
deal.II/lac/include/lac/constraint_matrix.templates.h

index b1e6df9e78bc9032617bd61033a6881b4e14c1d0..fb3fc0ca686bc9ab5064f00b0685fcf15b2b8dc8 100644 (file)
@@ -1539,6 +1539,26 @@ class ConstraintMatrix : public Subscriptor
                                 const Table<2,bool>             &dof_mask,
                                 internal::bool2type<true>) const;
 
+                                   /**
+                                    * This function returns a pointer to
+                                    * the respective ConstraintLine object
+                                    * if a dof is constrained, and a zero
+                                    * pointer otherwise.
+                                    */
+    std::vector<ConstraintLine>::const_iterator
+    find_constraint (const unsigned int line) const;
+
+                                   /**
+                                    * This function returns a pointer to
+                                    * the respective ConstraintLine object
+                                    * if a dof is constrained, and a zero
+                                    * pointer otherwise. This function is
+                                    * used if the constraint matrix has not
+                                    * been closed yet.
+                                    */
+    std::vector<ConstraintLine>::iterator
+    find_constraint (const unsigned int line);
+    
 #ifdef DEAL_II_USE_TRILINOS
 //TODO: Make use of the following member thread safe    
                                      /**
@@ -1615,28 +1635,7 @@ ConstraintMatrix::add_entry (const unsigned int line,
   Assert (line != column,
          ExcMessage ("Can't constrain a degree of freedom to itself"));
 
-  std::vector<ConstraintLine>::iterator line_ptr;
-  const std::vector<ConstraintLine>::const_iterator start=lines.begin();
-
-                                  // the usual case is that the line where
-                                  // a value is entered is the one we
-                                  // added last, so we search backward
-  for (line_ptr=(lines.end()-1); line_ptr!=start; --line_ptr)
-    if (line_ptr->line == line)
-      break;
-
-                                  // if the loop didn't break, then
-                                  // line_ptr must be begin().
-                                  // we have an error if that doesn't
-                                  // point to 'line' then
-  Assert (line_ptr->line==line, ExcLineInexistant(line));
-                                  // second check: the respective
-                                  // flag in the
-                                  // constraint_line_exists field
-                                  // must exist
-  Assert (line < constraint_line_exists.size(), ExcInternalError());
-  Assert (constraint_line_exists[line] == true, ExcInternalError());
-  
+  std::vector<ConstraintLine>::iterator line_ptr = find_constraint(line);
 
                                   // if in debug mode, check whether an
                                   // entry for this column already
@@ -1666,29 +1665,7 @@ void
 ConstraintMatrix::set_inhomogeneity (const unsigned int line,
                                     const double       value)
 {
-  std::vector<ConstraintLine>::iterator line_ptr;
-  const std::vector<ConstraintLine>::const_iterator start=lines.begin();
-
-                                  // the usual case is that the line where
-                                  // the inhomogeneity is set to the one we
-                                  // added last, so we search backward
-  for (line_ptr=(lines.end()-1); line_ptr!=start; --line_ptr)
-    if (line_ptr->line == line)
-      break;
-
-                                  // if the loop didn't break, then
-                                  // line_ptr must be begin().
-                                  // we have an error if that doesn't
-                                  // point to 'line' then
-  Assert (line_ptr->line==line, ExcLineInexistant(line));
-                                  // second check: the respective
-                                  // flag in the
-                                  // constraint_line_exists field
-                                  // must exist
-  Assert (line < constraint_line_exists.size(), ExcInternalError());
-  Assert (constraint_line_exists[line] == true, ExcInternalError());
-
-  line_ptr->inhomogeneity = value;
+  find_constraint(line)->inhomogeneity = value;
 }
 
 
@@ -1708,18 +1685,68 @@ inline
 bool
 ConstraintMatrix::is_inhomogeneously_constrained (const unsigned int index) const 
 {
-  if (is_constrained(index) == false)
-    return false;
+  const std::vector<ConstraintLine>::const_iterator position 
+    = find_constraint(index);
+  return position!=lines.end() ? position->inhomogeneity != 0 : false;
+}
+
+
+
+inline
+std::vector<ConstraintMatrix::ConstraintLine>::const_iterator 
+ConstraintMatrix::find_constraint (const unsigned int line) const
+{
+  if (is_constrained(line) == false)
+    return lines.end();
 
+  Assert (sorted==true, ExcMatrixNotClosed());
   ConstraintLine index_comparison;
-  index_comparison.line = index;
+  index_comparison.line = line;
 
   const std::vector<ConstraintLine>::const_iterator
     position = std::lower_bound (lines.begin(),
                                 lines.end(),
                                 index_comparison);
   Assert (position != lines.end(), ExcInternalError());
-  return position->inhomogeneity != 0;
+
+                                  // check whether we've really found the
+                                  // right constraint.
+  Assert (position->line == line,
+         ExcInternalError());
+
+  return position;
+}
+
+
+
+inline
+std::vector<ConstraintMatrix::ConstraintLine>::iterator 
+ConstraintMatrix::find_constraint (const unsigned int line)
+{
+  Assert (sorted==false, ExcMatrixIsClosed());
+  std::vector<ConstraintLine>::iterator line_ptr;
+  const std::vector<ConstraintLine>::const_iterator start=lines.begin();
+
+                                  // the usual case is that the line where
+                                  // a value is entered is the one we
+                                  // added last, so we search backward
+  for (line_ptr=(lines.end()-1); line_ptr!=start; --line_ptr)
+    if (line_ptr->line == line)
+      break;
+
+                                  // if the loop didn't break, then
+                                  // line_ptr must be begin().
+                                  // we have an error if that doesn't
+                                  // point to 'line' then
+  Assert (line_ptr->line==line, ExcLineInexistant(line));
+                                  // second check: the respective
+                                  // flag in the
+                                  // constraint_line_exists field
+                                  // must exist
+  Assert (line < constraint_line_exists.size(), ExcInternalError());
+  Assert (constraint_line_exists[line] == true, ExcInternalError());
+
+  return line_ptr;
 }
 
 DEAL_II_NAMESPACE_CLOSE
index 2a94f08a070076437cd3f01a9db1521ebd816b71..7e3857f4d5bc2670296c42eaf00353dfedcbda77 100644 (file)
@@ -749,58 +749,41 @@ distribute_local_to_global (const Vector<double>            &local_vector,
                                   // vector that tells about whether a
                                   // certain constraint exists. then, we
                                   // simply copy over the data.
-      if (is_constrained (local_dof_indices[i]) == false)
+      const std::vector<ConstraintLine>::const_iterator position = 
+       find_constraint(local_dof_indices[i]);
+
+      if (position==lines.end())
        {
          global_vector(local_dof_indices[i]) += local_vector(i);
          continue;
        }
 
-                                  // if the dof is constrained, we
-                                  // have to find it in the list of
-                                  // all constraints.
-      ConstraintLine index_comparison;
-      index_comparison.line = local_dof_indices[i];
-
-      const std::vector<ConstraintLine>::const_iterator
-       position = std::lower_bound (lines.begin(),
-                                    lines.end(),
-                                    index_comparison);
-
-                                  // check whether we've really found the
-                                  // right constraint.
-      Assert (position->line == local_dof_indices[i],
-             ExcInternalError());
-
       if (use_matrix)
        {
          const double val = position->inhomogeneity;
          if (val != 0)
            for (unsigned int j=0; j<n_local_dofs; ++j)
-             if (is_constrained (local_dof_indices[j]) == false)
-               {
+             {
+               const std::vector<ConstraintLine>::const_iterator 
+                 position_j = find_constraint(local_dof_indices[j]);
+
+               if (position_j == lines.end())
                  global_vector(local_dof_indices[j]) -= val * local_matrix(j,i);
-               }
-             else
-               {
-                 const double matrix_entry = local_matrix(j,i);
-                 if (matrix_entry == 0)
-                   continue;
-
-                 ConstraintLine index_comparison_j;
-                 index_comparison_j.line = local_dof_indices[j];
-
-                 const std::vector<ConstraintLine>::const_iterator
-                   position_j = std::lower_bound (lines.begin(),
-                                                  lines.end(),
-                                                  index_comparison_j);
-                 for (unsigned int q=0; q<position_j->entries.size(); ++q)
-                   {
-                     Assert (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;
-                   }
-               }
+               else
+                 {
+                   const double matrix_entry = local_matrix(j,i);
+                   if (matrix_entry == 0)
+                     continue;
+
+                   for (unsigned int q=0; q<position_j->entries.size(); ++q)
+                     {
+                       Assert (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;
+                     }
+                 }
+             }
        }
       else
                                   // in case the constraint is
@@ -1270,8 +1253,9 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
                                   // resolved in a second step.
     for (unsigned int i = 0; i<n_local_dofs; ++i)
       {
-       if (constraint_line_exists.size() <= local_dof_indices[i] ||
-           constraint_line_exists[local_dof_indices[i]] == false)
+       const std::vector<ConstraintLine>::const_iterator position =
+         find_constraint(local_dof_indices[i]);
+       if (position == lines.end())
          {
            my_indices[added_rows].global_row = local_dof_indices[i];
            my_indices[added_rows].local_row = i;
@@ -1279,16 +1263,6 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
            continue;
          }
 
-       ConstraintLine index_comparison;
-       index_comparison.line = local_dof_indices[i];
-
-       const std::vector<ConstraintLine>::const_iterator
-         position = std::lower_bound (lines.begin(),
-                                      lines.end(),
-                                      index_comparison);
-       Assert (position->line == local_dof_indices[i],
-               ExcInternalError());
-
        constraint_lines.push_back (std::make_pair<unsigned int,
                                    const ConstraintLine *>(i,&*position));
       }
@@ -1594,8 +1568,9 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
     unsigned int added_rows = 0;
     for (unsigned int i = 0; i<n_local_dofs; ++i)
       {
-       if (constraint_line_exists.size() <= local_dof_indices[i] ||
-           constraint_line_exists[local_dof_indices[i]] == false)
+       const std::vector<ConstraintLine>::const_iterator position
+         = find_constraint (local_dof_indices[i]);
+       if (position == lines.end())
          {
            my_indices[added_rows].global_row = local_dof_indices[i];
            my_indices[added_rows].local_row = i;
@@ -1603,16 +1578,6 @@ distribute_local_to_global (const FullMatrix<double>        &local_matrix,
            continue;
          }
 
-       ConstraintLine index_comparison;
-       index_comparison.line = local_dof_indices[i];
-
-       const std::vector<ConstraintLine>::const_iterator
-         position = std::lower_bound (lines.begin(),
-                                      lines.end(),
-                                      index_comparison);
-       Assert (position->line == local_dof_indices[i],
-               ExcInternalError());
-
        constraint_lines.push_back (std::make_pair<unsigned int,
                                    const ConstraintLine *>(i,&*position));
       }
@@ -1849,24 +1814,15 @@ add_entries_local_to_global (const std::vector<unsigned int> &local_dof_indices,
       std::vector<std::pair<unsigned int, const ConstraintLine *> > constraint_lines;
       for (unsigned int i = 0; i<n_local_dofs; ++i)
        {
-         if (constraint_line_exists.size() <= local_dof_indices[i] ||
-             constraint_line_exists[local_dof_indices[i]] == false)
+         const std::vector<ConstraintLine>::const_iterator position
+           = find_constraint(local_dof_indices[i]);
+         if (position == lines.end())
            {
              actual_dof_indices[added_rows] = local_dof_indices[i];
              ++added_rows;
              continue;
            }
 
-         ConstraintLine index_comparison;
-         index_comparison.line = local_dof_indices[i];
-
-         const std::vector<ConstraintLine>::const_iterator
-           position = std::lower_bound (lines.begin(),
-                                        lines.end(),
-                                        index_comparison);
-         Assert (position->line == local_dof_indices[i],
-                 ExcInternalError());
-
          constraint_lines.push_back (std::make_pair<unsigned int,
                                      const ConstraintLine *>(i,&*position));
       }
@@ -1949,8 +1905,9 @@ add_entries_local_to_global (const std::vector<unsigned int> &local_dof_indices,
                                   // resolved in a second step.
     for (unsigned int i = 0; i<n_local_dofs; ++i)
       {
-       if (constraint_line_exists.size() <= local_dof_indices[i] ||
-           constraint_line_exists[local_dof_indices[i]] == false)
+       const std::vector<ConstraintLine>::const_iterator position
+         = find_constraint(local_dof_indices[i]);
+       if (position == lines.end())
          {
            my_indices[added_rows].global_row = local_dof_indices[i];
            my_indices[added_rows].local_row = i;
@@ -1958,16 +1915,6 @@ add_entries_local_to_global (const std::vector<unsigned int> &local_dof_indices,
            continue;
          }
 
-       ConstraintLine index_comparison;
-       index_comparison.line = local_dof_indices[i];
-
-       const std::vector<ConstraintLine>::const_iterator
-         position = std::lower_bound (lines.begin(),
-                                      lines.end(),
-                                      index_comparison);
-       Assert (position->line == local_dof_indices[i],
-               ExcInternalError());
-
        constraint_lines.push_back (std::make_pair<unsigned int,
                                    const ConstraintLine *>(i,&*position));
       }
@@ -2184,24 +2131,15 @@ add_entries_local_to_global (const std::vector<unsigned int> &local_dof_indices,
       std::vector<std::pair<unsigned int, const ConstraintLine *> > constraint_lines;
       for (unsigned int i = 0; i<n_local_dofs; ++i)
        {
-         if (constraint_line_exists.size() <= local_dof_indices[i] ||
-             constraint_line_exists[local_dof_indices[i]] == false)
+         const std::vector<ConstraintLine>::const_iterator position
+           = find_constraint(local_dof_indices[i]);
+         if (position == lines.end())
            {
              actual_dof_indices[added_rows] = local_dof_indices[i];
              ++added_rows;
              continue;
            }
 
-         ConstraintLine index_comparison;
-         index_comparison.line = local_dof_indices[i];
-
-         const std::vector<ConstraintLine>::const_iterator
-           position = std::lower_bound (lines.begin(),
-                                        lines.end(),
-                                        index_comparison);
-         Assert (position->line == local_dof_indices[i],
-                 ExcInternalError());
-
          constraint_lines.push_back (std::make_pair<unsigned int,
                                      const ConstraintLine *>(i,&*position));
       }

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.