grad_uh.x.array
yields the underlying array of finite element function coefficients wrapped by a numpy array. The x
does not mean geometric component.
Adapted from Problem solving Harmonic Oscillator - #7 by nate, consider appending the following to the code to evaluate the finite element functions at positions in space:
from dolfinx import geometry
# Points at which to evaluate gradient
x = np.array([
[0.0, 0.0, 0.0],
[1.0, 0.0, 0.0],
[1.0, 1.0, 0.0],
[0.0, 1.0, 0.0]])
bbox = geometry.bb_tree(msh, msh.topology.dim)
candidate_cells = geometry.compute_collisions_points(bbox, x)
collided_cells = geometry.compute_colliding_cells(
msh, candidate_cells, x)
collided_cells = collided_cells.array[collided_cells.offsets[:-1]]
grad_uh_values = grad_uh.eval(x, collided_cells)
print(grad_uh_values)
Which yields the evaluations of the gradient:
[[4.30845614e-17 4.30845614e-17]
[2.00000000e+00 6.79377410e-17]
[2.00000000e+00 2.00000000e+00]
[6.79377410e-17 2.00000000e+00]]