u = Function(V) u.vector()[4] = 3.14
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.
array()
thanks a lot!!