Simultaneous installation of real and complex builds

I am new to fenics and still finding my way. I appreciate this has been an open issue for a while. I have what seems like a fairly common task which is to approximate with either a real or complex eigen system depending on what is found. I can tackle it with separate python processes and handling the IO or by dropping down to C with a single process but would prefer a single python process. Has a reasonable way of achieving this arisen since the issue was posted?

The only bit in DOLFINx that does not support mixed floating types is PETSc. See for instance: Solving PDEs with different scalar (float) types — DOLFINx 0.5.1 documentation

Thanks for the suggestion to use the solvers in scipy which might be an easier approach during the initial development phase on a workstation. Unfortunately I am getting the following error:

Traceback (most recent call last):
  File "/home/andy/work/fenicsx/modanal/", line 143, in <module>
    K = fem.assemble_matrix(kc, bcs=[bc])
  File "/usr/lib/python3.10/", line 889, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/fem/", line 273, in _assemble_matrix_form
    A: la.MatrixCSRMetaClass = create_matrix(a)
  File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/fem/", line 97, in create_matrix
    return la.matrix_csr(sp, dtype=a.dtype)
  File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/", line 81, in matrix_csr
    return matrixcls(sp)
  File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/", line 54, in __init__
RuntimeError: Block size not yet supported

which has been seen before with the work around to use petsc. I am also initially looking at elasticity problems.

If you want to have both builds installed and use PETSc, you can use the docker images, dolfinx/dolfinx:v0.6.0-r1 and use source dolfinx-real-mode and source dolfinx-complex-mode to switch between real and complex mode.

Thanks for the suggestion. I know little about how docker files work and so to check I have things straight: sourcing the docker script within a running python script via something like os.system(‘source dolfinx-real-mode’) plus a bit of fiddling with reloading will switch the petsc/slepc/dolfinx libraries the running python process is using? I will not have to leave the python script and perform something equivalent to changing the PETSC_DIR environment variable which currently works but is inconvenient.

You should execute this outside of the python code, as PYTHONPATHs do not get updated properly with os.system. So workflow would be:

source dolfinx-real-mode
source dolfinx-complex-mode

We also have docker images running JupyterLab, where you can select either the real or complex kernel. See for instance:

Navigate to Kernel->Change Kernel and select the appropriate kernel (The default kernel is DOLFINx in real mode). This can also be achieved with the dolfinx/lab:v0.6.0-r1 images.

Thanks for the clarification. The proposed solution doesn’t address my wish to solve real and complex problems with shared data from the same python script. It is not a stopper since I can write out the data, start another python script in the desired mode, read the data back and continue (or some equivalent) but it is less than ideal.

We’re missing some functionality in the native DOLFINx CSR matrix, especially for blocked problems like elasticity. Support should be finished in the next few weeks. It will then be possible to solve more problems using different scalar types from the same script.

1 Like