The PETScVector
object is a one dimensional vector including components in all spatial directions.
The get_local
method will return a numpy.ndarray
which can be easily manipulated.
For linear lagrange elements, the code
dim = mesh.geometric_dimension()
u_array = u.vector().get_local().reshape((-1, dim))
returns a ndofs x ndim
array where ndim
is the geometric dimension of the mesh and ndofs
the number of nodes. So for a 2D mesh, the first column would be the x component of u and the second column the y component.