Fenicsx - Complex Numbers

Hello guys,

I am new to Fenicsx and I am testing examples to understand how Fenicsx works before using it for my projects.
I installed fenicsx following the Nguyen Lab Wiki - fenicsx – Nguyen Lab Wiki
On windows, using WSL and Ubuntu I created a conda env for fenicsx. However I cannot run complex number problems and I saw there were many discussion on it here. Unfortunately they did not help me.
The Poisson problem with complex numbers — FEniCSx tutorial this is the example I am trying and it would be great if someone could help me get the complex numbers working. Since i did not go through docker I don’t know if there is another way to get it working.

The problem is I do not get this output
<class 'numpy.complex128'>
instead i get float64.
This is the code:

from petsc4py import PETSc
from dolfinx.fem.petsc import assemble_vector
print(PETSc.ScalarType)

Thanks everyone for helping.

Should be as simple as

conda install -c conda-forge fenics-dolfinx mpich petsc=*=complex*

which is mentioned several times in this forum, for instance at Conda install dolfinx for complex-valued problem

Hey @francesco-ballarin, thanks for the help. I did manage to get the complex-valued problems solved with the command you mentioned. However, I was wondering if there is a way to get the complex-problem solving capabilities into the fenicsx env itself rather than a new env, because there are some functionalities that I am missing when I create 2 separate envs.
For example, plotting solutions using pyvista.

I am not a conda user myself, but I’d say that installing again whatever functionality you are currently missing is the easiest solution.

1 Like

As Francesco said, you can install the remaining dependencies in the new (complex valued) conda environment. If you want it in an env called fenicsx-env, then remove the existing env, create a new one and call:
conda install -c conda-forge fenics-dolfinx mpich petsc=*=complex* pyvista matplotlib cycler so that you get the remaining deps. Alternatively, call:
conda install -c conda-forge pyvista matplotlib cycler in the environment that has the complex version of DOLFINx.

1 Like

Thank you @dokken & @francesco-ballarin !! I managed to get the remaining dependencies installed this way.