]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
new function for printing matrix
authorguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 11 Jun 2003 16:48:30 +0000 (16:48 +0000)
committerguido <guido@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 11 Jun 2003 16:48:30 +0000 (16:48 +0000)
conjugate_add with additional argument transpose

git-svn-id: https://svn.dealii.org/trunk@7795 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/sparse_matrix_ez.h
deal.II/lac/include/lac/sparse_matrix_ez.templates.h

index 1ce408f6aed5996795e74c694e2d9cf7fd0f5336..58a604d2009d52518973d0f7605c1c21ca34bcd2 100644 (file)
@@ -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 <class MATRIXA, class MATRIXB>
     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<number>::add_scaled (const number factor,
 
 template<typename number>
 template <class MATRIXA, class MATRIXB>
-void
+inline void
 SparseMatrixEZ<number>::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;
+      }
 }
 
 
index 40aaac0fe1683f92d11bc800af491c28cf6a7d21..cd1ea7b5fd6050f4c7b9d49df0c62aa5f6190e10 100644 (file)
@@ -399,6 +399,24 @@ SparseMatrixEZ<number>::compute_statistics(
 }
 
 
+template <typename number>
+void
+SparseMatrixEZ<number>::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'
+         <<i->value() << std::endl;
+      ++i;
+    }
+}
+
+
 template <typename number>
 void
 SparseMatrixEZ<number>::block_write (std::ostream &out) const 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.