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/main_sp.py", line 143, in <module> K = fem.assemble_matrix(kc, bcs=[bc]) File "/usr/lib/python3.10/functools.py", line 889, in wrapper return dispatch(args.__class__)(*args, **kw) File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/fem/assemble.py", 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/assemble.py", 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/la.py", line 81, in matrix_csr return matrixcls(sp) File "/usr/lib/petscdir/petsc3.15/x86_64-linux-gnu-complex/lib/python3/dist-packages/dolfinx/la.py", line 54, in __init__ super().__init__(sp) 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 python3 run_script_in_real_mode.py source dolfinx-complex-mode python3 run_script_in_complex_mode.py
We also have docker images running JupyterLab, where you can select either the
complex kernel. See for instance:
Kernel->Change Kernel and select the appropriate kernel (The default kernel is DOLFINx in real mode). This can also be achieved with the
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.