From e0917890673fc875a45270e72fab1b14e085ec46 Mon Sep 17 00:00:00 2001 From: Lei Qiao Date: Wed, 12 Aug 2015 16:29:02 -0500 Subject: [PATCH] make SparseMatrixEZ can accept new zero entry --- include/deal.II/lac/sparse_matrix_ez.h | 37 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/include/deal.II/lac/sparse_matrix_ez.h b/include/deal.II/lac/sparse_matrix_ez.h index 14e3bdcf05..6a4cd650a2 100644 --- a/include/deal.II/lac/sparse_matrix_ez.h +++ b/include/deal.II/lac/sparse_matrix_ez.h @@ -429,12 +429,23 @@ public: */ //@{ /** - * Set the element (i,j) to @p value. Allocates the entry, if it - * does not exist and @p value is non-zero. If value is not a - * finite number an exception is thrown. + * Set the element (i,j) to @p value. + * + * If value is not a finite number an exception is thrown. + * + * The optional parameter elide_zero_values can be used to specify + * whether zero values should be added anyway or these should be filtered + * away and only non-zero data is added. The default value is true, + * i.e., zero values won't be added into the matrix. + * + * If anyway a new element will be inserted and it does not exist, + * allocates the entry. + * + * @note You may need to insert some zero elements to keep a + * symmetric sparsity pattern for the matrix. */ void set (const size_type i, const size_type j, - const number value); + const number value, const bool elide_zero_values = true); /** * Add @p value to the element (i,j). Allocates the entry if it @@ -518,11 +529,16 @@ public: * The source matrix may be a matrix of arbitrary type, as long as its data * type is convertible to the data type of this matrix. * + * The optional parameter elide_zero_values can be used to specify + * whether zero values should be added anyway or these should be filtered + * away and only non-zero data is added. The default value is true, + * i.e., zero values won't be added into the matrix. + * * The function returns a reference to @p this. */ template SparseMatrixEZ & - copy_from (const MATRIX &source); + copy_from (const MATRIX &source, const bool elide_zero_values = true); /** * Add @p matrix scaled by @p factor to this matrix. @@ -1195,15 +1211,15 @@ template inline void SparseMatrixEZ::set (const size_type i, const size_type j, - const number value) + const number value, + const bool elide_zero_values) { - AssertIsFinite(value); Assert (i template inline SparseMatrixEZ & -SparseMatrixEZ::copy_from (const MATRIX &M) +SparseMatrixEZ::copy_from (const MATRIX &M, const bool elide_zero_values) { reinit(M.m(), M.n()); @@ -1383,8 +1399,7 @@ SparseMatrixEZ::copy_from (const MATRIX &M) const typename MATRIX::const_iterator end_row = M.end(row); for (typename MATRIX::const_iterator entry = M.begin(row); entry != end_row; ++entry) - if (entry->value() != 0) - set(row, entry->column(), entry->value()); + set(row, entry->column(), entry->value(), elide_zero_values); } return *this; -- 2.39.5