@@ -24,7 +24,10 @@ class LatticeData:
2424def calculate_optics (
2525 at_lattice : at .lattice_object .Lattice ,
2626 refpts : ArrayLike ,
27+ linopt_function : str = "linopt6" ,
2728 disable_emittance : bool = False ,
29+ disable_chromaticity : bool = False ,
30+ disable_radiation : bool = False ,
2831) -> LatticeData :
2932 """Perform the physics calculations on the lattice.
3033
@@ -43,21 +46,61 @@ def calculate_optics(
4346 LatticeData: The calculated lattice data.
4447 """
4548 logging .debug ("Starting physics calculations." )
46-
47- orbit0 , _ = at_lattice .find_orbit6 ()
48- logging .debug ("Completed orbit calculation." )
49-
50- _ , beamdata , twiss = at_lattice .linopt6 (
51- refpts = refpts , get_chrom = True , orbit = orbit0 , keep_lattice = True
49+ logging .debug (
50+ f"Using simulation params: { linopt_function } , disable_emittance="
51+ f"{ disable_emittance } , disable_chromaticity={ disable_chromaticity } , "
52+ f"disable_radiation={ disable_radiation } "
5253 )
54+ if linopt_function == "linopt6" :
55+ orbit0 , _ = at_lattice .find_orbit6 ()
56+ logging .debug ("Completed orbit calculation." )
57+
58+ _ , beamdata , twiss = at_lattice .linopt6 (
59+ refpts = refpts ,
60+ get_chrom = not disable_chromaticity ,
61+ orbit = orbit0 ,
62+ keep_lattice = True ,
63+ )
64+ elif linopt_function == "linopt4" :
65+ orbit0 , _ = at_lattice .find_orbit4 ()
66+ logging .debug ("Completed orbit calculation." )
67+
68+ _ , beamdata , twiss = at_lattice .linopt6 (
69+ refpts = refpts ,
70+ get_chrom = not disable_chromaticity ,
71+ orbit = orbit0 ,
72+ keep_lattice = True ,
73+ )
74+ elif linopt_function == "linopt2" :
75+ orbit0 , _ = at_lattice .find_orbit ()
76+ logging .debug ("Completed orbit calculation." )
77+
78+ _ , beamdata , twiss = at_lattice .linopt2 (
79+ refpts = refpts ,
80+ get_chrom = not disable_chromaticity ,
81+ orbit = orbit0 ,
82+ keep_lattice = True ,
83+ )
84+ else :
85+ raise ValueError (
86+ f"Error. Invalid linopt function selected: { linopt_function } . Simulation "
87+ "data not calculated."
88+ )
89+
5390 logging .debug ("Completed linear optics calculation." )
5491
5592 if not disable_emittance :
5693 emitdata = at_lattice .ohmi_envelope (orbit = orbit0 , keep_lattice = True )
5794 logging .debug ("Completed emittance calculation" )
5895 else :
5996 emitdata = ()
60- radint = at_lattice .get_radiation_integrals (twiss = twiss )
97+
98+ if not disable_radiation :
99+ radint = at_lattice .get_radiation_integrals (twiss = twiss )
100+ logging .debug ("Completed radiation calculation" )
101+ else :
102+ radint = ()
103+
61104 logging .debug ("All calculation complete." )
62105 return LatticeData (twiss , beamdata .tune , beamdata .chromaticity , emitdata , radint )
63106
@@ -98,7 +141,15 @@ class ATSimulator:
98141 physics data upon a change.
99142 """
100143
101- def __init__ (self , at_lattice , callback = None , disable_emittance = False ):
144+ def __init__ (
145+ self ,
146+ at_lattice ,
147+ linopt_function = "linopt6" ,
148+ disable_emittance = False ,
149+ disable_chromaticity = False ,
150+ disable_radiation = False ,
151+ callback = None ,
152+ ):
102153 """
103154 .. Note:: To avoid errors, the physics data must be initially
104155 calculated here, during creation, otherwise it could be accidentally
@@ -107,12 +158,16 @@ def __init__(self, at_lattice, callback=None, disable_emittance=False):
107158 the thread.
108159
109160 Args:
110- at_lattice (at.lattice_object.Lattice): An instance of an AT
111- lattice object.
112- callback (typing.Callable): Optional, if passed it is called on completion
113- of each round of physics calculations.
114- disable_emittance (bool): Whether or not to perform the beam
115- envelope based emittance calculations.
161+ at_lattice (at.lattice_object.Lattice): An instance of an AT lattice object.
162+ linopt_function (str): Which pyAT linear optics function to use: linopt2,
163+ linopt4, linopt6.
164+ disable_emittance (bool): Whether the emittance calculations should be
165+ disabled.
166+ disable_chromaticity (bool): Whether the chromaticity calculations should be
167+ disabled.
168+ disable_radiation (bool): Whether radiation calculations should be disabled.
169+ callback (typing.Callable): To be called after completion of each round of
170+ physics calculations.
116171
117172 **Methods:**
118173 """
@@ -122,12 +177,22 @@ def __init__(self, at_lattice, callback=None, disable_emittance=False):
122177 )
123178 self ._at_lat = at_lattice
124179 self ._rp = numpy .ones (len (at_lattice ) + 1 , dtype = bool )
180+ self ._linopt_function = linopt_function
125181 self ._disable_emittance = disable_emittance
126- self ._at_lat .radiation_on ()
182+ self ._disable_chromaticity = disable_chromaticity
183+ self ._disable_radiation = disable_radiation
184+
185+ if not self ._disable_radiation :
186+ self ._at_lat .radiation_on ()
127187
128188 # Initial phys data calculation.
129189 self ._lattice_data = calculate_optics (
130- self ._at_lat , self ._rp , self ._disable_emittance
190+ self ._at_lat ,
191+ self ._rp ,
192+ self ._linopt_function ,
193+ self ._disable_emittance ,
194+ self ._disable_chromaticity ,
195+ self ._disable_radiation ,
131196 )
132197
133198 # Threading stuff initialisation.
@@ -196,7 +261,12 @@ def _recalculate_phys_data(self, callback):
196261 if bool (self ._paused ) is False :
197262 try :
198263 self ._lattice_data = calculate_optics (
199- self ._at_lat , self ._rp , self ._disable_emittance
264+ self ._at_lat ,
265+ self ._rp ,
266+ self ._linopt_function ,
267+ self ._disable_emittance ,
268+ self ._disable_chromaticity ,
269+ self ._disable_radiation ,
200270 )
201271 except Exception as e :
202272 warn (at .AtWarning (e ), stacklevel = 1 )
0 commit comments