Skip to content

Commit

Permalink
corrected z position of geometry
Browse files Browse the repository at this point in the history
  • Loading branch information
shimwell committed Oct 12, 2023
1 parent e45fa4b commit 733d14b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 33 deletions.
4 changes: 2 additions & 2 deletions examples/plot_phir_slice_point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# plotted using the openmc_cylindrical_plotter in the Phi R axis.

import openmc
from openmc_cylindrical_mesh_plotter import plot_mesh_tally_rz_slice
from openmc_cylindrical_mesh_plotter import plot_mesh_tally_phir_slice
from matplotlib.colors import LogNorm


Expand Down Expand Up @@ -48,7 +48,7 @@

my_tally_result = statepoint.get_tally(name="my_tally")

plot = plot_mesh_tally_rz_slice(
plot = plot_mesh_tally_phir_slice(
tally=my_tally_result,
outline=True,
geometry=my_geometry,
Expand Down
2 changes: 1 addition & 1 deletion examples/plot_rz_slices_point_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,6 @@

for slice_index in range(1, len(mesh.phi_grid)):
plot = plot_mesh_tally_rz_slice(
tally=my_tally_result, geometry=my_geometry, norm=LogNorm()
tally=my_tally_result, outline=True, geometry=my_geometry, norm=LogNorm()
)
plot.figure.savefig(f"rz_point_source_{slice_index}.png")
25 changes: 15 additions & 10 deletions examples/plot_rz_slices_ring_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,30 @@
from matplotlib.colors import LogNorm

mesh = openmc.CylindricalMesh(
phi_grid=np.linspace(0.0, 2 * pi, 3),
r_grid=np.linspace(0, 10, 50),
z_grid=np.linspace(0, 8, 50),
phi_grid=np.linspace(0.0, 2 * pi, 4),
r_grid=np.linspace(0,100, 50),
z_grid=np.linspace(-100, 50, 50),
)
tally = openmc.Tally(name="my_tally")
mesh_filter = openmc.MeshFilter(mesh)
tally.filters.append(mesh_filter)
tally.scores.append("flux")

tally = openmc.Tally(name="my_tally")
tally.filters =[mesh_filter]
tally.scores=["flux"]
tallies = openmc.Tallies([tally])

outer_surface = openmc.Sphere(r=100, boundary_type="vacuum")
cell = openmc.Cell(region=-outer_surface)
surf1=openmc.model.RectangularParallelepiped(-100,100,-100,100,-100,50, boundary_type="vacuum")
surf2=openmc.model.RectangularParallelepiped(-95,95,-95,95,-95,45)
surf3 = openmc.Sphere(r=40)
cell1 = openmc.Cell(region=-surf3)
cell2 = openmc.Cell(region=+surf2&-surf1)
cell3 = openmc.Cell(region=+surf3&-surf2)

material = openmc.Material()
material.add_nuclide("Fe56", 1)
material.set_density("g/cm3", 0.1)
my_materials = openmc.Materials([material])

universe = openmc.Universe(cells=[cell])
my_geometry = openmc.Geometry(universe)
my_geometry = openmc.Geometry([cell1, cell2, cell3])

my_source = openmc.Source()

Expand Down Expand Up @@ -66,6 +70,7 @@
plot = plot_mesh_tally_rz_slice(
tally=my_tally_result,
geometry=my_geometry,
outline=True,
norm=LogNorm(),
slice_index=slice_index,
)
Expand Down
32 changes: 12 additions & 20 deletions src/openmc_cylindrical_mesh_plotter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,15 @@ def plot_mesh_tally_rz_slice(
xlabel, ylabel = f"r [{axis_units}]", f"z [{axis_units}]"
axis_scaling_factor = {"km": 0.00001, "m": 0.01, "cm": 1, "mm": 10}[axis_units]

extent = [mesh.r_grid[0], mesh.r_grid[-1], mesh.z_grid[0], mesh.z_grid[-1]]
if mesh.origin[0] != 0. or mesh.origin[1] != 0.:
raise ValueError('Plotter only works for cylindrical meshes with x,y origins of 0,0')

extent = [
mesh.r_grid[0],
mesh.r_grid[-1],
mesh.origin[2] + mesh.z_grid[0],
mesh.origin[2] + mesh.z_grid[-1]
]

x_min, x_max, y_min, y_max = [i * axis_scaling_factor for i in extent]

Expand All @@ -157,22 +165,6 @@ def plot_mesh_tally_rz_slice(
if outline and geometry is not None:
import matplotlib.image as mpimg

# code to make sure geometry outline is in the middle of the mesh voxel
# two of the three dimensions are just in the center of the mesh
# but the slice can move one axis off the center so this needs calculating
# x1, y1, z1 = mesh.upper_right
# x_origin, y_origin, z_origin = mesh.origin

# # width_x = abs(x_origin + x1)/2
# # width_y = abs(y_origin + y1)/2
# # width_z = abs(z_origin + z1)

# width_x, width_y, width_z = mesh.bounding_box.width
# width_x=width_x/2
# width_y=width_y/2
# print('width_x,width_y,width_z')
# print(width_x,width_y,width_z)

model = openmc.Model()
model.geometry = geometry
plot = openmc.Plot()
Expand All @@ -181,9 +173,9 @@ def plot_mesh_tally_rz_slice(
width_y = abs(extent[1] - extent[0]) # same
width_z = abs(extent[3] - extent[2])

x_center = abs(extent[0] + (width_x / 2))
y_center = abs(extent[0] + (width_y / 2))
z_center = abs(extent[2] + width_z * 0.5)
x_center = extent[0] + (width_x / 2)
y_center = extent[0] + (width_y / 2)
z_center = extent[2] + width_z * 0.5

if geometry_basis == "xz":
plot.origin = (x_center, 0, z_center)
Expand Down

0 comments on commit 733d14b

Please sign in to comment.