Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding optional outline to plots #2482

Merged
merged 10 commits into from Apr 20, 2023

Conversation

shimwell
Copy link
Member

This PR attempts to add outlines to the universe.plot method.

I had this functionality over in the openmc-geometry-plot package and thought it would be much better over here ♻️

Also inspired by @gridley and @pshriwise recent PR which improves the universe plot method.

before this PR
no_outline_plot_cell

after this PR using optional outline
outline_plot_cell

Minimal script for using this outline feature

import openmc
from matplotlib import pyplot as plt

mat_iron = openmc.Material()
mat_iron.name= 'iron'
mat_iron.add_element("Ni", 1.0)
mat_iron.set_density("g/cm3", 1)

mat_aluminum = openmc.Material()
mat_aluminum.add_element("W", 1.0)
mat_aluminum.set_density("g/cm3", 19.3)

sphere_surf_1 = openmc.Sphere(r=20, boundary_type="vacuum")
sphere_surf_2 = openmc.Sphere(r=1, y0=7)
sphere_surf_3 = openmc.Sphere(r=5, x0=7)

sphere_cell_1 = openmc.Cell(region=-sphere_surf_1 & +sphere_surf_2 & +sphere_surf_3)
sphere_cell_2 = openmc.Cell(region=-sphere_surf_2)
sphere_cell_3 = openmc.Cell(region=-sphere_surf_3)
sphere_cell_3.name= 'sphere_cell_3'

sphere_cell_2.fill = mat_iron
sphere_cell_3.fill = mat_aluminum

my_materials = openmc.Materials([mat_iron, mat_aluminum])
all_cells = [sphere_cell_1, sphere_cell_2, sphere_cell_3]
universe = openmc.Universe(cells=all_cells)


mat_colors = {
    my_materials[0] : 'green',
    my_materials[1] : 'gray'
}
cell_colors = {
    all_cells[0] : 'green',
    all_cells[1] : 'gray',
    all_cells[2] : 'yellow'
}

universe.plot(
    # legend=True, 
    width=(44, 44),
    origin=(0., 0., 0.),
    outline=True,
    colors=cell_colors,
    color_by='cell'
)
plt.savefig("plot_cell.png", bbox_inches="tight")

universe.plot(
    # legend=True, 
    width=(44, 44),
    origin=(0., 0., 0.),
    outline=True,
    colors=mat_colors,
    color_by='material'
)
plt.savefig("plot_material.png", bbox_inches="tight")

@shimwell
Copy link
Member Author

looks like the CI is failing for reasons unrelated to the PR, looks like there is a fix in already so I can rerun the CI after #2481 has been merged in

openmc/universe.py Outdated Show resolved Hide resolved
@shimwell shimwell marked this pull request as draft April 17, 2023 16:36
openmc/universe.py Outdated Show resolved Hide resolved
@shimwell shimwell marked this pull request as ready for review April 18, 2023 14:56
openmc/universe.py Outdated Show resolved Hide resolved
openmc/universe.py Show resolved Hide resolved
@shimwell
Copy link
Member Author

canceled the CI for the previous run as I had one more commit to sneak into this PR. Latest commit just improves the pytest a little bit

openmc/universe.py Outdated Show resolved Hide resolved
tests/unit_tests/test_plots.py Outdated Show resolved Hide resolved
shimwell and others added 2 commits April 19, 2023 15:59
Copy link
Contributor

@paulromano paulromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All looks good now; thanks @shimwell!

@paulromano
Copy link
Contributor

@shimwell The merging of #2472 caused a conflict here that you'll need to resolve

@paulromano paulromano merged commit 82ccbe0 into openmc-dev:develop Apr 20, 2023
17 checks passed
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.

None yet

2 participants