[petsc-users] Load dense matrices from hdf5

Smith, Barry F. bsmith at mcs.anl.gov
Fri Nov 30 16:47:31 CST 2018


    I would start by simply using the PETSc binary dense format for the matrices; it will work find for 1d (and 2d) development work with dozens of processes. Latter, if need be, you can switch to the HDF5, the only difference in your code would be the viewer you MatLoad() from will be an HDF5 file instead of a PETSc binary file.

    The format of a PETSc binary dense file is 

    4 integer values (the header) followed by the matrix as one contiguous array of doubles (stored by row). The header is of the form

    MAT_FILE_CLASSID, M, N, -1    (where M and N are number of rows and columns in the matrix.)

    You can easily create this file from Python (which I assume is where you are getting your h(t) values from).

    Barry


> On Nov 30, 2018, at 4:27 PM, Sajid Ali via petsc-users <petsc-users at mcs.anl.gov> wrote:
> 
> Hi, 
> 
> I'm trying to solve the Helmholtz equation in 1D for x-rays which roughly like :
> 
> u_dot = a*u_xx + h(t)*u 
> 
> I've already implemented the case where h(t) is always zero (free-space) in PETSc as per the last box on page 156 of the manual.
> 
> For the time dependent version of the same the next step is to modify the RHSMatrix by adding h(t) via MatDiagonalSet&Insert. (With h(t)=0, the RHS matrix is just a (scaled) Laplacian matrix)
> 
> The h(t) is related to x-ray refractive index at that time. These x-ray indices need to be (preferably) stored in matrix beforehand. Each column of the matrix would be the refractive index to be used in one iteration. Using hdf5 is something I'd like to do because I can make/view the grid using numpy in python and solve the PDE using PETSc in C. 
> 
> PS: I've seen past questions on this thread strongly discouraging users from storing dense matrices in hdf5 format. 
> 
> PPS : This 1D x-ray scattering problem is just a stepping stone to doing the same in 2D so if there's a better approach to adopt, I'm be open to new ideas. 
> 
> Thank You, 
> Sajid Ali
> Applied Physics
> Northwestern University



More information about the petsc-users mailing list