From c98547931d611bc5d5dd754ef29594b863f28eb9 Mon Sep 17 00:00:00 2001 From: Paul Garlick <pgarlick@tourbillion-technology.com> Date: Thu, 17 Mar 2016 20:40:18 +0000 Subject: pyfrm2xdmf: add Function DataItem to allow concatenation of 1D-arrays --- pyfrm2xdmf | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) (limited to 'pyfrm2xdmf') diff --git a/pyfrm2xdmf b/pyfrm2xdmf index b7e1be3..7b88716 100755 --- a/pyfrm2xdmf +++ b/pyfrm2xdmf @@ -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): -- cgit