Skip to content
Snippets Groups Projects
Commit 4a40c32f authored by Mauro Trovo's avatar Mauro Trovo :headphones:
Browse files

calcolo soluzioni by Allaria

parent a194db6f
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Feb 11 11:17:23 2025
@author: enrico
"""
from utili import DispersiveSection, Laser, ElectronBeam, Undulator, FELsetup
#from utili import calc_eehg_conf_s1fix
from utili import EEHGsetup
from scipy import constants as costanti
import numpy as np
# r561 = DispersiveSection()
# laser = Laser(wl = 20e-9, bdw = 0.020e-9,nrg = 4.0e-6,waist = 80.0e-6,wl_range = [2e-9, 200e-9])
# ebeam = ElectronBeam(energy = 1.22e9, energyspread = 100e3, current=500.0,
# emittance_n=1e-6, beamsize=100e-6)
# undulator = Undulator(lw = 0.055,lung = 2.42,helical = False, aw = 1.0)
# undulator.calc_aw(wl = laser.wl, energy = ebeam.energy, gamma=False, printout=True)
# risu = laser.calc_a_from_seedpower(ebeam, undulator, arange = False, printout = True)
# DE = risu[1]
# R56_opt = (ebeam.energy/DE)*laser.wl/4
printout = False
ebeam = ElectronBeam(energy = 1.22e9, energyspread = 100e3, current=500.0,
emittance_n=1e-6, beamsize=100e-6)
mod1 = Undulator(lw = 0.10, lung = 3.0, helical = False, aw = 1.0)
mod2 = Undulator(lw = 0.113, lung = 1.469, helical = False, aw = 1.0)
seed1 = Laser(wl = 260e-9, bdw = 1.0e-9, nrg = 4.0e-6, waist = 300.0e-6, wl_range = [260e-9, 260e-9])
seed1.set_duration(200e-15)
mod1.calc_aw(seed1.wl,ebeam.energy)
risu = seed1.calc_a_from_seedpower(ebeam, mod1, arange = True, printout = printout)
A1_range = risu[0]
seed2 = Laser(wl = 260e-9, bdw = 1.5e-9, nrg = 4.0e-6, waist = 300.0e-6, wl_range = [230e-9, 265e-9])
seed2.nrg_range = [0.0, 0.00002]
mod2.calc_aw(seed2.wl,ebeam.energy)
risu = seed2.calc_a_from_seedpower(ebeam, mod2, arange = True, printout = printout)
A2_range = risu[0]
r561 = DispersiveSection(r56=0.0, lung = 3.0, dx=0.0, dt=0.0, r56_range=[0.0, 10e-3])
R561_range = r561.r56_range
r562 = DispersiveSection(r56=0.0, lung = 1.2, dx=0.0, dt=0.0, r56_range=[0.0, 300e-6])
R562_range = r562.r56_range
eehg_ora = EEHGsetup(A1 = 3, A2 = 4, n= -1, m = 21, R56_1 = 2.0e-3, R56_2 = 200e-6)
par_err = np.array([5.0,5.0,2.0,2.0])
wl_fel = 21e-9
[n_sol,m_sol,wls1_sol,wls2_sol] = eehg_ora.calc_wls2_n_m(wl_fel, seed1, seed2, m_range = [1,50],
n_range = [-3,0], n_goal = -1, min_wls2_chg = True,
printout = printout)
solu = eehg_ora.calc_eehg_conf(ebeam, n_sol,m_sol,wls1_sol,wls2_sol,
fix1 = 'A1', fix2 = 'R561', peak = 'left', par_err = par_err,
printout = printout)
A1_sol = solu[0]
A2_sol = solu[1]
R561_sol = solu[2]
R562_sol = solu[3]
Wls1_sol = solu[4]
Wls2_sol = solu[5]
N_sol = solu[6]
M_sol = solu[7]
Bmax_sol = solu[8]
B_var = solu[9]
filtra_possibili = True
indTutto = np.where(Bmax_sol>0.00001)
printout = True
if filtra_possibili:
indA1 = np.where( (A1_sol>=A1_range[0]) & (A1_sol<=A1_range[1]))
indA2 = np.where( (A2_sol>=A2_range[0]) & (A2_sol<=A2_range[1]))
indR561 = np.where( (R561_sol>=R561_range[0]) & (R561_sol<=R561_range[1]))
indR562 = np.where( (R562_sol>=R562_range[0]) & (R562_sol<=R562_range[1]))
indOK = np.intersect1d(indTutto,indA1)
indOK = np.intersect1d(indOK,indA2)
indOK = np.intersect1d(indOK,indR561)
indOK = np.intersect1d(indOK,indR562)
if printout:
print((" %s over %s scartate per A1" %(np.size(indTutto)-np.size(indA1), np.size(indTutto))))
if np.size(indTutto)-np.size(indA1)>0:
print(A1_sol)
print((" %s over %s scartate per A2" %(np.size(indTutto)-np.size(indA2), np.size(indTutto))))
if np.size(indTutto)-np.size(indA2)>0:
print(A2_sol)
print((" %s over %s scartate per R561" %(np.size(indTutto)-np.size(indR561), np.size(indTutto))))
if np.size(indTutto)-np.size(indR561)>0:
print(R561_sol)
print((" %s over %s scartate per R562" %(np.size(indTutto)-np.size(indR562), np.size(indTutto))))
if np.size(indTutto)-np.size(indR562)>0:
print(R562_sol)
if printout:
print('=====================================================')
print('Possible solutions after filtering:')
print('--------------------------')
print('{txta:.<5} | {txtb:.<5} | {txt1:.<6} | {txt2:.<6} | {txt3:.<9} |{txt4:.<9} | {txt5:.<9} | {txt6:.<9} | {txt7:.<7} |'
.format(txta='N',txtb='M',txt1='A1',txt2='A2',txt3='wls1',txt4='wls2',txt5='R56_1',txt6='R56_2',txt7='Bunc'))
print('{txta:.<5} | {txtb:.<5} | {txt1:.<6} | {txt2:.<6} | {txt3:.<9} |{txt4:.<9} | {txt5:.<9} | {txt6:.<9} | {txt7:.<7} |'
.format(txta='N',txtb='M',txt1='rel',txt2='rel',txt3='nm',txt4='nm',txt5='mm',txt6='um',txt7='(%)'))
for ik in range(len(indOK)):
ii = indOK[ik]
print('{txta:.<5} | {txtb:.<5} | {txt1:.<6} | {txt2:.4f} | {txt3:.<9} |{txt4:.5f} | {txt5:.7f} | {txt6:.5f} | {txt7:.5f}|'
.format(txta=N_sol[ii],txtb=M_sol[ii],txt1=A1_sol[ii],txt2=A2_sol[ii],txt3=Wls1_sol[ii]*1e9,txt4=Wls2_sol[ii]*1e9,txt5=R561_sol[ii]*1e3,txt6=R562_sol[ii]*1e6,txt7=100*Bmax_sol[ii]))
print('=====================================================')
print('Sensitivity of the bunching to parameter fluctuatons (A1,A2,R561,R562) for each solution')
print('{txt3} | {txt4} | {txt5} | {txt6} |'
.format(txt3=' dB (%) ',txt4=' dB (%) ',txt5=' dB (%) ',txt6=' dB (%) '))
print(' dA1 {txt3} (%) | dA2 {txt4} (%) | dR561 {txt5} (%) | dR562 {txt6} (%) |'
.format(txt3=str(par_err[0]),txt4=str(par_err[1]),txt5=str(par_err[2]),txt6=str(par_err[3])))
for ik in range(len(indOK)):
ii = indOK[ik]
print('{txt3: <12} | {txt4: <11} | {txt5: <13} | {txt6: <13} |'
.format(txt3=" {:.1f}".format(B_var[ii][0]),
txt4=" {:.1f}".format(B_var[ii][1]),
txt5=" {:.1f}".format(B_var[ii][2]),
txt6=" {:.1f}".format(B_var[ii][3])))
#print(B_var)
# fig,ax = plt.subplots()
# ax.plot(xi, J_n,'-', linewidth=2.0)
# fig,ax = plt.subplots()
# ax.plot(xi, np.abs(term2),'-', linewidth=2.0)
# fel = FELsetup()
# print(R56_opt)
# print(fel.rho)
# undulator.helical = True
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment