Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add particle species in Beam classes and update tracking methods #276

Open
wants to merge 59 commits into
base: master
Choose a base branch
from

Conversation

cr-xu
Copy link
Member

@cr-xu cr-xu commented Oct 14, 2024

Description

Add the option to track with different particle species.

Changes:

  • Introduce a new Species class that tracks the name, charge and mass information of particles. Some basic species are pre-defined, with the possibility to define custom mass-to-charge ratio particles.
  • Now the transfer_map methods and the compute_relativistic_factors take two arguments:[energy, particle_mass_eV] to account for different species.
  • Beam classes now have (and take) a species property to keep track of the particle species.
  • Added new benchmark tests by running Bmad simulations directly.
  • Updated the CI/CD pipelines to install Bmad with conda. Windows tests are run without Bmad because that latter is not available for Windows.

Motivation and Context

  • I have raised an issue to propose this change (required for new features and bug fixes)

This was requested in #231 and #263.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation (update in the documentation)

Checklist

  • I have updated the changelog accordingly (required).
  • My change requires a change to the documentation.
  • I have updated the tests accordingly (required for a bug fix or a new feature).
  • I have updated the documentation accordingly.
  • I have reformatted the code and checked that formatting passes (required).
  • I have have fixed all issues found by flake8 (required).
  • I have ensured that all pytest tests pass (required).
  • I have run pytest on a machine with a CUDA GPU and made sure all tests pass (required).
  • I have checked that the documentation builds (required).

Note: We are using a maximum length of 88 characters per line.

@cr-xu cr-xu linked an issue Oct 14, 2024 that may be closed by this pull request
@cr-xu cr-xu changed the title 231 Add particle species in particlebeam 231 Add particle species in Beam classes and update tracking methods Oct 14, 2024
@jank324 jank324 changed the title 231 Add particle species in Beam classes and update tracking methods Add particle species in Beam classes and update tracking methods Oct 15, 2024
@cr-xu cr-xu self-assigned this Oct 15, 2024
@jank324 jank324 added the enhancement New feature or request label Oct 15, 2024
@cr-xu cr-xu requested a review from jank324 October 16, 2024 07:55
@cr-xu cr-xu marked this pull request as ready for review October 16, 2024 07:55
@cr-xu cr-xu marked this pull request as draft October 16, 2024 14:18
@cr-xu
Copy link
Member Author

cr-xu commented Oct 16, 2024

I just realized that I still need to take the particle charges into account for the cavities/elements with electric fields. So this should probably wait until #278 is merged.

@cr-xu cr-xu marked this pull request as ready for review October 22, 2024 15:26
@jank324 jank324 requested a review from Hespe January 20, 2025 12:03
Copy link
Member

@Hespe Hespe left a comment

Choose a reason for hiding this comment

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

Few minor suggestions, but in principle no blocking issues.

.github/workflows/pytest.yaml Outdated Show resolved Hide resolved
Comment on lines +25 to +27
:param voltage: Voltage of the cavity in volts. NOTE: This assumes the effective
voltage. If the particle does not have unit charge, the voltage needs to be
scaled properly.
Copy link
Member

Choose a reason for hiding this comment

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

This seems counterintuitive. Is this effect caused by us measuring energy in eV such that we cannot just set voltage = energy gain for non-unit charge particles?

This might especially lead to issues if we import lattices from external files. In that case the converter would have to know the intended particle species and adjust all voltages.

Copy link
Member

Choose a reason for hiding this comment

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

@cr-xu what do you think?

Copy link
Member Author

@cr-xu cr-xu Feb 5, 2025

Choose a reason for hiding this comment

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

Yes, I thought that confusing too at the beginning.
I went with this convention exactly due to the compatibility with the converters. Because Bmad also defines the voltage as the effective voltage for the ref. particle

Copy link
Member

@jank324 jank324 Feb 5, 2025

Choose a reason for hiding this comment

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

So @cr-xu you think we are fine as we are and won't run into problems when simulating other species?

Copy link
Member Author

@cr-xu cr-xu Feb 5, 2025

Choose a reason for hiding this comment

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

I think it's in the end a design choice... I see this convention (effective voltage rather than the physical one) as consistent with other normalized field strengths like $k_1$ for quadrupoles etc.
We can also just use the physical voltage,and just document/comment that extra caution is needed if they want to have non-unit charged particles.

Copy link
Member

Choose a reason for hiding this comment

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

I have no opinion on this. I just want to know if this is okay to merge 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

@Hespe Actually now the voltage = total energy gain for non-unit charged particles. Setting the voltage to physical voltage would mean that total energy gain = voltage * q

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that is what I meant. For non-unit charged particles, we would have to take the charge into account to calculate the energy gain.

I think your argument that the cavity is particle independent is what I would have thought before. Otherwise you would have to know the particle you are going to simulate the correctly configure the Cavity element.

Comment on lines +20 to +22
:param voltage: Voltage of the cavity in volts. NOTE: This assumes the effective
voltage. If the particle does not have unit charge, the voltage needs to be
scaled properly.
Copy link
Member

Choose a reason for hiding this comment

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

Same as above. At least for me, it would be more intuitive if this is the physical voltage of the cavity and the effective voltage would be an implementation detail.

cheetah/particles/beam.py Outdated Show resolved Hide resolved
cheetah/particles/parameter_beam.py Outdated Show resolved Hide resolved
tests/test_compare_bmad.py Outdated Show resolved Hide resolved
@Hespe Hespe mentioned this pull request Jan 22, 2025
14 tasks
@jank324
Copy link
Member

jank324 commented Feb 7, 2025

@Hespe I just committed the unfinished changes ... in case you want to continue them

@Hespe
Copy link
Member

Hespe commented Feb 10, 2025

I have no idea why the tests failed in the morning. I was unable to reproduce the failure and now it suddenly all works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add particle species in ParticleBeam
3 participants