open file only once

This commit is contained in:
Martin Diehl 2021-04-05 15:58:10 +02:00
parent c3a7a85f7a
commit faa9e6aa6a
1 changed files with 20 additions and 21 deletions

View File

@ -1059,33 +1059,32 @@ class Result:
attributes = [] attributes = []
data_items = [] data_items = []
for inc in self.visible['increments']: with h5py.File(self.fname,'r') as f:
for inc in self.visible['increments']:
grid=ET.SubElement(collection,'Grid') grid=ET.SubElement(collection,'Grid')
grid.attrib = {'GridType': 'Uniform', grid.attrib = {'GridType': 'Uniform',
'Name': inc} 'Name': inc}
topology=ET.SubElement(grid, 'Topology') topology=ET.SubElement(grid, 'Topology')
topology.attrib={'TopologyType': '3DCoRectMesh', topology.attrib={'TopologyType': '3DCoRectMesh',
'Dimensions': '{} {} {}'.format(*self.cells+1)} 'Dimensions': '{} {} {}'.format(*self.cells+1)}
geometry=ET.SubElement(grid, 'Geometry') geometry=ET.SubElement(grid, 'Geometry')
geometry.attrib={'GeometryType':'Origin_DxDyDz'} geometry.attrib={'GeometryType':'Origin_DxDyDz'}
origin=ET.SubElement(geometry, 'DataItem') origin=ET.SubElement(geometry, 'DataItem')
origin.attrib={'Format': 'XML', origin.attrib={'Format': 'XML',
'NumberType': 'Float', 'NumberType': 'Float',
'Dimensions': '3'} 'Dimensions': '3'}
origin.text="{} {} {}".format(*self.origin) origin.text="{} {} {}".format(*self.origin)
delta=ET.SubElement(geometry, 'DataItem') delta=ET.SubElement(geometry, 'DataItem')
delta.attrib={'Format': 'XML', delta.attrib={'Format': 'XML',
'NumberType': 'Float', 'NumberType': 'Float',
'Dimensions': '3'} 'Dimensions': '3'}
delta.text="{} {} {}".format(*(self.size/self.cells)) delta.text="{} {} {}".format(*(self.size/self.cells))
with h5py.File(self.fname,'r') as f:
attributes.append(ET.SubElement(grid, 'Attribute')) attributes.append(ET.SubElement(grid, 'Attribute'))
attributes[-1].attrib={'Name': 'u / m', attributes[-1].attrib={'Name': 'u / m',
'Center': 'Node', 'Center': 'Node',