ChristopherMayes / openPMD-beamphysics

Tools for analyzing and viewing particle data in the openPMD standard, extension beamphysics.
https://christophermayes.github.io/openPMD-beamphysics/
Apache License 2.0
16 stars 15 forks source link

issue with conversion from z to t when loading IMPACT-T particle distribution #20

Closed Alfven17 closed 2 years ago

Alfven17 commented 2 years ago

https://github.com/ChristopherMayes/openPMD-beamphysics/blob/master/pmd_beamphysics/interfaces/impact.py#L92

ChristopherMayes commented 2 years ago

What is the issue?

Alfven17 commented 2 years ago

For free space start, t is the same for all particles. This is not an issue itself but ParticleGroup uses t when writing to Bmad's ASCII file, and all the "z"s will be zeros.

https://github.com/ChristopherMayes/openPMD-beamphysics/blob/master/pmd_beamphysics/interfaces/bmad.py#L58

So it's really about making the two interfaces compatible. Maybe one can force a coordinate conversion from t to s?

ChristopherMayes commented 2 years ago

Bmad uses so-called s-coordinates that define all particles z=0, and uses the time (z_bmad = -beta*c*(t - t_ref)) as the longitudinal phase space coordinate. ParticleGroup provides some conveniences for converting these: https://github.com/ChristopherMayes/openPMD-beamphysics/blob/c7beed293330353cc1b25c534ba5b2360f5d79f1/pmd_beamphysics/particles.py#L122

Currently the write_bmad function does not do this conversion, but rather expects that you know what you are doing. https://github.com/ChristopherMayes/openPMD-beamphysics/blob/c7beed293330353cc1b25c534ba5b2360f5d79f1/pmd_beamphysics/interfaces/bmad.py#L3

Perhaps it could raise a warning?

Alfven17 commented 2 years ago

Yes, that's probably sufficient.