Beispiel #1
0
    def __init__(self, srwl_wavefront=None):
        """
        Create wavefront instance.

        The most important wavefront fields dynamically initialize from :mod:`wpg.glossry`

        :param srwl_wavefront: if present, wavefront inits with it's parameters  
        :type srwl_wavefront: srwlib.SRWLWfr
        :return: Wavefront instance.
        """
        if srwl_wavefront is None:
            self._srwl_wf = srwlib.SRWLWfr()
        else:
            self._srwl_wf = srwl_wavefront

        self._wf_fields = {}
        self.custom_fields = {}

        for wf_field in glossary.get_wf_fields():
            wf = wf_field(self)
            self._add_field(wf)
Beispiel #2
0
def build_gauss_wavefront_xy(nx, ny, ekev, xMin, xMax, yMin, yMax, sigX, sigY, d2waist,
                             xoff=0., yoff=0., tiltX=0., tiltY=0., 
                             pulseEn=None, pulseTau=None,repRate=None,_mx=None,_my=None):
    """
    Build 2D Gaussian beam.
    
    :param nx: Number of point along x-axis
    :param ny: Number of point along y-axis
    :param nz: Number of point along z-axis (slices)
    :param ekev: Energy in kEv
    :param xMin: Initial Horizontal Position [m]
    :param xMax: Final Horizontal Position [m]
    :param yMin: Initial Vertical Position [m]
    :param yMax: Final Vertical Position [m]
    :param sigX: Horiz. RMS size at Waist [m]
    :param sigY:  Vert. RMS size at Waist [m]
    :param d2waist: distance to Gaussian waist
    :param xoff:    Horizonal Coordinate of Gaussian Beam Center at Waist [m]
    :param yoff:    Vertical  Coordinate of Gaussian Beam Center at Waist [m]
    :param tiltX:   Average Angle of Gaussian Beam at Waist in Horizontal plane [rad] 
    :param tiltY:   Average Angle of Gaussian Beam at Waist in Vertical plane [rad]
    :param pulseEn:  Energy per Pulse [J]
    :param pulseTau: Coherence time [s] to get proper BW
    :param _mx: transverse Gauss-Hermite mode order in horizontal direction
    :param _my: transverse Gauss-Hermite mode order in vertical direction
    :return: wpg.Wavefront structure

    """
    GsnBm = srwlib.SRWLGsnBm()  # Gaussian Beam structure (just parameters)
    # Transverse Coordinates of Gaussian Beam Center at Waist [m]
    GsnBm.x = xoff
    GsnBm.y = yoff
    GsnBm.z = 0  # Longitudinal Coordinate of Waist [m]
    GsnBm.xp = tiltX  # Average Angles of Gaussian Beam at Waist [rad]
    GsnBm.yp = tiltY
    GsnBm.avgPhotEn = ekev * 1e3  # 5000 #Photon Energy [eV]
    if pulseEn is not None:
        GsnBm.pulseEn = pulseEn 
    else:
        GsnBm.pulseEn = 0.001  # Energy per Pulse [J] - to be corrected
    if repRate is not None:
        GsnBm.repRate = repRate 
    else:
        GsnBm.repRate = 1  # Rep. Rate [Hz] - to be corrected
    GsnBm.polar = 1  # 1- linear hoirizontal; 2 - linear vertical
    GsnBm.sigX = sigX  # Horiz. RMS size at Waist [m]
    GsnBm.sigY = sigY  # Vert. RMS size at Waist [m]
    if pulseTau is not None:
        GsnBm.sigT = pulseTau 
    else:
        GsnBm.sigT = 0.2e-15  # should be about coherence time to get proper BW
    if _mx is not None:
        GsnBm.mx = _mx 
    else:
        GsnBm.mx = 0  # Transverse Gauss-Hermite Mode Orders
    if _mx is not None:
        GsnBm.my = _my 
    else:
        GsnBm.my = 0

    wfr = srwlib.SRWLWfr()  # Initial Electric Field Wavefront
    wfr.allocate(1, nx, ny)
     # Numbers of points vs Photon Energy (1), Horizontal and
     # Vertical Positions (dummy)
    wfr.mesh.eStart = GsnBm.avgPhotEn  # Initial Photon Energy [eV]
    wfr.mesh.eFin = GsnBm.avgPhotEn  # Final Photon Energy [eV]
    wfr.avgPhotEn = (wfr.mesh.eStart + wfr.mesh.eFin) / 2
    wfr.mesh.zStart = d2waist
    wfr.mesh.xStart = xMin  # Initial Horizontal Position [m]
    wfr.mesh.xFin = xMax  # Final Horizontal Position [m]
    wfr.mesh.yStart = yMin  # Initial Vertical Position [m]
    wfr.mesh.yFin = yMax  # Final Vertical Position [m]

    #wfr.presFT = 1  # Defining Initial Wavefront in Time Domain
    wfr.presFT = 0  # Defining Initial Wavefront in Freq Domain

    # Some information about the source in the Wavefront structure
    wfr.partBeam.partStatMom1.x = GsnBm.x
    wfr.partBeam.partStatMom1.y = GsnBm.y
    wfr.partBeam.partStatMom1.z = GsnBm.z
    wfr.partBeam.partStatMom1.xp = GsnBm.xp
    wfr.partBeam.partStatMom1.yp = GsnBm.yp

    if (pulseEn is None) and (pulseTau is None):
        wfr.unitElFld = 0 # set to 'arbitrary'

    sampFactNxNyForProp = -1  # sampling factor for adjusting nx, ny (effective if > 0)
    arPrecPar = [sampFactNxNyForProp]
    srwlpy.CalcElecFieldGaussian(wfr, GsnBm, arPrecPar)
    return wfr
Beispiel #3
0
def build_gauss_wavefront(nx, ny, nz, ekev, xMin, xMax, yMin, yMax, tau, sigX, sigY, d2waist, 
                          pulseEn=None, pulseRange=None, _mx=None, _my=None):
    """
    Build 3D Gaussian beam.

    :param nx: Number of point along x-axis
    :param ny: Number of point along y-axis
    :param nz: Number of point along z-axis (slices)
    :param ekev: Energy in kEv
    :param xMin: Initial Horizontal Position [m]
    :param xMax: Final Horizontal Position [m]
    :param yMin: Initial Vertical Position [m]
    :param yMax: Final Vertical Position [m]
    :param tau: Pulse duration [s]
    :param sigX: Horiz. RMS size at Waist [m]
    :param sigY:  Vert. RMS size at Waist [m]
    :param d2waist: Distance to Gaussian waist
    :param pulseEn: Energy per Pulse [J]
    :param pulseRange: pulse duration range in sigT's
    :param _mx: transverse Gauss-Hermite mode order in horizontal direction
    :param _my: transverse Gauss-Hermite mode order in vertical direction
    :return: wpg.Wavefront structure
    """
    # TODO: fix comment


    GsnBm = srwlib.SRWLGsnBm()  # Gaussian Beam structure (just parameters)
    GsnBm.x = 0  # Transverse Coordinates of Gaussian Beam Center at Waist [m]
    GsnBm.y = 0
    GsnBm.z = 0  # Longitudinal Coordinate of Waist [m]
    GsnBm.xp = 0  # Average Angles of Gaussian Beam at Waist [rad]
    GsnBm.yp = 0

    GsnBm.avgPhotEn = ekev * 1.e3  # 15000. #Photon Energy [eV]
    if pulseEn is not None:
        GsnBm.pulseEn = pulseEn 
    else:
        GsnBm.pulseEn = 0.001 # was 1 mJ in the Tutorial exampes as well
    GsnBm.repRate = 1  # Rep. Rate [Hz] - to be corrected
    GsnBm.polar = 1  # 1- linear hoirizontal; 2 - linear vertical
    # Far field angular divergence: 14.1e-6 ./ (ekev) .^0.75
    # 0.17712e-09/(4*Pi)/(14.1e-06/((7)^0.75)) for 7 keV, 3.55561e-06 =
    # 0.0826561e-09/(4*Pi)/(14.1e-06/((15)^0.75)) for 15 keV #Horiz. RMS size
    # at Waist [m]
    GsnBm.sigX = sigX
    GsnBm.sigY = sigY  # Vert. RMS size at Waist [m]
    # Coherence time (~ Gaussian pulse duration)           0.12 fs @ 15 keV
    # and 0.17 fs @ 7 keV
    # 0.12e-15 #0.17e-15 for 15 keV #Pulse duration [s] #To check: Is it 0.12
    # fs or 12 fs ?
    GsnBm.sigT = tau
    if _mx is not None:
        GsnBm.mx = _mx 
    else:
        GsnBm.mx = 0  # Transverse Gauss-Hermite Mode Orders
    if _mx is not None:
        GsnBm.my = _my 
    else:
        GsnBm.my = 0

    wfr = srwlib.SRWLWfr()  # Initial Electric Field Wavefront
    wfr.allocate(nz, nx, ny)
    # Numbers of points vs Photon Energy (1), Horizontal and
    # Vertical Positions (dummy)
    wfr.presFT = 1  # Defining Initial Wavefront in Time Domain
    #wfr.presFT = 0 #Defining Initial Wavefront in Frequency Domain

    wfr.avgPhotEn = GsnBm.avgPhotEn
    if pulseRange is not None:
        wfr.mesh.eStart = -pulseRange/2. * GsnBm.sigT  # Initial Time [s]
        wfr.mesh.eFin   =  pulseRange/2. * GsnBm.sigT  # Final Time [s]
    else:
        #wfr.mesh.eStart = -100 * GsnBm.sigT  # Initial Time [s]
        #wfr.mesh.eFin = 100 * GsnBm.sigT  # Final Time [s]
        wfr.mesh.eStart = -4. * GsnBm.sigT  # Initial Time [s]
        wfr.mesh.eFin = 4. * GsnBm.sigT  # Final Time [s]

    # Longitudinal Position [m] at which Electric Field has to be calculated,
    # i.e. the position of the first optical element
    wfr.mesh.zStart = d2waist
    wfr.mesh.xStart = xMin  # Initial Horizontal Position [m]
    wfr.mesh.xFin = xMax  # Final Horizontal Position [m]
    wfr.mesh.yStart = yMin  # Initial Vertical Position [m]
    wfr.mesh.yFin = yMax  # Final Vertical Position [m]

    wfr.mesh.ne = nz

    # Some information about the source in the Wavefront structure
    wfr.partBeam.partStatMom1.x = GsnBm.x
    wfr.partBeam.partStatMom1.y = GsnBm.y
    wfr.partBeam.partStatMom1.z = GsnBm.z
    wfr.partBeam.partStatMom1.xp = GsnBm.xp
    wfr.partBeam.partStatMom1.yp = GsnBm.yp

    sampFactNxNyForProp = -1  # 5 #sampling factor for adjusting nx, ny (effective if > 0)
    arPrecPar = [sampFactNxNyForProp]
    #**********************Calculating Initial Wavefront
    srwlpy.CalcElecFieldGaussian(wfr, GsnBm, arPrecPar)

    return wfr
Beispiel #4
0
        npTraj = 10000  # v.tr_np #Number of points for trajectory calculation
        useTermin = 1  # 1 #Use "terminating terms" (i.e. asymptotic expansions at zStartInteg and zEndInteg) or not (1 or 0 respectively)
        sampFactNxNyForProp = (
            0  # sampling factor for adjusting nx, ny (effective if > 0)
        )
        arPrecPar = [
            meth,
            relPrec,
            zStartInteg,
            zEndInteg,
            npTraj,
            useTermin,
            sampFactNxNyForProp,
        ]

        wf1 = srwlib.SRWLWfr()  # intialize wave feild object

        # ***********Initial Wavefront data placeholder
        wf1.allocate(
            1, i, i
        )  # Numbers of points vs Photon Energy, Horizontal and Vertical Positions
        # wf1.allocate(1, 720, 720)  # Numbers of points vs Photon Energy, Horizontal and Vertical Positions
        # wf1.mesh.zStart = 1
        wf1.mesh.zStart = 14  # Initial drift to first element
        # Longitudinal Position [m] from Center of Straight Section at which SR has to be calculated
        wf1.mesh.eStart = v.w_e  # Initial Photon Energy [eV]
        wf1.mesh.eFin = v.w_e  # Final Photon Energy [eV]
        wf1.mesh.xStart = -1e-3  # Initial Horizontal Position [m]
        wf1.mesh.xFin = 1e-3  # Final Horizontal Position [m]
        wf1.mesh.yStart = -1e-3  # Initial Vertical Position [m]
        wf1.mesh.yFin = 1e-3  # Final Vertical Position [m]