Beispiel #1
0
def test_prime_maps(u, final = False):
    
    ext_surf                        =   make_periodic(u.ext_surf, 'surf', phi_period = u.phi_period)
    ext_umat                        =   make_periodic(u.ext_umat, 'umat', sym_op = u.sym_op)
    [rmin, rmax], [phimin, phimax]  =   valminmax(ext_surf)
    
    rdev_max                        =   0
    phidev_max                      =   0
    iphidev, irdev                  =   [], []
    
    for ir, r_vec in np.ndenumerate(np.delete(ext_surf, -1, 1)):        
        
        i, j                =   ir
        C                   =   u.curve_Lphi[i]/u.phi_period #(phimax - phimin)
        
        drprimedphi         =   u.dudphipol[i,j][0]
        dphiprimedphi       =   1 + u.dudphipol[i,j][1] #(u.phips[i, j + 1] - u.phips[ir]) / u.dphi_mat[ir]  #(u.phips[i,dj] - u.phips[i,j])/dphi    
        duzdphi             =   u.dudphipol[i,j][2] # u.du(r_vec, 'duz')[1]
        
        Ct                  =   np.sqrt((r_vec[0] + ext_umat[ir][0])**2*dphiprimedphi**2 \
                                        + drprimedphi**2 + duzdphi**2)   
        
        if  phidev_max  <   abs(Ct - C):
            phidev_max  =   abs(Ct - C) 
            iphidev     =   [i,j]

    for iphi, phi_vec in np.ndenumerate(np.delete(ext_surf, -1, 0)):        
        
        i, j                =   iphi
        K                   =   u.curve_Lr[j]/(rmax - rmin)
        
        drprimedr           =   1 + u.dudrpol[i,j][0] #(u.rps[i + 1, j] - u.rps[iphi]) / u.dr_mat[iphi]   
        dphiprimedr         =   u.dudrpol[i,j][1] 
        duzdr               =   u.dudrpol[i,j][2] # u.du(r_vec, 'duz')[1]
        
        rprime              =   phi_vec[0] + ext_umat[i, j][0]
        
        Kt                  =   np.sqrt(drprimedr**2 + rprime**2*dphiprimedr**2 + duzdr**2)   
        
        if  rdev_max    <   abs(Kt - K) :
            rdev_max    =   abs(Kt - K) 
            irdev       =   [i,j]    
    
    if final and rdev_max > 1e-10:
        print 'screwed up: rdev_max = ' + str(rdev_max) 

    if final and phidev_max > 1e-10:
        print 'screwed up: phidev_max = ' + str(phidev_max) 
    
    return rdev_max, phidev_max, irdev, iphidev
Beispiel #2
0
    def __init__(self, rmin, rmax, nr, phimin, delta_phi, nphi):

        phimax = phimin + delta_phi
        # S = (r, phi, z)
        rs = np.linspace(rmin, rmax, nr)
        phis = np.linspace(phimin, phimax, nphi)

        r_0 = rs[0] - (rs[1] - rs[0])
        r0 = np.array([r_0])
        r_f = rs[-1] + (rs[-1] - rs[-2])
        rf = np.array([r_f])

        rs = np.concatenate((r0, rs, rf))

        self.ext_surf = np.empty((len(rs), len(phis) - 1), dtype="object")

        for ir, r in enumerate(rs):
            for iphi, phi in enumerate(phis[:-1]):
                self.ext_surf[ir, iphi] = np.array([r, phi, 0.0])
                # if ir < len(rs) - 1 and iphi < len(phis) - 1:
                #    self.d_ext_surf[ir,iphi]     =   np.array([r + delta_r(rs, ir)/2., phi + delta_phi(phis, iphi)/2., 0.])

        # phi_period          =   max(phis) - min(phis)
        self.phys_surf = make_periodic(np.delete(np.delete(self.ext_surf, 0, 0), -1, 0), "surf", phi_period=delta_phi)
        self.calc_surf = np.delete(np.delete(self.phys_surf, -1, 0), -1, 1)

        """
Beispiel #3
0
def parse_surf(mat_r, mat_phi, mat_z, phi_period, sym_op, key):

    mat = np.empty(mat_r.shape, dtype="object")

    for index, val in np.ndenumerate(mat):
        mat[index] = np.array([mat_r[index], mat_phi[index], mat_z[index]])

    if key == "surf":
        phys_mat = make_periodic(np.delete(np.delete(mat, 0, 0), -1, 0), "surf", phi_period=phi_period)
    elif key == "umat":
        phys_mat = make_periodic(np.delete(np.delete(mat, 0, 0), -1, 0), "umat", sym_op=sym_op)
    # elif key    == 'normals':
    #    phys_mat     =   make_periodic(mat, 'surf', phi_period = phi_period)

    calc_mat = np.delete(np.delete(phys_mat, -1, 0), -1, 1)

    return mat, phys_mat, calc_mat
Beispiel #4
0
def plot_surf(u):
    
    from help_classes import make_periodic
    
    umat        =   make_periodic(u.ext_umat, 'umat', sym_op = u.sym_op)
    init_surf   =   make_periodic(u.ext_surf, 'surf', phi_period = u.phi_period)
    

    X_init, Y_init, Z_init  =   get_coord(init_surf)
    X, Y, Z                 =   get_coord(init_surf + umat)
    xs, ys, zs              =   get_coord(u.phys_surf + u.phys_umat)    
    xss, yss, zss           =   get_coord(u.calc_surf + u.calc_umat)    

    limits          =   [np.amin([np.amin(X),np.amin(Y),np.amin(Z)]), np.amax([np.amax(X),np.amax(Y),np.amax(Z)])]
        
    fig             =   plt.figure(figsize=plt.figaspect(0.5)*1.5)
    
    vv              =   max(int(len(X)/30), 1)
    
    
    #1
    ax              =   fig.add_subplot(131, projection='3d')
    
    ax.plot_surface(X_init, Y_init, Z_init, alpha = 0.2, rstride = vv, cstride = vv) 
    ax.plot_surface(X, Y, Z, rstride = vv, cstride = vv, alpha = 1., shade=False)
    
    ax.auto_scale_xyz(limits, limits, limits)
    
    
    
    #2
    ax1 = fig.add_subplot(132, projection='3d')
    ax1.plot_surface(xs, ys, zs, rstride = vv, cstride = vv, alpha = 1., shade=False) #, c='r', marker='o')
    ax1.auto_scale_xyz(limits, limits, limits)
    
    #3
    ax2 = fig.add_subplot(133, projection='3d')
    ax2.plot_surface(xss, yss, zss, rstride = vv, cstride = vv, alpha = 1., shade=False) #, c='r', marker='o')
    ax2.auto_scale_xyz(limits, limits, limits)
    
    
    plt.show()
    plt.clf()
Beispiel #5
0
def path_integral_r(u):
    
    ext_surf    =   make_periodic(u.ext_surf, 'surf', phi_period = u.phi_period)
    ext_umat    =   make_periodic(u.ext_umat, 'umat', sym_op = u.sym_op)

    inte_r      =   np.zeros(ext_umat.shape[1])
    inte_phi    =   np.zeros(ext_umat.shape[0])
    
    for ir, r_vec in np.ndenumerate(np.delete(ext_surf, -1, 0)):
        
        i,j         =   ir
        dvr         =   ext_umat[i + 1, j] + ext_surf[i + 1, j] \
                      - ext_umat[ir]       - ext_surf[ir]   
        rp          =   r_vec[0] + ext_umat[ir][0]
        
        inte_r[ir[1]] +=  np.sqrt(dvr[0]**2 + rp**2*dvr[1]**2 + dvr[2]**2) 
    
    for iphi, phi_vec in np.ndenumerate(np.delete(ext_surf, -1, 1)):

        i,j         =   iphi
        dvphi       =   ext_umat[i, j + 1]     + ext_surf[i, j + 1] \
                      - ext_umat[iphi]         - ext_surf[iphi]    
        rp          =   phi_vec[0] + ext_umat[iphi][0]
        
        inte_phi[i]+=  np.sqrt(dvphi[0]**2 + rp**2*dvphi[1]**2 + dvphi[2]**2) 
    

    for i, integ in enumerate(inte_phi):
        if abs(integ - u.curve_Lphi[i]) > 1e-10:
            print 'curve l: constant r, screwed up... dev = ' + str(abs(integ - u.curve_Lphi[i]))

    for i, integ in enumerate(inte_r):
        if abs(integ - u.curve_Lr[i]) > 1e-10:
            print 'curve l: constant phi, screwed up... dev = ' + str(abs(integ - u.curve_Lr[i]))
    
     
        
    #print inte, valminmax(ext_surf)[0][1] - valminmax(ext_surf)[0][0]
        
        
                    
Beispiel #6
0
    def parse_u(self, flat_u_pol):
        
        n       =   0
        
        for index, vec in np.ndenumerate( self.ext_umat ):
            for i in range(3):
                self.ext_umat[index][i]  =   flat_u_pol[n]
                n                      +=   1
            
        self.phys_umat   =   make_periodic(np.delete(np.delete(self.ext_umat,  0, 0), \
                                                       -1, 0), 'umat', sym_op = self.sym_op)
        self.calc_umat   =   np.delete(np.delete(self.phys_umat,      -1, 0), -1, 1)  

        self.du()
        self.ddu()        
        self.dA()
Beispiel #7
0
    def du(self):
        
        
#        r_mat                   =   make_periodic_surf(self.ext_surf, self.phi_period)
        r_mat                   =   make_periodic(self.ext_surf, 'surf', phi_period = self.phi_period)
 
        u_mat_pol               =   make_periodic(self.ext_umat, 'umat', sym_op = self.sym_op)
          
        dr_mat                  =   np.delete(r_mat, 0, 0)  - np.delete(r_mat, -1, 0) 
        dphi_mat                =   np.delete(r_mat, 0, 1)  - np.delete(r_mat, -1, 1)   
        
        dr_mat_r                =   np.empty(dr_mat.shape)
        dphi_mat_phi            =   np.empty(dphi_mat.shape)
        
        
        for ir,dr in np.ndenumerate(dr_mat):
            dr_mat_r[ir]        =   dr[0]
        
        for iphi, dphi in np.ndenumerate(dphi_mat):   
            dphi_mat_phi[iphi]  =   dphi[1]
        
        
        dudrpol            =   (np.delete(u_mat_pol,  0, 0)   \
                               -np.delete(u_mat_pol, -1, 0))  / dr_mat_r 
        dudphipol          =   (np.delete(u_mat_pol,  0, 1)   \
                               -np.delete(u_mat_pol, -1, 1))  / dphi_mat_phi  
        
        self.dr_mat        =   dr_mat_r
        self.dphi_mat      =   make_periodic_der(dphi_mat_phi, 1, nums = True)
        
        self.dudrpol       =   dudrpol
        
        self.dudphipol     =   make_periodic_der(dudphipol)
        
        # testi
        dudrcart           =   np.empty(self.dr_mat.shape, dtype = 'object')
        dudphicart         =   np.empty(self.dphi_mat.shape, dtype = 'object')
            
        
        for ind, vec in np.ndenumerate(self.dr_mat):
            dudrcart[ind]      =   np.zeros(3)
            
            r, phi                  =   r_mat[ind][:2] #self.ext_surf[ind][:2]
            #rp, phip                =   r + self.ext_umat[ind][0], phi + self.ext_umat[ind][1]
            rp, phip                =   r + u_mat_pol[ind][0], phi + u_mat_pol[ind][1] 
            durdr, duphidr, duzdr   =   self.dudrpol[ind] 
            
            dudrcart[ind][0]   =  -np.cos(phi) - rp*duphidr*np.sin(phip) \
                                       +(1 + durdr)*np.cos(phip) 
            dudrcart[ind][1]   =  -np.sin(phi) + rp*duphidr*np.cos(phip) \
                                       +(1 + durdr)*np.sin(phip) 
            dudrcart[ind][2]   =   duzdr

        for ind, vec in np.ndenumerate(self.dphi_mat):
            dudphicart[ind]    =   np.zeros(3)
            
            r, phi                  =   r_mat[ind][:2] #self.ext_surf[ind][:2]
            #rp, phip                =   r + self.ext_umat[ind][0], phi + self.ext_umat[ind][1] 
            rp, phip                =   r + u_mat_pol[ind][0], phi + u_mat_pol[ind][1] 
            
            durdphi, duphidphi, duzdphi \
                                    =   self.dudphipol[ind] 
            
            dudphicart[ind][0] =   r*np.sin(phi) + np.cos(phip)*durdphi \
                                       -rp*(1 + duphidphi)*np.sin(phip)   
            dudphicart[ind][1] =  -r*np.cos(phi) + np.sin(phip)*durdphi \
                                       +rp*(1 + duphidphi)*np.cos(phip)   
            dudphicart[ind][2] =   duzdphi
        
        
        self.dudrcart           =   dudrcart
        self.dudphicart         =   dudphicart
Beispiel #8
0
    def u(self):
        
        self.umat       =   np.empty(3, dtype = 'object')
        
        r_mat           =   self.ext_surf
        
        if self.system in ['spiral_w_wave_sqr', 'spiral_w_wave_str']:
            z_set       =   get_z_set(self.system, r_mat, self.hangle, self.consts, self.phi_period)
        
        
        #print z_set
        umat_b          =   np.empty(r_mat.shape, dtype = 'object')
        umat_cart_b     =   np.empty(r_mat.shape, dtype = 'object')
        
        [rmin, rmax]    =   valminmax(r_mat)[0]
        
        for index, r_vec in np.ndenumerate( r_mat ):
            
            umat_b[index]         =   np.zeros(3)
            umat_cart_b[index]    =   np.zeros(3)
            r, phi                =   r_vec[:2] 

            
            # Map r -> r'
            if self.opt[0] == 0:
                ur     =   0
            
            elif self.opt[0] == 1:
                ur     =   self.consts[0]
            
            elif self.opt[0] == 2:
                ur     =   self.rps[index] - r
                
            else:
                print 'MIta shiivaddia' 
            

            # Map phi -> phi'
            if self.opt[1] == 0:
                uphi   =   0
                                
            elif self.opt[1] == 1:
                uphi   =   heaviside(r, self.consts[2])*((r - self.consts[2])/(rmax - self.consts[2]))**2* \
                                            self.consts[3]*np.sin(phi/self.phi_period*2*pi)
            
            elif self.opt[1] == 2:
                uphi   =   self.consts[3]
            
            elif self.opt[1] == 3:
                uphi   =   self.phips[index] - phi
                
            else:
                print 'mita shiivaddia!'
            
            
            # Map z -> z'
            if self.opt[2] == 0:
                uz     =   self.hangle*phi   

            elif self.opt[2] == 1:
                #print self.consts
                #curve_start     =   rmin + self.consts[2] # + self.consts[0]
                #uz     =   self.hangle*phi  +   heaviside(r, curve_start)*((r - curve_start)/ \
                #                        (rmax - curve_start))**2 \
                #                        *self.consts[1]*np.sin(phi/self.phi_period*2*pi*self.consts[4])
                uz      =   z_set[index]
                
            elif self.opt[2] == 2:
                uz     =   self.consts[0]/2*r**2
            
            elif self.opt[2] == 3:
                uz     =   self.hangle*phi  +   self.consts[0]*(r - rmin)  
            
            elif self.opt[2] == 4:
                uz     =   self.consts[0]   -   np.sqrt(self.consts[0]**2 - r**2) 
            
            elif self.opt[2] == 5:
                uz      =   self.hangle*phi +   \
                            (r - rmin + self.consts[0])/(rmax - rmin) \
                            *self.consts[1]*np.sin(phi/self.phi_period*2*pi)
            
            elif self.opt[2] == 6:
                phase   =   0 #-pi/2 
                uz      =   self.hangle*phi  +   heaviside(r, self.consts[2])*((r - self.consts[2])/ \
                                        (rmax - self.consts[2]))**2 \
                                        *self.consts[1]*np.cos(phi/self.phi_period*2*pi + phase)
                                        
            
            else:
                print 'mita shiivaddia!'    
            
            umat_b[index][0]    =   ur
            umat_b[index][1]    =   uphi
            umat_b[index][2]    =   uz
            
        
        #self.ext_umat           =   make_periodic(umat_b, self.sym_op) 
        self.ext_umat           =   umat_b 
        self.phys_umat          =   make_periodic(np.delete(np.delete(self.ext_umat,  0, 0), -1, 0), 'umat', sym_op = self.sym_op)
        self.calc_umat          =   np.delete(np.delete(self.phys_umat,      -1, 0), -1, 1)