Create a complex petsc matrix from a dolfinx.cpp.fem.Form_float64

Dear community,

I am using a complex build of PETSc and I would like to compute the complex PETSc matrix associated to a real bilinear form of type dolfinx.cpp.fem.Form_float64.

The reason behind this it is because the underlying formulation is real and contains ufl.conditional which are not defined for complex forms. Then, I would like to solve an eigenvalue problem with a complex shift, so for this reason I use a complex build of PETSc. However, when using a complex build _cpp.fem.petsc.create_matrix or dolfinx.fem.petsc.assemble_matrix expects a dolfinx.cpp.fem.Form_complex128.

Is there a way to cast a dolfinx.cpp.fem.Form_float64 to a dolfinx.cpp.fem.Form_complex128 ? Or do you know of any other way to compute the associated PETSc matrix, even if it is real-valued, because I could then do the cast to complex-values.

Thanks!

Could you provide a minimal working example? Most likely you could use ufl.real within the conditional to make it work.