def test_ASTRA_Elegant_C2V(quads, phase=4, charge=70): global dir, lattice, scaling, bestdelta dir = './SETUP/TOMP_SETUP' lattice = Framework(dir, clean=True, verbose=False) lattice.loadSettings('CLA10-BA1_TOMP_ASTRA.def') lattice.change_Lattice_Code('C2V', 'elegant') scaling = 6 if not os.name == 'nt': lattice.defineASTRACommand(scaling=(scaling)) lattice.defineCSRTrackCommand(scaling=(scaling)) lattice.define_gpt_command(scaling=(scaling)) lattice['S02'].file_block['input'][ 'prefix'] = '../SETUP/TOMP_SETUP_' + str(phase) + '_' + str( charge) + '/' lattice['S02'].sample_interval = 1 #2**(3*2) dir = './test_EleC2V_' + str(phase) + '_' + str(charge) lattice.setSubDirectory(dir) lattices = lattice.latticeObjects.values() # for l in lattices: # if hasattr(l, 'headers'): # if isinstance(l.headers, (dict)): # if 'charge' in l.headers.keys(): # l.headers['charge'].space_charge_mode = False optFuncVELA(quads, track=False) lattice.track(startfile='S02', track=True)
def optimise_Lattice(phase=None, q=70, do_optimisation=False): global dir, lattice, scaling, bestdelta bestdelta = 1e10 dir = './SETUP/TOMP_SETUP' lattice = Framework(dir, clean=False, verbose=False) lattice.loadSettings('CLA10-BA1_TOMP.def') scaling = 6 if not os.name == 'nt': lattice.defineASTRACommand(scaling=(scaling)) lattice.defineCSRTrackCommand(scaling=(scaling)) lattice.define_gpt_command(scaling=(scaling)) lattice['L01'].file_block['input']['prefix'] = '../basefiles_' + str( scaling) + '_' + str(q) + '/' quads = 0.107 * np.array([ 21.11058462, -11.36377551, 24.69336696, -22.63264054, 56.07039682, -51.58739658 ]) # quads = setChicane(quads) # optFuncChicane(quads) # print('Chicane = ', quads) quads = [ lattice.getElement('CLA-S02-MAG-QUAD-01', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-02', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-03', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-04', 'k1l'), lattice.getElement('CLA-C2V-MAG-QUAD-01', 'k1l'), lattice.getElement('CLA-C2V-MAG-QUAD-02', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-07', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-08', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-09', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-10', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-11', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-15', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-01', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-02', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-03', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-04', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-05', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-06', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-07', 'k1l'), ] quadsNEW = np.array([ 1.7901911899775773, -1.6407693149976745, 2.2849042966309447, -1.3685069221066561, 5.7572751421298305, -4.696861959661223, 1.653747009525063, -1.597658628810405, 0.3920095459041216, -0.3922879907823872, 0.16851104048712628, 0.12208077087083297, -0.26073294653351364, -0.9516625759490311, 1.2270249450337767, 1.1374710985669274, 0.038188155183286554, -1.3227126094830322, 1.360338937783752 ]) lattice['S02'].file_block['output']['end_element'] = 'EBT-BA1-DIA-FCUP-01' lattice['S02'].sample_interval = 2**(3 * 3) if do_optimisation: if phase is not None: lattice['S02'].file_block['input'][ 'prefix'] = '../TOMP_SETUP_' + str(phase) + '_' + str(q) + '/' quads = setVELA(quads) optFuncVELA(quads) lattice['S02'].file_block['output']['end_element'] = 'EBT-BA1-DIA-FCUP-01' lattice['S02'].sample_interval = 1
def optimise_Lattice(phase=None, q=70, do_optimisation=False): global dir, lattice, scaling, bestdelta bestdelta = 1e10 dir = './SETUP/TOMP_SETUP' lattice = Framework(dir, clean=False, verbose=False) lattice.loadSettings('CLA10-BA1_TOMP_Separated.def') scaling = 6 if not os.name == 'nt': lattice.defineASTRACommand(scaling=(scaling)) lattice.defineCSRTrackCommand(scaling=(scaling)) lattice.define_gpt_command(scaling=(scaling)) lattice['L01'].file_block['input']['prefix'] = '../basefiles_' + str( scaling) + '_' + str(q) + '/' quads = 0.107 * np.array([ 21.11058462, -11.36377551, 24.69336696, -22.63264054, 56.07039682, -51.58739658 ]) # quads = setChicane(quads) # optFuncChicane(quads) # print('Chicane = ', quads) quads = [ lattice.getElement('CLA-S02-MAG-QUAD-01', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-02', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-03', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-04', 'k1l'), lattice.getElement('CLA-C2V-MAG-QUAD-01', 'k1l'), lattice.getElement('CLA-C2V-MAG-QUAD-02', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-07', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-08', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-09', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-10', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-11', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-15', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-01', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-02', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-03', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-04', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-05', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-06', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-07', 'k1l'), ] quads = np.array([ 1.7815538119218322, -1.6517067100557492, 2.3043853160232697, -1.3861969157005136, 5.757177173351052, -4.733558263809512, 1.7234634394591193, -1.5865723560117138, 0.3758596578541717, -0.3895175193164829, 0.17091495276247198, 0.12327634704511606, -0.2637956911506127, -0.9593369561940668, 1.2250265489541068, 1.150196537233205, 0.0385787389105507, -1.3341278723969179, 1.3605277843974064 ]) lattice['S02'].file_block['output']['end_element'] = 'EBT-BA1-DIA-FCUP-01' lattice['S02'].sample_interval = 2**(3 * 3) if do_optimisation: if phase is not None: lattice['S02'].file_block['input'][ 'prefix'] = '../TOMP_SETUP_' + str(phase) + '_' + str(q) + '/' quads = setVELA(quads) optFuncVELA(quads) lattice['S02'].file_block['output']['end_element'] = 'EBT-BA1-DIA-FCUP-01' lattice['S02'].sample_interval = 1
def optimise_Lattice(phase=None, q=70, do_optimisation=False): global dir, lattice, scaling, bestdelta bestdelta = 1e10 dir = './SETUP/TOMP_SETUP' lattice = Framework(dir, clean=False, verbose=False) lattice.loadSettings('CLA10-FE.def') lattice.modifyElement('CLA-L01-CAV-SOL-01', 'field_amplitude', 0.07) lattice.modifyElement('CLA-L01-CAV-SOL-02', 'field_amplitude', -0.05) scaling = 6 if not os.name == 'nt': lattice.defineASTRACommand(scaling=(scaling)) lattice.defineCSRTrackCommand(scaling=(scaling)) lattice.define_gpt_command(scaling=(scaling)) # lattice['L01'].file_block['input']['prefix'] = '../../CLARA_BA1_Gaussian/basefiles_'+str(scaling)+'_'+str(q)+'/' quads = [ lattice.getElement('CLA-S02-MAG-QUAD-01', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-02', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-03', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-04', 'k1l'), lattice.getElement('CLA-S02-MAG-QUAD-05', 'k1l'), ] quads = np.array([ 2.018036284043403, -1.6775106326141502, 2.0713066380968943, -1.4092617257511626, 0.07875236608471231 ]) lattice['S02'].sample_interval = 8 if do_optimisation: if phase is not None: lattice['S02'].file_block['input'][ 'prefix'] = '../TOMP_SETUP_' + str(phase) + '_' + str(q) + '/' quads = setVELA(quads) optFuncVELA(quads) print('VELA = ', quads) lattice['S02'].sample_interval = 1 #2**(3*2)
def optimise_Lattice(phase=4, q=70, do_optimisation=False): global dir, lattice, scaling, bestdelta bestdelta = 1e10 dir = './SETUP/TOMP_SETUP' lattice = Framework(dir, clean=False, verbose=False) lattice.loadSettings('CLA10-BA1_TOMP_ASTRA.def') lattice.change_Lattice_Code('S02', 'elegant') lattice.change_Lattice_Code('C2V', 'elegant') scaling = 6 if not os.name == 'nt': lattice.defineASTRACommand(scaling=(scaling)) lattice.defineCSRTrackCommand(scaling=(scaling)) lattice.define_gpt_command(scaling=(scaling)) lattice['L01'].file_block['input']['prefix'] = '../basefiles_' + str( scaling) + '_' + str(q) + '/' quads = 0.107 * np.array([ 21.11058462, -11.36377551, 24.69336696, -22.63264054, 56.07039682, -51.58739658 ]) quads = [ # lattice.getElement('CLA-S02-MAG-QUAD-01', 'k1l'), # lattice.getElement('CLA-S02-MAG-QUAD-02', 'k1l'), # lattice.getElement('CLA-S02-MAG-QUAD-03', 'k1l'), # lattice.getElement('CLA-S02-MAG-QUAD-04', 'k1l'), # lattice.getElement('CLA-C2V-MAG-QUAD-01', 'k1l'), # lattice.getElement('CLA-C2V-MAG-QUAD-02', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-07', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-08', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-09', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-10', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-11', 'k1l'), lattice.getElement('EBT-INJ-MAG-QUAD-15', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-01', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-02', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-03', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-04', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-05', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-06', 'k1l'), lattice.getElement('EBT-BA1-MAG-QUAD-07', 'k1l'), ] quads = np.array([ 1.813883341270411, -1.657984997152041, 2.436078305927638, -1.3805803719324001, 5.757521138743945, -4.774512264530579, 1.5759640821849459, -1.5658635139945611, 0.4665090704522008, -0.3701448642096947, 0.14139459095219498, 0.1294045271940972, -0.26170990073523187, -0.972243028906357, 1.2999713197810956, 1.3880410074706666, 0.043801044316032774, -1.3992446074305926, 1.3604179976621753 ]) quadsCHICANE = quads[:6] # quadsCHICANE = np.array([ 1.81966806, -1.60694003, 2.52387281, -1.34318408, 5.75696896, # -4.86231975,]) lattice['S02'].sample_interval = 2**(3 * 3) if do_optimisation: if phase is not None: lattice['S02'].file_block['input'][ 'prefix'] = '../TOMP_SETUP_' + str(phase) + '_' + str(q) + '/' lattice['S02'].file_block['output']['end_element'] = 'CLA-C2V-MARK-02' val = optFuncChicane(quadsCHICANE) quadsCHICANE = setChicane(quadsCHICANE) val = optFuncChicane(quadsCHICANE) print val print('Chicane = ', quadsCHICANE) quads[:6] = quadsCHICANE # exit() lattice['S02'].file_block['output'][ 'end_element'] = 'EBT-BA1-DIA-FCUP-01' val = optFuncVELA(quads) while val > 10: print('################ CURRENT VALUE OF OPTIMISATION IS ', val, ' ##################') quads = setVELA(quads) val = optFuncVELA(quads) else: val = optFuncVELA(quads) lattice['S02'].file_block['output']['end_element'] = 'EBT-BA1-DIA-FCUP-01' lattice['S02'].sample_interval = 1 return quads