Complex valued Neumann b.c

Hello everybody,

I have some trouble in formulating complex-valued boundary conditions of Neumann type in dolfinx.

Using the real mode of PETSc the following

V = FunctionSpace(mesh, ("Lagrange", 1))
v = TestFunction(V)
V0=-1
g = k0*c*rho*V0
p=Function(V)
p.interpolate(lambda x: x[0]+g)
L = p*v*ds(1)  

works quite well, whereas in complex-mode (export PETSC_DIR=/usr/lib/petscdir/petsc-complex before running the script) and changing ‘g’ to

g = -(1+4j)

I got

Traceback (most recent call last):
  File "/mnt/hgfs/host_shared/helmholtz_refine_geo-stl.py", line 94, in <module>
    problem = fem.LinearProblem(a, L, u=uh, 
  File "/usr/lib/petscdir/petsc-complex/lib/python3/dist-packages/dolfinx/fem/problem.py", line 60, in __init__
    self._L = fem.Form(L, form_compiler_parameters=form_compiler_parameters, jit_parameters=jit_parameters)
  File "/usr/lib/petscdir/petsc-complex/lib/python3/dist-packages/dolfinx/fem/form.py", line 42, in __init__
    ufc_form = jit.ffcx_jit(
  File "/usr/lib/petscdir/petsc-complex/lib/python3/dist-packages/dolfinx/jit.py", line 62, in mpi_jit
    return local_jit(*args, **kwargs)
  File "/usr/lib/petscdir/petsc-complex/lib/python3/dist-packages/dolfinx/jit.py", line 212, in ffcx_jit
    r = ffcx.codegeneration.jit.compile_forms([ufl_object], parameters=p_ffcx, **p_jit)
  File "/usr/lib/python3/dist-packages/ffcx/codegeneration/jit.py", line 167, in compile_forms
    _compile_objects(decl, forms, form_names, module_name, p, cache_dir,
  File "/usr/lib/python3/dist-packages/ffcx/codegeneration/jit.py", line 232, in _compile_objects
    _, code_body = ffcx.compiler.compile_ufl_objects(ufl_objects, prefix=module_name, parameters=parameters)
  File "/usr/lib/python3/dist-packages/ffcx/compiler.py", line 98, in compile_ufl_objects
    analysis = analyze_ufl_objects(ufl_objects, parameters)
  File "/usr/lib/python3/dist-packages/ffcx/analysis.py", line 65, in analyze_ufl_objects
    form_data = tuple(_analyze_form(form, parameters) for form in forms)
  File "/usr/lib/python3/dist-packages/ffcx/analysis.py", line 65, in <genexpr>
    form_data = tuple(_analyze_form(form, parameters) for form in forms)
  File "/usr/lib/python3/dist-packages/ffcx/analysis.py", line 158, in _analyze_form
    form_data = ufl.algorithms.compute_form_data(
  File "/usr/lib/python3/dist-packages/ufl/algorithms/compute_form_data.py", line 407, in compute_form_data
    check_form_arity(preprocessed_form, self.original_form.arguments(), complex_mode)  # Currently testing how fast this is
  File "/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py", line 177, in check_form_arity
    check_integrand_arity(itg.integrand(), arguments, complex_mode)
  File "/usr/lib/python3/dist-packages/ufl/algorithms/check_arities.py", line 170, in check_integrand_arity
    raise ArityMismatch("Failure to conjugate test function in complex Form")
ufl.algorithms.check_arities.ArityMismatch: Failure to conjugate test function in complex Form

I would be very glad if someone has any idea what happens there.

You need to set both the PETSc dir and PETSc arch to point to the complex installation, and rebuild dolfinx with these options. If you are using the docker images, you can simply run the following commands, as the PETSc complex dolfinx version is preinstalled: dolfinx/dolfinx-complex-mode at main · FEniCS/dolfinx · GitHub

1 Like

This might also be occuring because you’re not taking the inner product (p, v)_{\partial\Omega} = \int_{\partial\Omega} p \, \overline{v} \, \mathrm{d}s which can be achieved with ufl.inner.

1 Like

Great @nate, that is the solution. Thank you very much!

1 Like