 # How to evaluate a vector valued function?

Hello,

I am running a simple elasticity problem and this may serve as a MWE for my question. According to the FEniCS tutorial (Section 5.4.3 Function evalution) functions can be evaluated in different ways, which vary in compuational cost: A Function object u can be evaluated via

1. u(x) for a point x
2. u.vector().array()[i] for a dof number i
3. u.compute_vertex_values()[i] at vertex number i

This works for scalar function, but how does this translate to vector valued functions? If I take

V = VectorFunctionSpace(mesh, 'Largrange', 2)
u = Function(V)


and let FEniCS solve the problem, i.e. filling u with the solution values, the evaluation method

1. gives me a vector (as expected but it takes time to evaluate all vertices or even all nodes)
2. throws an error (AttributeError: 'dolfin.cpp.la.PETScVector' object has no attribute 'array') but u.vector()[i] works yet gives me a number (instead of a vector)
3. gives me a number (as for method 2. I have no idea what this number is (it’s not the norm of the vector))

How do these function evaluation methods translate to functions on a VectorFunctionSpace?

Thanks!

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.

1 Like