From 8cc815d4f2ebf56460f0f0f6f9195bf46afc968a Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Thu, 21 Jul 2022 22:24:17 -0500 Subject: [PATCH 1/2] Add numpy arrays to a list so they persist to the time of the VTK write --- openmc/mesh.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openmc/mesh.py b/openmc/mesh.py index 1fe5429d07..d08213f77d 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -248,8 +248,10 @@ class StructuredMesh(MeshBase): # create VTK arrays for each of # the data sets + datasets_out = [] for label, dataset in datasets.items(): dataset = np.asarray(dataset).flatten() + datasets_out.append(dataset) if volume_normalization: dataset /= self.volumes.flatten() @@ -692,7 +694,7 @@ class RegularMesh(StructuredMesh): root_cell.fill = lattice return root_cell, cells - + def write_data_to_vtk(self, filename, datasets, volume_normalization=True): """Creates a VTK object of the mesh @@ -1605,7 +1607,7 @@ class UnstructuredMesh(MeshBase): Raises ------ RuntimeError - when the size of a dataset doesn't match the number of cells + when the size of a dataset doesn't match the number of cells """ import vtk From 3b33fb830624d8c0e7959e6326214f52ae988eb0 Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 22 Jul 2022 07:55:22 -0500 Subject: [PATCH 2/2] Adding comment as suggested by @paulromano --- openmc/mesh.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/openmc/mesh.py b/openmc/mesh.py index d08213f77d..4af7018923 100644 --- a/openmc/mesh.py +++ b/openmc/mesh.py @@ -248,6 +248,10 @@ class StructuredMesh(MeshBase): # create VTK arrays for each of # the data sets + + # maintain a list of the datasets as added + # to the VTK arrays to ensure they persist + # in memory until the file is written datasets_out = [] for label, dataset in datasets.items(): dataset = np.asarray(dataset).flatten()