Skip to content

Add momentum_aperture method to Line class#751

Open
gbrogginess wants to merge 14 commits intoxsuite:mainfrom
gbrogginess:momentum_aperture
Open

Add momentum_aperture method to Line class#751
gbrogginess wants to merge 14 commits intoxsuite:mainfrom
gbrogginess:momentum_aperture

Conversation

@gbrogginess
Copy link
Copy Markdown
Contributor

Description

This PR introduces a new method:

line.momentum_aperture(...)

to compute the local momentum aperture (also referred to as local momentum acceptance, LMA) along a beamline by tracking particles with varying momentum offsets from selected elements.

The method evaluates, for each selected longitudinal location, the maximum stable negative and positive momentum deviations (δ) over a configurable number of turns.

For each location, particles are generated around the local closed orbit, a grid of momentum offsets is applied, and particles are tracked to determine the largest surviving negative and positive δ values.

The output is returned as an xt.Table indexed by longitudinal position s.

This feature is important because the local momentum acceptance is a key quantity for Touschek and quantum lifetime studies and their optimization.

A dedicated test suite covering this new functionality has been added.

Checklist

Mandatory:

  • I have added tests to cover my changes
  • All the tests are passing, including my new ones
  • I described my changes in this PR description

Optional:

  • The code I wrote follows good style practices (see PEP 8 and PEP 20).
  • I have updated the docs in relation to my changes, if applicable
  • I have tested also GPU contexts

Comment thread xtrack/line.py
multi_element_monitor_at=multi_element_monitor_at,
**kwargs)

def momentum_aperture(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Rename to get_local_momentum_acceptance

Comment thread xtrack/line.py
delta_co= twiss['delta', ee]

# On-momentum, matched, test particles
particles = self.build_particles(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Try not to redo twiss

Comment thread xtrack/line.py
deltan = float(0.0)
deltap = float(0.0)

rows.append({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Add a name as column and use it as index

Comment thread xtrack/line.py
s_start: float = 0.0,
s_end: float | None = None,
include_name_pattern: str | None = None,
include_type_pattern: str | None = None,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

try to reuse Table.rows on twiss table or line table instead of reimplementing

Comment thread xtrack/line.py
# Compute twiss (use 6D by default, overridable via kwargs['method'])
twiss_method = kwargs.pop('method', '6d')
if twiss is None:
twiss = self.twiss(method=twiss_method)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pass reverse=False (to avoid surprises form line.twiss.default)

Comment thread xtrack/line.py
delta_positive_limit: float = +0.10,
delta_step_size: float = 0.01,
skip_elements: int = 0,
process_elements: int = 2**31 - 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

make it internal

Comment thread xtrack/line.py
include_name_pattern: str | None = None,
include_type_pattern: str | None = None,
n_turns: int = 512,
forbid_resonance_crossing: int = 0,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remove, we add it when we have it

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants