Skip to content

Commit bc2afa1

Browse files
committed
visualize: added dynamic cell grid
1 parent 70d672c commit bc2afa1

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

files/inp/todo_41.inp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Bad Geometry INP File!
2+
1 0 3 4 imp:@=1
3+
4+
1 so 3
5+
6+
sdef
7+
nps 10

src/pymcnp/Visualize.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,6 @@ class Visualize(_doer.Doer):
1919
inpt: Files to visualize.
2020
"""
2121

22-
GRID = pyvista.ImageData(
23-
dimensions=(_show.pyvista.RESOLUTION, _show.pyvista.RESOLUTION, _show.pyvista.RESOLUTION),
24-
spacing=(_show.pyvista.BOUND / _show.pyvista.RESOLUTION, _show.pyvista.BOUND / _show.pyvista.RESOLUTION, _show.pyvista.BOUND / _show.pyvista.RESOLUTION),
25-
origin=(-_show.pyvista.BOUND / 2, -_show.pyvista.BOUND / 2, -_show.pyvista.BOUND / 2),
26-
)
27-
2822
def __init__(self, inpt: Inp):
2923
"""
3024
Initializes `Visualize`.
@@ -41,6 +35,20 @@ def __init__(self, inpt: Inp):
4135

4236
self.inpt = inpt
4337

38+
@property
39+
def _grid(self):
40+
surfaces = self.to_show_surfaces()
41+
42+
return pyvista.ImageData(
43+
dimensions=(_show.pyvista.RESOLUTION, _show.pyvista.RESOLUTION, _show.pyvista.RESOLUTION),
44+
spacing=(
45+
(surfaces.bounds[1] - surfaces.bounds[0]) / _show.pyvista.RESOLUTION,
46+
(surfaces.bounds[3] - surfaces.bounds[2]) / _show.pyvista.RESOLUTION,
47+
(surfaces.bounds[5] - surfaces.bounds[4]) / _show.pyvista.RESOLUTION,
48+
),
49+
origin=(-(surfaces.bounds[1] - surfaces.bounds[0]) / 2, -(surfaces.bounds[3] - surfaces.bounds[2]) / 2, -(surfaces.bounds[5] - surfaces.bounds[4]) / 2),
50+
)
51+
4452
def to_show_cells(self) -> pyvista.Plotter:
4553
"""
4654
Visualizes INP cells.
@@ -62,8 +70,9 @@ def to_show_cells(self) -> pyvista.Plotter:
6270

6371
cells[str(cell.number)] = shape
6472

65-
self.GRID['cell'] = shape.cell(self.GRID.points).astype(numpy.float32)
66-
plot.add_volume(self.GRID, scalars='cell', opacity=[0, 0, 0.01, 0.01])
73+
grid = self._grid
74+
grid['cell'] = shape.cell(grid.points).astype(numpy.float32)
75+
plot.add_volume(grid, scalars='cell', opacity=[0, 0, 0.01, 0.01])
6776
plot.add_mesh(shape.surface, opacity=0.9)
6877

6978
return plot
@@ -113,8 +122,9 @@ def to_show_cell(self, number: str) -> pyvista.Plotter:
113122
if str(cell.number) != number:
114123
continue
115124

116-
self.GRID['cell'] = shape.cell(self.GRID.points).astype(numpy.float32)
117-
plot.add_volume(self.GRID, scalars='cell', opacity=[0, 0, 0.01, 0.01])
125+
grid = self._grid
126+
grid['cell'] = shape.cell(grid.points).astype(numpy.float32)
127+
plot.add_volume(grid, scalars='cell', opacity=[0, 0, 0.01, 0.01])
118128
plot.add_mesh(shape.surface, opacity=0.9)
119129

120130
break

src/pymcnp/_cli/visualize.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,8 @@ def main() -> None:
9393
except errors.CliError as err:
9494
_io.error(str(err))
9595
exit(3)
96+
except errors.TypesError as err:
97+
_io.error(str(err))
98+
exit(3)
9699

97100
_io.done()

tests/test_pymcnp/test__cli/test_visualize.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ def test_invalid(self):
2020
os.system(f'pymcnp visualize {pathlib.Path(__file__).parent.parent.parent.parent / "files" / "inp" / "invalid_00.inp"}')
2121
os.system(f'pymcnp visualize {pathlib.Path(__file__).parent.parent.parent.parent / "files" / "inp" / "invalid_01.inp"}')
2222
os.system(f'pymcnp visualize {pathlib.Path(__file__).parent.parent.parent.parent / "files" / "inp" / "invalid_02.inp"}')
23+
os.system(f'pymcnp visualize {pathlib.Path(__file__).parent.parent.parent.parent / "files" / "inp" / "todo_41.inp"}')
2324
os.system(f'pymcnp visualize {pathlib.Path(__file__).parent.parent.parent.parent / "files" / "inp" / "valid_00.inp"} --cell=934587439')
2425
os.system('pymcnp visualize hello')

0 commit comments

Comments
 (0)