Hi, I am trying to solve a problem which requires me to form a variational formulation with a term involving the conjugate of a function, as in the following minimum working code example:
from petsc4py import PETSc
import dolfinx
import dolfinx.fem.petsc
import dolfinx.nls.petsc
import ufl
from mpi4py import MPI
mesh = dolfinx.mesh.create_unit_square(MPI.COMM_WORLD, 10, 10)
V = dolfinx.fem.functionspace(mesh, ("Lagrange", 1))
u = dolfinx.fem.Function(V)
v = ufl.TestFunction(V)
F = ufl.inner(ufl.grad(ufl.conj(u)), ufl.grad(v)) * ufl.dx
mesh.topology.create_connectivity(mesh.topology.dim-1, mesh.topology.dim)
boundary_facets = dolfinx.mesh.exterior_facet_indices(mesh.topology)
boundary_dofs = dolfinx.fem.locate_dofs_topological(V, mesh.topology.dim-1, boundary_facets)
bc = dolfinx.fem.dirichletbc(dolfinx.fem.Function(V), boundary_dofs)
ns_problem = dolfinx.fem.petsc.NonlinearProblem(F, u, bcs=bc)
newton_solver = dolfinx.nls.petsc.NewtonSolver(mesh.comm, ns_problem)
newton_solver.solve(u)
The error message I am having with this code is:
Traceback (most recent call last):
File "/app/fx4f/run_simulation.py", line 40, in <module>
run_simulation(simulation.main)
File "/app/fx4f/run_simulation.py", line 25, in run_simulation
main( logger, **kwargs )
File "/app/simulation.py", line 35, in main
ns_problem = dolfinx.fem.petsc.NonlinearProblem(F, u, bcs=bc)
File "/usr/local/dolfinx-complex/lib/python3.10/dist-packages/dolfinx/fem/petsc.py", line 907, in __init__
self._a = _create_form(
File "/usr/local/dolfinx-complex/lib/python3.10/dist-packages/dolfinx/fem/forms.py", line 249, in form
return _create_form(form)
File "/usr/local/dolfinx-complex/lib/python3.10/dist-packages/dolfinx/fem/forms.py", line 244, in _create_form
return _form(form)
File "/usr/local/dolfinx-complex/lib/python3.10/dist-packages/dolfinx/fem/forms.py", line 186, in _form
ufcx_form, module, code = jit.ffcx_jit(
File "/usr/local/dolfinx-complex/lib/python3.10/dist-packages/dolfinx/jit.py", line 51, in mpi_jit
return local_jit(*args, **kwargs)
File "/usr/local/dolfinx-complex/lib/python3.10/dist-packages/dolfinx/jit.py", line 201, in ffcx_jit
r = ffcx.codegeneration.jit.compile_forms([ufl_object], options=p_ffcx, **p_jit)
File "/usr/local/lib/python3.10/dist-packages/ffcx/codegeneration/jit.py", line 256, in compile_forms
impl = _compile_objects(
File "/usr/local/lib/python3.10/dist-packages/ffcx/codegeneration/jit.py", line 383, in _compile_objects
_, code_body = ffcx.compiler.compile_ufl_objects(
File "/usr/local/lib/python3.10/dist-packages/ffcx/compiler.py", line 108, in compile_ufl_objects
analysis = analyze_ufl_objects(ufl_objects, options["scalar_type"]) # type: ignore
File "/usr/local/lib/python3.10/dist-packages/ffcx/analysis.py", line 94, in analyze_ufl_objects
form_data = tuple(_analyze_form(form, scalar_type) for form in forms)
File "/usr/local/lib/python3.10/dist-packages/ffcx/analysis.py", line 94, in <genexpr>
form_data = tuple(_analyze_form(form, scalar_type) for form in forms)
File "/usr/local/lib/python3.10/dist-packages/ffcx/analysis.py", line 180, in _analyze_form
form_data = ufl.algorithms.compute_form_data(
File "/usr/local/lib/python3.10/dist-packages/ufl/algorithms/compute_form_data.py", line 427, in compute_form_data
check_form_arity(preprocessed_form, self.original_form.arguments(), complex_mode)
File "/usr/local/lib/python3.10/dist-packages/ufl/algorithms/check_arities.py", line 211, in check_form_arity
check_integrand_arity(itg.integrand(), arguments, complex_mode)
File "/usr/local/lib/python3.10/dist-packages/ufl/algorithms/check_arities.py", line 205, in check_integrand_arity
raise ArityMismatch(f"Argument {arg} is spuriously conjugated in complex Form")
ufl.algorithms.check_arities.ArityMismatch: Argument v_1 is spuriously conjugated in complex Form
My fenicsx version is 0.8.0, and I installed it using Docker. I am using my PETSc in complex mode, which was again set from the Dockerfile.
The code above is created only to represent the problem I am facing with my original code.
I don’t know how I am supposed to include the conjugate of a function in the variational formulation, and why I am getting this error. I would appreciate it if you could inform me about the usage of conjugates. Thank you in advance!