From: Wolfgang Bangerth Date: Wed, 21 Mar 2018 20:08:55 +0000 (-0600) Subject: Relax a couple of assertions for empty matrices. X-Git-Tag: v9.0.0-rc1~287^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85370f88cb052a336fb9ee8ec540f467eb113eab;p=dealii.git Relax a couple of assertions for empty matrices. --- diff --git a/include/deal.II/lac/sparsity_pattern.h b/include/deal.II/lac/sparsity_pattern.h index 2644d4597d..ae5b6576ff 100644 --- a/include/deal.II/lac/sparsity_pattern.h +++ b/include/deal.II/lac/sparsity_pattern.h @@ -1409,9 +1409,13 @@ inline std::size_t SparsityPattern::n_nonzero_elements () const { - Assert ((rowstart!=nullptr) && (colnums!=nullptr), ExcEmptyObject()); Assert (compressed, ExcNotCompressed()); - return rowstart[rows]-rowstart[0]; + + if ((rowstart!=nullptr) && (colnums!=nullptr)) + return rowstart[rows]-rowstart[0]; + else + // the object is empty or has zero size + return 0; } diff --git a/source/lac/sparsity_pattern.cc b/source/lac/sparsity_pattern.cc index 4051dffa4c..c71504eee0 100644 --- a/source/lac/sparsity_pattern.cc +++ b/source/lac/sparsity_pattern.cc @@ -356,7 +356,12 @@ SparsityPattern::reinit (const size_type m, void SparsityPattern::compress () { - Assert ((rowstart!=nullptr) && (colnums!=nullptr), ExcEmptyObject()); + // nothing to do if the object corresponds to an empty matrix + if ((rowstart==nullptr) && (colnums==nullptr)) + { + compressed = true; + return; + } // do nothing if already compressed if (compressed)