ufl icon indicating copy to clipboard operation
ufl copied to clipboard

Issue with complex-valued expressions

Open garth-wells opened this issue 3 years ago • 1 comments

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)

garth-wells avatar Feb 11 '22 12:02 garth-wells

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?

wence- avatar Apr 08 '22 12:04 wence-

The idea here is that remove_complex_node is only called when compiling for real mode, so encountering a complex value is an error.

dham avatar Sep 12 '23 08:09 dham