Getting Nodal Values of the Solution

I am new to Fenics and doing the first Poisson example. I cannot seem to find the solution of the system at nodes of the mesh. If I use the following code:

u_nodal_values = u.vector()
u_array = u_nodal_values.array()

I am getting an error "‘dolfin.cpp.la.PETScVector’ object has no attribute ‘array’ "

Also, using u.vector().get_local() seems to give me a tuple with too many values, more than number of nodes (81 nodes, 289 values).

Any suggestions on how resolve it? Also, I would prefer if my output is as numpy array.

Thank you.

You should use the following in the latest version of FEniCS

u_nodal_values = u.vector().vec()
u_array = u_nodal_values.array
2 Likes

Or, perhaps, a little bit shorter

u_array = u.vector()[:]

For me (2018) both achieve the same

2 Likes

`Thank you so much. It is working.

1 Like