This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

How can I set manually the i-th coordinates of a PETScVector?

–1 vote
asked Jan 26, 2014 by fotini.karakatsani FEniCS Novice (500 points)

1 Answer

0 votes
u = Function(V)
u.vector()[4] = 3.14
answered Jan 26, 2014 by nschloe FEniCS User (7,120 points)

Thanks for your answer but it is not what I want ...
Here is my code:

patch = SubMesh(mesh, subdomains, 1)
local_grad_uh = PETScVector(2)
for cell in cells(patch):
local_index = cell.index()
local_grad_uh.array()[local_index] = 1.0
print 'local_grad_uh[%d]=%e' %(local_index, local_grad_uh.array()[local_index] )

Result:
local_grad_uh[0]=0.000000e+00
local_grad_uh[1]=0.000000e+00

Omit array(). It creates (numpy) copy.

thanks a lot!!

...