Convert .xml to .hd5 format


295
views
0
6 months ago by
Ovais  
Hi there ,
I am working on a fenics 1.6.0 code that requires input in hd5 format where as the fiber orientations that i have are in .xml format
the code utilizes hd5 file as under:-
def Load(h5name, h5group, func):
	group1 = "{}/function".format(h5group)

    # Open file and read
	with HDF5File(mpi_comm_world(), h5name, "r") as h5file:
		h5file.read(func, group1)

FiberSpace = VectorFunctionSpace(mesh,'Quadrature',2) # "Quadrature" with degrees of freedom being function evaluations at quadrature points
													  # using the standard FiniteElement leads to a poor convergence whereas the QuadratureElement 
													  # still leads to quadratic convergence	
f_0 = Function(FiberSpace) 	# fiber direction
s_0 = Function(FiberSpace) 	# sheet vector
n_0 = Function(FiberSpace) 	# sheet normal
Load('fiberfield.h5','f_0',f_0)
Load('fiberfield.h5','s_0',s_0)
Load('fiberfield.h5','n_0',n_0)​

My fiberfield is in .xml format . Is there any easy way to convert my .xml file to .hd5 format ?

Please do advise
thanks.
Community: FEniCS Project

2 Answers


2
6 months ago by

may be this will help...

mesh = Mesh('mesh.xml')
# if have subdomains...
#subdomains = MeshFunction("size_t", mesh, "cube_physical_region.xml")    
hdf = HDF5File(mesh.mpi_comm(), "file.h5", "w")
hdf.write(mesh, "/mesh")
# if have sudomains from gmsh...
#hdf.write(subdomains, "/subdomains")


mesh = Mesh()
hdf = HDF5File(mesh.mpi_comm(), "file.h5", "r")
hdf.read(mesh, "/mesh", False)
#subdomains = CellFunction("size_t", mesh)
#hdf.read(subdomains, "/subdomains")​
0
6 months ago by
RR  
This was answeared quite often in the old FEniCS Q/A, have a look here:

https://fenicsproject.org/qa/5337/importing-marked-mesh-for-parallel-use/

or here:

https://fenicsproject.org/qa/12431/reading-hdf5-file-with-fenics-2016-2/
Please login to add an answer/comment or follow this question.

Similar posts:
Search »