*/
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
* 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.
+ 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
{
+ 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
//