From: kronbichler Date: Thu, 1 Oct 2009 17:07:55 +0000 (+0000) Subject: Can simplify collective set and add functions a little bit. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3360e656f878d6f1d6eec2ff419a449793d861bf;p=dealii-svn.git Can simplify collective set and add functions a little bit. git-svn-id: https://svn.dealii.org/trunk@19641 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index 90afcc5e5a..f59371ec4e 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -499,8 +499,13 @@ SparseMatrix::add (const unsigned int row, ExcMessage("The given value is not finite but either " "infinite or Not A Number (NaN)")); - if (value == 0 && elide_zero_values == true) +#ifdef DEBUG + if (elide_zero_values==true && value == 0) + continue; +#else + if (value == 0) continue; +#endif // check whether the next index to add is // the next present index in the sparsity @@ -517,9 +522,7 @@ SparseMatrix::add (const unsigned int row, // value we add is zero if (index == SparsityPattern::invalid_entry) { - Assert ((index != SparsityPattern::invalid_entry) || - (value == 0.), - ExcInvalidIndex(row,col_indices[j])); + Assert (value == 0., ExcInvalidIndex(row,col_indices[j])); continue; } @@ -550,39 +553,69 @@ SparseMatrix::set (const unsigned int row, std::size_t index = cols->get_rowstart_indices()[row], next_index = index; const std::size_t next_row_index = cols->get_rowstart_indices()[row+1]; - for (unsigned int j=0; joperator()(row, col_indices[j]); + next_index = cols->operator()(row, col_indices[j]); // it is allowed to set elements in // the matrix that are not part of // the sparsity pattern, if the // value to which we set it is zero - if (next_index == SparsityPattern::invalid_entry) - { - Assert (value == 0., ExcInvalidIndex(row,col_indices[j])); - continue; + if (next_index == SparsityPattern::invalid_entry) + { + Assert (false, ExcInvalidIndex(row,col_indices[j])); + continue; + } + index = next_index; + + set_value: + val[index] = value; + ++index; } - index = next_index; + } + else + { + // same code as above, but now check for zeros + for (unsigned int j=0; joperator()(row, col_indices[j]); + + if (next_index == SparsityPattern::invalid_entry) + { + Assert (value == 0., ExcInvalidIndex(row,col_indices[j])); + continue; + } + index = next_index; + + set_value_checked: + val[index] = value; + ++index; + } } }