Skip to content

Normalized surface current density, OFT migration, small improvements for field line tracing - #17

Open
chandrarn wants to merge 3 commits into
mainfrom
rnc/Normalized_Current_Density
Open

chandrarn wants to merge 3 commits into
mainfrom
rnc/Normalized_Current_Density

Conversation

@chandrarn

@chandrarn chandrarn commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Key changes building on Filament vectorization and tracing harmoics PR #15 - #16: Replaces PR #11

  • Swaps out OFT loading scheme entirely (for the new, more pythonic virtualenvironment install from PyPi),
  • Scales the individual filament currents such that the effective poloidal surface current density $\sigma$ is normalized [1 A/m],
  • Slightly changes the way e_Bp for COCOS is calculated (this will also be migrated into dispy-extra
  • Adds an option to the filament tracer to just directly solve the magnetic field ODE,
  • Adds an option to bound the root-solver for psi(q), which slightly fixes some edge cases from DIII-D where the x-point confused the algorithm.

OFT swap is validated to work in pytest (test_thincurr.py), as is the new Field tracing option (see test_field_trace_matches_average_endpoint within test_filaments.py)
Note: OFT no longer ships with the example DIII-D gEQDSK file at OpenFUSIONToolkit/examples/TokaMaker/DIIID/g192185.02440, this impacts pytest options.
Note that the pytests in test_flux_matrix.py needed to be updated to handle assertions of current as normalized density not normalized amplitude.

All pytest scripts pass.

Minor fix for e_Bp, produces more stable outcomes.
image

Bounding root-solver for psi(q) fixes some edge cases with high m/n on DIII-D
image

…R#15-16: Replaces PR#11: swaps out OFT loading scheme entirely (for the new, more pythonic virtualenvironment install from PyPi), scales the individual filament currents such that the effective poloidal surface current density is normalized [1 A/m], adds an option to the filament tracer to just directly solve the magnetic field ODE, adds an option to bound the root-solver for psi(q), which slightly fixes some edge cases from DIII-D where the x-point confused the algorithm. OFT swap is validated to work in pytest, as is the new Field tracing option (see test_field_trace_matches_average_endpoint)
…tween the raw interpolation for psi(q) and the Newton or bounded root-solver method
@chandrarn
chandrarn marked this pull request as ready for review September 18, 2026 23:18
"eqdsk_d3d",
marks=pytest.mark.skipif(
condition=not os.path.exists(D3D_EQDSK_FILE),
reason="Test requires DIII-D data which is not open source",

@ZanderKeith ZanderKeith Sep 19, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is open-source. In install.sh just have it get downloaded from here: https://github.com/OpenFUSIONToolkit/OpenFUSIONToolkit/blob/v26.9/src/examples/TokaMaker/DIIID/g192185.02440

Put it in a place like synthwave/tests/test_data so that we always know where it is.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are any of these diagnostic scripts necessary? They seem like things used during the development process but should not live in the repo itself.

Comment thread .gitignore
CLAUDE.md

# Install
submodules/OpenFUSIONToolkit

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be safe to leave this in, or perhaps ignore all submodules going forward.

Comment thread install.sh
sed -i "s|^LD_LIBRARY_PATH=|LD_LIBRARY_PATH=${HDF5_LIB_PATH}:|" "${SCRIPT_DIR}/.env"
fi

# Create setup_env.sh

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we are using PyPI for OFT, we should be able to completely remove setup_env.sh.

return np.array([Br, Bt, Bz])

def get_psi_of_q(self, q):
def get_psi_of_q_old(self, q):

@ZanderKeith ZanderKeith Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is no longer called anywhere. If we're replacing it, remove it.

sign_Bp = int(psi_increasing * sign_Ip)

def _e_Bp(eqdsk):
def _e_Bp_new(eqdsk):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should just be _e_Bp

from synthwave.magnetic_geometry.utils import cylindrical_to_cartesian


def _average_phi0_poloidal_arc_spacing(

@ZanderKeith ZanderKeith Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I don't fully understand what you're doing here, but is the average poloidal arc spacing not just

total_arc * n_local / (num_filaments * m_local)?

psi_norm_1d,
np.asarray(eqdsk.ffprime, float),
)
# RHS from the stored profiles, mapped over the raw physical psi grid.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please send me the DIII-D eqdsk where this differs? I'm finding the result is bit-identical for the included g192185.02440, as well as some C-Mod and TCV shots.

@ZanderKeith

Copy link
Copy Markdown
Collaborator

Left some comments, we should chat briefly Monday/Tuesday.


# Bound possible psi values around initial guess from psi grid
psi_lo = (
self.psi_grid[psi_guess_index - 5]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 5 and 10 in particular? Could these be made constants defined at the top with some descriptive names?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants