def main(): E = 9000 energy = np.linspace(8500, 9500, 501) theta = np.linspace(-1, 1, 512) * 20e-6 psi = np.linspace(-1, 1, 512) * 20e-6 # kwargs = dict(eE=3.0, eI=0.5, eEpsilonX=0.263, eEpsilonZ=0.008, # betaX=9.539, betaZ=1.982, period=18.5, n=108, K=0.52, # eEspread=1e-3, # xPrimeMax=theta[-1]*1e3, zPrimeMax=psi[-1]*1e3, # targetOpenCL='CPU', # distE='BW') kwargs = dict(eE=6.083, eEpsilonX = 1.3, #0.02,#1.3, #1300 pmrad eEpsilonZ = 0.01,#0.004,#0.01, #10pmrad period=32.8, n=63, targetE=[9000, 3], eMin= E + 500, eMax= E - 500, xPrimeMax=0.02, #xPrimeMax=0.1, zPrimeMax=0.02, #xPrimeMax=0.1, gp=1e-06, distE='BW', taper = (1., 12.), targetOpenCL='GPU') # energy = [200000., 200000.] # theta = np.linspace(-2./25000., 2./25000., 51) # psi = np.linspace(-2./25000., 2./25000., 51) # kwargs = dict(name='IVU18.5', eE=3.0, eI=0.5, # eEpsilonX=0.263, eEpsilonZ=0.008, # betaX=9., betaZ=2., # period=18.5, n=108, K=1.92, # xPrimeMax=theta[-1]*1e3, zPrimeMax=psi[-1]*1e3, distE='BW') if True: # xrt Undulator source = rs.Undulator(**kwargs) I0, l1, l2, l3 = source.intensities_on_mesh(energy, theta, psi) else: # Urgent kwargs['eSigmaX'] = (kwargs['eEpsilonX']*kwargs['betaX']*1e3)**0.5 kwargs['eSigmaZ'] = (kwargs['eEpsilonZ']*kwargs['betaZ']*1e3)**0.5 del(kwargs['distE']) del(kwargs['betaX']) del(kwargs['betaZ']) kwargs['eMin'] = energy[0] kwargs['eMax'] = energy[-1] kwargs['eN'] = len(energy) kwargs['icalc'] = 3 kwargs['nx'] = len(theta)//2 kwargs['nz'] = len(psi)//2 import xrt.backends.raycing as raycing beamLine = raycing.BeamLine(azimuth=0, height=0) source = rs.UndulatorUrgent(beamLine, **kwargs) I0, l1, l2, l3 = source.intensities_on_mesh() I0 = np.concatenate((I0[:, :0:-1, :], I0), axis=1) I0 = np.concatenate((I0[:, :, :0:-1], I0), axis=2) # flux_through_aperture(energy, theta, psi, I0) save_3dMatrix(energy, theta, psi, I0)
def main(): energy = np.linspace(3850, 4150, 601) theta = np.linspace(-1, 1, 51) * 30e-6 psi = np.linspace(-1, 1, 51) * 30e-6 kwargs = dict( eE=3.0, eI=0.5, eEpsilonX=0.263, eEpsilonZ=0.008, betaX=9.539, betaZ=1.982, period=18.5, n=108, K=0.52, # eEspread=1e-3, xPrimeMax=theta[-1] * 1e3, zPrimeMax=psi[-1] * 1e3, # targetOpenCL='CPU', distE='BW') # energy = [200000., 200000.] # theta = np.linspace(-2./25000., 2./25000., 51) # psi = np.linspace(-2./25000., 2./25000., 51) # kwargs = dict(name='IVU18.5', eE=3.0, eI=0.5, # eEpsilonX=0.263, eEpsilonZ=0.008, # betaX=9., betaZ=2., # period=18.5, n=108, K=1.92, # xPrimeMax=theta[-1]*1e3, zPrimeMax=psi[-1]*1e3, distE='BW') if True: # xrt Undulator source = rs.Undulator(**kwargs) I0, l1, l2, l3 = source.intensities_on_mesh(energy, theta, psi) else: # Urgent kwargs['eSigmaX'] = (kwargs['eEpsilonX'] * kwargs['betaX'] * 1e3)**0.5 kwargs['eSigmaZ'] = (kwargs['eEpsilonZ'] * kwargs['betaZ'] * 1e3)**0.5 del (kwargs['distE']) del (kwargs['betaX']) del (kwargs['betaZ']) kwargs['eMin'] = energy[0] kwargs['eMax'] = energy[-1] kwargs['eN'] = len(energy) kwargs['icalc'] = 3 kwargs['nx'] = len(theta) // 2 kwargs['nz'] = len(psi) // 2 import xrt.backends.raycing as raycing beamLine = raycing.BeamLine(azimuth=0, height=0) source = rs.UndulatorUrgent(beamLine, **kwargs) I0, l1, l2, l3 = source.intensities_on_mesh() I0 = np.concatenate((I0[:, :0:-1, :], I0), axis=1) I0 = np.concatenate((I0[:, :, :0:-1], I0), axis=2) flux_through_aperture(energy, theta, psi, I0)
def main(): energy = np.linspace(3850, 4150, 601) theta = np.linspace(-1, 1, 51) * 30e-6 psi = np.linspace(-1, 1, 51) * 30e-6 kwargs = dict( eE=3.0, eI=0.5, eEpsilonX=0.263, eEpsilonZ=0.008, betaX=9.539, betaZ=1.982, period=18.5, n=108, K=0.52, xPrimeMax=theta[-1] * 1e3, zPrimeMax=psi[-1] * 1e3, # targetOpenCL='CPU', distE='BW') source = rs.Undulator(**kwargs) I0, l1, l2, l3 = source.intensities_on_mesh(energy, theta, psi) flux_through_aperture(energy, theta, psi, I0) # intensity_in_transverse_plane(energy, theta, psi, I0) # colored_intensity_in_transverse_plane(energy, theta, psi, I0) if wantUrgentUndulator: kwargs['eSigmaX'] = (kwargs['eEpsilonX'] * kwargs['betaX'] * 1e3)**0.5 kwargs['eSigmaZ'] = (kwargs['eEpsilonZ'] * kwargs['betaZ'] * 1e3)**0.5 del (kwargs['distE']) del (kwargs['betaX']) del (kwargs['betaZ']) kwargs['eMin'] = energy[0] kwargs['eMax'] = energy[-1] kwargs['eN'] = len(energy) kwargs['icalc'] = 3 kwargs['nx'] = len(theta) // 2 kwargs['nz'] = len(psi) // 2 import xrt.backends.raycing as raycing beamLine = raycing.BeamLine(azimuth=0, height=0) sourceU = rs.UndulatorUrgent(beamLine, **kwargs) I0, l1, l2, l3 = sourceU.intensities_on_mesh() I0 = np.concatenate((I0[:, :0:-1, :], I0), axis=1) I0 = np.concatenate((I0[:, :, :0:-1], I0), axis=2) urgentEnergy = sourceU.Es flux_through_aperture(urgentEnergy, theta, psi, I0 * 1e6)
axplot(energy * 1e-3, fluxX, label='xrt') # end xrt Undulator if case == 3: eS, fS = np.loadtxt("misc/bessy.dc0.gz", skiprows=2, usecols=(0, 1), unpack=True) axplot(eS * 1e-3, fS, label='Spectra') # UrgentUndulator import xrt.backends.raycing as raycing beamLine = raycing.BeamLine(azimuth=0, height=0) kwargs = kwargsCommon.copy() kwargs.update(kwargsURGENT) sourceU = rs.UndulatorUrgent(beamLine, **kwargs) I0u, l1, l2, l3 = sourceU.intensities_on_mesh() # add the other 3 quadrants, except the x=0 and z=0 lines: I0u = np.concatenate((I0u[:, :0:-1, :], I0u), axis=1) I0u = np.concatenate((I0u[:, :, :0:-1], I0u), axis=2) fluxU = I0u.sum(axis=(1, 2)) * sourceU.dx * sourceU.dz urgentEnergy = sourceU.Es axplot(urgentEnergy * 1e-3, fluxU, label='Urgent') # end UrgentUndulator ax.set_ylim(1e9, 4e13) ax.legend() fig.savefig(u'flux_case{0}_xrt_UrgentICALC{1}.png'.format(case, icalc)) # fig = plt.figure() # intensity_in_transverse_plane(energy, theta, psi, I0x)
print('Ec = {0} eV'.format(Ec)) if withUrgentUndulator: ukwargs = copy.copy(kwargs) del (ukwargs['distE']) del (ukwargs['betaX']) del (ukwargs['betaZ']) ukwargs['eSigmaX'] = (kwargs['eEpsilonX'] * kwargs['betaX'] * 1e3)**0.5 ukwargs['eSigmaZ'] = (kwargs['eEpsilonZ'] * kwargs['betaZ'] * 1e3)**0.5 ukwargs['eMin'] = energy[0] ukwargs['eMax'] = energy[-1] ukwargs['eN'] = len(energy) - 1 ukwargs['nx'] = len(theta) // 2 ukwargs['nz'] = len(psi) // 2 ukwargs['icalc'] = 3 sourceU = rs.UndulatorUrgent(**ukwargs) I0U = sourceU.intensities_on_mesh()[0] fluxUU = I0U.sum(axis=(1, 2)) * dtheta * dpsi * 4e6 fluxUU[fluxUU <= 0] = 1 fluxUU[np.isnan(fluxUU)] = 1 if withSRWUndulator: import pickle with open('c:\Ray-tracing\srw\SRWres.pickle', 'rb') as f: energySRW, thetaSRW, psiSRW, I0SRW = pickle.load(f)[0:4] dtheta = thetaSRW[1] - thetaSRW[0] dpsi = psiSRW[1] - psiSRW[0] fluxSRWU = I0SRW.sum(axis=(1, 2)) * dtheta * dpsi if withUndulator: # kwargs['targetOpenCL'] = None