From 5e42b02de1d3001fffe2c12b2f7f65b62ded43aa Mon Sep 17 00:00:00 2001 From: Felix Soubelet Date: Mon, 7 Jun 2021 17:31:16 +0200 Subject: [PATCH] transfer function to special --- pyhdtoolkit/cpymadtools/matching.py | 22 ---------------------- pyhdtoolkit/cpymadtools/special.py | 26 ++++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/pyhdtoolkit/cpymadtools/matching.py b/pyhdtoolkit/cpymadtools/matching.py index fcaff80e..dfa447a6 100644 --- a/pyhdtoolkit/cpymadtools/matching.py +++ b/pyhdtoolkit/cpymadtools/matching.py @@ -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 ----- # diff --git a/pyhdtoolkit/cpymadtools/special.py b/pyhdtoolkit/cpymadtools/special.py index 69bf2d5c..f91b94bd 100644 --- a/pyhdtoolkit/cpymadtools/special.py +++ b/pyhdtoolkit/cpymadtools/special.py @@ -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 ----- #