From fb65dfd53cf8de6a360e23234bcc77f6a1d1f3c2 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 14 Dec 2023 10:49:59 -0600 Subject: [PATCH] Avoid high memory use when writing unstructured mesh VTK files (#2806) --- openmc/mesh.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index f3cd69a8f39..435a44d2c8a 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -2181,7 +2181,6 @@ def write_data_to_vtk( grid.SetPoints(vtk_pnts) n_skipped = 0 - elems = [] for elem_type, conn in zip(self.element_types, self.connectivity): if elem_type == self._LINEAR_TET: elem = vtk.vtkTetra() @@ -2195,15 +2194,13 @@ def write_data_to_vtk( if c == -1: break elem.GetPointIds().SetId(i, c) - elems.append(elem) + + grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) if n_skipped > 0: warnings.warn(f'{n_skipped} elements were not written because ' 'they are not of type linear tet/hex') - for elem in elems: - grid.InsertNextCell(elem.GetCellType(), elem.GetPointIds()) - # check that datasets are the correct size datasets_out = [] if datasets is not None: