Skip to content

Commit

Permalink
added gui outline option;
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Mar 20, 2024
1 parent 6dd5397 commit f39e223
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import openmc
import numpy as np
from math import pi
import matplotlib.pyplot as plt
from openmc_cylindrical_mesh_plotter import plot_mesh_tally_rz_slice

mesh = openmc.CylindricalMesh(
Expand Down
1 change: 1 addition & 0 deletions src/openmc_cylindrical_mesh_plotter/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .core import *
from .app import *
76 changes: 52 additions & 24 deletions src/openmc_cylindrical_mesh_plotter/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ def get_tallies_with_cylindrical_mesh_filters(statepoint: openmc.StatePoint):
mf = tally.find_filter(filter_type=openmc.MeshFilter)
if isinstance(mf.mesh, openmc.CylindricalMesh):
matching_tally_ids.append(tally.id)
print("found regmeshfilter")
except ValueError:
mf = None

Expand Down Expand Up @@ -78,8 +77,6 @@ def header():
💾 Raise a feature request, report and issue or make a contribution on [GitHub](https://github.com/fusion-energy/openmc_cylindrical_mesh_plotter)
📧 Email feedback to [email protected]
🔗 This package forms part of a more [comprehensive openmc plot](https://github.com/fusion-energy/openmc_plot) package where geometry, tallies, slices, etc can be plotted and is hosted on [xsplot.com](https://www.xsplot.com/) .
"""
)
Expand All @@ -94,8 +91,7 @@ def main():
"""
# Not got a h5 file handy, right mouse 🖱️ click and save these links
# [ example 1 ](https://fusion-energy.github.io/openmc_cylindrical_mesh_plotter/examples/csg_tokamak/geometry.xml),
# [ example 2 ](https://fusion-energy.github.io/openmc_cylindrical_mesh_plotter/examples/csg_cylinder_box/geometry.xml)

)

statepoint_file = st.file_uploader("Select your statepoint h5 file", type=["h5"])
Expand All @@ -108,6 +104,8 @@ def main():
save_uploadedfile(statepoint_file)
statepoint = openmc.StatePoint(statepoint_file.name)

geometry = statepoint.summary.geometry

tally_description = get_cylindricalmesh_tallies_and_scores(statepoint)
tally_description_str = [
f"ID={td['id']} score={td['score']} name={td['name']}"
Expand All @@ -123,15 +121,16 @@ def main():
basis = st.sidebar.selectbox(
label="view direction",
options=("PhiR", "RZ"),
index=0,
index=1,
key="axis",
help="",
)

value = st.sidebar.radio("Tally mean or std dev", options=["mean", "std_dev"])
value = st.sidebar.radio(
"Tally mean or std dev", options=["mean", "std_dev"])

axis_units = st.sidebar.selectbox(
"Axis units", ["km", "m", "cm", "mm"], index=2
"Axis units", ["km", "m", "cm", "mm"], index=2, help='The units that appear on the X and Y axis'
)

volume_normalization = st.sidebar.radio(
Expand All @@ -146,8 +145,6 @@ def main():

tally = statepoint.get_tally(id=int(tally_id_to_plot))

mesh = tally.find_filter(filter_type=openmc.MeshFilter).mesh

if basis == "RZ":
max_value = int(tally.shape[1] / 2) # index 1 is the phi value
if basis == "PhiR":
Expand Down Expand Up @@ -175,33 +172,64 @@ def main():
# else:
# contour_levels = None

colorbar = st.sidebar.radio("Include colorbar", options=[True, False])

title = st.sidebar.text_input(
"Colorbar title",
help="Optionally set your own colorbar label for the plot",
value="colorbar title",
)

log_lin_scale = st.sidebar.radio("Scale", options=["log", "linear"])
log_lin_scale = st.sidebar.radio(
"Scale", options=["log", "linear"], help='The color scale applied')
if log_lin_scale == "linear":
norm = None
else:
norm = LogNorm()

colorbar = st.sidebar.radio("Include colorbar", options=[True, False])

if colorbar:
title = st.sidebar.text_input(
"Colorbar title",
help="Optionally set your own colorbar label for the plot",
value="colorbar title",
)
else:
title=None

if basis == "RZ":
outline = st.sidebar.radio("Geometry outline", options=[True, False])
if outline:
geometry_basis = st.sidebar.selectbox(
label="geometry outline basis",
options=("xz", "yz"),
index=0,
key="outline_axis",
help="The axis/basis to use for the geometry outline plot",
)
outline_by = st.sidebar.selectbox(
label="geometry outline basis",
options=("cell", "material"),
index=0,
key="outline_by",
help="The type of geometry outline to plot",
)
outline_pixels = st.sidebar.number_input(
"Scaling factor",
value=40000,
help="The resolution to use for the outline plot. Increaing the value produces a smoother outline but takes longer.",
)
else:
# outline not plotted but varibles still need values
geometry_basis ='xz'
outline_by='cell'
outline_pixels=40000

plot = plot_mesh_tally_rz_slice(
tally=tally,
slice_index=slice_index,
score=score,
axes=None,
axis_units=axis_units,
value=value,
# outline: bool = False,
# outline_by: str = "cell",
# geometry: Optional["openmc.Geometry"] = None,
# geometry_basis: str = "xz",
# pixels: int = 40000,
outline = outline,
outline_by=outline_by,
geometry=geometry,
geometry_basis=geometry_basis,
pixels = outline_pixels,
colorbar=colorbar,
volume_normalization=volume_normalization,
scaling_factor=scaling_factor,
Expand Down
2 changes: 2 additions & 0 deletions src/openmc_cylindrical_mesh_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import openmc
import openmc.checkvalue as cv
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('agg')

from packaging import version

Expand Down

0 comments on commit f39e223

Please sign in to comment.