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

how I can stoker values of f in a vector?

0 votes

Hello everyone,

my goal is to store all the values of f in a vector for use it after.

I tried the following commands:

coor=mesh.coordinates()
u_arr=u.vector().array()
N=mesh.num_vertices()

print"N",N

if N==len(u_arr):
for i in range(mesh.num_vertices()):
# print'u(%8g,%8g)=%g'% (coor[i][0], coor[i][1],u_arr[i])
print'f[%i]=%g' %(i, pow(coor[i][0],2)+ pow(coor[i][1],2)-pow(5,2))

this command display the values of f (ex f(1), f(2), f(3) ..........), this is not my goal :\

Does anyone have any idea what to do??
I am looking forward to anyone's reply,
Marwa
thank you

asked Sep 10, 2015 by marwa FEniCS Novice (150 points)

1 Answer

0 votes

Hi, maybe you can try something like this:

comm = mesh.mpi_comm()
f = Vector(comm, mesh.num_vertices())

for i in range(mesh.coordinates())
   f[i] = pow(coor[i][0],2)+ pow(coor[i][1],2)-pow(5,2)
answered Sep 15, 2015 by hernan_mella FEniCS Expert (19,460 points)
edited Sep 15, 2015 by hernan_mella
...