From: kronbichler Date: Wed, 7 Jan 2009 15:03:00 +0000 (+0000) Subject: Some more functions in TrilinosWrappers::SparsityPattern. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a753650709daf364e2a48b1e710650436cd1a1e0;p=dealii-svn.git Some more functions in TrilinosWrappers::SparsityPattern. git-svn-id: https://svn.dealii.org/trunk@18118 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/trilinos_sparsity_pattern.h b/deal.II/lac/include/lac/trilinos_sparsity_pattern.h index 3ef763066d..7bab1edc20 100755 --- a/deal.II/lac/include/lac/trilinos_sparsity_pattern.h +++ b/deal.II/lac/include/lac/trilinos_sparsity_pattern.h @@ -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 * (line,col). */ void print (std::ostream &out) const; + + /** + * Print the sparsity of the matrix + * in a format that gnuplot + * understands and which can be used + * to plot the sparsity pattern in a + * graphical way. The format consists + * of pairs i j 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 + * (0,0) 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 + * plot command. + */ + void print_gnuplot (std::ostream &out) const; // TODO: Write an overloading // of the operator << for output. diff --git a/deal.II/lac/source/trilinos_sparsity_pattern.cc b/deal.II/lac/source/trilinos_sparsity_pattern.cc index 3a1379ea0b..5b5fdaacfa 100755 --- a/deal.II/lac/source/trilinos_sparsity_pattern.cc +++ b/deal.II/lac/source/trilinos_sparsity_pattern.cc @@ -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; iExtractMyRowView(i, num_entries, indices); + for (unsigned int j=0; j<(unsigned int)num_entries; ++j) + { + if (static_cast(std::abs(static_cast(i-indices[j]))) > local_b) + local_b = std::abs(static_cast(i-indices[j])); + } + } + graph->Comm().MaxAll((int *)&local_b, &global_b, 1); + return static_cast(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; rowExtractMyRowView (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(row) + << std::endl; + } + + AssertThrow (out, ExcIO()); + } + + + // explicit instantiations //