- changed status to resolved
PETScMatrix.array() getting transposed when copying values into a new petsc4py matrix
Issue #982
resolved
Dear all,
in the following MWE I am trying to assign a DOLFIN PETScMatrix to a custom petsc4py matrix.
import petsc4py
petsc4py.init()
from petsc4py import PETSc
from dolfin import *
mesh = UnitIntervalMesh(4)
V = FunctionSpace(mesh, "CG", 1)
u = TrialFunction(V)
v = TestFunction(V)
a = u*v.dx(0)*dx
A = assemble(a)
A = A.array()
print(A)
B = PETSc.Mat().createDense(A.shape)
B.setUp()
B[:, :] = A
B.assemble()
B.view()
When running with the former swig backend copy of A into B is done successfuly
[[ 0.5 0.5 0. 0. 0. ]
[-0.5 0. 0.5 0. 0. ]
[ 0. -0.5 0. 0.5 0. ]
[ 0. 0. -0.5 0. 0.5]
[ 0. 0. 0. -0.5 -0.5]]
Mat Object: 1 MPI processes
type: seqdense
5.0000000000000000e-01 5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
-5.0000000000000000e-01 0.0000000000000000e+00 5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00
0.0000000000000000e+00 -5.0000000000000000e-01 0.0000000000000000e+00 5.0000000000000000e-01 0.0000000000000000e+00
0.0000000000000000e+00 0.0000000000000000e+00 -5.0000000000000000e-01 0.0000000000000000e+00 5.0000000000000000e-01
0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 -5.0000000000000000e-01 -5.0000000000000000e-01
When running with current master instead I get that B = A^T
[[ 0.5 0.5 0. 0. 0. ]
[-0.5 0. 0.5 0. 0. ]
[ 0. -0.5 0. 0.5 0. ]
[ 0. 0. -0.5 0. 0.5]
[ 0. 0. 0. -0.5 -0.5]]
Mat Object: 1 MPI processes
type: seqdense
5.0000000000000000e-01 -5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00
5.0000000000000000e-01 0.0000000000000000e+00 -5.0000000000000000e-01 0.0000000000000000e+00 0.0000000000000000e+00
0.0000000000000000e+00 5.0000000000000000e-01 0.0000000000000000e+00 -5.0000000000000000e-01 0.0000000000000000e+00
0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 0.0000000000000000e+00 -5.0000000000000000e-01
0.0000000000000000e+00 0.0000000000000000e+00 0.0000000000000000e+00 5.0000000000000000e-01 -5.0000000000000000e-01
What's going on here? I used the same petsc and petsc4py in both cases.
Thanks,
Francesco
Comments (1)
-
reporter - Log in to comment
Resolved by pull request #451