Hello! I’m currently fighting my way around the lack of complex support in the stable FEniCS Project, and gratefully awaiting its inclusion in the next release. I am using UFL to construct a long variational form that is infeasible to separate into real and complex parts by hand so that I can solve them separately. I am using a combination of ufl.real()
, ufl.imag()
to split the real and imaginary parts. Since ufl.imag()
returns a complex expression, I am trying to remove the Imag()
node with remove_complex_nodes()
in ufl.algorithms
. However, remove_complex_nodes()
does not accept complex expressions! I have replicated this with fenics 2019.1.0 in a docker image and a conda environment. Does anyone have a solution? I would be very grateful! Thank you.
p1 = TrialFunction(Q)
ufl.algorithms.remove_complex_nodes.remove_complex_nodes(1j*p1)
---------------------------------------------------------------------------
UFLException Traceback (most recent call last)
<ipython-input-18-09a33dfa5617> in <module>
1 p1, p2 = TrialFunction(Q), TrialFunction(Q)
2
----> 3 ufl.algorithms.remove_complex_nodes.remove_complex_nodes(p1+1j*p2)
/usr/local/lib/python3.6/dist-packages/ufl/algorithms/remove_complex_nodes.py in remove_complex_nodes(expr)
35 support from the preprocessed form.
36 """
---> 37 return map_integrand_dags(ComplexNodeRemoval(), expr)
/usr/local/lib/python3.6/dist-packages/ufl/algorithms/map_integrands.py in map_integrand_dags(function, form, only_integral_type, compress)
56 def map_integrand_dags(function, form, only_integral_type=None, compress=True):
57 return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
---> 58 form, only_integral_type)
/usr/local/lib/python3.6/dist-packages/ufl/algorithms/map_integrands.py in map_integrands(function, form, only_integral_type)
49 elif isinstance(form, Expr):
50 integrand = form
---> 51 return function(integrand)
52 else:
53 error("Expecting Form, Integral or Expr.")
/usr/local/lib/python3.6/dist-packages/ufl/algorithms/map_integrands.py in <lambda>(expr)
55
56 def map_integrand_dags(function, form, only_integral_type=None, compress=True):
---> 57 return map_integrands(lambda expr: map_expr_dag(function, expr, compress),
58 form, only_integral_type)
/usr/local/lib/python3.6/dist-packages/ufl/corealg/map_dag.py in map_expr_dag(function, expression, compress)
35 Return the result of the final function call.
36 """
---> 37 result, = map_expr_dags(function, [expression], compress=compress)
38 return result
39
/usr/local/lib/python3.6/dist-packages/ufl/corealg/map_dag.py in map_expr_dags(function, expressions, compress)
84 r = handlers[v._ufl_typecode_](v)
85 else:
---> 86 r = handlers[v._ufl_typecode_](v, *[vcache[u] for u in v.ufl_operands])
87
88 # Optionally check if r is in rcache, a memory optimization
/usr/local/lib/python3.6/dist-packages/ufl/algorithms/remove_complex_nodes.py in terminal(self, t, *ops)
24 def terminal(self, t, *ops):
25 if isinstance(t, ComplexValue):
---> 26 error('Unexpected complex value in real expression.')
27 else:
28 return t
/usr/local/lib/python3.6/dist-packages/ufl/log.py in error(self, *message)
170 "Write error message and raise an exception."
171 self._log.error(*message)
--> 172 raise self._exception_type(self._format_raw(*message))
173
174 def begin(self, *message):
UFLException: Unexpected complex value in real expression.