]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Some more functions in TrilinosWrappers::SparsityPattern.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 7 Jan 2009 15:03:00 +0000 (15:03 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 7 Jan 2009 15:03:00 +0000 (15:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@18118 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/trilinos_sparsity_pattern.h
deal.II/lac/source/trilinos_sparsity_pattern.cc

index 3ef763066dfdd8ecdbe32c767f8b4882d28c5201..7bab1edc20185c3f7a278eb02a77ddca4935a60d 100755 (executable)
@@ -750,6 +750,19 @@ namespace TrilinosWrappers
                                         */
       unsigned int row_length (const unsigned int row) const;
 
+                                       /**
+                                       * Compute the bandwidth of the
+                                       * matrix represented by this
+                                       * structure. The bandwidth is the
+                                       * maximum of $|i-j|$ for which the
+                                       * index pair $(i,j)$ represents a
+                                       * nonzero entry of the
+                                       * matrix. Consequently, the maximum
+                                       * bandwidth a $n\times m$ matrix can
+                                       * have is $\max\{n-1,m-1\}$.
+                                        */
+      unsigned int bandwidth () const;
+
                                        /**
                                         * Return whether the object is
                                         * empty. It is empty if no memory is
@@ -860,13 +873,40 @@ namespace TrilinosWrappers
                                        * implemented.
                                        */
       void write_ascii ();
-      
+
                                       /**
                                        * Print the sparsity pattern to the
                                        * given stream, using the format
                                        * <tt>(line,col)</tt>.
                                        */
       void print (std::ostream &out) const;
+
+                                      /**
+                                       * Print the sparsity of the matrix
+                                       * in a format that <tt>gnuplot</tt>
+                                       * understands and which can be used
+                                       * to plot the sparsity pattern in a
+                                       * graphical way. The format consists
+                                       * of pairs <tt>i j</tt> of nonzero
+                                       * elements, each representing one
+                                       * entry of this matrix, one per line
+                                       * of the output file. Indices are
+                                       * counted from zero on, as
+                                       * usual. Since sparsity patterns are
+                                       * printed in the same way as
+                                       * matrices are displayed, we print
+                                       * the negative of the column index,
+                                       * which means that the
+                                       * <tt>(0,0)</tt> element is in the
+                                       * top left rather than in the bottom
+                                       * left corner.
+                                       *
+                                       * Print the sparsity pattern in
+                                       * gnuplot by setting the data style
+                                       * to dots or points and use the
+                                       * <tt>plot</tt> command.
+                                       */
+      void print_gnuplot (std::ostream &out) const;
     
                                         // TODO: Write an overloading
                                         // of the operator << for output.
index 3a1379ea0baf417cbdcd381caf55ca8f3b3368cd..5b5fdaacfaecd9c82f6d775d8802efa42bf94c77 100755 (executable)
@@ -616,6 +616,28 @@ namespace TrilinosWrappers
 
 
 
+  unsigned int
+  SparsityPattern::bandwidth () const
+  {
+    unsigned int local_b=0;
+    int global_b=0;
+    for (unsigned int i=0; i<local_size(); ++i)
+      {
+       int * indices;
+       int num_entries;
+       graph->ExtractMyRowView(i, num_entries, indices);
+       for (unsigned int j=0; j<(unsigned int)num_entries; ++j)
+         {
+           if (static_cast<unsigned int>(std::abs(static_cast<int>(i-indices[j]))) > local_b)
+             local_b = std::abs(static_cast<signed int>(i-indices[j]));
+         }
+      }
+    graph->Comm().MaxAll((int *)&local_b, &global_b, 1);
+    return static_cast<unsigned int>(global_b);
+  }
+
+
+
   unsigned int
   SparsityPattern::n_rows () const
   {
@@ -732,6 +754,31 @@ namespace TrilinosWrappers
 
 
 
+  void
+  SparsityPattern::print_gnuplot (std::ostream &out) const
+  { 
+    Assert (graph->Filled() == true, ExcInternalError());
+    for (unsigned int row=0; row<local_size(); ++row)
+      {
+       signed int * indices;
+       int num_entries;
+       graph->ExtractMyRowView (row, num_entries, indices);
+
+       for (unsigned int j=0; j<(unsigned int)num_entries; ++j)
+                                         // while matrix entries are usually
+                                         // written (i,j), with i vertical and
+                                         // j horizontal, gnuplot output is
+                                         // x-y, that is we have to exchange
+                                         // the order of output
+         out << indices[graph->GRID(j)] << " " << -static_cast<signed int>(row) 
+             << std::endl;
+      }      
+
+    AssertThrow (out, ExcIO());
+  }
+
+
+
 
   // explicit instantiations
   //

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.