From: kronbichler Date: Fri, 11 Jan 2013 13:36:14 +0000 (+0000) Subject: Replace SparseMatrix::global_entry by iterators. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f7c0824b39446d33ec545cab8959fa56de8d9234;p=dealii-svn.git Replace SparseMatrix::global_entry by iterators. git-svn-id: https://svn.dealii.org/trunk@28020 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/sparsity_pattern.h b/deal.II/include/deal.II/lac/sparsity_pattern.h index a31894c2c8..f0f1a1490e 100644 --- a/deal.II/include/deal.II/lac/sparsity_pattern.h +++ b/deal.II/include/deal.II/lac/sparsity_pattern.h @@ -136,7 +136,7 @@ namespace SparsityPatternIterators * pattern's lifetime, you will iterate over elements that are not * valid. If this is so, then this function will return false. */ - inline bool is_valid_entry () const; + bool is_valid_entry () const; /** @@ -619,12 +619,12 @@ public: * iterator can be used to walk over all nonzero entries of the sparsity * pattern. */ - inline iterator begin () const; + iterator begin () const; /** * Final iterator. */ - inline iterator end () const; + iterator end () const; /** * STL-like iterator with the first entry of row r. @@ -634,7 +634,7 @@ public: * end(r). Note also that the iterator may not be dereferencable in * that case. */ - inline iterator begin (const unsigned int r) const; + iterator begin (const unsigned int r) const; /** * Final iterator of row r. It points to the first element past the @@ -644,7 +644,7 @@ public: * particular the case if it is the end iterator for the last row of a * matrix. */ - inline iterator end (const unsigned int r) const; + iterator end (const unsigned int r) const; /** * STL-like iterator with the first entry of row r. @@ -654,7 +654,7 @@ public: * end(r). Note also that the iterator may not be dereferencable in * that case. */ - inline row_iterator row_begin (const unsigned int r) const; + row_iterator row_begin (const unsigned int r) const; /** * Final iterator of row r. It points to the first element past the @@ -664,7 +664,7 @@ public: * particular the case if it is the end iterator for the last row of a * matrix. */ - inline row_iterator row_end (const unsigned int r) const; + row_iterator row_end (const unsigned int r) const; // @} /** @@ -716,13 +716,13 @@ public: * Return number of rows of this matrix, which equals the dimension of the * image space. */ - inline unsigned int n_rows () const; + unsigned int n_rows () const; /** * Return number of columns of this matrix, which equals the dimension of * the range space. */ - inline unsigned int n_cols () const; + unsigned int n_cols () const; /** * Number of entries in a specific row. @@ -976,7 +976,7 @@ public: * yourself, you should also rename this function to avoid programs relying * on outdated information! */ - inline const std::size_t *get_rowstart_indices () const; + const std::size_t *get_rowstart_indices () const; /** * @deprecated. Use @p row_length and @p column_number instead. Also, using @@ -995,7 +995,7 @@ public: * yourself, you should also rename this function to avoid programs relying * on outdated information! */ - inline const unsigned int *get_column_numbers () const; + const unsigned int *get_column_numbers () const; BOOST_SERIALIZATION_SPLIT_MEMBER() /** @addtogroup Exceptions diff --git a/deal.II/source/lac/trilinos_sparse_matrix.cc b/deal.II/source/lac/trilinos_sparse_matrix.cc index e916447720..91d1957e22 100644 --- a/deal.II/source/lac/trilinos_sparse_matrix.cc +++ b/deal.II/source/lac/trilinos_sparse_matrix.cc @@ -598,14 +598,11 @@ namespace TrilinosWrappers } set_matrix_values: - // fill the values. the same as above: go - // through all rows of the matrix, and then - // all columns. since the sparsity patterns of - // the input matrix and the specified sparsity - // pattern might be different, need to go - // through the row for both these sparsity - // structures simultaneously in order to - // really set the correct values. + // fill the values. the same as above: go through all rows of the matrix, + // and then all columns. since the sparsity patterns of the input matrix + // and the specified sparsity pattern might be different, need to go + // through the row for both these sparsity structures simultaneously in + // order to really set the correct values. const std::size_t *const in_rowstart_indices = dealii_sparse_matrix.get_sparsity_pattern().get_rowstart_indices(); const unsigned int *const in_cols @@ -617,38 +614,48 @@ set_matrix_values: unsigned int maximum_row_length = matrix->MaxNumEntries(); std::vector row_indices (maximum_row_length); std::vector values (maximum_row_length); - std::size_t in_index, index; for (unsigned int row=0; row(row)) == true) { - index = rowstart_indices[row]; - in_index = in_rowstart_indices[row]; + ::dealii::SparsityPattern::iterator select_index = + sparsity_pattern.begin(row); + typename ::dealii::SparseMatrix::const_iterator it = + dealii_sparse_matrix.begin(row); unsigned int col = 0; if (sparsity_pattern.optimize_diagonal()) { - values[col] = dealii_sparse_matrix.global_entry(in_index); - row_indices[col++] = row; - ++index; - ++in_index; + Assert(dealii_sparse_matrix.get_sparsity_pattern().optimize_diagonal(), + ExcMessage("If the manual sparsity pattern optimizes the " + "diagonal, the deal.II matrix must optimize it," + " too. And vice versa.")); + AssertDimension(it->column(), row); + values[col] = it->value(); + row_indices[col++] = it->column(); + ++select_index; + ++it; } - while (in_index < in_rowstart_indices[row+1] && - index < rowstart_indices[row+1]) + while (it != dealii_sparse_matrix.end(row) && + select_index != sparsity_pattern.end(row)) { - while (cols[index] < in_cols[in_index] && index < rowstart_indices[row+1]) - ++index; - while (in_cols[in_index] < cols[index] && in_index < in_rowstart_indices[row+1]) - ++in_index; - - if (std::fabs(dealii_sparse_matrix.global_entry(in_index)) > drop_tolerance) + while (select_index->column() < it->column() && + select_index != sparsity_pattern.end(row)) + ++select_index; + while (it->column() < select_index->column() && + it != dealii_sparse_matrix.end(row)) + ++it; + + if (it == dealii_sparse_matrix.end(row)) + break; + if (std::fabs(it->value()) > drop_tolerance) { - values[col] = dealii_sparse_matrix.global_entry(in_index); - row_indices[col++] = in_cols[in_index]; + values[col] = it->value(); + row_indices[col++] = it->column(); } - ++index; - ++in_index; + ++select_index; + ++it; } set (row, col, reinterpret_cast(&row_indices[0]), &values[0], false);