reverts previous commit & append adds new attribute to single xdmf file!

This commit is contained in:
Tiago Pestana 2020-09-16 22:15:42 +02:00
parent abd7b0c4f5
commit fcadbd2e5d
1 changed files with 47 additions and 31 deletions

View File

@ -417,11 +417,6 @@ class ibmppp:
ioflag = 'a'
else:
ioflag = 'w'
# get information about origin and grid spacing
delta = [self.__dx[key], self.__dx[key], self.__dx[key]]
origin = [self.grid[key][0][ib-1]-nghx*dx, \
self.grid[key][1][jb-1]-nghy*dx, \
self.grid[key][2][kb-1]-nghz*dx]
# Open the file and write data, then close it because we are done
fid = h5py.File(file_chunk,ioflag)
if not append:
@ -432,8 +427,6 @@ class ibmppp:
fid.create_dataset('nxproc',data=self.__nxp)
fid.create_dataset('nyproc',data=self.__nyp)
fid.create_dataset('nzproc',data=self.__nzp)
fid.create_dataset('origin',data=origin)
fid.create_dataset('delta',data=delta)
gid = fid.create_group('/'+key)
gid.create_dataset('ib',data=self.__localChunkBounds[key][0])
gid.create_dataset('ie',data=self.__localChunkBounds[key][1])
@ -455,11 +448,13 @@ class ibmppp:
did.attrs['F_CONTIGUOUS'] = 1
did.attrs['DIM'] = (self.__localChunkSize[key][0]+2*nghx,self.__localChunkSize[key][1]+2*nghy,self.__localChunkSize[key][2]+2*nghz)
fid.close()
# Create an XDMF file for the field
# Create an XDMF file for the field --> if append write only attribute
if xdmf and self.__rank==0:
# Construct XDMF filename
file_xdmf = filename+'_'+key+'.xdmf'
# Open file and write header
# file_xdmf = filename+'_'+key+'.xdmf'
file_xdmf = filename+'.xdmf'
# Open file and write header; or skip if appending
if not append:
fid = open(file_xdmf,'w')
fid.write('<?xml version="1.0"?>\n')
fid.write('<Xdmf Version="2.0">\n')
@ -491,6 +486,27 @@ class ibmppp:
nxl = ie-ib+1+2*nghx
nyl = je-jb+1+2*nghy
nzl = ke-kb+1+2*nghz
if append:
#find where the Geometry ends... and add new attribute
fid = open(file_xdmf,'r')
lines = fid.readlines()
fid.close()
lnb=0
for i in lines:
logical = "</Geometry>" in i
if logical:
newAttrb = ' <Attribute Name="{}" Dimensions="{:d} {:d} {:d}">\n'.format(key,nzl,nyl,nxl)
newAttrb += ' <DataItem Format="HDF5" DataType="Float" Dimensions="{:d} {:d} {:d}">\n'.format(nzl,nyl,nxl)
newAttrb += ' {}:/{}/data </DataItem>\n'.format(subfile,key)
newAttrb += ' </Attribute>\n'
break
lnb+=1
fid = open(file_xdmf,'w')
fid.writelines(lines[0:lnb+1])
fid.write(newAttrb)
fid.writelines(lines[lnb+1:])
fid.close()
else:
# Write XDMF for this processor
fid.write(' <Grid Name="rank {:5d} position {:3d},{:3d},{:3d}">\n'.format(iprank,iproc,jproc,kproc))
fid.write(' <Topology TopologyType="3DCORECTMesh" NumberOfElements="{:d} {:d} {:d}"/>\n'.format(nzl,nyl,nxl))