[petsc-dev] MatNest in petsc4py with empty submatrices
Lawrence Mitchell
lawrence.mitchell at imperial.ac.uk
Wed Feb 17 08:53:39 CST 2016
On 17/02/16 14:47, Chris Eldred wrote:
> Hey All,
>
> I was wondering if anyone had used MatNest with petsc4py. I am having
> issues trying to create a MatNest where some of the submatrices are
> empty. In PETSc, I can just pass NULL in the array that I give to
> MatCreateNest and it works fine. However, the following code
We use it, but haven't used it with empty slots.
> nest_list = [[None,None],[None,None]]
> nest_list[0][0] = some matrix
> nest_list[0][1] = some matrix
> nest_list[1][0] = some matrix
> A = PETSc.Mat().createNest(nest_list,comm=PETSc.COMM_WORLD)
>
> fails with:
> File "Mat.pyx", line 445, in petsc4py.PETSc.Mat.createNest
> (src/petsc4py.PETSc.c:103202)
> TypeError: Cannot convert NoneType to petsc4py.PETSc.Mat
>
> Is there an equivalent to NULL in petsc4py (there doesn't appear to be one)?
>
> If all of the entries in nest_list are filled, everything works fine.
>
> Any help would be appreciated!
Maybe a patch like this to petsc4py?
diff --git a/src/PETSc/Mat.pyx b/src/PETSc/Mat.pyx
index f281ba0..490c58e 100644
--- a/src/PETSc/Mat.pyx
+++ b/src/PETSc/Mat.pyx
@@ -460,7 +460,10 @@ cdef class Mat(Object):
tmp1 = oarray_p(empty_p(nr*nc), NULL, <void**>&cmats)
for i from 0 <= i < mr:
for j from 0 <= j < mc:
- cmats[i*mc+j] = (<Mat?>mats[i][j]).mat
+ if mats[i][j] is None:
+ cmats[i*mc+j] = NULL
+ else:
+ cmats[i*mc+j] = (<Mat?>mats[i][j]).mat
if isrows is not None:
tmp2 = oarray_p(empty_p(nr), NULL, <void**>&cisrows)
for i from 0 <= i < mr: cisrows[i] = (<IS?>isrows[i]).iset
Untested.
If you want to pass null isrows and iscols as well you'll need to do a
similar thing there.
Cheers,
Lawrence
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
URL: <http://lists.mcs.anl.gov/pipermail/petsc-dev/attachments/20160217/cefbc745/attachment.sig>
More information about the petsc-dev
mailing list