Skip to content

Commit 0e234ac

Browse files
committed
Fix sparsity builder for case of no owned dofs
1 parent d48b95a commit 0e234ac

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

pyop2/sparsity.pyx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,17 @@ cdef get_preallocation(PETSc.Mat preallocator, PetscInt nrow):
101101
_p_Mat *A = <_p_Mat *>(preallocator.mat)
102102
Mat_Preallocator *p = <Mat_Preallocator *>(A.data)
103103

104-
dnz = <PetscInt[:nrow]>p.dnz
105-
onz = <PetscInt[:nrow]>p.onz
106-
return np.asarray(dnz).copy(), np.asarray(onz).copy()
104+
if p.dnz != NULL:
105+
dnz = <PetscInt[:nrow]>p.dnz
106+
dnz = np.asarray(dnz).copy()
107+
else:
108+
dnz = np.zeros(0, dtype=IntType)
109+
if p.onz != NULL:
110+
onz = <PetscInt[:nrow]>p.onz
111+
onz = np.asarray(onz).copy()
112+
else:
113+
onz = np.zeros(0, dtype=IntType)
114+
return dnz, onz
107115

108116

109117
def build_sparsity(sparsity):

0 commit comments

Comments
 (0)