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 accelerator lattice, starting with quadrupoles #3063

Merged
merged 77 commits into from
Dec 21, 2022

Conversation

dpgrote
Copy link
Member

@dpgrote dpgrote commented Apr 26, 2022

This PR is the initial implementation of an accelerator lattice, starting with hard edge quadrupoles. The implementation follows the scheme in Warp, where the lattice is laid out along the z axis. Each lattice element is specified by an extent in z and information about its field structure.

To locate which element particles are in, a grid is laid out in z and at each grid cell, the index of the nearest element is saved. Then for each particle, a look up is done from the table. This grid is updated as needed in a moving frame and with load balancing.

For the GPU, host level and device level classes are defined. The data is read in and setup in the host level class and the needed data copied to the GPU. The device level class only holds pointers to the needed data. This hasn't been tested but does compile.

To do:

  • Add a CI test in the moving window
  • Test on GPU
  • Add handling of the boosted frame
  • Add plasma lens using the new lattice infrastructure
  • Add documentation

This PR assumes that elements within a type do not overlap each other. A future PR can be added to allow the overlapping.

@dpgrote dpgrote added the enhancement New feature or request label Apr 26, 2022
@lgtm-com
Copy link
Contributor

lgtm-com bot commented Apr 26, 2022

This pull request introduces 2 alerts when merging fa21501 into 8eb3163 - view on LGTM.com

new alerts:

  • 1 for Unused import
  • 1 for Variable defined multiple times

It is not clear why there was a change, but the difference is
essentially round off in the E field. The important thing is that the
particles are still correct.
@@ -1384,6 +1390,54 @@ External fields
and :math:`E_z = 0`, and
:math:`B_x = \mathrm{strength} \cdot y`, :math:`B_y = -\mathrm{strength} \cdot x`, and :math:`B_z = 0`.

Accelerator Lattice
Copy link
Member

Choose a reason for hiding this comment

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

@dpgrote @cemitch99 let us double check again if we can keep them as close as possible to ImpactX :)
https://impactx.readthedocs.io/en/latest/usage/parameters.html#lattice-elements

Copy link
Member

Choose a reason for hiding this comment

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

Looks good on first view to me. See plasmalens -> ConstF below.

* ``<element_name>.dBdx`` (``float``, in Tesla/meter) optional (default: 0.) the magnetic quadrupole field gradient
The field applied to the particles will be `Bx = dBdx*y` and `By = dBdx*x`.

* ``plasmalens`` for a field modeling a plasma lens
Copy link
Member

Choose a reason for hiding this comment

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

Checking how similar this is in ImpactX to ConstF element with @cemitch99

Copy link
Member

Choose a reason for hiding this comment

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

Discussed on slack: ConstF is more general. We might want to replace plasmalens with the equivalent description of ConstF in a follow-up PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, using the more general ConstF would be good in a later PR. In this PR, I wanted to reproduce the existing capability.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed, tracking in #3566

Comment on lines +26 to +39
lattice.elements = lattice1 lattice2

lattice1.type = lattice
lattice1.elements = drift1 quad1

lattice2.type = lattice
lattice2.elements = drift2 quad2

drift1.type = drift
drift1.ds = 0.2

quad1.type = quad
quad1.ds = 0.2
quad1.dEdx = 1.e4
Copy link
Member

@ax3l ax3l Dec 13, 2022

Choose a reason for hiding this comment

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

Clever recursive way to do segments 🤓
We could to the same in ImpactX @cemitch99 ?

Copy link
Member

Choose a reason for hiding this comment

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

Will track here ECP-WarpX/impactx#284

Copy link
Member

Choose a reason for hiding this comment

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

Implemented via ECP-WarpX/impactx#335

Copy link
Member

@ax3l ax3l left a comment

Choose a reason for hiding this comment

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

Awesome work, thanks a lot! 🚀 ✨

@ax3l ax3l enabled auto-merge (squash) December 21, 2022 17:43
@ax3l ax3l merged commit 8985852 into ECP-WarpX:development Dec 21, 2022
@dpgrote dpgrote deleted the add_accelerator_lattice_quads branch December 21, 2022 19:42
A list of names (one name per lattice element), in the order that they
appear in the lattice.

* ``<element_name>.type`` (``string``)
Copy link
Member

Choose a reason for hiding this comment

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

@dpgrote I just realized we forgot to document the lattice type here, for lines.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed offline: will add and rename to line

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.

None yet

8 participants