Skip to content

Add Python script for Fourier coefficients#1316

Open
cemitch99 wants to merge 18 commits intoBLAST-ImpactX:developmentfrom
cemitch99:add_fcoef_example
Open

Add Python script for Fourier coefficients#1316
cemitch99 wants to merge 18 commits intoBLAST-ImpactX:developmentfrom
cemitch99:add_fcoef_example

Conversation

@cemitch99
Copy link
Member

@cemitch99 cemitch99 commented Feb 23, 2026

This PR addresses Issue #1314

  • add working Python script based on IMPACT-Z utility here
  • add example input file
  • add README
  • add plotting script
  • add analysis script
  • move into helper API for individual elements

@cemitch99 cemitch99 self-assigned this Feb 23, 2026
@cemitch99 cemitch99 added enhancement New feature or request component: elements Elements/external fields component: tests examples, tests and benchmarks labels Feb 23, 2026
@cemitch99 cemitch99 added this to the Advanced Methods (SciDAC-5) milestone Feb 23, 2026
@cemitch99 cemitch99 requested review from ax3l and qianglbl February 23, 2026 23:23
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 24, 2026

Merging this PR will not alter performance

✅ 37 untouched benchmarks


Comparing cemitch99:add_fcoef_example (d07615b) with development (7dd7fca)

Open in CodSpeed

@ax3l ax3l assigned ax3l and unassigned cemitch99 Feb 25, 2026
@@ -0,0 +1,500 @@
0.0000000000000000 -4.1031444226780268E-004
Copy link
Member

Choose a reason for hiding this comment

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

@cemitch99 what are the columns and units of this data set?

Copy link
Member Author

Choose a reason for hiding this comment

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

The data in the second column will be scaled internally based on the element input (e.g. bscale, escale, etc.), so the units have no physical interpretation in isolation. I usually scale the values in the second column so that the maximum value is 1. Then e.g. for a SoftSolenoid the value of bscale fixes the peak on-axis value of B_z in 1/m (if unit=0) or in T (if unit=1).

Comment on lines 114 to 118
data = read_data("onaxis_data.in")
ncoef = int(input("How many Fourier coefficients do you want? "))
cos_coeffs, sin_coeffs, emax = calculate_coefficients(data, ncoef)
write_coefficients(cos_coeffs, sin_coeffs, "fcoef.out")
write_data(cos_coeffs, sin_coeffs, data[:, 0], emax, "onaxis_datax")
Copy link
Member

Choose a reason for hiding this comment

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

Memo to myself:
Move into a pytest unit test.

@ax3l ax3l force-pushed the add_fcoef_example branch from abd5112 to 64bf753 Compare February 26, 2026 06:42
ax3l added 2 commits February 25, 2026 22:48
Not used anywhere, re-scaled anyway, arb.u.
split the 2d array into two named 1D arrays for better
readability / descript variable names.
ns = 1 # number of slices per ds in the element

# read in the on-axis quadrupole gradient data
z, field_or_gradient = read_data("onaxis_data.in")
Copy link
Member

Choose a reason for hiding this comment

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

@cemitch99 one thing I do not yet fully understand: what is the reference point of z for this data (first column)?

  • Is z=0 the entrance or mid or exit of the element?
  • Can it only have positive values, meaning "away from the element"?
  • Are the same fringe fields applied at entry and exit of the element? Are they exactly mirrored?

Comment on lines +64 to +65
cos_coefficients=cos_coeffs,
sin_coefficients=sin_coeffs,
Copy link
Member

Choose a reason for hiding this comment

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

User-facing API: I will add an overload to this constructor that accepts simply z and field_or_gradient and then calls the converter below automatically for the user. Data is still stored as cos & sin coefficients internally.

We will need to very clearly document what z means, see above.

)

# Reconstruction of On-Axis Data from Coefficients #############
# without space charge
Copy link
Member

@ax3l ax3l Feb 26, 2026

Choose a reason for hiding this comment

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

Simplifying a bit in #1327

Suggested change
# without space charge
#

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

Labels

component: elements Elements/external fields component: tests examples, tests and benchmarks enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants