In the below MWE, I have unit square mesh with two elements. The four nodes of the mesh have the coordinates
[[0. 0.]
[1. 0.]
[0. 1.]
[1. 1.]]
I want to define a function that assigns vectors to each of the nodes. For example, if
B = [
[1.0, 5.0],
[7.0, 1.0],
[9.0, 10.0],
[13.0, 5.0]
]
then I want u(0,0)=[1.0,5.0], u(1,0)=[7,1], u(0,1)=[9,10], and u(1,1)=[13,5]
So I tried the following MWE:
mesh = UnitSquareMesh(1, 1)
mesh_coords = mesh.coordinates()
V = VectorFunctionSpace(mesh, 'P', 1)
B = as_matrix([[1.0,5.0],[7.0,1.0],[9.0,10.0],[13.0,5.0]])
u = Function(V)
for i in range(0,len(mesh_coords)):
u(mesh_coords[:,:][i]) = B[:,:][i]
This produces the error
SyntaxError: cannot assign to function call
What is wrong with the way I am assigning the vectors to the function? Any suggestion would be greatly appreciated.