Is there any full code example of ProjectionPlot?
Hi, great question, and nice username. I am working on merging some code that has more examples. If you look in the latest user guide under the plotting section, there should be an example to revolve around a lattice.
The new ProjectionPlot function is well document and the example looks straigthforward (and very nice)
The only issue is that, in the example, the function <plot_file.append()> does not seems to be integrated in openmc and is probably part of another package.
Did you try running the code? I just looked at plots.py and it seems it should work. If not can you please post your error message? I am happy to fix whatever you come across.
Thanks!
Gavin
Dear Gavin,
I am attaching a simplified script (geometry + tentative ProjectionPlot)
I simply copied the example from the manual at the page
https://docs.openmc.org/en/stable/usersguide/plots.html?highlight=geometry%20plotting#voxel-plots
The problem is with the function >plot_file.append(thisp)
(Attachment Test_ProjectionPlot.zip is missing)
Dear Gavin,
I am attaching a simplified script (geometry + tentative ProjectionPlot)
I simply copied the example from the manual at the page
https://docs.openmc.org/en/stable/usersguide/plots.html?highlight=geometry%20plotting#voxel-plots
The problem is with the function >plot_file.append(thisp)
(attachments)
Test_ProjectionPlot.ipynb (43.7 KB)
Dear Gavin,
Forget about my previous mail.
I did not get that plot_file was a simple collection of plots
Wonderful, so itâs all figured out now?
By the way, there is an update coming soon that should speed these up quite a bit and also add some new functionality. So keep that on your radar if youâre not quite satisfied with the results!
Dear Gavin,
Thank you for you time.
I think that the problem is that new users will mostly use OpenMC via the very nice Python interface.
Hence I totally overlooked the âopenmc âplotâ capability and had to dig into the manual to discover it.
Anyway, the ProjectionPlot is a very useful capability so that external interlocutors can easily understand the basics of a geometry without having to dig into multiple 2D cuts.
Best Regards
For future users, you will find below a âworking exampleâ using ProjectionPlot (based on existing pieces of code) â
import openmc
###############################################################################
Simulation Input File Parameters
###############################################################################
OpenMC simulation parameters
batches = 20
inactive = 10
particles = 10000
###############################################################################
Exporting to OpenMC materials.xml File
###############################################################################
Instantiate some Materials and register the appropriate Nuclides
fuel = openmc.Material(material_id=1, name=âfuelâ)
fuel.set_density(âg/ccâ, 4.5)
fuel.add_nuclide(âU235â, 1.)
moderator = openmc.Material(material_id=2, name=âmoderatorâ)
moderator.set_density(âg/ccâ, 1.0)
moderator.add_element(âHâ, 2.)
moderator.add_element(âOâ, 1.)
moderator.add_s_alpha_beta(âc_H_in_H2Oâ)
iron = openmc.Material(material_id=3, name=âironâ)
iron.set_density(âg/ccâ, 7.9)
iron.add_element(âFeâ, 1.)
Instantiate a Materials collection and export to XML
materials_file = openmc.Materials([moderator, fuel, iron])
materials_file.export_to_xml()
###############################################################################
Exporting to OpenMC geometry.xml file
###############################################################################
Instantiate Surfaces
left = openmc.XPlane(surface_id=1, x0=-3, name=âleftâ)
right = openmc.XPlane(surface_id=2, x0=3, name=ârightâ)
bottom = openmc.YPlane(surface_id=3, y0=-4, name=âbottomâ)
top = openmc.YPlane(surface_id=4, y0=4, name=âtopâ)
fuel_surf = openmc.ZCylinder(surface_id=5, x0=0, y0=0, r=0.4)
left.boundary_type = âvacuumâ
right.boundary_type = âvacuumâ
top.boundary_type = âvacuumâ
bottom.boundary_type = âvacuumâ
Instantiate Cells
cell1 = openmc.Cell(cell_id=1, name=âCell 1â)
cell2 = openmc.Cell(cell_id=101, name=âcell 2â)
cell3 = openmc.Cell(cell_id=102, name=âcell 3â)
cell4 = openmc.Cell(cell_id=500, name=âcell 4â)
cell5 = openmc.Cell(cell_id=600, name=âcell 5â)
cell6 = openmc.Cell(cell_id=601, name=âcell 6â)
Use surface half-spaces to define regions
cell1.region = +left & -right & +bottom & -top
cell2.region = -fuel_surf
cell3.region = +fuel_surf
cell5.region = -fuel_surf
cell6.region = +fuel_surf
Register Materials with Cells
cell2.fill = fuel
cell3.fill = moderator
cell4.fill = moderator
cell5.fill = iron
cell6.fill = moderator
Instantiate Universe
univ1 = openmc.Universe(universe_id=1)
univ2 = openmc.Universe(universe_id=3)
univ3 = openmc.Universe(universe_id=4)
root = openmc.Universe(universe_id=0, name=âroot universeâ)
Register Cells with Universe
univ1.add_cells([cell2, cell3])
univ2.add_cells([cell4])
univ3.add_cells([cell5, cell6])
root.add_cell(cell1)
Instantiate a Lattice
lattice = openmc.HexLattice(lattice_id=5)
lattice.center = [0., 0., 0.]
lattice.pitch = [1., 2.]
lattice.universes =
[ [ [univ2] + [univ3]*11, [univ2] + [univ3]*5, [univ3] ],
[ [univ2] + [univ1]*11, [univ2] + [univ1]*5, [univ1] ],
[ [univ2] + [univ3]*11, [univ2] + [univ3]*5, [univ3] ] ]
lattice.outer = univ2
Fill Cell with the Lattice
cell1.fill = lattice
Instantiate a Geometry, register the root Universe, and export to XML
geometry = openmc.Geometry(root)
geometry.export_to_xml()
###############################################################################
Exporting to OpenMC settings.xml file
###############################################################################
Instantiate a Settings object, set all runtime parameters, and export to XML
settings_file = openmc.Settings()
settings_file.batches = batches
settings_file.inactive = inactive
settings_file.particles = particles
Create an initial uniform spatial source distribution over fissionable zones
bounds = [-1, -1, -1, 1, 1, 1]
uniform_dist = openmc.stats.Box(bounds[:3], bounds[3:])
settings_file.source = openmc.IndependentSource(
space=uniform_dist, constraints={âfissionableâ: True})
settings_file.keff_trigger = {âtypeâ : âstd_devâ, âthresholdâ : 5E-4}
settings_file.trigger_active = True
settings_file.trigger_max_batches = 100
settings_file.export_to_xml()
###############################################################################
Exporting to OpenMC plots.xml file
###############################################################################
plot_xy = openmc.Plot(plot_id=1)
plot_xy.filename = âplot_xyâ
plot_xy.origin = [0, 0, 0]
plot_xy.width = [6, 6]
plot_xy.pixels = [400, 400]
plot_xy.color_by = âmaterialâ
plot_yz = openmc.Plot(plot_id=2)
plot_yz.filename = âplot_yzâ
plot_yz.basis = âyzâ
plot_yz.origin = [0, 0, 0]
plot_yz.width = [8, 8]
plot_yz.pixels = [400, 400]
plot_yz.color_by = âmaterialâ
Instantiate a Plots collection, add plots, and export to XML
plot_file = openmc.Plots()
r = 5 # set the camear distance from the system
import numpy as np
for i in range(10):
phi = 2 * np.pi * i/100
thisp = openmc.ProjectionPlot(plot_id = 4 + i)
thisp.filename = âframe%sâ%(str(i).zfill(3))
thisp.look_at = [0, 0, 0]
thisp.camera_position = [r * np.cos(phi), r * np.sin(phi), 6 * np.sin(phi)]
thisp.pixels = [400, 400]
thisp.color_by = âmaterialâ
thisp.colorize(geometry)
thisp.set_transparent(geometry)
thisp.xs[fuel] = 1.0
thisp.xs[iron] = 1.0
thisp.wireframe_domains = [fuel]
thisp.wireframe_thickness = 1
plot_file.append(thisp)
plot_file.export_to_xml() # create the plots.xml file
openmc.plot_geometry() # uses the plots.xml file to generate a set of png images
# the equivalent command line is openmc --plot