def rand_scal_eta(x):
return StSt[0]+perm*(np.random.rand(x.shape[1])-np.random.rand(x.shape[1]))
def Initial_eta(out):
#perm and StSt must be declared as global
out.interpolate(rand_scal_eta)
return out
x0=0
y0=0
xm=10
ym=10
nx=10
ny=10
r_mesh=mesh.create_rectangle(MPI.COMM_WORLD,(np.array([x0,y0]),np.array([xm,ym])),(nx,ny), mesh.CellType.triangle)
V = fem.FunctionSpace(r_mesh, ('Lagrange',1))
u= fem.Function(V)
global perm, StSt
StSt=[0,1]
perm=0.1
u=Initial_eta(u)
xdmf=io.XDMFFile(r_mesh.comm,"var.xdmf","w")
xdmf.write_mesh(r_mesh)
xdmf.write_function(u,0)
I get the Output:
HDF5-DIAG: Error detected in HDF5 (1.12.1) MPI-process 0: #000: H5F.c line 532 in H5Fcreate(): unable to create file
major: File accessibility
minor: Unable to open file #001: H5VLcallback.c line 3282 in H5VL_file_create(): file create failed
major: Virtual Object Layer
minor: Unable to create file #002: H5VLcallback.c line 3248 in H5VL__file_create(): file create failed
major: Virtual Object Layer
minor: Unable to create file #003: H5VLnative_file.c line 63 in H5VL__native_file_create(): unable to create file
major: File accessibility
minor: Unable to open file #004: H5Fint.c line 1858 in H5F_open(): unable to truncate a file which is already open
major: File accessibility
minor: Unable to open file
RuntimeError Traceback (most recent call last)
Input In [7], in <cell line: 1>()
----> 1 xdmf=io.XDMFFile(r_mesh.comm,“var.xdmf”,“w”)
2 xdmf.write_mesh(r_mesh)
3 xdmf.write_function(u,0)
RuntimeError: Failed to create HDF5 file.
I cannot reproduce the error on my PC. However, a similar error has been reported in the post below. It seems to be related to MPI. How are you running your code?