Problem with use of a ufl function in a NonlinearProblem

Hello,

I am trying to solve an equation using complex numbers. However I get the following error:

ufl.algorithms.check_arities.ArityMismatch: Applying nonlinear operator Real to expression depending on form argument v_1.

It would seem that this is a classical problem but I have not found a satisfactory solution yet.
Here’s a MWE.

from dolfinx import *
from mpi4py import MPI
import numpy as np
import ufl
mesh = mesh.create_rectangle(MPI.COMM_WORLD, [[0,0], [1,1]], [5, 5])
V = fem.FunctionSpace(mesh, ("Lagrange", 1))
u_c = fem.Function(V, dtype=np.complex128)
u_c.interpolate(lambda x:0.5 * (1 - x[1]) +3j)
u_R = ufl.real(u_c)

#Bilinear form
v = ufl.TestFunction(V)
a = ufl.inner(ufl.grad(u_R), ufl.grad(v)) * ufl.dx
problem = fem.petsc.NonlinearProblem(a, u_c)

This has been discussed on the slack channel #fenicsx, here is screenshot of the discussion:

Hello dokken,

Thank you for inquiring this much.

I understand the explanation for the MWE I posted. But I get the same error for the case I am really interested in which is

from dolfinx import *
from mpi4py import MPI
import numpy as np
import ufl
mesh = mesh.create_rectangle(MPI.COMM_WORLD, [[0,0], [1,1]], [5, 5])
V = fem.FunctionSpace(mesh, ("Lagrange", 1))
u_c = fem.Function(V, dtype=np.complex128)
u_c.interpolate(lambda x:0.5 * (1 - x[1]) +3j)
u_R = ufl.real(u_c)

#Bilinear form
v = ufl.TestFunction(V)
a = (u_R+1) * ufl.inner(ufl.grad(u_c), ufl.grad(v)) * ufl.dx
u = ufl.TrialFunction(V)
problem = fem.petsc.NonlinearProblem(a, u_c)

In this case, the fact that the real operator is applied does not create a singular system and I use a bilinear form on the gradients. Therefore, this should work no?

The problem is as David Ham mentions, that the real operator is not linear in complex space. Thus creating a sesquilinear operator (as required from the analysis point of view), is quite tricky (Im not sure how to do it).

I am fairly confident that the bilinear form a defined in my second post is sesquilinear and verifies the Lax-Milgram theorem for complex valued forms.
Should I engage in the discussion on slack on #fenicsx to make my argument?

Sure. That is a good idea.