reverts previous commit & append adds new attribute to single xdmf file!
This commit is contained in:
parent
abd7b0c4f5
commit
fcadbd2e5d
|
|
@ -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,16 +448,18 @@ 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
|
||||
fid = open(file_xdmf,'w')
|
||||
fid.write('<?xml version="1.0"?>\n')
|
||||
fid.write('<Xdmf Version="2.0">\n')
|
||||
fid.write(' <Domain>\n')
|
||||
fid.write(' <Grid Name="{}" GridType="Collection" CollectionType="Spatial">\n'.format(key))
|
||||
# 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')
|
||||
fid.write(' <Domain>\n')
|
||||
fid.write(' <Grid Name="{}" GridType="Collection" CollectionType="Spatial">\n'.format(key))
|
||||
#fid.write(' <Time Value="%.2f" />\n',params.general.simtime)
|
||||
# Get ghost cell setup
|
||||
if keepAllGhost:
|
||||
|
|
@ -491,22 +486,43 @@ class ibmppp:
|
|||
nxl = ie-ib+1+2*nghx
|
||||
nyl = je-jb+1+2*nghy
|
||||
nzl = ke-kb+1+2*nghz
|
||||
# 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))
|
||||
fid.write(' <Geometry Origin="" Type="ORIGIN_DXDYDZ">\n')
|
||||
fid.write(' <DataItem DataType="Float" Dimensions="3" Format="XML" Precision="8"> {:12f} {:12f} {:12f}</DataItem>\n'.format(z0,y0,x0))
|
||||
fid.write(' <DataItem DataType="Float" Dimensions="3" Format="XML" Precision="8"> {:12f} {:12f} {:12f}</DataItem>\n'.format(dx,dx,dx))
|
||||
fid.write(' </Geometry>\n')
|
||||
fid.write(' <Attribute Name="{}" Dimensions="{:d} {:d} {:d}">\n'.format(key,nzl,nyl,nxl))
|
||||
fid.write(' <DataItem Format="HDF5" DataType="Float" Dimensions="{:d} {:d} {:d}">\n'.format(nzl,nyl,nxl))
|
||||
fid.write(' {}:/{}/data </DataItem>\n'.format(subfile,key))
|
||||
fid.write(' </Attribute>\n')
|
||||
fid.write(' </Grid>\n')
|
||||
# Write footer and close file
|
||||
fid.write(' </Grid>\n')
|
||||
fid.write(' </Domain>\n')
|
||||
fid.write('</Xdmf> \n')
|
||||
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))
|
||||
fid.write(' <Geometry Origin="" Type="ORIGIN_DXDYDZ">\n')
|
||||
fid.write(' <DataItem DataType="Float" Dimensions="3" Format="XML" Precision="8"> {:12f} {:12f} {:12f}</DataItem>\n'.format(z0,y0,x0))
|
||||
fid.write(' <DataItem DataType="Float" Dimensions="3" Format="XML" Precision="8"> {:12f} {:12f} {:12f}</DataItem>\n'.format(dx,dx,dx))
|
||||
fid.write(' </Geometry>\n')
|
||||
fid.write(' <Attribute Name="{}" Dimensions="{:d} {:d} {:d}">\n'.format(key,nzl,nyl,nxl))
|
||||
fid.write(' <DataItem Format="HDF5" DataType="Float" Dimensions="{:d} {:d} {:d}">\n'.format(nzl,nyl,nxl))
|
||||
fid.write(' {}:/{}/data </DataItem>\n'.format(subfile,key))
|
||||
fid.write(' </Attribute>\n')
|
||||
fid.write(' </Grid>\n')
|
||||
# Write footer and close file
|
||||
fid.write(' </Grid>\n')
|
||||
fid.write(' </Domain>\n')
|
||||
fid.write('</Xdmf> \n')
|
||||
fid.close()
|
||||
|
||||
def saveFieldOriginal(self,filename,key,append=False,xdmf=False):
|
||||
|
|
|
|||
Loading…
Reference in New Issue