Thanks, @francesco-ballarin!
Could you also tell me how the code would change if the displacement values are a constant instead of zero?
Additionally, out of curiosity, do you know why my solution doesn’t work with Serendipity Elements but works with Lagrange Elements?