Good evening,
I am trying to solve a coupled set of complex-valued PDE’s. These contain an absolute value of one of the functions to be solved. However, the complex ufl form which contains an abs() causes a compiler error. Note that the full problem uses abs(u)**2 which could be replaced with u*conj(u) (as in MWE) which is similarly illegal. This may be because the form is non-sesquillinear but I am unsure whether that is required with a non-linear solver. I get:
ValueError: not enough values to unpack (expected 2, got 1)
when running:
from dolfinx import fem, mesh, io
from ufl import dx, inner, grad, TestFunction, sqrt, conj
from mpi4py import MPI
import numpy as np
from dolfinx.nls.petsc import NewtonSolver
from petsc4py import PETSc
domain = mesh.create_rectangle(MPI.COMM_WORLD, [[0, 0], [1, 1]], [10, 10], mesh.CellType.quadrilateral)
V = fem.functionspace(domain, ("Lagrange", 1)) # Scalar function space of degree 1
v = TestFunction(V)
u = fem.Function(V, dtype=np.complex128)
u.x.array[:] = 0.0 # Initialize with zero
F = inner(grad(u), grad(v)) * dx + inner(u**2, v) * dx # Generic math for illustration
# Add a complex term: For example, a complex coefficient in the non-linearity
F = F + 1j * inner(u*conj(u), v) * dx # Possible alternative which also fails
# F = F + 1j * inner(u*u, v) * dx # Regular non-linear term
# F = F + 1j * inner(abs(u)**2, v) * dx # take the absolute value of a function
boundary_facets = mesh.locate_entities_boundary(domain, 1, lambda x: np.full(x.shape[1], True))
bc = fem.dirichletbc(1+0j, fem.locate_dofs_topological(V, 1, boundary_facets), V)
# Create the nonlinear problem and solver
problem = fem.petsc.NonlinearProblem(F, u, bcs = [bc])
solver = NewtonSolver(MPI.COMM_WORLD, problem)
solver.rtol = 1e-8
n, converged = solver.solve(u)
print("Solved the non-linear problem with complex terms.")
I would expect the abs() function to be usable within the UFL form when using a non-linear solver within the complex kernel. Any tips on why the above forms with u*conj(u) or abs(u)**2 are illegal would be greatly appreciated.
Thank you