In my work, during solving the problem, I need to compute some quantity in each node of the mesh (by loop on the nodes of the mesh) and then consider a piecewise linear function with computed nodal’s value. How can I do that by FEinCS.
nx = ny = 8
mesh = UnitSquareMesh(nx, ny, “right/left”)
mesh_points = mesh.coordinates()
x = SpatialCoordinate(mesh)
V = FiniteElement(“CG”, mesh.ufl_cell(), 1)
g = Function(V)
i = 0
nvertices = len(g.vector().array())
gnodal = [0 for xn in range(nvertices)]
for x1,y1 in mesh_points:
gnodal[i] = f(x1,y1) # f(x1,y1) means some computation on x1 and y1
i = i+1
How to define the function g of V-space in which to assign the value of nodes by vector gnodal?
Thank you in advance.