beam-tracing / Scotty

Beam tracing code for diagnostics
https://scotty.readthedocs.io/en/latest/
GNU General Public License v3.0
7 stars 4 forks source link

Errors with very large aspect ratio tokamaks (quasi-slab mode) #124

Closed quinntpratt closed 3 months ago

quinntpratt commented 11 months ago

In an effort to "trick" SCOTTY into running in a slab, I shifted my R launch location and R-grid in the topfile.json by a huge constant value, in my case: 1000 m. This makes the tokamak have vanishing aspect ratio: r/R.

This exercise revealed several issues in the routines which find the ray/beam entry location... and SCOTTY cannot run properly.

Disclaimer: I'm using the version of SCOTTY which is currently installed on the GA iris cluster at: /fusion/projects/codes/scotty/SCOTTY.

Issues I found myself

In beam_me_up.py around line 1080 there's the line:

R_coarse_search_array = np.linspace(
    launch_position[0], 0.0, numberOfCoarseSearchPoints
    )

This doesn't work for my slab case because its coarse grid is np.linspace(1000, 0, 50) so it skips the whole plasma. I recommend changing to something like,

R_coarse_search_array = np.linspace(
    launch_position[0], np.average(R_array) , numberOfCoarseSearchPoints
    )

Where R_array would be the grid from the topfile. This would search from the launch to roughly the center of the plasma.

In beam_me_up.py around line 1072 there's the line:

# Finds entry point
search_Z_end = launch_position[2] - launch_position[0]* np.tan(
    np.radians(poloidal_launch_angle_Torbeam)
    )

Which should be modified to something like,

# Finds entry point
search_Z_end = launch_position[2] - (launch_position[0] - np.average(R_array))* np.tan(
    np.radians(poloidal_launch_angle_Torbeam)
    )

This way the triangle implied by the R and poloidal launch angle isn't absolutely huge, causing the search_Z_end to be huge.

Anyway... after fixing these issues SCOTTY just "hangs" and never finishes running... so clearly there's another bug which I have not identified when running in this quasi-slab mode.

My input files are attached in a zip file, scotty_inputs_slab.zip

ZedThree commented 9 months ago

Hi @quinntpratt, sorry it's taken me so long to dig into this. It looks like the version on iris is a bit out of date, and running with the latest version of scotty, it's a little bit more explicit about what's gone wrong:

RuntimeError: Beam does not hit plasma. Closest point is at (R=227.2481870542996, zeta=3.1415926535897927, Z=150.96696612924634), distance in poloidal flux to boundary=0.35728014602049196

Looking at the flux surface plots, and the launch position and angle, it's clear this is a bug.

I've found the issue and will make a PR for it now.

Just to note, that there's some input arguments that have changed since the version you seem to be using. Here's the script I used to run your case:

import scotty
import json

with open("argsdict.json") as f:
    args = json.load(f)

args.pop("verbose_output_flag")     # Everything is saved now
args["poloidal_flux_enter"] = 1.0   # I had an issue with the value 1.1025
args["Psi_BC_flag"] = "continuous"  # True/False is deprecated, replaced by None/"continuous"/"discontinuous"

scotty.beam_me_up(**args)

With my fix, I get the following result:

Ray1_ png

valerian-chen commented 3 months ago

Resolved by @ZedThree 's fix.