Unexpected behavior of "Function" when dtype of mesh is f32

If I define a mesh with:

domain = create_box(comm=MPI.COMM_WORLD, points= [(-L/2, -L/2, 0), ( L/2, L/2, t) ], n= [Nx,Ny,Nz], dtype=np.float32)

then the following code:

from dolfinx.fem import functionspace, Function
H = functionspace( mesh=domain,element=("Lagrange",1))
Q = Function(H)

returns the following error:

Traceback (most recent call last):
  File "/home/manuel/Documentos/MultiPhysics/src/clean_plate.py", line 56, in <module>
    Q = Function(H)
        ^^^^^^^^^^^
  File "/usr/lib/petsc/lib/python3/dist-packages/dolfinx/fem/function.py", line 339, in __init__
    assert np.issubdtype(
           ^^^^^^^^^^^^^^
AssertionError: Incompatible FunctionSpace dtype and requested dtype.

which does not happen if I set np.float64 as the dtype instead.

I don’t know if this is the expected behaviour and I’m doing something wrong.

You need to give Q the correct dtype as well. This also holds for constant and form.