Skip to content

Commit

Permalink
fix quadric surface coincidence issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ilhamv committed Aug 21, 2024
1 parent 48c4624 commit 5d62cd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 56 deletions.
64 changes: 11 additions & 53 deletions mcdc/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,57 +251,6 @@ def distance_to_nearest_surface(particle, cell, mcdc):
return distance, surface_ID


@njit
def distance_to_lattice_grid(particle, lattice):
# TODO: docs
d = INF
d = min(d, lattice_grid_distance(x, ux, lattice["x0"], lattice["dx"]))
d = min(d, lattice_grid_distance(y, uy, lattice["y0"], lattice["dy"]))
d = min(d, lattice_grid_distance(z, uz, lattice["z0"], lattice["dz"]))
return d


# ======================================================================================
# Lattice operations
# ======================================================================================


@njit
def lattice_get_indices(x, y, z, ux, uy, uz, lattice):
# TODO: docs
ix = lattice_get_grid_index(x, ux, lattice["x0"], lattice["dx"])
iy = lattice_get_grid_index(y, uy, lattice["y0"], lattice["dy"])
iz = lattice_get_grid_index(z, uz, lattice["z0"], lattice["dz"])
return ix, iy, iz


@njit
def lattice_grid_distance(value, direction, x0, dx):
# TODO: docs
if direction == 0.0:
return INF
idx = math.floor((value - x0) / dx)
if direction > 0.0:
idx += 1
ref = x0 + idx * dx
dist = (ref - value) / direction
return dist


@njit
def lattice_get_grid_index(value, direction, x0, dx):
idx = int64(math.floor((x - lattice["x0"]) / lattice["dx"]))

# Coinciding cases
if direction > 0.0:
if abs(grid[idx + 1] - value) < COINCIDENCE_TOLERANCE:
idx += 1
else:
if abs(grid[idx] - value) < COINCIDENCE_TOLERANCE:
idx -= 1
return idx


# =============================================================================
# Surface operations
# =============================================================================
Expand Down Expand Up @@ -360,10 +309,15 @@ def surface_distance(particle, surface, mcdc):
uy = particle["uy"]
uz = particle["uz"]

# Check if coincident
# Check if coincident and leaving the surface
evaluation = surface_evaluate(particle, surface)
coincident = False
if abs(evaluation) < COINCIDENCE_TOLERANCE:
return INF
coincident = True
if surface["linear"]:
return INF
elif surface_normal_component(particle, surface) > 0.0:
return INF

# Surface coefficients
G = surface["G"]
Expand Down Expand Up @@ -423,6 +377,10 @@ def surface_distance(particle, surface, mcdc):
root_1 = (-b + sqrt) / denom
root_2 = (-b - sqrt) / denom

# Coincident treatment
if coincident:
return max(root_1, root_2)

# Negative roots, moving away from the surface
if root_1 < 0.0:
root_1 = INF
Expand Down
6 changes: 3 additions & 3 deletions mcdc/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,7 @@ def loop_particle(P, prog):
mcdc = adapt.device(prog)

while P["alive"]:
print('start', P['x'], P['y'], P['z'], P['t'])
step_particle(P, prog)
print('end', P['x'], P['y'], P['z'], P['t'])
input()


@njit(cache=caching)
Expand All @@ -445,6 +442,9 @@ def step_particle(P, prog):
kernel.move_to_event(P, mcdc)
event = P["event"]

if event == EVENT_LOST:
return

# The & operator here is a bitwise and.
# It is used to determine if an event type is part of the particle event.

Expand Down

0 comments on commit 5d62cd5

Please sign in to comment.