srwl.PropagElecField(wfr, opBL)  # Propagate Electric Field

print(' 9. Selecting data to plot')
Polar = 6  ## 0- Linear Horizontal /  1- Linear Vertical 2- Linear 45 degrees / 3- Linear 135 degrees / 4- Circular Right /  5- Circular /  6- Total
Intens = 0  ## 0=Single-e I/1=Multi-e I/2=Single-e F/3=Multi-e F/4=Single-e RadPhase/5=Re single-e Efield/6=Im single-e Efield
DependArg = 3  ## 0 - vs e, 1 - vs x, 2 - vs y, 3- vs x&y, 4-vs x&e, 5-vs y&e, 6-vs x&y&e
plotNum = 1000
plotMeshx = [plotNum * wfr.mesh.xStart, plotNum * wfr.mesh.xFin, wfr.mesh.nx]
plotMeshy = [plotNum * wfr.mesh.yStart, plotNum * wfr.mesh.yFin, wfr.mesh.ny]

print(' 10. Plotting initial and output wavefront')
arIin = array('f', [0] * wfrIn.mesh.nx * wfrIn.mesh.ny)
srwl.CalcIntFromElecField(arIin, wfrIn, 0, 0, 3, wfr.mesh.eStart, 0, 0)
plotMeshInX = [1000 * wfrIn.mesh.xStart, 1000 * wfrIn.mesh.xFin, wfrIn.mesh.nx]
plotMeshInY = [1000 * wfrIn.mesh.yStart, 1000 * wfrIn.mesh.yFin, wfrIn.mesh.ny]
uti_plot.uti_plot2d(arIin, plotMeshInX, plotMeshInY,
                    ['Horizontal Position [mm]', 'Vertical Position [mm]', 'Intensity Before Propagation [a.u.]'])
arIinY = array('f', [0] * wfrIn.mesh.ny)
srwl.CalcIntFromElecField(arIinY, wfrIn, 0, 0, 2, wfrIn.mesh.eStart, 0, 0)  # extracts intensity
uti_plot.uti_plot1d(arIinY, plotMeshInY, ['Vertical Position [mm]', 'Intensity [a.u.]',
                                          'Intensity Before Propagation\n(cut vs vertical position at x = 0)'])

arIout = array('f', [0] * wfr.mesh.nx * wfr.mesh.ny)  # "flat" array to take 2D intensity data
arII = arIout
arIE = array('f', [0] * wfr.mesh.nx * wfr.mesh.ny)
srwl.CalcIntFromElecField(arII, wfr, Polar, Intens, DependArg, wfr.mesh.eStart, 0, 0)
uti_plot.uti_plot2d(arII, plotMeshx, plotMeshy,
                    ['Horizontal Position [mm]', 'Vertical Position [mm]', 'Intenisty, a.u.'])
uti_plot.uti_plot_show()

print(' 11. Extracting intensity for comparison with analytic calculation')
arI1y = array('f', [0] * wfr.mesh.ny)
Beispiel #2
0
    qx0 = complex(0, 3.1415 / Lam * GsnBm.sigX ** 2)
    qy0 = complex(0, 3.1415 / Lam * GsnBm.sigY ** 2)
    Wthx = []
    Wthy = []
    for m in range(len(s)):
        Wx = (WRx[m][0][0] * qx0 + WRx[m][0][1]) / (WRx[m][1][0] * qx0 + WRx[m][1][1])  # MatrixMultiply(WR,qxP)
        RMSbx = sqrt(1.0 / (-1.0 / Wx).imag / 3.1415 * Lam) * 2.35
        Wthx.append(RMSbx)
        Wy = (WRy[m][0][0] * qy0 + WRy[m][0][1]) / (WRy[m][1][0] * qy0 + WRy[m][1][1])  # MatrixMultiply(WR,qxP)
        RMSby = sqrt(1.0 / (-1.0 / Wy).imag / 3.1415 * Lam) * 2.35
        Wthy.append(RMSby)

    # 7. Plotting
    for i in range(len(intensitiesToPlot['intensity'])):
        uti_plot.uti_plot2d(intensitiesToPlot['intensity'][i], intensitiesToPlot['mesh_x'][i],
                            intensitiesToPlot['mesh_y'][i],
                            ['Horizontal Position [mm]', 'Vertical Position [mm]',
                             'Intenisty at {} m, [a.u.]'.format(intensitiesToPlot['distance'][i])])

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.plot(s, xRMS, '-r.', label="X envelope via SRW")
    ax.plot(s, Wthx, '--ro', label="X envelope via analytical propagator")
    ax.plot(s, yRMS, '-b.', label="Y envelope via SRW")
    ax.plot(s, Wthy, '--bo', label="Y envelope via analytical propagator")
    ax.legend()
    ax.set_xlabel('Distance along beam line, [m]')
    ax.set_ylabel('Horizontal and Vertical RMS beam sizes, [m]')
    ax.set_title('Gaussian beam envelopes through a drift after a lens')
    ax.grid()

    plt.show()
Beispiel #3
0
#   srwlib.srwl.CalcPowDenSR(wfr2, elecBeam, 0, magFldCnt, arPrecPar)
#This computes "thick" electron beam
    print('11. Calculating SR Wavefront vua multi-electron propagation...')     
    srwlib.srwl_wfr_emit_prop_multi_e(elecBeam,magFldCnt, meshRes, meth, 
    relPrec, 1, _n_part_avg_proc=1, _n_save_per=100, 
    _file_path=None, _sr_samp_fact=-1, _opt_bl=None, _pres_ang=0, _char=0, 
    _x0=0, _y0=0, _e_ph_integ=0, _rand_meth=1)

print('12. Extracting Intensity from calculated Electric Field ...')
if el1==0:
    print('13. Plotting results ...')
#   2-D distribution
    arI2 = array('f', [0]*wfr2.mesh.nx*wfr2.mesh.ny) #"flat" array to take 2D intensity data
    srwlib.srwl.CalcIntFromElecField(arI2, wfr2, 6, 1, 3, wfr2.mesh.eStart, 0, 0)
    uti_plot.uti_plot2d(arI2, [1000*wfr2.mesh.xStart, 1000*wfr2.mesh.xFin, wfr2.mesh.nx], 
    [1000*wfr2.mesh.yStart, 1000*wfr2.mesh.yFin, wfr2.mesh.ny], 
    ['Horizontal Position [mm]', 'Vertical Position [mm]', 
    'Intensity at ' + str(wfr2.mesh.eStart) + ' eV'])
                
#   1-D distribution
    arI1 = array('f', [0]*wfr2.mesh.nx)
    srwlib.srwl.CalcIntFromElecField(arI1, wfr2, 6, 1, 1, wfr2.mesh.eStart, 0, 0)
    uti_plot.uti_plot1d(arI1, [wfr2.mesh.xStart, wfr2.mesh.xFin*0, wfr2.mesh.nx], 
    ['Horizontal coordinate [mm]', 'Intensity [ph/s/.1%bw/mm^2]', 'Distribution'])
else:
    print('13. Plotting results ...')
#   1-D distribution
#   plotMeshX = [1000*wfr2.mesh.xStart, 1000*wfr2.mesh.xFin*0, wfr2.mesh.nx]
#   powDenVsX = array('f', [0]*wfr2.mesh.nx)
#   for i in range(wfr2.mesh.nx): powDenVsX[i] = wfr2.arS[wfr2.mesh.nx*int(wfr2.mesh.ny*0.5) + i]
#   uti_plot.uti_plot1d(powDenVsX, plotMeshX, ['Horizontal Position [mm]', 'Power Density [W/mm^2]', 'Power Density\n(horizontal cut at y = 0)'])
		
for i in range(4):
    RedF=np.round(RedF*FactorScan)
    stktP=stk(1,Nx/RedF,Ny/RedF,wfr2.mesh.zStart,wfr2.mesh.eStart,wfr2.mesh.eFin,AperXY)
    tic = time.clock()
    arPrecP[4]=arPrecP[4]/RedA
    srwl.CalcPowDenSR(stktP, elecBeam, 0, magFldCnt, arPrecP)
    toc = time.clock()
    ticPowerDen.append(toc - tic)
    print("# Time elapsed heat load calculations 1/Redc: %1.1f %1.3e" % (RedF, (toc - tic)))

#Power Spectrum and Density
#print(stktF.mesh.ne)
uti_plot.uti_plot1d(stktF.arS, [stktF.mesh.eStart, stktF.mesh.eFin, stktF.mesh.ne], ['Photon Energy [eV]', 'Flux [ph/s/.1%bw]', 'Flux through Finite Aperture'])
plotMeshX = [1000*stktP.mesh.xStart, 1000*stktP.mesh.xFin, stktP.mesh.nx]
plotMeshY = [1000*stktP.mesh.yStart, 1000*stktP.mesh.yFin, stktP.mesh.ny]
uti_plot.uti_plot2d(stktP.arS, plotMeshX, plotMeshY, ['Horizontal Position [mm]', 'Vertical Position [mm]', 'Power Density'])
uti_plot.uti_plot_show()

#-----------------------------------------------------------

print('5) Main calculation segment')
tic = time.clock()
arPrecF[2] = 1.0 #arPrecF[2]*RedF #longitudinal integration precision parameter
arPrecF[3] = 1.0 #arPrecF[2]*RedF #azimuthal integration precision parameter
srwl.CalcStokesUR(stkF, elecBeam, und, arPrecF)
toc = time.clock()
print("Time elapsed spectral calculations: %1.3e" % (toc - tic))

tic = time.clock()
arPrecP[4]=arPrecP[4]*RedF
srwl.CalcPowDenSR(stkP, elecBeam, 0, magFldCnt, arPrecP)