However, is there a specfic reason for using sympy?
Good question. I am not sure. So I am using sympy to create manufactured solutions. So for instance I would like to take the derivative of cos(x) + x**2 symbolically and obtain -sin(x) + 2*x. I can do that in sympy. Can ufl also do this for me?
No, as calling grad on a ufl expression does not compute the gradient until it is required (for instance in an assembly loop), you will not be able to see the symbolic representation of the derivative as you would like to.
How to use ufl expressions in connection with mixed elements. With sympy I would do something like
bc = DirichlectBC(V.sub(1),
Expression(sympy.printing.ccode(ex), degree=2),
"on_boundary")
If I try an ufl expression with
bc = DirichlectBC(V.sub(1), ex, "on_boundary")
I get
*** Error: Unable to create function.
*** Reason: Cannot be created from subspace. Consider collapsing the function space.
*** Where: This error was encountered inside Function.cpp.