Read HDF5 file with a segmentation error
I am solving a linear heat equation with a point source. Within the code, I want to save the gradient of temperature, grad(u). This is how I saved it:
# load mesh from abaqus input mesh=Mesh('HC_80umnew.xml') V = FunctionSpace(mesh, 'P', 1) u = TrialFunction(V) v = TestFunction(V) # define function space VV = VectorFunctionSpace(mesh, 'P', 1) # rhs L=-dt*(dot(grad(u0), grad(v))*dx - f*v*dx) # lhs a=u*v*dx # Prepare solution function and solver u = Function(V) grad_u = HDF5File(mpi_comm_world(),'../results/gradu_HC.h5','w') # within the main code for time loop ii=1 for i in range(0,10): ii+=1 # long code here to solve the variation form ... # after solve the u field. want to save the grad(u) gradu = project(grad(u),VV, solver_type="cg") grad_u.write(gradu,'/%d/delu/%d'%(1,ii))
When reading the file, I did this:
# load mesh from abaqus input mesh1=Mesh('HC_80umnew.xml') # define function space V1= FunctionSpace(mesh1, 'P', 1) # Define function for solution at previous time-step gradu=Function(V1) grad_u = HDF5File(mpi_comm_world(),'../results/gradu_HC.h5','r') # within a for loop for n- timesteps for i in range(1,10): grad_u.read(gradu,'/1/delu/%d'%(i)) gradient= gradu(37.855/5.0-0.03-0.006*i,0.0,-1.99/5.0) # gradient at a specific position
Then I got the error;
Segmentation fault (core dumped)
First of all I don't think it is a ram problem since the grad_u file I saved is below 10 GB and I can load a larger file (20GB) without a problem.
Probably when I load it, I shouldn't define gradu as a Function since it is projected data? Or doesn't anyone know a better way to save the gradient field of a thermal problem?
Any help will be highly appreciated!!
for i in range(1,10): grad_u.read(gradu,'/1/delu/%d'%(n))
Ok, the real problem is that gradu is a vector function, but when reading you try to store it a scalar function.