]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Don't let SparsityPattern be a friend of CompressedSparsityPattern. There are
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 19 Jun 2004 22:21:01 +0000 (22:21 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Sat, 19 Jun 2004 22:21:01 +0000 (22:21 +0000)
better ways to access the data of the latter class.

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

deal.II/lac/include/lac/compressed_sparsity_pattern.h
deal.II/lac/source/sparsity_pattern.cc

index c19ebb5e3f8608547a4d679efcd2ce077a528c9a..4e675de5a57c15b5100da2dcca12074c02ce8723 100644 (file)
@@ -353,8 +353,6 @@ class CompressedSparsityPattern : public Subscriptor
                                      * entries.
                                      */
     std::vector<std::set<unsigned int> > column_indices;
-
-    friend class SparsityPattern;
 };
 
 /*@}*/
index 537617041e286b1bad6cb11d788f50716c47a756..5a2dfbbf2f2a9746e52aa5a789b52983dc765890 100644 (file)
@@ -517,10 +517,49 @@ void
 SparsityPattern::copy_from (const CompressedSparsityPattern &csp,
                            const bool optimize_diag) 
 {
-  copy_from (csp.n_rows(), csp.n_cols(),
-            csp.column_indices.begin(),
-            csp.column_indices.end(),
-            optimize_diag);
+//   copy_from (csp.n_rows(), csp.n_cols(),
+//          csp.column_indices.begin(),
+//          csp.column_indices.end(),
+//          optimize_diag);
+                                  // first determine row lengths for
+                                  // each row. if the matrix is
+                                  // quadratic, then we might have to
+                                  // add an additional entry for the
+                                  // diagonal, if that is not yet
+                                  // present. as we have to call
+                                  // compress anyway later on, don't
+                                  // bother to check whether that
+                                  // diagonal entry is in a certain
+                                  // row or not
+  const bool is_square = optimize_diag && (csp.n_rows() == csp.n_cols());
+  std::vector<unsigned int> row_lengths (csp.n_rows());
+  for (unsigned int i=0; i<csp.n_rows(); ++i)
+    row_lengths[i] = csp.row_length(i) +
+                     (is_square ? 1 : 0);
+  reinit (csp.n_rows(), csp.n_cols(), row_lengths, is_square);
+
+                                  // now enter all the elements into
+                                  // the matrix. note that if the
+                                  // matrix is quadratic, then we
+                                  // already have the diagonal
+                                  // element preallocated
+  for (unsigned int row = 0; row<csp.n_rows(); ++row)
+    {
+      unsigned int *cols = &colnums[rowstart[row]] + (is_square ? 1 : 0);
+      for (unsigned int j=0; j<csp.row_length(row); ++j)
+       {
+         const unsigned int col = csp.column_number(row,j);
+         Assert (col < csp.n_cols(), ExcInvalidIndex(col,csp.n_cols()));
+         
+         if ((col!=row) || !is_square)
+           *cols++ = col;
+       }
+    }
+
+                                  // finally compress
+                                  // everything. this also sorts the
+                                  // entries within each row
+  compress ();
 }
 
 

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.