Skip to content

Commit

Permalink
transfer function to special
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoubelet committed Jun 7, 2021
1 parent d3861cf commit 5e42b02
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
22 changes: 0 additions & 22 deletions pyhdtoolkit/cpymadtools/matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,28 +216,6 @@ def get_closest_tune_approach(
return abs(dqmin)


def match_no_coupling_through_ripkens(
madx: Madx, sequence: str = None, location: str = None, vary_knobs: Sequence[str] = None
) -> None:
"""
Matching commands to get cross-term Ripken parameters beta_12 and beta_21 to be 0 at a given location,
using skew quad correctors independently.
"""
logger.info(f"Matching Ripken parameters for no coupling at location {location}")
logger.debug("Creating macro tu update Ripkens")
madx.input("do_ripken: macro = {twiss, ripken=True;}") # cpymad needs .input for macros

logger.debug("Matching Parameters")
madx.command.match(sequence=sequence, use_macro=True, chrom=True)
for knob in vary_knobs:
madx.command.vary(name=knob)
madx.command.use_macro(name="do_ripken")
madx.input(f"constraint, expr=table(twiss, {location}, beta12)=0") # need input else includes " and fails
madx.input(f"constraint, expr=table(twiss, {location}, beta21)=0")
madx.command.lmdif(calls=500, tolerance=1e-21)
madx.command.endmatch()


# ----- Helpers ----- #


Expand Down
26 changes: 26 additions & 0 deletions pyhdtoolkit/cpymadtools/special.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,32 @@ def re_cycle_sequence(madx: Madx, sequence: str = "lhcb1", start: str = "IP3") -
madx.command.endedit()


def match_no_coupling_through_ripkens(
madx: Madx, sequence: str = None, location: str = None, vary_knobs: Sequence[str] = None
) -> None:
"""
Matching routine to get cross-term Ripken parameters beta_12 and beta_21 to be 0 at a given location.
Args:
madx (cpymad.madx.Madx): an instanciated cpymad Madx object.
sequence (str): name of the sequence to activate for the matching.
location (str): the name of the element at which one wants the cross-term Ripkens to be 0.
vary_knobs (Sequence[str]): the variables names to 'vary' in the MADX routine.
"""
logger.info(f"Matching Ripken parameters for no coupling at location {location}")
logger.debug("Creating macro tu update Ripkens")
madx.input("do_ripken: macro = {twiss, ripken=True;}") # cpymad needs .input for macros

logger.debug("Matching Parameters")
madx.command.match(sequence=sequence, use_macro=True, chrom=True)
for knob in vary_knobs:
madx.command.vary(name=knob)
madx.command.use_macro(name="do_ripken")
madx.input(f"constraint, expr=table(twiss, {location}, beta12)=0") # need input else includes " and fails
madx.input(f"constraint, expr=table(twiss, {location}, beta21)=0") # need input else includes " and fails
madx.command.lmdif(calls=500, tolerance=1e-21)
madx.command.endmatch()

# ----- Helpers ----- #


Expand Down

0 comments on commit 5e42b02

Please sign in to comment.