Hi,
After solving a 3D linear elasticity problem, I would like to find the displacement at a node closest to a given location, is the following code correct?
dof_coords = Vp.tabulate_dof_coordinates()
distances = np.linalg.norm(dof_coords - grasp_node, axis=1)
dof_index = np.argmin(distances)
u_node = np.sqrt(uh.x.array[3*dof_index]**2 + uh.x.array[3*dof_index+1]**2 + uh.x.array[3*dof_index+2]**2)
I checked with the following example and it seems to work. One question I have is, why does V.tabulate_dof_coordinates() give 3D points with z values set to zero?
import numpy as np
import dolfinx
from mpi4py import MPI
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
V = dolfinx.fem.functionspace(mesh, (“Lagrange”, 1, (mesh.geometry.dim,)))
u = dolfinx.fem.Function(V)
u.interpolate(lambda x: np.vstack((x[0], x[1]))) # Populating with sample data
target_coords = np.array([0.5, 0.5])
dof_coords = V.tabulate_dof_coordinates()
distances = np.linalg.norm(dof_coords[:,0:2] - target_coords, axis=1)
dof_index = np.argmin(distances)
closest_node_magnitude = np.sqrt(u.x.array[2*dof_index]**2 + u.x.array[2*dof_index+1]**2)
print(closest_node_magnitude)
Thank you,
Alex