FEniCSx tutorial on heat equation

Hello,

While trying to run the tutorial “Diffusion of a Gaussian function”, I have an error when I run the following cell:

bilinear_form = fem.form(a)
linear_form = fem.form(L)

The error is as follows:

File /usr/local/lib/python3.9/dist-packages/ufl/algorithms/check_arities.py:170, in check_integrand_arity(expr, arguments, complex_mode)
    168 for arg, conj in arg_tuples:
    169     if arg.number() == 0 and not conj:
--> 170         raise ArityMismatch("Failure to conjugate test function in complex Form")
    171     elif arg.number() > 0 and conj:
    172         raise ArityMismatch("Argument {0} is spuriously conjugated in complex Form".format(arg))

ArityMismatch: Failure to conjugate test function in complex Form

Do you know where the problem comes from?
I guess it comes from the following variational problem but I don’t see how to fix it:

a = u * v * ufl.dx + dt*ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx 
L = (u_n + dt * f) * v * ufl.dx

Thanks again for your help !

You can’t use billinear forms like u * v * ufl.dx in complex builds of dolfinx, because it will not conjugate v properly. Try changing the code to

a = ufl.inner(u * v) * ufl.dx + dt*ufl.dot(ufl.grad(u), ufl.grad(v)) * ufl.dx 
L = ufl.inner((u_n + dt * f) * v) * ufl.dx

which will properly conjugate v. Alternatively you can swap to real mode of dolfinx and the code will run as is. I don’t know if this behaviour is intended or a bug, but if intended I think it may be a good idea to change the code in the tutorials so that everything works in both real and complex modes.

2 Likes

I guess you mean

ufl.inner(u,v)*ufl.dx

I would like to point out that I do mention this in the section: Implementation — FEniCSx tutorial

2 Likes

Thank you very much, that makes sense!
To run my codes, I use the Jupyter lab Docker image. Is there a simple way to swap to real mode?

There should be two kernels available in the docker-image dolfinx/lab. Go to Kernel->Change Kernel->Python 3 (ipykernel) as opposed to Python3 (DOLFINx complex)

1 Like