ufl
ufl copied to clipboard
Issue with complex-valued expressions
The below code gives the error ufl.log.UFLException: Unexpected complex value in real expression. Should it be expected to work?
import ufl
cell = ufl.triangle
x = ufl.SpatialCoordinate(cell)
f = x[0] + x[0] * 1j
# f = ufl.Constant(x[0] + x[0] * 1j) # this works
# f = ufl.real(f) # this doesn't work either
ufl.algorithms.remove_complex_nodes.remove_complex_nodes(f)
I think this is working "as designed" (reading the docstring of remove_complex_nodes) but it is rather counter-intuitive. Can @dham comment on the choice of what is intended here?
The idea here is that remove_complex_node is only called when compiling for real mode, so encountering a complex value is an error.