Read HDF5 file with a segmentation error


124
views
0
12 weeks ago by
Peipei  
Hello Everyone,

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!!


Community: FEniCS Project
What do you mean by "upload"?
You can also try TimeSeries instead of HDF5File -- it's simpler and suited for what you're trying (store/retrieve timeseries of functions).
written 12 weeks ago by David Nolte  
Thanks for the reply, David!   

Sorry. I meant load instead of upload. 

I'll try Timeseries as you suggested. (But personally I don't think it will work since I can load another hdf5 without the segmentation problem and that hdf5 file is even larger.)
written 12 weeks ago by Peipei  
1
I don't see why the segmentation fault should be caused by the file size, normally it's due to memory access violations.
Anyways, you made an error with the indices, see answer below
written 12 weeks ago by David Nolte  
Thanks! Thought segmentation error is a RAM problem.

I can read the hdf5 file grad_u, just can't write it to the Function gradu i defined. if it is due to memory access violations, maybe their data formats don't match?
written 12 weeks ago by Peipei  

1 Answer


3
12 weeks ago by
In your code, you iterate over i, but try to load function index 'n'
for i in range(1,10):

    grad_u.read(gradu,'/1/delu/%d'%(n))​


edit:
Ok, the real problem is that gradu is a vector function, but when reading you try to store it a scalar function.

Thanks for the correction! The loop index in my original code is correct. The original code is kind of long so I typed a small fraction to the above and made a mistake here. Just corrected it.

But the segmentation error is due to the index.
written 12 weeks ago by Peipei  
1
You seem to be contradicting yourself.
Anyways, I just realized that the function you write, gradu, is from a VectorFunctionSpace and the reading function is from a scalar FunctionSpace. If you replace V1 by the VV in the second code, it should work.
written 12 weeks ago by David Nolte  
Ahhh... I meant the segmentation error is not due to the index....

I just changed V1 to VectorFunctionSpace and the code is working now!!!

Thanks a lot, David!
written 12 weeks ago by Peipei  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »