Skip to content

Comments

Feature/flux surface integrals#392

Open
rossmfusion wants to merge 21 commits intomasterfrom
feature/flux_surface_integrals
Open

Feature/flux surface integrals#392
rossmfusion wants to merge 21 commits intomasterfrom
feature/flux_surface_integrals

Conversation

@rossmfusion
Copy link
Collaborator

This PR includes updates to the flux surface averaging of quantities relevant to TORAY runs in ECpy. It puts the "hf" helical flux function in gm10 in the IMAS data scheme. It also updates EC launcher angle conversion functions.

rossmfusion and others added 14 commits August 25, 2025 14:35
…rting between IMAS and DIIID ECH launcher angle coordinates.
…erages. Also figured out how to import the b_field_tor using the derive_equilibrium_profiles_2d_quantity function. Still only partway through updating add_volume_profle to compute accurate flux surface averages. Committing now in order to merge changes from the main branch into this one in order to merge in an update to the b_field_tor definition (there was an error that has been recently fixed).
@AreWeDreaming
Copy link
Collaborator

Thanks for your contribution @rossmfusion. @torrinba and I will work on creating a test for this.

… omas_physics instead of "add_voluem_profile" now that that function name has been change. This appears to fix the failed test encountered in the original PR for this branch.
…s requireed explicit definition of trapz function.
@AreWeDreaming AreWeDreaming self-requested a review January 29, 2026 17:05
Copy link
Collaborator

@AreWeDreaming AreWeDreaming left a comment

Choose a reason for hiding this comment

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

This could be slightly more numerically efficient if we interpolate the total magnetic field instead of the individual compoonents.

Comment on lines +653 to +656
try:
trapz = np.trapezoid # modern NumPy >=1.20
except AttributeError:
trapz = np.trapz # older NumPy
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
try:
trapz = np.trapezoid # modern NumPy >=1.20
except AttributeError:
trapz = np.trapz # older NumPy

Please look at the top of this file. trapz has already been imported

Comment on lines 683 to 698
@@ -671,15 +691,34 @@ def add_volume_profile(ods, grid_index=0):
eq_slice[f'profiles_2d.{grid_index}.grid.dim2'],
eq_slice[f'profiles_2d.{grid_index}.b_field_z'])

b_field_tor_spline = RectBivariateSpline(
eq_slice[f'profiles_2d.{grid_index}.grid.dim1'],
eq_slice[f'profiles_2d.{grid_index}.grid.dim2'],
eq_slice[f'profiles_2d.{grid_index}.b_field_tor'])

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
b_field_tot_spline = RectBivariateSpline(
eq_slice[f'profiles_2d.{grid_index}.grid.dim1'],
eq_slice[f'profiles_2d.{grid_index}.grid.dim2'],
np.sqrt(eq_slice[f'profiles_2d.{grid_index}.b_field_tor']**2
+ eq_slice[f'profiles_2d.{grid_index}.b_field_r']**2
+ eq_slice[f'profiles_2d.{grid_index}.b_field_r']**2 ))

This saves 2/3 of the operations

if k == 0:
RMAXIS = ods['equilibrium.time_slice.'+str(time_index)+'.global_quantities.magnetic_axis.r']
ZMAXIS = ods['equilibrium.time_slice.'+str(time_index)+'.global_quantities.magnetic_axis.z']
Btot = numpy.sqrt(b_field_r_spline(RMAXIS, ZMAXIS, grid=False)**2 + b_field_z_spline(RMAXIS, ZMAXIS, grid=False)**2 + b_field_tor_spline(RMAXIS, ZMAXIS, grid=False)**2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Btot = numpy.sqrt(b_field_r_spline(RMAXIS, ZMAXIS, grid=False)**2 + b_field_z_spline(RMAXIS, ZMAXIS, grid=False)**2 + b_field_tor_spline(RMAXIS, ZMAXIS, grid=False)**2)
Btot = b_field_tot_spline(RMAXIS, ZMAXIS, grid=False)

* (2.0 * numpy.pi) ** (1.0 - cocos['exp_Bp']))

# determine flux-surface-averaged quantities
Btot = numpy.sqrt(b_field_r_spline(r, z, grid=False)**2 + b_field_z_spline(r, z, grid=False)**2 + b_field_tor_spline(r, z, grid=False)**2)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Btot = numpy.sqrt(b_field_r_spline(r, z, grid=False)**2 + b_field_z_spline(r, z, grid=False)**2 + b_field_tor_spline(r, z, grid=False)**2)
Btot = b_field_tot_spline(r, z, grid=False)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Actually now I see that B_tor is needed for hf so I recommend to instead create a B_pol^2 = b_field_r2 + b_field_z2 spline and evaluating B_t and adding it.

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.

3 participants