From: Guido Kanschat Date: Wed, 11 Jun 2003 16:48:30 +0000 (+0000) Subject: new function for printing matrix X-Git-Tag: v8.0.0~16414 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b75be1a4ff0600f6893a50878cedd95dcd81dc31;p=dealii.git new function for printing matrix conjugate_add with additional argument transpose git-svn-id: https://svn.dealii.org/trunk@7795 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/sparse_matrix_ez.h b/deal.II/lac/include/lac/sparse_matrix_ez.h index 1ce408f6ae..58a604d200 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.h @@ -778,11 +778,21 @@ class SparseMatrixEZ : public Subscriptor /** * Add the matrix @p{A} * conjugated by @p{B}, that is, - * $B A B^T$ to this object. + * $B A B^T$ to this object. If + * the parameter @p{transpose} is + * true, compute $B^T A B$. + * + * This function requires that + * @p{B} has a @p{const_iterator} + * traversing all matrix entries + * and that @p{A} has a function + * @p{el(i,j)} for access to a + * specific entry. */ template void conjugate_add (const MATRIXA& A, - const MATRIXB& B); + const MATRIXB& B, + const bool transpose = false); /** * STL-like iterator with the @@ -832,7 +842,7 @@ class SparseMatrixEZ : public Subscriptor * nonzero entry of the matrix * per line. */ -// void print (std::ostream &out) const; + void print (std::ostream &out) const; /** * Print the matrix in the usual @@ -1574,33 +1584,61 @@ SparseMatrixEZ::add_scaled (const number factor, template template -void +inline void SparseMatrixEZ::conjugate_add (const MATRIXA& A, - const MATRIXB& B) + const MATRIXB& B, + bool transpose) { // Compute the result // r_ij = \sum_kl b_ik b_jl a_kl + +// Assert (n() == B.m(), ExcDimensionMismatch(n(), B.m())); +// Assert (m() == B.m(), ExcDimensionMismatch(m(), B.m())); +// Assert (A.n() == B.n(), ExcDimensionMismatch(A.n(), B.n())); +// Assert (A.m() == B.n(), ExcDimensionMismatch(A.m(), B.n())); typename MATRIXB::const_iterator b1 = B.begin(); - typename MATRIXB::const_iterator b2 = B.begin(); const typename MATRIXB::const_iterator b_final = B.end(); - while (b1 != b_final) - { - const unsigned int i = b1->row(); - const unsigned int k = b1->column(); - while (b2 != b_final) - { - const unsigned int j = b2->row(); - const unsigned int l = b2->column(); - - const typename MATRIXA::value_type a = A.el(k,l); - - if (a != 0.) - add (i, j, a * b1->value() * b2->value()); - ++b2; - } - ++b1; - } + if (transpose) + while (b1 != b_final) + { + const unsigned int i = b1->column(); + const unsigned int k = b1->row(); + typename MATRIXB::const_iterator b2 = B.begin(); + while (b2 != b_final) + { + const unsigned int j = b2->column(); + const unsigned int l = b2->row(); + + const typename MATRIXA::value_type a = A.el(k,l); + + if (a != 0.) + add (i, j, a * b1->value() * b2->value()); + ++b2; + } + ++b1; + } + else + while (b1 != b_final) + { + const unsigned int i = b1->row(); + const unsigned int k = b1->column(); + typename MATRIXB::const_iterator b2 = B.begin(); + while (b2 != b_final) + { + const unsigned int j = b2->row(); + const unsigned int l = b2->column(); + + const typename MATRIXA::value_type a = A.el(k,l); + + if (a != 0.) + { + add (i, j, a * b1->value() * b2->value()); + } + ++b2; + } + ++b1; + } } 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 40aaac0fe1..cd1ea7b5fd 100644 --- a/deal.II/lac/include/lac/sparse_matrix_ez.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix_ez.templates.h @@ -399,6 +399,24 @@ SparseMatrixEZ::compute_statistics( } +template +void +SparseMatrixEZ::print (std::ostream &out) const +{ + AssertThrow (out, ExcIO()); + + const_iterator i = begin(); + const const_iterator e = end(); + while (i != e) + { + out << i->row() << '\t' + << i->column() << '\t' + <value() << std::endl; + ++i; + } +} + + template void SparseMatrixEZ::block_write (std::ostream &out) const