A question regarding the complex support of FEniCSx

When I was studying the solution code for the Helmholtz equation, the tutorial mentioned, “This example is designed to be executed with complex-valued degrees of freedom. To be able to solve this problem, we use the complex build of PETSc.”

I first executed the code from the tutorial.

from mpi4py import MPI

import numpy as np

import dolfinx.fem.petsc
import ufl

import sys

from petsc4py import PETSc

if not np.issubdtype(PETSc.ScalarType, np.complexfloating):
    print("This tutorial requires complex number support")
    sys.exit(0)
else:
    print(f"Using {PETSc.ScalarType}.")

The output result is as follows:‘This tutorial requires complex number support.’

Next, I executed this code in the terminal according to the tutorial provided on the official website.PETSC_DIR=/usr/lib/petscdir/petsc-complex python3 Helmholtz_equation2.py
The output result is as follows:‘Using <class ‘numpy.complex128’>.’

However, when I ran the tutorial’s code again, the output changed back to ‘This tutorial requires complex number support.’

Therefore, I am confused as to whether the system’s variable is complex or real when I run the subsequent code.Do I need to run ‘PETSC_DIR=/usr/lib/petscdir/petsc-complex python3 Helmholtz_equation2.py’ in the terminal again after the entire code has executed?

I am looking forward to your response and would be immensely grateful.

PETSC_DIR is an environment variable.

You can learn more about them in a linux tutorial, e.g.