Reaction forces on a surface/edge FEniCSx

Dear all,

I would like to obtain and sum the nodal reaction forces on a surface subjected to DirichletBCs (mechanical displacement). To this end, I wonder how I can obtain the nodal forces only at the nodes on such a surface, then sum them (a same component to get the total reaction force).

For a 2d simulation instead of 3d, would it be the same to determine the reaction forces on an edge subjected to DirichtletBCs?

Many thanks.