Skip to main content

DA-based FFAG accelerator tracking using differential algebra

Project description

pyffag

DA-based FFAG accelerator tracking using differential algebra.

Built on daceypy for arbitrary-order transfer map computation through FFAG sector magnets via integration of the exact midplane Hamiltonian.

Installation

pip install pyffag

Quick start

import numpy as np
from daceypy import DA
from pyffag import sector_map, compose_sequence, compose_n, tune, twiss
from pyffag.constants import kinetic_to_brho, M_PROTON

# 250 MeV proton FFAG ring: 8 FD doublet cells
DA.init(5, 2)  # DA order 5, 2 variables (x, px)
Brho = kinetic_to_brho(250.0, M_PROTON)

# F magnet: horizontally focusing sector, 25 degrees
F = sector_map([0.9, 2.0], Brho, angle=np.radians(25.0))

# D magnet: horizontally defocusing sector, 20 degrees
D = sector_map([0.9, -3.0], Brho, angle=np.radians(20.0))

cell = compose_sequence([F, D])
ring = compose_n(cell, 8)

print(f"Cell tune: {twiss(cell)['tune']:.4f}")
print(f"Ring tune: {tune(ring):.4f}")

Features

  • Sector tracking — exact curvilinear Hamiltonian integration through sector magnets with polynomial midplane field By(x) = Σ B_k x^k. Midplane 2-DOF (sector_map) and 4-DOF (sector_map_4d, Maxwell-consistent off-midplane expansion).
  • Element maps — exact drift, thin quadrupole / sextupole / octupole, edge kicks.
  • Ring operations — map composition, N-fold composition, closed-orbit finding (Newton with DA Jacobian; see below).
  • Optics — transfer matrix, tune, Twiss (β, α, γ), stability check, symplecticity error.
  • Shared lattice format — JSON schema that defines a sequence of elements and drives pyffag.build_map(). Portable across pyffag versions and, when paired with external cross-validation harnesses, across codes.

Lattice format (JSON)

{
  "name": "fd_doublet",
  "brho": 2.0,
  "elements": [
    {"type": "sector", "B": [1.0, 2.0], "angle_deg": 15.0},
    {"type": "drift",  "length": 0.3},
    {"type": "sector", "B": [1.0, -1.0], "angle_deg": 15.0},
    {"type": "thin_sext", "kL": 0.05}
  ]
}
import pyffag
from daceypy import DA

lattice = pyffag.load("fd_doublet.json")
DA.init(5, 2)
ring = pyffag.build_map(lattice)
print(pyffag.tune(ring), pyffag.twiss(ring))

Element types: sector, drift, drift_paraxial, thin_quad, thin_sext, thin_oct, edge_kick. See pyffag.lattice for the full schema.

Closed-orbit finding

from daceypy import DA
from pyffag import sector_map, find_closed_orbit

DA.init(5, 2)
x_co, px_co, converged = find_closed_orbit(
    lambda: sector_map([1.0, 2.0], 2.0, angle=0.4363),
    x_guess=0.0, px_guess=0.0,
)

The solver expands the DA map internally about the current guess and uses the DA Jacobian for a Newton step. Converges in one iteration for linear maps; quadratic convergence for nonlinear.

Physics

sector_map() integrates the midplane equations of motion in Frenet-Serret (curvilinear) coordinates with arc length as the independent variable. Sector magnets have radial edge faces (no edge focusing); non-radial edges are modelled explicitly via edge_kick.

Integration with danf

For nonlinear normal-form analysis (detuning, chromaticity, complex-basis NF) use danf:

from danf import NormalForm, chromaticity_1d

nf = NormalForm(ring)
nf.compute()
print(nf.tunes, nf.detuning)

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyffag-0.3.0.tar.gz (20.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyffag-0.3.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file pyffag-0.3.0.tar.gz.

File metadata

  • Download URL: pyffag-0.3.0.tar.gz
  • Upload date:
  • Size: 20.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pyffag-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c8e4e1f1f7642bb29e4534e8a695a05e6dcf192bdb5272ceb589e228a27c3440
MD5 f086eb9309ed3e0afb3e3630af15f07e
BLAKE2b-256 528ace06f30a37c1900a72bfdad8f8d567403413ba56a9f9a754c2b76f7e5698

See more details on using hashes here.

File details

Details for the file pyffag-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pyffag-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for pyffag-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3a01f054359d4b2b747c13a5a870b3c453a83d35283e2e75720e2516640395c7
MD5 361c9c33ae77ea4799896feda1317c88
BLAKE2b-256 62a7491373c15befa57ab253d0161aa95a38f53cfe826dd56188f85a367b686b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page