Skip to content

Conversation

@shimwell
Copy link
Owner

Description

Plotting mesh tallies along with the outline geometry in one function call.
This would be very helpful as a mesh tally plot is a very common output for posters, presentations papers.
The function allows lots of options for scaling, log plots, colorbars with args and lots of customizable options for imshow and contour via kwarg
testing of the plot includes some axis attribute checks and checking function runs but I've also been writting scripts to test the geometry like the one below

Checklist

  • I have performed a self-review of my own code
    - [ ] I have run clang-format on any C++ source files (if applicable)
  • I have followed the style guidelines for Python source files (if applicable)
  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works (if applicable)

Example script to show this function in use

import openmc
from matplotlib.colors import LogNorm
lithium = openmc.Material(name='lithium')
lithium.add_element('Li', 1.0)
lithium.set_density('g/cm3', 1.0)
multiplier = openmc.Material(name='Be')
multiplier.add_element('Be', 1)
multiplier.set_density('g/cm3', 2)
iron = openmc.Material(name="Iron")
iron.add_element("Fe", 1.)
iron.set_density("g/cm3", 7.874)
materials = openmc.Materials([lithium, multiplier, iron])
c0 = openmc.ZCylinder(r=1)
c1 = openmc.ZCylinder(r=2)
c2 = openmc.ZCylinder(r=3)
c3 = openmc.ZCylinder(r=4)
c4 = openmc.ZCylinder(r=5, boundary_type='vacuum')
x_mid = openmc.XPlane()
z_top = openmc.ZPlane(z0=1., boundary_type='vacuum')
z_bottom = openmc.ZPlane(z0=-1, boundary_type='vacuum')
large_void_region = -c3 & +x_mid & +z_bottom & -z_top
small_void_region = -c0 & -x_mid & +z_bottom & -z_top
semi_circle_region_1 = +c0 & -c1 & -x_mid & +z_bottom & -z_top
semi_circle_region_2 = +c1 & -c2 & +c1 & -x_mid & +z_bottom & -z_top
semi_circle_region_3 = +c2 & -c3 & -x_mid & +z_bottom & -z_top 
outer_circle_region = +c3 & -c4 & +z_bottom & -z_top 
cell0 = openmc.Cell(region=large_void_region)
cell1 = openmc.Cell(region=small_void_region)
cell2 = openmc.Cell(fill=lithium, region=semi_circle_region_1)
cell3 = openmc.Cell(fill=lithium, region=semi_circle_region_2)
cell4 = openmc.Cell(fill=iron, region=semi_circle_region_3)
cell5 = openmc.Cell(fill=multiplier, region=outer_circle_region)
my_geometry = openmc.Geometry([cell0, cell1, cell2, cell3, cell4, cell5])
sett = openmc.Settings()
batches = 20
sett.batches = batches
sett.inactive = 0
sett.particles = 5000
sett.run_mode = 'fixed source'
source = openmc.Source()
source.angle = openmc.stats.Isotropic()
source.energy = openmc.stats.Discrete([14e6], [1])
source.space = openmc.stats.Point((2, 2, 0))
sett.source = source
mesh = openmc.RegularMesh().from_domain(my_geometry, dimension=[50,50,50])
tallies = openmc.Tallies()
mesh_filter = openmc.MeshFilter(mesh)
mesh_tally_1 = openmc.Tally(name='tbr_on_mesh')
mesh_tally_1.filters = [mesh_filter]
mesh_tally_1.scores = ['(n,Xt)']  # where X is a wildcard
tallies.append(mesh_tally_1)
mesh_tally_2 = openmc.Tally(name='heating_on_mesh')
mesh_tally_2.filters = [mesh_filter]
mesh_tally_2.scores = ['heating']
tallies.append(mesh_tally_2)
model = openmc.Model(my_geometry, materials, sett, tallies)
sp_filename = model.run()
statepoint = openmc.StatePoint(sp_filename)
my_tbr_tally = statepoint.get_tally(name='tbr_on_mesh')
my_heating_tally = statepoint.get_tally(name='heating_on_mesh')

plot= my_geometry.root_universe.plot(basis='xy', outline=True, legend=True)
plot.figure.savefig('geom.png')
plot = openmc.plot_mesh_tally(tally=my_heating_tally)
plot.figure.savefig('heating-default.png')
plot = openmc.plot_mesh_tally(
    tally=my_heating_tally,
    basis='xy',
    axis_units='m',
    value= 'std_dev',
    outline=True,
    geometry=my_geometry,
    outline_by='material',
    volume_normalization=False,
    pixels=400000,
    colorbar=False
)
plot.figure.savefig('xy-heating-normalized-pixels-no_cbar.png')

plot = openmc.plot_mesh_tally(
    tally=my_heating_tally,
    basis='xy',
    axis_units='cm',
    value= 'std_dev',
    outline=True,
    geometry=my_geometry,
    outline_by='material',
    scaling_factor=1e6,
    outline_kwargs={'colors':'k'}
)
plot.figure.savefig('xy-heating-scaled.png')

plot = openmc.plot_mesh_tally(
    tally=my_heating_tally,
    basis='xy',
    axis_units='km',
    value= 'std_dev',
    outline=True,
    geometry=my_geometry,
    outline_by='cell',
    norm=LogNorm(),
    cmap='gray',
    outline_kwargs={'colors':'red'}
)
plot.figure.savefig('xy-heating-log-cell.png')

plot = openmc.plot_mesh_tally(
    tally=my_tbr_tally,
    basis='xy',
    axis_units='m',
    value= 'mean',
    outline=True,
    geometry=my_geometry,
    outline_by='cell',
    norm=LogNorm(),
    cmap='gray',
)
plot.figure.savefig('xy-tbr-cell.png')

@shimwell
Copy link
Owner Author

@eepeterson and @pshriwise I've been busy working on that mesh tally plotting function that I tried to implement in openmc-dev#2491

I remember that PR when in circles a bit but I think this attempt is more aligned to what is needed?

@coveralls
Copy link

coveralls commented Aug 4, 2023

Pull Request Test Coverage Report for Build 5811914403

  • 69 of 79 (87.34%) changed or added relevant lines in 1 file are covered.
  • 30 unchanged lines in 13 files lost coverage.
  • Overall coverage increased (+0.03%) to 84.498%

Changes Missing Coverage Covered Lines Changed/Added Lines %
openmc/plots.py 69 79 87.34%
Files with Coverage Reduction New Missed Lines %
include/openmc/container_util.h 1 0%
include/openmc/material.h 1 0%
include/openmc/particle_data.h 1 66.67%
include/openmc/tallies/filter_legendre.h 1 83.33%
include/openmc/tallies/filter_sph_harm.h 1 85.71%
include/openmc/tallies/tally.h 1 25.0%
include/openmc/angle_energy.h 2 0%
include/openmc/distribution_multi.h 2 50.0%
include/openmc/tallies/filter.h 2 16.67%
include/openmc/shared_array.h 3 0%
Totals Coverage Status
Change from base Build 5669845301: 0.03%
Covered Lines: 46806
Relevant Lines: 55393

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants