Skip to content

Commit 9b675ad

Browse files
bpolaniapaulromano
andauthored
Introduce SlicePlot and VoxelPlot to replace the Plot class (#3528)
Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
1 parent f281392 commit 9b675ad

File tree

16 files changed

+618
-112
lines changed

16 files changed

+618
-112
lines changed

docs/source/pythonapi/base.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,8 @@ Geometry Plotting
176176
:nosignatures:
177177
:template: myclass.rst
178178

179-
openmc.Plot
179+
openmc.SlicePlot
180+
openmc.VoxelPlot
180181
openmc.WireframeRayTracePlot
181182
openmc.SolidRayTracePlot
182183
openmc.Plots

docs/source/usersguide/plots.rst

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ Geometry Visualization
66

77
.. currentmodule:: openmc
88

9-
OpenMC is capable of producing two-dimensional slice plots of a geometry as well
10-
as three-dimensional voxel plots using the geometry plotting :ref:`run mode
11-
<usersguide_run_modes>`. The geometry plotting mode relies on the presence of a
12-
:ref:`plots.xml <io_plots>` file that indicates what plots should be created. To
13-
create this file, one needs to create one or more :class:`openmc.Plot`
14-
instances, add them to a :class:`openmc.Plots` collection, and then use the
15-
:class:`Plots.export_to_xml` method to write the ``plots.xml`` file.
9+
OpenMC is capable of producing two-dimensional slice plots of a geometry,
10+
three-dimensional voxel plots, and three-dimensional raytrace plots using the
11+
geometry plotting :ref:`run mode <usersguide_run_modes>`. The geometry plotting
12+
mode relies on the presence of a :ref:`plots.xml <io_plots>` file that indicates
13+
what plots should be created. To create this file, one needs to create one or
14+
more instances of the various plot classes described below, add them to a
15+
:class:`openmc.Plots` collection, and then use the :class:`Plots.export_to_xml`
16+
method to write the ``plots.xml`` file.
1617

1718
-----------
1819
Slice Plots
@@ -21,15 +22,14 @@ Slice Plots
2122
.. image:: ../_images/atr.png
2223
:width: 300px
2324

24-
By default, when an instance of :class:`openmc.Plot` is created, it indicates
25-
that a 2D slice plot should be made. You can specify the origin of the plot
26-
(:attr:`Plot.origin`), the width of the plot in each direction
27-
(:attr:`Plot.width`), the number of pixels to use in each direction
28-
(:attr:`Plot.pixels`), and the basis directions for the plot. For example, to
29-
create a :math:`x` - :math:`z` plot centered at (5.0, 2.0, 3.0) with a width of
30-
(50., 50.) and 400x400 pixels::
25+
The :class:`openmc.SlicePlot` class indicates that a 2D slice plot should be
26+
made. You can specify the origin of the plot (:attr:`SlicePlot.origin`), the
27+
width of the plot in each direction (:attr:`SlicePlot.width`), the number of
28+
pixels to use in each direction (:attr:`SlicePlot.pixels`), and the basis
29+
directions for the plot. For example, to create a :math:`x` - :math:`z` plot
30+
centered at (5.0, 2.0, 3.0) with a width of (50., 50.) and 400x400 pixels::
3131

32-
plot = openmc.Plot()
32+
plot = openmc.SlicePlot()
3333
plot.basis = 'xz'
3434
plot.origin = (5.0, 2.0, 3.0)
3535
plot.width = (50., 50.)
@@ -47,7 +47,7 @@ that location.
4747

4848
By default, a unique color will be assigned to each cell in the geometry. If you
4949
want your plot to be colored by material instead, change the
50-
:attr:`Plot.color_by` attribute::
50+
:attr:`SlicePlot.color_by` attribute::
5151

5252
plot.color_by = 'material'
5353

@@ -68,8 +68,8 @@ particular cells/materials should be given colors of your choosing::
6868
Note that colors can be given as RGB tuples or by a string indicating a valid
6969
`SVG color <https://www.w3.org/TR/SVG11/types.html#ColorKeywords>`_.
7070

71-
When you're done creating your :class:`openmc.Plot` instances, you need to then
72-
assign them to a :class:`openmc.Plots` collection and export it to XML::
71+
When you're done creating your :class:`openmc.SlicePlot` instances, you need to
72+
then assign them to a :class:`openmc.Plots` collection and export it to XML::
7373

7474
plots = openmc.Plots([plot1, plot2, plot3])
7575
plots.export_to_xml()
@@ -97,13 +97,11 @@ Voxel Plots
9797
.. image:: ../_images/3dba.png
9898
:width: 200px
9999

100-
The :class:`openmc.Plot` class can also be told to generate a 3D voxel plot
101-
instead of a 2D slice plot. Simply change the :attr:`Plot.type` attribute to
102-
'voxel'. In this case, the :attr:`Plot.width` and :attr:`Plot.pixels` attributes
103-
should be three items long, e.g.::
100+
The :class:`openmc.VoxelPlot` class enables the generation of a 3D voxel plot
101+
instead of a 2D slice plot. In this case, the :attr:`VoxelPlot.width` and
102+
:attr:`VoxelPlot.pixels` attributes should be three items long, e.g.::
104103

105-
vox_plot = openmc.Plot()
106-
vox_plot.type = 'voxel'
104+
vox_plot = openmc.VoxelPlot()
107105
vox_plot.width = (100., 100., 50.)
108106
vox_plot.pixels = (400, 400, 200)
109107

docs/source/usersguide/random_ray.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,11 +1131,10 @@ given below:
11311131
tallies.export_to_xml()
11321132

11331133
# Create voxel plot
1134-
plot = openmc.Plot()
1134+
plot = openmc.VoxelPlot()
11351135
plot.origin = [0, 0, 0]
11361136
plot.width = [2*pitch, 2*pitch, 1]
11371137
plot.pixels = [1000, 1000, 1]
1138-
plot.type = 'voxel'
11391138

11401139
# Instantiate a Plots collection and export to XML
11411140
plots = openmc.Plots([plot])
@@ -1215,11 +1214,10 @@ given below:
12151214
tallies.export_to_xml()
12161215

12171216
# Create voxel plot
1218-
plot = openmc.Plot()
1217+
plot = openmc.VoxelPlot()
12191218
plot.origin = [0, 0, 0]
12201219
plot.width = [2*pitch, 2*pitch, 1]
12211220
plot.pixels = [1000, 1000, 1]
1222-
plot.type = 'voxel'
12231221

12241222
# Instantiate a Plots collection and export to XML
12251223
plots = openmc.Plots([plot])

examples/lattice/hexagonal/build_xml.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,14 @@
128128
# Exporting to OpenMC plots.xml file
129129
###############################################################################
130130

131-
plot_xy = openmc.Plot(plot_id=1)
131+
plot_xy = openmc.SlicePlot(plot_id=1)
132132
plot_xy.filename = 'plot_xy'
133133
plot_xy.origin = [0, 0, 0]
134134
plot_xy.width = [6, 6]
135135
plot_xy.pixels = [400, 400]
136136
plot_xy.color_by = 'material'
137137

138-
plot_yz = openmc.Plot(plot_id=2)
138+
plot_yz = openmc.SlicePlot(plot_id=2)
139139
plot_yz.filename = 'plot_yz'
140140
plot_yz.basis = 'yz'
141141
plot_yz.origin = [0, 0, 0]

examples/lattice/nested/build_xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
# Exporting to OpenMC plots.xml file
136136
###############################################################################
137137

138-
plot = openmc.Plot(plot_id=1)
138+
plot = openmc.SlicePlot(plot_id=1)
139139
plot.origin = [0, 0, 0]
140140
plot.width = [4, 4]
141141
plot.pixels = [400, 400]

examples/lattice/simple/build_xml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
# Exporting to OpenMC plots.xml file
129129
###############################################################################
130130

131-
plot = openmc.Plot(plot_id=1)
131+
plot = openmc.SlicePlot(plot_id=1)
132132
plot.origin = [0, 0, 0]
133133
plot.width = [4, 4]
134134
plot.pixels = [400, 400]

examples/pincell_random_ray/build_xml.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,10 @@
192192
# Exporting to OpenMC plots.xml file
193193
###############################################################################
194194

195-
plot = openmc.Plot()
195+
plot = openmc.VoxelPlot()
196196
plot.origin = [0, 0, 0]
197197
plot.width = [pitch, pitch, pitch]
198198
plot.pixels = [1000, 1000, 1]
199-
plot.type = 'voxel'
200199

201200
# Instantiate a Plots collection and export to XML
202201
plots = openmc.Plots([plot])

openmc/examples.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def pwr_pin_cell() -> openmc.Model:
8383
constraints={'fissionable': True}
8484
)
8585

86-
plot = openmc.Plot.from_geometry(model.geometry)
86+
plot = openmc.SlicePlot.from_geometry(model.geometry)
8787
plot.pixels = (300, 300)
8888
plot.color_by = 'material'
8989
model.plots.append(plot)
@@ -429,7 +429,7 @@ def pwr_core() -> openmc.Model:
429429
model.settings.source = openmc.IndependentSource(space=openmc.stats.Box(
430430
[-160, -160, -183], [160, 160, 183]))
431431

432-
plot = openmc.Plot()
432+
plot = openmc.SlicePlot()
433433
plot.origin = (125, 125, 0)
434434
plot.width = (250, 250)
435435
plot.pixels = (3000, 3000)
@@ -544,7 +544,7 @@ def pwr_assembly() -> openmc.Model:
544544
constraints={'fissionable': True}
545545
)
546546

547-
plot = openmc.Plot()
547+
plot = openmc.SlicePlot()
548548
plot.origin = (0.0, 0.0, 0)
549549
plot.width = (21.42, 21.42)
550550
plot.pixels = (300, 300)

openmc/executor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def plot_inline(plots, openmc_exec='openmc', cwd='.', path_input=None):
164164
165165
Parameters
166166
----------
167-
plots : Iterable of openmc.Plot
167+
plots : Iterable of openmc.PlotBase
168168
Plots to display
169169
openmc_exec : str
170170
Path to OpenMC executable

openmc/model/model.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ def plot(
11701170
self.settings.plot_seed = seed
11711171

11721172
# Create plot object matching passed arguments
1173-
plot = openmc.Plot()
1173+
plot = openmc.SlicePlot()
11741174
plot.origin = origin
11751175
plot.width = width
11761176
plot.pixels = pixels

0 commit comments

Comments
 (0)