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

Prevent out-of-bounds error in find_psisurface near axis #98

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions freegs/critical.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,22 @@ def find_psisurface(eq, psifunc, r0, z0, r1, z1, psival=1.0, n=100, axis=None):
# Only one value
ind = argmax(pnorm > psival)

# Edited by Bhavin 31/07/18
# Changed 1.0 to psival in f
# make f gradient to psival surface
f = (pnorm[ind] - psival) / (pnorm[ind] - pnorm[ind - 1])

r = (1.0 - f) * r[ind] + f * r[ind - 1]
z = (1.0 - f) * z[ind] + f * z[ind - 1]
if ind == 0:
# If the point is very close to the magnetic axis, don't
# try to do extrapolation.
r = r[ind]
z = z[ind]
else:
# Edited by Bhavin 31/07/18
# Changed 1.0 to psival in f
# make f gradient to psival surface
f = (pnorm[ind] - psival) / (pnorm[ind] - pnorm[ind - 1])

# Interpolate between points
r = (1.0 - f) * r[ind] + f * r[ind - 1]
z = (1.0 - f) * z[ind] + f * z[ind - 1]

if f > 1.0: warn(f"find_psisurface has encountered an extrapolation. This will probably result in a point where you don't expect it.")

if axis is not None:
axis.plot(r, z, "bo")
Expand Down Expand Up @@ -505,8 +514,8 @@ def find_safety(
psifunc,
r0,
z0,
r0 + 8.0 * sin(theta),
z0 + 8.0 * cos(theta),
r0 + np.ptp(eq.R) * sin(theta),
z0 + np.ptp(eq.Z) * cos(theta),
psival=psin,
axis=axis,
)
Expand Down