From 3e2ec4f9786fb77e8265495bafe10bb0f39eb990 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 30 Aug 2024 13:57:20 -0400 Subject: [PATCH 1/3] store coord_type in the output file + fix reading this allows us to plot the output again --- pyro/mesh/patch.py | 5 +++++ pyro/util/io_pyro.py | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pyro/mesh/patch.py b/pyro/mesh/patch.py index f31dc13c2..0afa05cd0 100644 --- a/pyro/mesh/patch.py +++ b/pyro/mesh/patch.py @@ -755,6 +755,11 @@ def write_data(self, f): ggrid.attrs["ymin"] = self.grid.ymin ggrid.attrs["ymax"] = self.grid.ymax + try: + ggrid.attrs["coord_type"] = self.grid.coord_type + except KeyError: + pass + # data gstate = f.create_group("state") diff --git a/pyro/util/io_pyro.py b/pyro/util/io_pyro.py index a75a245e5..81823e751 100644 --- a/pyro/util/io_pyro.py +++ b/pyro/util/io_pyro.py @@ -6,7 +6,7 @@ import h5py import pyro.mesh.boundary as bnd -from pyro.mesh.patch import CellCenterData2d, Grid2d +from pyro.mesh.patch import CellCenterData2d, Cartesian2d, SphericalPolar from pyro.particles import particles @@ -48,9 +48,14 @@ def read(filename): # read in the grid info and create our grid grid = f["grid"].attrs - myg = Grid2d(grid["nx"], grid["ny"], ng=grid["ng"], - xmin=grid["xmin"], xmax=grid["xmax"], - ymin=grid["ymin"], ymax=grid["ymax"]) + if grid["coord_type"] == 0: + grid_class = Cartesian2d + elif grid["coord_type"] == 1: + grid_class = SphericalPolar + + myg = grid_class(grid["nx"], grid["ny"], ng=grid["ng"], + xmin=grid["xmin"], xmax=grid["xmax"], + ymin=grid["ymin"], ymax=grid["ymax"]) # sometimes problems define custom BCs -- at the moment, we # are going to assume that these always map to BC.user. We From 684682dab74d872c84f8d6301f36f6493f524097 Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 30 Aug 2024 14:34:53 -0400 Subject: [PATCH 2/3] fix access --- pyro/mesh/patch.py | 2 +- pyro/util/io_pyro.py | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pyro/mesh/patch.py b/pyro/mesh/patch.py index 0afa05cd0..1b5d6997b 100644 --- a/pyro/mesh/patch.py +++ b/pyro/mesh/patch.py @@ -757,7 +757,7 @@ def write_data(self, f): try: ggrid.attrs["coord_type"] = self.grid.coord_type - except KeyError: + except AttributeError: pass # data diff --git a/pyro/util/io_pyro.py b/pyro/util/io_pyro.py index 81823e751..d3812b4f8 100644 --- a/pyro/util/io_pyro.py +++ b/pyro/util/io_pyro.py @@ -48,10 +48,15 @@ def read(filename): # read in the grid info and create our grid grid = f["grid"].attrs - if grid["coord_type"] == 0: - grid_class = Cartesian2d - elif grid["coord_type"] == 1: + try: + coord_type = grid["coord_type"] + except KeyError: + coord_type = 0 + + if coord_type == 1: grid_class = SphericalPolar + else: + grid_class = Cartesian2d myg = grid_class(grid["nx"], grid["ny"], ng=grid["ng"], xmin=grid["xmin"], xmax=grid["xmax"], From eb9552993447744c5a4a63abd3b189b9b4fee04f Mon Sep 17 00:00:00 2001 From: Michael Zingale Date: Fri, 30 Aug 2024 14:36:45 -0400 Subject: [PATCH 3/3] fix isort --- examples/mesh/bc_demo.py | 3 +-- pyro/util/io_pyro.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/examples/mesh/bc_demo.py b/examples/mesh/bc_demo.py index 6b198fd3b..3521d7fee 100644 --- a/examples/mesh/bc_demo.py +++ b/examples/mesh/bc_demo.py @@ -1,10 +1,9 @@ # test the boundary fill routine -import numpy as np - import mesh.boundary as bnd import mesh.patch +import numpy as np def doit(): diff --git a/pyro/util/io_pyro.py b/pyro/util/io_pyro.py index d3812b4f8..8188b53b3 100644 --- a/pyro/util/io_pyro.py +++ b/pyro/util/io_pyro.py @@ -6,7 +6,7 @@ import h5py import pyro.mesh.boundary as bnd -from pyro.mesh.patch import CellCenterData2d, Cartesian2d, SphericalPolar +from pyro.mesh.patch import Cartesian2d, CellCenterData2d, SphericalPolar from pyro.particles import particles