- changed status to invalid
function.vector().vec() not working?
Issue #414
invalid
I'm trying to get a petsc4py vector from a function with the .vec() command, but it fails with
AttributeError: 'GenericVector' object has no attribute 'vec'
Defining an empty PETScVector works fine though.
MWE:
from dolfin import *
from petsc4py import *
mesh = RectangleMesh(0,0,1,1,10,10)
V = FunctionSpace(mesh, 'Lagrange',1)
f = interpolate(Constant(1.0),V).vector()
g = PETScVector()
print g
print g.vec()
print f
print f.vec() # Fails
Comments (3)
-
-
reporter Thanks for the quick help! The error message is strange then no? The output that I get is:
<Uninitialized PETScVector> <petsc4py.PETSc.Vec object at 0x2982950> <PETScVector of size 121>
before the crash. To me this is saying that both g and f are of type PETScVector ...
-
- removed milestone
Removing milestone: 1.5 (automated comment)
- Log in to comment
In your case,
f
is aVector
and not aPETScVector
. You need to castf
to aPETScVector
. It goes something like