Skip to content

Conversation

kyrsjo
Copy link
Contributor

@kyrsjo kyrsjo commented Jul 11, 2025

This pulls out the changes to ConstF from PR #1030 . It allows the ConstF elements to handle negative (defocusing) k values.

  • Add testing.

Question: Why is the unit of kx and ky in this element 1/m, i.e. the square root of the more common definition of k?

@cemitch99
Copy link
Member

@kyrsjo I don't see an element exactly analogous to this one in the MAD-X documentation. However, (at least for the transverse focusing), the closest analogy is the SOLENOID. If the rotation in x-y is ignored, then the solenoid provides equal focusing in x/y with strength k=Bz/Brho, following the convention defined here. In other words, the focusing field strength normalized by Brho.

m_cos_kyds = cos_kyds;
m_const_y = -m_ky * sin_kyds;
// Note: The convention here is m_kx[1/m] = sign(k)*sqrt(abs(k))
// where k[1/m^2] is in the usual MADX convention
Copy link
Member

Choose a reason for hiding this comment

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

This statement is not clear, since there is not direct MADX analog. For solenoids, the focusing strength is k [1/m].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was mainly thinking that this is a strong analog to quadrupole mangets and plasma lenses, since the equations are exactly the same*, and there is no rotation implemented between the horizontal/vertical plane? So providing the conversion explicitly to the units used for quadrupoles makes sense IMO.

* Except for the convention of how k works.

auto const [sin_kyds, cos_kyds] = amrex::Math::sincos(m_ky * slice_ds);
amrex::ParticleReal const_y = -m_ky * sin_kyds;
// Note: The convention here is m_kx[1/m] = sign(k)*sqrt(abs(k))
// where k[1/m^2] is in the usual MADX convention
Copy link
Member

Choose a reason for hiding this comment

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

See the comment above.

@cemitch99
Copy link
Member

This looks great; thanks a lot! I made only a minor comment. It looks ready to go once a simple test is added. Let us know if you would like some help with this.

@ax3l ax3l added the component: elements Elements/external fields label Jul 12, 2025
@kyrsjo
Copy link
Contributor Author

kyrsjo commented Jul 18, 2025

Hi, that's great!

I'm on summer holiday right now, will be back in August. I can look at it then, or if you want to add the test and merge, please feel free!

Thanks again for all the help - it makes it a lot more likely that I will contribute again, and now I know your setup and standards!

@kyrsjo
Copy link
Contributor Author

kyrsjo commented Sep 22, 2025

TODO: Fix https://github.com/BLAST-ImpactX/impactx/pull/1030/files/4866ef838a31ed23f185e52f1978a544c740fafe#r2361158766

Basically in run_APL_tracking(), delete the comment

# [Doesn't give same result as ChrPlasmaLens and ChrQuad for some reason, even when sigpt_0 = 0]

@kyrsjo kyrsjo changed the title ConstF: Allow kx<0 and ky<0 [WIP] ConstF: Allow kx<0 and ky<0 Sep 22, 2025
@kyrsjo
Copy link
Contributor Author

kyrsjo commented Sep 22, 2025

In tests, also look at this for how I get the data out:
#1030 (comment)
Says:

Note: This works, but the values defined here are computed internally and stored as reduced_diagnostics. See this example for an alternative approach: https://impactx.readthedocs.io/en/latest/usage/examples/fodo_space_charge/README.html
It's fine to keep this for now.

Relative to:
return (beta_x, beta_y, alpha_x, alpha_y)
in analysis_APL_ChrPlasmaLens.py
function get_twiss()

@kyrsjo
Copy link
Contributor Author

kyrsjo commented Oct 2, 2025

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

Labels

component: elements Elements/external fields

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants