openmc-dev / openmc

OpenMC Monte Carlo Code
https://docs.openmc.org
Other
760 stars 488 forks source link

R-Z Polygon incorrectly rendered #2357

Closed hassec closed 1 year ago

hassec commented 1 year ago

Reproducer:

import numpy as np
import openmc as mc
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon

rz_points = np.array(
    [
        [6.88, 3.02],
        [6.88, 2.32],
        [7.63, 0.0],
        [5.75, 0.0],
        [5.75, 1.22],
        [6.30, 1.22],
        [6.30, 3.02],
        [6.88, 3.02],
    ]
)

# plot matplotlib polygon
poly = Polygon(rz_points)
ax = plt.subplot()
ax.add_patch(poly)
ax.autoscale()
plt.savefig("mpl.png")

p0 = mc.model.Polygon(rz_points, basis="rz")
p0.boundary_type = "vacuum"

cell = mc.Cell(region=(-p0), name="my_cell")
geom = mc.Geometry([cell])

model = mc.Model()
model.geometry = geom
plot = mc.Plot()
plot.origin = (0, 0, 0)
plot.width = (20, 20)
plot.basis = "xz"
model.plots = [plot]
model.plot_geometry(False)

The matplotlib plot shows the shape of the polygon: image

But the geometry of the cell that is created by OpenMC doesn't correctly reproduce the top left cutout but has a diagonal instead.

image

fyi @eepeterson

hassec commented 1 year ago

Adding a plot of the delaunay triangulation: image

If I understand the current algorithm correctly it assumes that it can build the original polygon back from sets of convex subpolygons which are created by grouping the simplices created by the Delaunay triangulation.

But, this doesn't seem to be possible for this specific case.

Maybe a different approach to splitting the polygon into convex subsets, could work?

eepeterson commented 1 year ago

Ah, sorry for the delay - I've been away for a bit. The issue here is that the triangulation didn't produce an edge along one of the boundaries of the polygon. I'll see if there is an option in the QHull library to force a set of edges just from the input points. The polygon can always be decomposed into convex subsets as long as there are edges on the boundary of the polygon.

eepeterson commented 1 year ago

closed via #2362