From 851888ef58fd55309851bdf2df5dd062d8f7ab6a Mon Sep 17 00:00:00 2001 From: bangerth Date: Thu, 31 Jul 2008 12:33:50 +0000 Subject: [PATCH] Implement the stores_only_added_elements function for all sparsity patterns. git-svn-id: https://svn.dealii.org/trunk@16462 0785d39b-7218-0410-832d-ea1e28bc413d --- .../lac/include/lac/chunk_sparsity_pattern.h | 24 ++++++++++++++ .../lac/compressed_set_sparsity_pattern.h | 30 ++++++++++++++++- .../include/lac/compressed_sparsity_pattern.h | 30 ++++++++++++++++- deal.II/lac/include/lac/sparsity_pattern.h | 33 +++++++++++++++++++ deal.II/lac/source/chunk_sparsity_pattern.cc | 12 +++++++ 5 files changed, 127 insertions(+), 2 deletions(-) diff --git a/deal.II/lac/include/lac/chunk_sparsity_pattern.h b/deal.II/lac/include/lac/chunk_sparsity_pattern.h index a144707b77..c334af2500 100644 --- a/deal.II/lac/include/lac/chunk_sparsity_pattern.h +++ b/deal.II/lac/include/lac/chunk_sparsity_pattern.h @@ -591,6 +591,30 @@ class ChunkSparsityPattern : public Subscriptor */ bool optimize_diagonal () const; + /** + * Return whether this object stores only + * those entries that have been added + * explicitly, or if the sparsity pattern + * contains elements that have been added + * through other means (implicitly) while + * building it. For the current class, + * the result is false because we store + * entire chunks, not individual + * elements, and adding one entry to the + * sparsity pattern requires also adding + * all the other elements of a chunk. The + * only exception is if + * chunk_size==1, the + * sparsity pattern is nonsymmetric or + * optimize_diag has been set to false. + * + * This function mainly serves the + * purpose of describing the current + * class in cases where several kinds of + * sparsity patterns can be passed as + * template arguments. + */ + bool stores_only_added_elements () const; /** * Write the data of this object diff --git a/deal.II/lac/include/lac/compressed_set_sparsity_pattern.h b/deal.II/lac/include/lac/compressed_set_sparsity_pattern.h index 7cbcccf0e4..1d6f79e251 100644 --- a/deal.II/lac/include/lac/compressed_set_sparsity_pattern.h +++ b/deal.II/lac/include/lac/compressed_set_sparsity_pattern.h @@ -304,10 +304,29 @@ class CompressedSetSparsityPattern : public Subscriptor /** * Return the number of nonzero elements - * allocated through this sparsity pattern. + * allocated through this sparsity + * pattern. */ unsigned int n_nonzero_elements () const; + /** + * Return whether this object stores only + * those entries that have been added + * explicitly, or if the sparsity pattern + * contains elements that have been added + * through other means (implicitly) while + * building it. For the current class, + * the result is always true. + * + * This function mainly serves the + * purpose of describing the current + * class in cases where several kinds of + * sparsity patterns can be passed as + * template arguments. + */ + static + bool stores_only_added_elements (); + private: /** * Number of rows that this sparsity @@ -429,6 +448,15 @@ CompressedSetSparsityPattern::row_end (const unsigned int row) const } + +inline +bool +CompressedSetSparsityPattern::stores_only_added_elements () +{ + return true; +} + + DEAL_II_NAMESPACE_CLOSE #endif diff --git a/deal.II/lac/include/lac/compressed_sparsity_pattern.h b/deal.II/lac/include/lac/compressed_sparsity_pattern.h index 85b90b4ae7..0a4e6dba2c 100644 --- a/deal.II/lac/include/lac/compressed_sparsity_pattern.h +++ b/deal.II/lac/include/lac/compressed_sparsity_pattern.h @@ -275,10 +275,29 @@ class CompressedSparsityPattern : public Subscriptor /** * Return the number of nonzero elements - * allocated through this sparsity pattern. + * allocated through this sparsity + * pattern. */ unsigned int n_nonzero_elements () const; + /** + * Return whether this object stores only + * those entries that have been added + * explicitly, or if the sparsity pattern + * contains elements that have been added + * through other means (implicitly) while + * building it. For the current class, + * the result is always true. + * + * This function mainly serves the + * purpose of describing the current + * class in cases where several kinds of + * sparsity patterns can be passed as + * template arguments. + */ + static + bool stores_only_added_elements (); + private: /** * Number of rows that this sparsity @@ -499,6 +518,15 @@ CompressedSparsityPattern::column_number (const unsigned int row, +inline +bool +CompressedSparsityPattern::stores_only_added_elements () +{ + return true; +} + + + DEAL_II_NAMESPACE_CLOSE diff --git a/deal.II/lac/include/lac/sparsity_pattern.h b/deal.II/lac/include/lac/sparsity_pattern.h index 2209cdf516..a103d53abb 100644 --- a/deal.II/lac/include/lac/sparsity_pattern.h +++ b/deal.II/lac/include/lac/sparsity_pattern.h @@ -1170,6 +1170,26 @@ class SparsityPattern : public Subscriptor * the diagonal storage optimization. */ bool optimize_diagonal () const; + + /** + * Return whether this object stores only + * those entries that have been added + * explicitly, or if the sparsity pattern + * contains elements that have been added + * through other means (implicitly) while + * building it. For the current class, + * the result is true iff optimize_diag + * in the constructor or reinit() calls + * has been set to false, or if the + * represented matrix is not square. + * + * This function mainly serves the + * purpose of describing the current + * class in cases where several kinds of + * sparsity patterns can be passed as + * template arguments. + */ + bool stores_only_added_elements () const; /** * Use the METIS partitioner to generate @@ -1903,6 +1923,19 @@ SparsityPattern::optimize_diagonal () const } +inline +bool +SparsityPattern::stores_only_added_elements () const +{ + if ((diagonal_optimized == true) + && + (n_cols() == n_rows())) + return false; + else + return true; +} + + inline const std::size_t * SparsityPattern::get_rowstart_indices () const diff --git a/deal.II/lac/source/chunk_sparsity_pattern.cc b/deal.II/lac/source/chunk_sparsity_pattern.cc index c2b1fae0f9..07dcf829ca 100644 --- a/deal.II/lac/source/chunk_sparsity_pattern.cc +++ b/deal.II/lac/source/chunk_sparsity_pattern.cc @@ -436,6 +436,18 @@ ChunkSparsityPattern::bandwidth () const } + +bool +ChunkSparsityPattern::stores_only_added_elements () const +{ + if (chunk_size == 1) + return sparsity_pattern.stores_only_added_elements (); + else + return false; +} + + + void ChunkSparsityPattern::block_write (std::ostream &out) const { -- 2.39.5