How to construct petsc matrices? -
i'm using petsc4py , face problems. have number of small petsc dense matrices mij, , want construct them big matrix m this:
[ m11 m12 m13 ] m = | m21 m22 m23 | , [ m31 m32 m33 ]
a mcve code showing below, , i'm using python wrap of petsc, however, grammars similar.
import numpy np petsc4py import petsc msizes = (5, 8, 6) mij = [] # create sub-matrices mij in range(len(msizes)): j in range(len(msizes)): temp_m = petsc.mat().create(comm=petsc.comm_world) temp_m.setsizes(((none, msizes[i]), (none, msizes[j]))) temp_m.settype('mpidense') temp_m.setfromoptions() temp_m.setup() temp_m[:, :] = np.random.random_sample((msizes[i], msizes[j])) temp_m.assemble() mij.append(temp_m) # have 4 sub-matrices. # construct them big matrix m. m = petsc.mat().create(comm=petsc.comm_world) m.setsizes(((none, np.sum(msizes)), (none, np.sum(msizes)))) m.settype('mpidense') m.setfromoptions() m.setup() mlocations = np.insert(np.cumsum(msizes), 0, 0) # mlocations = [0, msizes] in range(len(msizes)): j in range(len(msizes)): m[mlocations[i]:mlocations[i+1], mlocations[j]:mlocations[j+1]] = \ mij[i*len(msizes)+j][:, :] m.assemble()
which report such error messages:
traceback (most recent call last): file "trymatconstuct.py", line 29, in <module> mij[i*len(msizes)+j][:, :] file "petsc/mat.pyx", line 227, in petsc4py.petsc.mat.__getitem__ (src/petsc4py.petsc.c:110477) file "petsc/petscmat.pxi", line 997, in petsc4py.petsc.mat_getitem (src/petsc4py.petsc.c:30481) file "petsc/petscmat.pxi", line 917, in petsc4py.petsc.matgetvalues (src/petsc4py.petsc.c:29242) petsc4py.petsc.error: error code 56 [1] matgetvalues() line 1818 in /home/zhangji/pycharmprojects/petsc-petsc-31a1859eaff6/src/mat/interface/matrix.c [1] matgetvalues_mpidense() line 154 in /home/zhangji/pycharmprojects/petsc-petsc-31a1859eaff6/src/mat/impls/dense/mpi/mpidense.c [1] no support operation object type [1] local values supported
i have use 2d array instead of petsc matrix short sub-matrix mij.
in petsc4py function petsc.mat().getdensearray(), i.e.
temp_m = mij[i*len(msizes)+j].getdensearray()
Comments
Post a Comment