` Hello,
I have a similar issue with the one in this post Problem with use of a ufl function in a NonlinearProblem
I’m trying to solve an eigenvalue problem in FEniCSx with complex-valued functions, and I’m encountering an ArityMismatch error when trying to assemble the discrete matrices from the variational form.
ArityMismatch: Adding expressions with non-matching form arguments (‘v_1’,) vs (‘conj(v_1)’,).
Here, I post the respective code snippet:
v=ufl.TrialFunction(V)
w=ufl.TestFunction(V)
#Terms of left-hand side
grad_term= ufl.dot(grad_r(v, omega, domain), ufl.conj(grad_r(w, omega, domain)))
pot_term= ufl.dot((potential_r + beta * ufl.inner(phi, phi)) * v,ufl.conj(w))
beta_expression=(ufl.dot(ufl.conj(phi),v))
beta_expression_real= 0.5 * (beta_expression + ufl.conj(beta_expression)) # line that produces the error
beta_term=2*beta*ufl.dot(beta_expression_real*phi,ufl.conj(w))
#Left-hand side
lhs = (grad_term + pot_term + beta_term)*ufl.dx(degree=4)
# Right-hand side
rhs = ufl.dot(v, ufl.conj(w)) * ufl.dx(degree=4)
# Assemble the matrices
form_lhs = dolfinx.fem.form(lhs)
form_rhs = dolfinx.fem.form(rhs)
A=assemble_matrix(form_lhs,[bc])
A.assemble()
B=assemble_matrix(form_rhs,[bc])
B.assemble()
Here, phi is a precomputed wavefunction, beta and omega some constants, and potential_r another interpolated function on the mesh.
The problem is with the computation of beta_expression_real, which causes incompatibility with the form arguments. Alternatively, when I tried intead to extract the real part of beta_expression by using ufl.real(), I encouter the following error:
ArityMismatch: Applying nonlinear operator Real to expression depending on form argument v_1.
Is there any recommended way to ompute the real part of beta expression?
I didn’t post the entire code, as I thought it might be too overwhelming, but in case it is needed let me know.