示例#1
0
    def pol(self):
        '''This method calculates the sum over final polarizations'''
        try:
          kin = self.kin
          kout = self.kout
          kipol = self.kipol
        except Exception as e:
          print "k vectors have not been defined in the crystal"
          print "program will stop"
          print e
          exit()

        # unit vectors for input polarization
        zvec = vec3.vec3(0.,0.,1.) 
        in1 = vec3.cross( zvec, kin )
        in1 = in1 / abs(in1) 
        in2 = vec3.cross( kin, in1)
        in2 = in2 / abs(in2)
        # input polarization
        inpol = kipol[0]*in1 + kipol[1]*in2
        
        # unit vectors for output polarization 
        out1 = vec3.cross( zvec, kout )
        out1 = out1 / abs(out1) 
        out2 = vec3.cross( kout, out1)
        out2 = out2 / abs(out2)

        # polarization of transition
        splus =  1/np.sqrt(2.) *( vec3.vec3(1.,0.,0.) + 1j * vec3.vec3(0.,1.,0.))
        sminus = 1/np.sqrt(2.) *( vec3.vec3(1.,0.,0.) - 1j * vec3.vec3(0.,1.,0.))

        # sum over output polarizations
        
        polsum = 0.
        for i,pout in enumerate([out1, out2]):
            term =  abs( (splus * pout)*(inpol*sminus) )**2.
            polsum = polsum + term
        if verbose:
            print "\tSum over output pol (vectors) = ", polsum
        self.polsum = polsum
   
        # also obtain this result using the angles 
        # with respect to the magnetic field
        cosIN  = kin/abs(kin) * zvec 
        cosOUT = kout/abs(kout) * zvec
        polsumANGLE =  1./4. * (1 + cosIN**2.) * (1 + cosOUT**2.)
        #print "Sum over output pol (angles)  = ", polsumANGLE
   
        # optional draw polarization vectors on bloch sphere
        if False: 
            b = bsphere.Bloch()
            origin = vec3.vec3()
            b.add_arrow( -kin/abs(kin), origin, 'red')
            b.add_arrow( -kin/abs(kin), -kin/abs(kin) + in1/2., 'black')
            b.add_arrow( -kin/abs(kin), -kin/abs(kin) + in2/2., 'black')
            b.add_arrow( origin, kout/abs(kout), 'red')
            b.add_arrow( origin, out1/2., 'black')
            b.add_arrow( origin, out2/2., 'black')
            b.show()
        return self.polsum
示例#2
0
 def __init__(self, origin, lookat, up, fov, aspect):
     theta = fov * math.pi / 180
     half_height = math.tan(theta / 2)
     half_width = aspect * half_height
     self.origin = origin
     w = vec3.normalize(vec3.subtract(origin, lookat))
     u = vec3.normalize(vec3.cross(up, w))
     v = vec3.cross(w, u)
     self.horizontal = vec3.scale(u, 2 * half_width)
     self.vertical = vec3.scale(v, 2 * half_height)
     center = vec3.subtract(origin, w)
     shift = vec3.scale(vec3.add(self.horizontal, self.vertical), 0.5)
     self.llc = vec3.subtract(center, shift)
示例#3
0
def fromnormals_faster(n1, n2):
	axis = vec3.normalize(vec3.cross(n1, n2))

	half_n = vec3.normalize(vec3.add(n1, n2))
	cos_half_angle = vec3.dot(n1, half_n)
	sin_half_angle = 1.0 - cos_half_angle ** 2
	
	return vec3.mulN(axis, sin_half_angle) + (cos_half_angle,)
示例#4
0
文件: quat.py 项目: Eelis/klee
def fromnormals_faster(n1,n2):
	axis= vec3.normalize(vec3.cross(n1, n2))

	half_n= vec3.normalize(vec3.add(n1, n2))
	cos_half_angle= vec3.dot(n1, half_n)
	sin_half_angle= 1.0 - cos_half_angle**2
	
	return vec3.mulN(axis, sin_half_angle) + (cos_half_angle,)
示例#5
0
    def __init__(self, lookfrom, lookat, vup, vfov, image_width, image_height):

        aspect = image_width / image_height
        theta = math.radians(vfov)
        half_height = math.tan(theta / 2.0)
        half_width = aspect * half_height

        from_to_at = lookfrom - lookat
        w = from_to_at.norm()
        u = cross(vup, w).norm()
        v = cross(w, u)

        self.origin = lookfrom
        self.lower_left_corner = self.origin - (u * half_width) - (
            v * half_height) - w
        self.horizontal = u * half_width * 2
        self.vertical = v * half_height * 2
        self.image_width = image_width
        self.image_height = image_height
   def plotCross(self,
           axes = None,
           func = None,
           origin  = vec3(0.,0.,0.), 
           normal   = (np.pi/2, 0),
           lims0   = (-50,50), 
           lims1   = (-50,50),
           extents = None,
           npoints = 240 ):
       
       if func is None:
           func = self.evalpotential
       
       if extents is not None:
           lims0 = (-extents, extents)
           lims1 = (-extents, extents)
       
       # Make the unit vectors that define the plane
       unit = vec3()
       th = normal[0]
       ph = normal[1]
       unit.set_spherical( 1, th, ph) 
       #orth1 = -1.*vec3( np.cos(th)*np.cos(ph) , np.cos(th)*np.sin(ph), -1.*np.sin(th) )
       orth0 = vec3( -1.*np.sin(ph), np.cos(ph), 0. )
       orth1 = cross(unit,orth0)
       
       t0 = np.linspace( lims0[0], lims0[1], npoints )
       t1 = np.linspace( lims1[0], lims1[1], npoints ) 
       
       # Obtain points on which function will be evaluated
       T0,T1 = np.meshgrid(t0,t1)
       X = origin[0] + T0*orth0[0] + T1*orth1[0] 
       Y = origin[1] + T0*orth0[1] + T1*orth1[1]
       Z = origin[2] + T0*orth0[2] + T1*orth1[2] 
       
   
       if axes is None:
           # Prepare figure
           fig = plt.figure(figsize=(9,4.5))
           gs = matplotlib.gridspec.GridSpec( 1,2, wspace=0.2)
       
           ax0 = fig.add_subplot( gs[0,0], projection='3d')
           ax1 = fig.add_subplot( gs[0,1])
       else:
           ax0 = axes[0]
           ax1 = axes[1]
       
       
       # Plot the reference surface
       ax0.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3, linewidth=0.)
       ax0.set_xlabel('X')
       ax0.set_ylabel('Y')
       ax0.set_zlabel('Z')
       lmin = min([ ax0.get_xlim()[0], ax0.get_ylim()[0], ax0.get_zlim()[0] ] )
       lmax = max([ ax0.get_xlim()[1], ax0.get_ylim()[1], ax0.get_zlim()[1] ] )
       ax0.set_xlim( lmin, lmax )
       ax0.set_ylim( lmin, lmax )
       ax0.set_zlim( lmin, lmax )
       ax0.set_yticklabels([])
       ax0.set_xticklabels([])
       ax0.set_zticklabels([])
       
       
       # Evaluate function at points and plot
       EVAL = func(X,Y,Z)
 
       T1_1d = np.ravel(T1)
       EVAL_1d = np.ravel(EVAL)
       
       im =ax1.pcolormesh(T0, T1, EVAL, cmap = plt.get_cmap('jet')) # cmaps:  rainbow, jet
       plt.axes( ax1)
       cbar = plt.colorbar(im)
       cbar.set_label(self.unitlabel, rotation=0 )#self.unitlabel
       
       if axes is None:
           # Finalize figure
           gs.tight_layout(fig, rect=[0.,0.,1.0,1.0])
           
       return EVAL.min(), EVAL.max(), im
示例#7
0
kout100.set_spherical( 2.*np.pi/l671, np.pi/2 - braggTH100, np.pi / 2)
kMANTA = kout100



# Incoming light vector HHH 
thi = np.pi/2 - braggTH2
phi = 90. * np.pi / 180.
kin = vec3.vec3()
kin.set_spherical( 2.*np.pi/l671, thi, phi )

# Default polarization of incoming light vector
kipol = [1.,0] 

# Unit vector that points perp to Bragg cone
kinperp = vec3.cross( kin, vec3.cross(Q,kin) ) 
kinperp = kinperp / abs(kinperp)

# Direction of A2 detector
kout = kin + Q  
a2 = kout / abs(kout)
kA2 = kout

# Unit vector perpendicular to plane of Q and A2
Qperp1 = vec3.cross( Q, a2 )
Qperp1 = Qperp1 / abs(Qperp1)

# Unit vector perpendicular to Q and in plane of kin,kout,Q
Qperp2 = vec3.cross( Q, Qperp1)
Qperp2 = Qperp2 / abs(Qperp2)
# Using Qunit and Qperp2 one can use the Bragg angle to 
示例#8
0
def fromnormals(n1, n2):
	axis, angle = vec3.normalize(vec3.cross(n1, n2)), math.acos(vec3.dot(n1, n2))
	return fromaxisangle((axis, angle))
示例#9
0
文件: quat.py 项目: Eelis/klee
def fromnormals(n1,n2):
	axis,angle= vec3.normalize(vec3.cross(n1, n2)), math.acos(vec3.dot(n1, n2))
	return fromaxisangle((axis,angle))
示例#10
0
def surfcut_points(**kwargs):
    """ 
    Defines an surface cut through the potential geometry.  Parameters are given
    as keyword arguments (kwargs).

    All distances are in microns. 

    Parameters 
    ----------
    npoints     :  number of points along the cut
 
    extents     :  a way of specifying the limits for a cut that is symmetric
                   about the cut origin.  the limits will be 
                   lims = (-extents, extents)  

    lims        :  used only if extents = None.   limits are specified using
                   a tuple  ( min, max ) 

    direc       :  tuple, two elements.  polar coordinates for the direcdtion 
                   of the cut 
 
    origin      :  tuple, three elements.  cartesian coordinates for the origin
                   of the cut  

    ax0         :  optional axes where the reference surface for the surface 
                   cut can be plotted 


    Returns 
    -------
    T0, T1      :  arrays which parameterizes the position on the cut surface
  
    X, Y, Z     :  each of X,Y,Z is an array with the same shape as T0 and T1. 
                   They correspond to the cartesian coordinates of all the 
                   points on the cut surface.  
                   
    Notes 
    ----  

    Examples
    --------
    """
    npoints = kwargs.get( 'npoints', 240  )
    origin = kwargs.get( 'origin', vec3(0.,0.,0.)) 
    normal = kwargs.get( 'normal', (np.pi/2., 0.) )  
    lims0  = kwargs.get( 'lims0', (-50., 50.) ) 
    lims1  = kwargs.get( 'lims1', (-50., 50.) ) 
    extents = kwargs.get( 'extents', None)  
    
    if extents is not None:
        lims0 = (-extents, extents)
        lims1 = (-extents, extents)
    
    # Make the unit vectors that define the plane
    unit = vec3()
    th = normal[0]
    ph = normal[1]
    unit.set_spherical( 1, th, ph) 
    orth0 = vec3( -1.*np.sin(ph), np.cos(ph), 0. )
    orth1 = cross(unit,orth0)
    
    t0 = np.linspace( lims0[0], lims0[1], npoints )
    t1 = np.linspace( lims1[0], lims1[1], npoints ) 
    
    # Obtain points on which function will be evaluated
    T0,T1 = np.meshgrid(t0,t1)
    X = origin[0] + T0*orth0[0] + T1*orth1[0] 
    Y = origin[1] + T0*orth0[1] + T1*orth1[1]
    Z = origin[2] + T0*orth0[2] + T1*orth1[2] 
    

    # If given an axes it will plot the reference surface to help visusalize
    # the surface cut
    
    # Note that the axes needs to be created with a 3d projection. 
    # For example: 
    #    fig = plt.figure( figsize=(4.,4.) ) 
    #    gs = matplotlib.gridspec.GridSpec( 1,1 ) 
    #    ax0 = fig.add_subplot( gs[0,0], projection='3d' )  
 
    ax0 = kwargs.get( 'ax0', None ) 
    if ax0 is not None: 

        # Plot the reference surface
        ax0.plot_surface(X, Y, Z, rstride=8, cstride=8, alpha=0.3, linewidth=0.)
        ax0.set_xlabel('X')
        ax0.set_ylabel('Y')
        ax0.set_zlabel('Z')
        lmin = min([ ax0.get_xlim()[0], ax0.get_ylim()[0], ax0.get_zlim()[0] ] )
        lmax = max([ ax0.get_xlim()[1], ax0.get_ylim()[1], ax0.get_zlim()[1] ] )
        ax0.set_xlim( lmin, lmax )
        ax0.set_ylim( lmin, lmax )
        ax0.set_zlim( lmin, lmax )
        ax0.set_yticklabels([])
        ax0.set_xticklabels([])
        ax0.set_zticklabels([])
    
    # If given an axes and a potential it will plot the surface cut of the 
    # potential   

    ax1 = kwargs.get( 'ax1', None) 
    pot = kwargs.get( 'potential', None)  

    if (ax1 is not None) and (pot is not None):
        # Evaluate function at points and plot
        EVAL = pot.evalpotential(X,Y,Z)

        im =ax1.pcolormesh(T0, T1, EVAL, cmap = plt.get_cmap('jet')) 
        # cmaps:  rainbow, jet

        plt.axes( ax1)
        cbar = plt.colorbar(im)
        cbar.set_label(pot.unitlabel, rotation=0 )#self.unitlabel
    
    return T0, T1, X, Y, Z  
示例#11
0
def surfcut_points(**kwargs):
    """ 
    Defines an surface cut through the potential geometry.  Parameters are given
    as keyword arguments (kwargs).

    All distances are in microns. 

    Parameters 
    ----------
    npoints     :  number of points along the cut
 
    extents     :  a way of specifying the limits for a cut that is symmetric
                   about the cut origin.  the limits will be 
                   lims = (-extents, extents)  

    lims        :  used only if extents = None.   limits are specified using
                   a tuple  ( min, max ) 

    direc       :  tuple, two elements.  polar coordinates for the direcdtion 
                   of the cut 
 
    origin      :  tuple, three elements.  cartesian coordinates for the origin
                   of the cut  

    ax0         :  optional axes where the reference surface for the surface 
                   cut can be plotted 


    Returns 
    -------
    T0, T1      :  arrays which parameterizes the position on the cut surface
  
    X, Y, Z     :  each of X,Y,Z is an array with the same shape as T0 and T1. 
                   They correspond to the cartesian coordinates of all the 
                   points on the cut surface.  
                   
    Notes 
    ----  

    Examples
    --------
    """
    npoints = kwargs.get('npoints', 240)
    origin = kwargs.get('origin', vec3(0., 0., 0.))
    normal = kwargs.get('normal', (np.pi / 2., 0.))
    lims0 = kwargs.get('lims0', (-50., 50.))
    lims1 = kwargs.get('lims1', (-50., 50.))
    extents = kwargs.get('extents', None)

    if extents is not None:
        lims0 = (-extents, extents)
        lims1 = (-extents, extents)

    # Make the unit vectors that define the plane
    unit = vec3()
    th = normal[0]
    ph = normal[1]
    unit.set_spherical(1, th, ph)
    orth0 = vec3(-1. * np.sin(ph), np.cos(ph), 0.)
    orth1 = cross(unit, orth0)

    t0 = np.linspace(lims0[0], lims0[1], npoints)
    t1 = np.linspace(lims1[0], lims1[1], npoints)

    # Obtain points on which function will be evaluated
    T0, T1 = np.meshgrid(t0, t1)
    X = origin[0] + T0 * orth0[0] + T1 * orth1[0]
    Y = origin[1] + T0 * orth0[1] + T1 * orth1[1]
    Z = origin[2] + T0 * orth0[2] + T1 * orth1[2]

    # If given an axes it will plot the reference surface to help visusalize
    # the surface cut

    # Note that the axes needs to be created with a 3d projection.
    # For example:
    #    fig = plt.figure( figsize=(4.,4.) )
    #    gs = matplotlib.gridspec.GridSpec( 1,1 )
    #    ax0 = fig.add_subplot( gs[0,0], projection='3d' )

    ax0 = kwargs.get('ax0', None)
    if ax0 is not None:

        # Plot the reference surface
        ax0.plot_surface(X,
                         Y,
                         Z,
                         rstride=8,
                         cstride=8,
                         alpha=0.3,
                         linewidth=0.)
        ax0.set_xlabel('X')
        ax0.set_ylabel('Y')
        ax0.set_zlabel('Z')
        lmin = min([ax0.get_xlim()[0], ax0.get_ylim()[0], ax0.get_zlim()[0]])
        lmax = max([ax0.get_xlim()[1], ax0.get_ylim()[1], ax0.get_zlim()[1]])
        ax0.set_xlim(lmin, lmax)
        ax0.set_ylim(lmin, lmax)
        ax0.set_zlim(lmin, lmax)
        ax0.set_yticklabels([])
        ax0.set_xticklabels([])
        ax0.set_zticklabels([])

    # If given an axes and a potential it will plot the surface cut of the
    # potential

    ax1 = kwargs.get('ax1', None)
    pot = kwargs.get('potential', None)

    if (ax1 is not None) and (pot is not None):
        # Evaluate function at points and plot
        EVAL = pot.evalpotential(X, Y, Z)

        im = ax1.pcolormesh(T0, T1, EVAL, cmap=plt.get_cmap('jet'))
        # cmaps:  rainbow, jet

        plt.axes(ax1)
        cbar = plt.colorbar(im)
        cbar.set_label(pot.unitlabel, rotation=0)  #self.unitlabel

    return T0, T1, X, Y, Z