Hi, if you run
X.element().value_rank()
somewhere before the code crashes, you'll see that the rank is 2 and consequently
the terms in your form are vectors and not scalars as they should be. The problem lies in your definition of X. It should be
X = FunctionSpace(mesh, "RT", 2)
This gives you vectors already. There are no scalar RT elements.