From: kronbichler Date: Thu, 17 Sep 2009 16:38:20 +0000 (+0000) Subject: Wrote an internal find_constraint function so that the implementation gets a bit... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=142b1d01217a781931fcef9b0cc79653e732ac75;p=dealii-svn.git Wrote an internal find_constraint function so that the implementation gets a bit more handy in some places. git-svn-id: https://svn.dealii.org/trunk@19469 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/constraint_matrix.h b/deal.II/lac/include/lac/constraint_matrix.h index b1e6df9e78..fb3fc0ca68 100644 --- a/deal.II/lac/include/lac/constraint_matrix.h +++ b/deal.II/lac/include/lac/constraint_matrix.h @@ -1539,6 +1539,26 @@ class ConstraintMatrix : public Subscriptor const Table<2,bool> &dof_mask, internal::bool2type) const; + /** + * This function returns a pointer to + * the respective ConstraintLine object + * if a dof is constrained, and a zero + * pointer otherwise. + */ + std::vector::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::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::iterator line_ptr; - const std::vector::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::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::iterator line_ptr; - const std::vector::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::const_iterator position + = find_constraint(index); + return position!=lines.end() ? position->inhomogeneity != 0 : false; +} + + + +inline +std::vector::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::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::iterator +ConstraintMatrix::find_constraint (const unsigned int line) +{ + Assert (sorted==false, ExcMatrixIsClosed()); + std::vector::iterator line_ptr; + const std::vector::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 diff --git a/deal.II/lac/include/lac/constraint_matrix.templates.h b/deal.II/lac/include/lac/constraint_matrix.templates.h index 2a94f08a07..7e3857f4d5 100644 --- a/deal.II/lac/include/lac/constraint_matrix.templates.h +++ b/deal.II/lac/include/lac/constraint_matrix.templates.h @@ -749,58 +749,41 @@ distribute_local_to_global (const Vector &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::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::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::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::const_iterator - position_j = std::lower_bound (lines.begin(), - lines.end(), - index_comparison_j); - for (unsigned int q=0; qentries.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; qentries.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 &local_matrix, // resolved in a second step. for (unsigned int i = 0; i::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 &local_matrix, continue; } - ConstraintLine index_comparison; - index_comparison.line = local_dof_indices[i]; - - const std::vector::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(i,&*position)); } @@ -1594,8 +1568,9 @@ distribute_local_to_global (const FullMatrix &local_matrix, unsigned int added_rows = 0; for (unsigned int i = 0; i::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 &local_matrix, continue; } - ConstraintLine index_comparison; - index_comparison.line = local_dof_indices[i]; - - const std::vector::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(i,&*position)); } @@ -1849,24 +1814,15 @@ add_entries_local_to_global (const std::vector &local_dof_indices, std::vector > constraint_lines; for (unsigned int i = 0; i::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::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(i,&*position)); } @@ -1949,8 +1905,9 @@ add_entries_local_to_global (const std::vector &local_dof_indices, // resolved in a second step. for (unsigned int i = 0; i::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 &local_dof_indices, continue; } - ConstraintLine index_comparison; - index_comparison.line = local_dof_indices[i]; - - const std::vector::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(i,&*position)); } @@ -2184,24 +2131,15 @@ add_entries_local_to_global (const std::vector &local_dof_indices, std::vector > constraint_lines; for (unsigned int i = 0; i::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::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(i,&*position)); }