From: kronbichler Date: Tue, 21 Apr 2009 08:53:55 +0000 (+0000) Subject: My previously committed version did not work for SparseMatrixEZ. This should now... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fee646e996d4af3b49217f284c5e98c732e758f;p=dealii-svn.git My previously committed version did not work for SparseMatrixEZ. This should now be fixed. git-svn-id: https://svn.dealii.org/trunk@18671 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/precondition.h b/deal.II/lac/include/lac/precondition.h index d0194995c4..21c48d756e 100644 --- a/deal.II/lac/include/lac/precondition.h +++ b/deal.II/lac/include/lac/precondition.h @@ -18,6 +18,7 @@ #include #include #include +#include DEAL_II_NAMESPACE_OPEN @@ -928,16 +929,24 @@ PreconditionSSOR::initialize (const MATRIX &rA, { this->PreconditionRelaxation::initialize (rA, parameters); + // in case we have a SparseMatrix class, + // we can extract information about the + // diagonal. + const SparseMatrix * mat = + dynamic_cast *>(&*this->A); + // calculate the positions first after // the diagonal. - const std::size_t * rowstart_ptr = - this->A->get_sparsity_pattern().get_rowstart_indices(); - const unsigned int * const colnums = - this->A->get_sparsity_pattern().get_column_numbers(); - const unsigned int n = this->A->n(); - pos_right_of_diagonal.resize(n); - for (unsigned int row=0; rowget_sparsity_pattern().get_rowstart_indices(); + const unsigned int * const colnums = + mat->get_sparsity_pattern().get_column_numbers(); + const unsigned int n = this->A->n(); + pos_right_of_diagonal.resize(n); + for (unsigned int row=0; row::initialize (const MATRIX &rA, // note: the first entry in each // line denotes the diagonal element, // which we need not check. - pos_right_of_diagonal[row] = - std::lower_bound (&colnums[*rowstart_ptr+1], - &colnums[*(rowstart_ptr+1)], - row) - - colnums; + pos_right_of_diagonal[row] = + std::lower_bound (&colnums[*rowstart_ptr+1], + &colnums[*(rowstart_ptr+1)], + row) + - colnums; + } } } @@ -971,7 +981,7 @@ inline void PreconditionSSOR::Tvmult (VECTOR &dst, const VECTOR &src) const { Assert (this->A!=0, ExcNotInitialized()); - this->A->precondition_SSOR (dst, src, this->relaxation); + this->A->precondition_SSOR (dst, src, this->relaxation, pos_right_of_diagonal); } diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index a9e7711739..dc3b73c97c 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -1192,7 +1192,7 @@ SparseMatrix::precondition_SSOR (Vector &dst, pos_right_of_diagonal[row]; Assert (first_right_of_diagonal_index <= *(rowstart_ptr+1), ExcInternalError()); - double s = *dst_ptr; + number s = *dst_ptr; for (unsigned int j=(*rowstart_ptr)+1; jcolnums[j]); @@ -1213,7 +1213,7 @@ SparseMatrix::precondition_SSOR (Vector &dst, const unsigned int end_row = *(rowstart_ptr+1); const unsigned int first_right_of_diagonal_index = pos_right_of_diagonal[row]; - double s = *dst_ptr; + number s = *dst_ptr; for (unsigned int j=first_right_of_diagonal_index; jcolnums[j]); @@ -1243,7 +1243,7 @@ SparseMatrix::precondition_SSOR (Vector &dst, - &cols->colnums[0]); - double s = *dst_ptr; + number s = *dst_ptr; for (unsigned int j=(*rowstart_ptr)+1; jcolnums[j]); @@ -1267,10 +1267,9 @@ SparseMatrix::precondition_SSOR (Vector &dst, &cols->colnums[end_row], static_cast(row)) - &cols->colnums[0]); - double s = *dst_ptr; + number s = *dst_ptr; for (unsigned int j=first_right_of_diagonal_index; jcolnums[j]); - *dst_ptr = s * om / val[*rowstart_ptr]; }; } diff --git a/deal.II/lac/include/lac/sparse_matrix_ez.h b/deal.II/lac/include/lac/sparse_matrix_ez.h index d49976abe3..f89d46f87e 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.h @@ -713,7 +713,8 @@ class SparseMatrixEZ : public Subscriptor template void precondition_SSOR (Vector &dst, const Vector &src, - const number om = 1.) const; + const number om = 1., + const std::vector &pos_right_of_diagonal = std::vector()) const; /** * Apply SOR preconditioning matrix to @p src. diff --git a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h index 0a069ec10a..9ff6264c6a 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h @@ -326,7 +326,8 @@ template void SparseMatrixEZ::precondition_SSOR (Vector &dst, const Vector &src, - const number om) const + const number om, + const std::vector &) const { Assert (m() == n(), ExcNotQuadratic()); Assert (dst.size() == n(), ExcDimensionMismatch (dst.size(), n())); @@ -344,9 +345,9 @@ SparseMatrixEZ::precondition_SSOR (Vector &dst, number s = *src_ptr; const unsigned int end_row = ri->start + ri->diagonal; for (unsigned int i=ri->start;istart + ri->diagonal].value; + *dst_ptr = s * om / data[ri->start + ri->diagonal].value; } // Diagonal dst_ptr = dst.begin(); @@ -361,9 +362,11 @@ SparseMatrixEZ::precondition_SSOR (Vector &dst, for (rri = row_info.rbegin(); rri != rend; --dst_ptr, ++rri) { const unsigned int end_row = rri->start + rri->length; + number s = *dst_ptr; for (unsigned int i=rri->start+rri->diagonal+1;istart + rri->diagonal].value; + s -= om * data[i].value * dst(data[i].column); + + *dst_ptr = s * om / data[rri->start + rri->diagonal].value; } } diff --git a/deal.II/lac/source/sparse_matrix_ez.inst.in b/deal.II/lac/source/sparse_matrix_ez.inst.in index 29cd69e257..db7689a5bd 100644 --- a/deal.II/lac/source/sparse_matrix_ez.inst.in +++ b/deal.II/lac/source/sparse_matrix_ez.inst.in @@ -36,7 +36,8 @@ for (S1, S2 : REAL_SCALARS) template void SparseMatrixEZ::precondition_SSOR (Vector &, const Vector &, - const S1) const; + const S1, + const std::vector&) const; template void SparseMatrixEZ::precondition_SOR (Vector &, const Vector &,