]> https://gitweb.dealii.org/ - dealii.git/commitdiff
improved readability inside SparseMatrix::mmult(..) with DynamicSparsityPattern:...
authorChristoph Goering <christoph.goering@tum.de>
Fri, 22 Dec 2017 22:01:27 +0000 (23:01 +0100)
committerChristoph Goering <christoph.goering@tum.de>
Sun, 24 Dec 2017 09:49:26 +0000 (10:49 +0100)
include/deal.II/lac/sparse_matrix.templates.h

index f3969d8d7dc769d00bea98ecf2065817ce098eb1..53cfc4452044bc1b8f471a9f4c55aa2bf746825b 100644 (file)
@@ -1008,37 +1008,10 @@ SparseMatrix<number>::mmult (SparseMatrix<numberC>       &C,
       C.clear();
       sp_C.reinit (0,0,0);
 
-      // create a sparsity pattern for the matrix. we will go through all the
-      // rows in the matrix A, and for each column in a row we add the whole
-      // row of matrix B with that row number. This means that we will insert
-      // a lot of entries to each row, which is best handled by the
-      // DynamicSparsityPattern class.
+      // create a sparsity pattern for the matrix C.
       {
-        DynamicSparsityPattern dsp (m(), B.n());
-        for (size_type i = 0; i < dsp.n_rows(); ++i)
-          {
-            const size_type *rows = &sp_A.colnums[sp_A.rowstart[i]];
-            const size_type *const end_rows =
-              &sp_A.colnums[sp_A.rowstart[i+1]];
-            for (; rows != end_rows; ++rows)
-              {
-                const size_type col = *rows;
-                size_type *new_cols = const_cast<size_type *>
-                                      (&sp_B.colnums[sp_B.rowstart[col]]);
-                size_type *end_new_cols = const_cast<size_type *>
-                                          (&sp_B.colnums[sp_B.rowstart[col+1]]);
-
-                // if B has a diagonal, need to add that manually. this way,
-                // we maintain sortedness.
-                if (sp_B.n_rows() == sp_B.n_cols())
-                  {
-                    ++new_cols;
-                    dsp.add(i, col);
-                  }
-
-                dsp.add_entries (i, new_cols, end_new_cols, true);
-              }
-          }
+        DynamicSparsityPattern dsp ;
+        dsp.compute_mmult_pattern(sp_A,sp_B);
         sp_C.copy_from (dsp);
       }
 

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.