From 84f2440754ed7fdda51368315dd1647b56dde8aa Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 26 Mar 2004 17:12:49 +0000 Subject: [PATCH] Unconvolute an unnecessarily convoluted loop. git-svn-id: https://svn.dealii.org/trunk@8877 0785d39b-7218-0410-832d-ea1e28bc413d --- .../include/dofs/dof_constraints.templates.h | 87 +++++++++---------- 1 file changed, 43 insertions(+), 44 deletions(-) diff --git a/deal.II/deal.II/include/dofs/dof_constraints.templates.h b/deal.II/deal.II/include/dofs/dof_constraints.templates.h index d32a004c7b..e05841c5ed 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.templates.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.templates.h @@ -168,21 +168,22 @@ ConstraintMatrix::condense (SparseMatrix &uncondensed) const average_diagonal += std::fabs (uncondensed.diag_element(i)); average_diagonal /= uncondensed.m(); - // store for each index whether it - // must be distributed or not. If entry - // is -1, no distribution is necessary. - // otherwise, the number states which - // line in the constraint matrix handles - // this index - std::vector distribute (sparsity.n_rows(), -1); + // store for each index whether it must be + // distributed or not. If entry is + // invalid_unsigned_int, no distribution is + // necessary. otherwise, the number states + // which line in the constraint matrix + // handles this index + std::vector distribute (sparsity.n_rows(), + deal_II_numbers::invalid_unsigned_int); for (unsigned int c=0; c(c); + distribute[lines[c].line] = c; const unsigned int n_rows = sparsity.n_rows(); for (unsigned int row=0; row &uncondensed) const SparsityPattern::invalid_entry, ExcMatrixNotClosed()); - if (distribute[sparsity.get_column_numbers()[j]] != -1) + if (distribute[sparsity.get_column_numbers()[j]] != + deal_II_numbers::invalid_unsigned_int) // distribute entry at // regular row @p{row} // and irregular column @@ -231,7 +233,8 @@ ConstraintMatrix::condense (SparseMatrix &uncondensed) const SparsityPattern::invalid_entry, ExcMatrixNotClosed()); - if (distribute[sparsity.get_column_numbers()[j]] == -1) + if (distribute[sparsity.get_column_numbers()[j]] == + deal_II_numbers::invalid_unsigned_int) // distribute entry at // irregular row // @p{row} and regular @@ -272,9 +275,9 @@ ConstraintMatrix::condense (SparseMatrix &uncondensed) const uncondensed.global_entry(j) = (row == sparsity.get_column_numbers()[j] ? average_diagonal : 0. ); - }; - }; - }; + } + } + } } @@ -308,16 +311,18 @@ ConstraintMatrix::condense (BlockSparseMatrix &uncondensed) const const BlockIndices & index_mapping = sparsity.get_column_indices(); - // store for each index whether it - // must be distributed or not. If entry - // is -1, no distribution is necessary. - // otherwise, the number states which - // line in the constraint matrix handles - // this index - std::vector distribute (sparsity.n_rows(), -1); + // store for each index whether it must be + // distributed or not. If entry is + // deal_II_numbers::invalid_unsigned_int, + // no distribution is necessary. + // otherwise, the number states which line + // in the constraint matrix handles this + // index + std::vector distribute (sparsity.n_rows(), + deal_II_numbers::invalid_unsigned_int); for (unsigned int c=0; c(c); + distribute[lines[c].line] = c; const unsigned int n_rows = sparsity.n_rows(); for (unsigned int row=0; row &uncondensed) const block_index = index_mapping.global_to_local(row); const unsigned int block_row = block_index.first; - if (distribute[row] == -1) + if (distribute[row] == deal_II_numbers::invalid_unsigned_int) // regular line. loop over // all columns and see // whether this column must @@ -369,7 +374,7 @@ ConstraintMatrix::condense (BlockSparseMatrix &uncondensed) const = index_mapping.local_to_global(block_col, block_sparsity.get_column_numbers()[j]); - if (distribute[global_col] != -1) + if (distribute[global_col] != deal_II_numbers::invalid_unsigned_int) // distribute // entry at // regular row @@ -434,7 +439,8 @@ ConstraintMatrix::condense (BlockSparseMatrix &uncondensed) const = index_mapping.local_to_global (block_col, block_sparsity.get_column_numbers()[j]); - if (distribute[global_col] == -1) + if (distribute[global_col] == + deal_II_numbers::invalid_unsigned_int) // distribute // entry at // irregular @@ -575,27 +581,20 @@ ConstraintMatrix::condense (VectorType &vec) const { Assert (sorted == true, ExcMatrixNotClosed()); + // check if there is anything to do at all if (lines.size() == 0) - // nothing to do return; - - std::vector::const_iterator next_constraint = lines.begin(); - for (unsigned int row=0; rowline) - // line must be distributed - { - for (unsigned int q=0; q!=next_constraint->entries.size(); ++q) - vec(next_constraint->entries[q].first) - += - vec(row) * next_constraint->entries[q].second; - // set entry to zero - vec(row) = 0.; - - ++next_constraint; - if (next_constraint == lines.end()) - // nothing more to do - break; - }; + + // distribute all entries, and set them to zero + std::vector::const_iterator constraint_line = lines.begin(); + for (; constraint_line!=lines.end(); ++constraint_line) + { + for (unsigned int q=0; q!=constraint_line->entries.size(); ++q) + vec(constraint_line->entries[q].first) + += (vec(constraint_line->line) * + constraint_line->entries[q].second); + vec(constraint_line->line) = 0.; + } } -- 2.39.5