]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Relax a couple of assertions for empty matrices.
authorWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Mar 2018 20:08:55 +0000 (14:08 -0600)
committerWolfgang Bangerth <bangerth@colostate.edu>
Wed, 21 Mar 2018 20:08:55 +0000 (14:08 -0600)
include/deal.II/lac/sparsity_pattern.h
source/lac/sparsity_pattern.cc

index 2644d4597d67c639ac5ad2787cdbb56f982be210..ae5b6576ffe7d086d710a55367a409a7bd6444ce 100644 (file)
@@ -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;
 }
 
 
index 4051dffa4c4d87f5dd3e94d73d1a14637769edf0..c71504eee0059965fb51063199a60bbda2f9bfb7 100644 (file)
@@ -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)

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.