diff options
-rwxr-xr-x | pyfrm2xdmf | 42 |
1 files changed, 23 insertions, 19 deletions
@@ -37,30 +37,34 @@ def writeGeometry(xdmfFile, nDims, nCells, nVerts, pyfrm, dataset): xdmfFile.write(' <Geometry GeometryType="X_Y">\n') # co-ordinates in separate arrays else: xdmfFile.write(' <Geometry GeometryType="X_Y_Z">\n') # co-ordinates in separate arrays - writeHyperSlab(xdmfFile, nDims, nCells, nVerts, pyfrm, dataset) + for coord in range(nDims): + xdmfFile.write(' <DataItem ItemType="Function" Dimensions="{}"\n'.format(nVerts*nCells)) # 1D-array + xdmfFile.write(' Function="JOIN({})">\n'.format(' ; '.join("$" + str(k) for k in range(nVerts)))) + writeHyperSlab(xdmfFile, coord, nDims, nCells, nVerts, pyfrm, dataset) + xdmfFile.write(' </DataItem>\n') xdmfFile.write(' </Geometry>\n') return -def writeHyperSlab(xdmfFile, nDims, nCells, nVerts, pyfrm, dataset): +def writeHyperSlab(xdmfFile, coord, nDims, nCells, nVerts, pyfrm, dataset): "write HyperSlab element" - for coord in range(nDims): - xdmfFile.write(' <DataItem ItemType="HyperSlab"\n') - xdmfFile.write(' Dimensions="{} 1 1"\n'.format(nCells*nVerts)) - xdmfFile.write(' Type="HyperSlab">\n') - xdmfFile.write(' <DataItem\n') # start, stride and count of hyperslab region - xdmfFile.write(' Dimensions="3 3"\n') - xdmfFile.write(' Format="XML">\n') - xdmfFile.write(' 0 0 {}\n'.format(coord)) # select co-ordinate - xdmfFile.write(' 1 1 1\n') # select every vertex in every cell - xdmfFile.write(' {:<3} {} 1\n'.format(nVerts, nCells)) # loop over cells (first) and vertices (second) - xdmfFile.write(' </DataItem>\n') - xdmfFile.write(' <DataItem\n') - xdmfFile.write(' Name="Points" \n') - xdmfFile.write(' Dimensions="{} {} {}"\n'.format(nVerts, nCells, nDims)) - xdmfFile.write(' Format="HDF">\n') - xdmfFile.write(' {}:/{}\n'.format(pyfrm, dataset)) + for vert in range(nVerts): + xdmfFile.write(' <DataItem ItemType="HyperSlab"\n') + xdmfFile.write(' Dimensions="{} 1 1"\n'.format(nCells)) + xdmfFile.write(' Type="HyperSlab">\n') + xdmfFile.write(' <DataItem\n') # start, stride and count of hyperslab region + xdmfFile.write(' Dimensions="3 3"\n') + xdmfFile.write(' Format="XML">\n') + xdmfFile.write(' {:<3} 0 {}\n'.format(vert, coord)) # select vertex and co-ordinate (format is vertex, cell, co-ordinate) + xdmfFile.write(' 1 1 1\n') # select every cell, for this vertex and co-ordinate + xdmfFile.write(' 1 {} 1\n'.format(nCells)) # loop over cells + xdmfFile.write(' </DataItem>\n') + xdmfFile.write(' <DataItem\n') + xdmfFile.write(' Name="Points" \n') + xdmfFile.write(' Dimensions="{} {} {}"\n'.format(nVerts, nCells, nDims)) + xdmfFile.write(' Format="HDF">\n') + xdmfFile.write(' {}:/{}\n'.format(pyfrm, dataset)) + xdmfFile.write(' </DataItem>\n') xdmfFile.write(' </DataItem>\n') - xdmfFile.write(' </DataItem>\n') return def writeAttribute(xdmfFile, tag): |