analytic jacobians formulas optimizations
Noto una ridondanza :
160 elif (thick_quadrupole and not(thick_steerers)) or
(not(thick_quadrupole) and thick_steerers):
161 # thin quads thick steerers or thin quad thick steerers
162 PCmwj = [JCwj[p] * ICmw[p] for p in [x, y]]
163 PSmwj = [JSwj[p] * ISmw[p] for p in [x, y]]
165 else:
166 # thin quad and thin steerers
167 PCmwj = [cor[w].beta[p] ** 0.5 * math.cos(twj[p]) *
qua[m].beta[p] * math.cos(2*tmw[p]) for p in [x, y]]
169 PSmwj = [cor[w].beta[p] ** 0.5 * math.sin(twj[p]) *
qua[m].beta[p] * math.sin(2*tmw[p]) for p in [x, y]]
Non capisco bene il primo elif della linea 160, ma visto che hai gia' definito sopra JCwj, JSwj, ICmw e ISmw nel caso di quadrupoli e/o steerers sottili, l'ultimo else di linea 165 e' inutile. Suggerisco di rimpiazzare l'elif della linea 160 con un semplice else e di usare le definizioni di linea 167 e 169 come controllo delle 162 e 163.
Alcune ottimizzazioni numeriche (per il futuro, non per ora):
- OT1) possono andare fuori e prima del ciclo for w degli steerer:
121 tmj = [tau(p, qua[m], bpm[j]) for p in [x, y]]
128 ISmj = [math.sin(2 * tmj[p]) * ICm[p] - math.cos(2 * tmj[p]) *
ISm[p] for p in [x, y]] # eq. C14
129 ICmj = [math.cos(2 * tmj[p]) * ICm[p] + math.sin(2 * tmj[p]) *
ISm[p] for p in [x, y]]
135 Ibm = [qua[m].beta[p] for p in [x, y]]
136 ISmj = [qua[m].beta[p] * math.sin(2 * tmj[p]) for p in [x, y]]
# eq. C14
137 ICmj = [qua[m].beta[p] * math.cos(2 * tmj[p]) for p in [x, y]]
- OT2) i fattori
((bpm[j].beta[x]) ** 0.5) / (2 * math.sin(math.pi * Q[x]))
((bpm[j].beta[y]) ** 0.5) / (2 * math.sin(math.pi * Q[y]))
in linea 174-175 e 188-189 posso essere calcolati fuori del ciclo w degli steerers
- OT3) i fattori
178 1 / (4 * math.sin(2 * math.pi * Q[x]))
185 1 / (4 * math.sin(math.pi * Q[x]))
192 1 / (4 * math.sin(2 * math.pi * Q[y]))
199 1 / (4 * math.sin(math.pi * Q[y]))
posso essere calcolati all'inizio fuori da tutti i 3 cicli.
- OT4) I termini
(PI(qua[m], bpm[j]) - PI(qua[m], cor[w]) + PI(bpm[j], cor[w]))
di linea 182 e 193 possono essere calcolati una sola volta all'inizio del ciclo for interno sugli steerers, e richiamati la seconda (una variabile in piu', ma tre chiamate a funzioni e 2 operazioni in meno all'interno dei 3 cicli for)