def diffrot(n_,n,l_,l,r,omega_ref,s=np.array([1,3,5])):
    wig_calc = np.vectorize(fn.wig)
    
    r_full = np.loadtxt('r.dat')
    r_start, r_end = np.argmin(np.abs(r_full-r[0])),np.argmin(np.abs(r_full-r[-1]))+1
    rho = np.loadtxt('rho.dat')[r_start:r_end]
    
    m = np.arange(-min(l,l_),min(l,l_)+1,1)    #-l<=m<=l
    m_ = m  #-l_<=m<=l_    
    
    mm,ss = np.meshgrid(m,s,indexing='ij')
    
    kern = gkerns.Hkernels(n_,l_,m,n,l,m,s,r)
    T_kern = kern.Tkern(s)
    
    w = np.loadtxt('w.dat')[:,r_start:r_end]

    C = np.zeros(mm.shape)
    
    tstamp()

    C = scipy.integrate.trapz((w*T_kern)*(rho*(r**2))[np.newaxis,:],x=r,axis=1)
    C = C[np.newaxis,:] * (2*((-1)**np.abs(mm))*omega_ref*wig_calc(l_,ss,l,-mm,0,mm))
    C *= np.sqrt((2*l+1) * (2*l_+1) * (2*ss+1)/(4.*np.pi))
    C = np.sum(C, axis = 1)

    return C
def lorentz_diagonal(n_,n,l_,l,r,field_type = 'dipolar',smoothen = False): 
    m = np.arange(-min(l,l_),min(l,l_)+1,1)    #-l<=m<=l
    s = np.array([0,1,2])
    s0 = 1
    r_new = r

    #transition radii for mixed field type
    R1 = 0.75
    R2 = 0.78

    if(smoothen == True):
        npts = 300      #should be less than the len(r) in r.dat
        r_new = np.linspace(np.amin(r),np.amax(r),npts)

    B_mu_r = fn.getB_comps(s0,r_new,R1,R2,field_type)[:,s0,:] #choosing t = 0 comp
    get_h = hcomps.getHcomps(s,m,m,s0,np.array([s0]),r_new,B_mu_r)
    tstamp()

    H_super = get_h.ret_hcomps_axis_symm()  #- sign due to i in B 

    tstamp('Computed H-components in')

    #distributing the components
    hmm = H_super[0,0]
    h0m = H_super[1,0]
    h00 = H_super[1,1]
    hpm = H_super[2,0]
    hp0 = H_super[2,1]
    hpp = H_super[2,2]

    kern = gkerns.Hkernels(n_,l_,m,n,l,m,s,r,True)
    Bmm,B0m,B00,Bpm,Bp0,Bpp = kern.ret_kerns_axis_symm(smoothen = smoothen)
    #sys.exit()

    #find integrand by summing all component
    Lambda_sr = hpp[np.newaxis,:,:]*Bpp + h00[np.newaxis,:,:]*B00 + hmm[np.newaxis,:,:]*Bmm \
            + 2*hpm[np.newaxis,:,:]*Bpm + 2*h0m[np.newaxis,:,:]*B0m + 2*hp0[np.newaxis,:,:]*Bp0

    #summing over s before carrying out radial integral
    Lambda_r = np.sum(Lambda_sr,axis=1)

    if(smoothen==True):
        r = r_new

    #radial integral
    Lambda = scipy.integrate.trapz(Lambda_r*(r**2)[np.newaxis,:],x=r,axis=1)
    
    return Lambda
def lorentz(n_,n,l_,l,r,beta =0., field_type = 'dipolar'):   
    m = np.arange(-l,l+1,1)    #-l<=m<=l
    m_ = np.arange(-l_,l_+1,1)  #-l_<=m<=l_    
    s = np.array([0,1,2])
    s0 = 1  
    t0 = np.arange(-s0,s0+1)                                       
    #transition radii for mixed field type
    R1 = r[0]
    R2 = r[-1]
    B_mu_t_r = fn.getB_comps(s0,r,R1,R2,field_type)

    get_h = hcomps.getHcomps(s,m_,m,s0,t0,r,B_mu_t_r, beta)

    tstamp()

    H_super = get_h.ret_hcomps()  #- sign due to i in B

    tstamp('Computed H-components in')

    #distributing the components
    hmm = H_super[0,0,:,:,:,:]
    h0m = H_super[1,0,:,:,:,:]
    h00 = H_super[1,1,:,:,:,:]
    hpm = H_super[2,0,:,:,:,:]
    hp0 = H_super[2,1,:,:,:,:]
    hpp = H_super[2,2,:,:,:,:]


    kern = gkerns.Hkernels(n_,l_,m_,n,l,m,s,r,False)
    Bmm,B0m,B00,Bpm,Bp0,Bpp = kern.ret_kerns()
    #sys.exit()

    #find integrand by summing all component
    Lambda_sr = hpp*Bpp + h00*B00 + hmm*Bmm \
            + 2*hpm*Bpm + 2*h0m*B0m + 2*hp0*Bp0

    #summing over s before carrying out radial integral
    Lambda_r = np.sum(Lambda_sr,axis=2)

    #radial integral
    Lambda = scipy.integrate.trapz(Lambda_r*(r**2)[np.newaxis,:],x=r,axis=2)

    return Lambda
omega_nl2 = omega_list[fn.find_nl(n2, l2)]
omega_nl3 = omega_list[fn.find_nl(n3, l3)]

m = np.array([0])
m_ = np.array([0])
s = np.array([2])

#condition about whether or not to scale by rho
multiplyrho = True
smoothen = True

# plot_fac = OM**2 * 1e12 * (4.*np.pi/3) * 1e-10 #unit = muHz G^(-2) V_sol^(-1)
plot_fac = OM**2 * 1e12 * 1e-10  #unit = muHz G^(-2)

#extracting rho in an unclean fashion
rho,__,__,__,__,__,__ = np.array(gkerns.Hkernels(n1,l1,m,n1,l1,m,s,r)\
                        .ret_kerns_axis_symm(smoothen,a_coeffkerns = True))

#Kernels for a-coefficients for Lorentz stress

# kern = gkerns.Hkernels(n1,l1,m,n1,l1,m,s,r)
__, Bmm1, B0m1,B001, Bpm1,_,_ = np.array(gkerns.Hkernels(n1,l1,m,n1,l1,m,s,r)\
                        .ret_kerns_axis_symm(smoothen,a_coeffkerns = True))*plot_fac/(-2*omega_nl1)
__, Bmm2, B0m2,B002, Bpm2,_,_ = np.array(gkerns.Hkernels(n2,l2,m,n2,l2,m,s,r).\
                        ret_kerns_axis_symm(smoothen,a_coeffkerns = True))*plot_fac/(-2*omega_nl2)
__, Bmm3, B0m3,B003, Bpm3,_,_ = np.array(gkerns.Hkernels(n3,l3,m,n3,l3,m,s,r).\
                        ret_kerns_axis_symm(smoothen,a_coeffkerns = True))*plot_fac/(-2*omega_nl3)

#############################################################################

#Purely lorentz stress kernels
    def ret_coupled_nn_ll_(self):
        #loading and chopping r grid
        r = np.loadtxt('r.dat')
        rpts = 700
        r = r[-rpts:]

        #variable set in stone
        mu = np.array([-1, 0, 1])
        nu = np.array([-1, 0, 1])

        #Choosing n,l and n_,l_
        n, l = self.n, self.l
        n_, l_ = self.n_, self.l_

        #mode for toroidal magnetic field
        l_b = 1
        m_b = 0

        r_cen = 0.998
        b_r = b_radial(r, r_cen)

        #Choosing s
        smin = 0
        #smax = 'max_s' for 0 <= s <= 2l+1
        #smax = False for s = s_arr (custom choice)
        #smax = <some integral value>
        smax = 0
        #custom made s array
        s = np.array([0, 1, 2, 3, 4])

        m = np.arange(-l, l + 1, 1)  # -l<=m<=l
        m_ = np.arange(-l_, l_ + 1, 1)  # -l_<=m<=l_

        #For the current case where l=l_,n=n_
        kern_eval = gkerns.Hkernels(l, l_, r, rpts)

        Bmm, B0m, B00, Bpm, Bpp, B0p = kern_eval.isol_multiplet(n, l, s)

        tstamp('kernel evaluated')

        #Fetching the H-components
        get_h = hcomps.getHcomps(s, m, l_b, m_b, r, b_r)

        tstamp()
        H_super = get_h.ret_hcomps()  #this is where its getting computed
        tstamp('Computed H-components in')

        #distributing the components
        hmm = H_super[:, :, 0, 0, :, :]
        h0m = H_super[:, :, 1, 0, :, :]
        h00 = H_super[:, :, 1, 1, :, :]
        hp0 = H_super[:, :, 2, 1, :, :]
        hpp = H_super[:, :, 2, 2, :, :]
        hpm = H_super[:, :, 2, 0, :, :]

        #find integrand by summing all component
        cp_mat_s = hpp*Bpp + h00*B00 + hmm*Bmm \
                + 2*hpm*Bpm + 2*h0m*B0m + 2*hp0*B0p

        #summing over s before carrying out radial integral
        cp_mat_befint = np.sum(cp_mat_s, axis=2)

        #radial integral
        cp_mat = scipy.integrate.trapz(cp_mat_befint, x=r, axis=2)

        plt.pcolormesh(cp_mat)
        plt.colorbar()
        plt.show('Block')

        return cp_mat
Example #6
0
nl_arr = nl_arr.astype(int)

Bmm_all = np.zeros((len(nl_arr), npts))
B0m_all = np.zeros((len(nl_arr), npts))
B00_all = np.zeros((len(nl_arr), npts))
Bpm_all = np.zeros((len(nl_arr), npts))

for i in range(len(nl_arr)):
    nl = nl_arr[i]
    n = nl[0]
    l = nl[1]
    print(n, l)

    if (np.abs(l0 - l) > s[0]): continue

    Bmm, B0m,B00, Bpm,_,_ = np.array(gkerns.Hkernels(n0,l0,m,n,l,m,s,r)\
                                .ret_kerns_axis_symm())*plot_fac

    Bmm_all[i, :] = Bmm
    B0m_all[i, :] = B0m
    B00_all[i, :] = B00
    Bpm_all[i, :] = Bpm

# np.savetxt('./kernels/Bmm_all.dat',Bmm_all)
# np.savetxt('./kernels/B0m_all.dat',B0m_all)
# np.savetxt('./kernels/B00_all.dat',B00_all)
# np.savetxt('./kernels/Bpm_all.dat',Bpm_all)

np.savetxt('./cross_kernels/Bmm_all_s50.dat', Bmm_all)
np.savetxt('./cross_kernels/B0m_all_s50.dat', B0m_all)
np.savetxt('./cross_kernels/B00_all_s50.dat', B00_all)
np.savetxt('./cross_kernels/Bpm_all_s50.dat', Bpm_all)
kernclock = timing.stopclock()
tstamp = kernclock.lap

r = np.loadtxt('r.dat')
r_start, r_end = 0.9, 0.98
start_ind, end_ind = [fn.nearest_index(r, pt) for pt in (r_start, r_end)]
#end_ind = start_ind + 700
r = r[start_ind:end_ind]

n,l = 1,60
n_,l_ = n,l
m = np.array([2])
m_ = np.array([2])
s = np.array([22])

kern = gkerns.Hkernels(n_,l_,m_,n,l,m,s,r,False)
Bmm, B0m,B00, Bpm,_,_ = kern.ret_kerns()
tstamp('kernel calculation time')
kern1 = gkerns_sep.Hkernels(n_,l_,m_,n,l,m,s,start_ind,end_ind)
Bmm1, B0m1,B001, Bpm1,_,_ = kern1.ret_kerns()
tstamp('kernel calculation time separate')

plt.subplot(221)
plt.plot(r,np.abs(Bpm-Bpm1)[0,0,0],'r--',label = '$\mathcal{B}^{+-}$')
plt.plot(r,Bpm[0,0,0],'r-',label = '$\mathcal{B}^{+-}$')
plt.grid(True)
plt.legend()

plt.subplot(222)
plt.plot(r,np.abs(Bmm-Bmm1)[0,0,0],'b--',label = '$\mathcal{B}^{--}$')
plt.plot(r,Bmm[0,0,0],'b-',label = '$\mathcal{B}^{--}$')
Example #8
0
end_ind = fn.nearest_index(r,1.)
r = r[start_ind:end_ind+1]
OM = np.loadtxt('OM.dat')

n1,l1 = 4,3
n2,l2 = 1,10
n3,l3 = 0,20

m = np.array([0])
m_ = np.array([0])
s = np.array([2])

plot_fac = OM**2 * 1e12 * (4.*np.pi/3) * 1e-10 #unit = muHz^2 G^(-2) V_sol^(-1)

#kern = gkerns.Hkernels(n1,l1,m,n1,l1,m,s,r)
Bmm1, B0m1,B001, Bpm1,_,_ = np.array(gkerns.Hkernels(n1,l1,m,n1,l1,m,s,r).ret_kerns_axis_symm())*plot_fac
Bmm2, B0m2,B002, Bpm2,_,_ = np.array(gkerns.Hkernels(n2,l2,m,n2,l2,m,s,r).ret_kerns_axis_symm())*plot_fac
Bmm3, B0m3,B003, Bpm3,_,_ = np.array(gkerns.Hkernels(n3,l3,m,n3,l3,m,s,r).ret_kerns_axis_symm())*plot_fac
tstamp('kernel calculation time')

npts = 1000
r_new = np.linspace(np.amin(r),np.amax(r),npts)
r = r_new

plt.subplot(221)
plt.plot(r,Bmm1[0,0], label = '('+str(n1)+','+str(l1)+')')
plt.plot(r,Bmm2[0,0], label = '('+str(n2)+','+str(l2)+')')
plt.plot(r,Bmm3[0,0], label = '('+str(n3)+','+str(l3)+')')
plt.xlabel('$r/R_{odot}$')
plt.legend()
plt.grid(True)
    nl_arr_temp = nl_list[nl_list[:, 0] == i]
    nl_arr = np.append(nl_arr, nl_arr_temp[nl_arr_temp[:, 1] > 2], axis=0)

nl_arr = nl_arr.astype(int)

Bmm_all = np.zeros((len(nl_arr), npts))
B0m_all = np.zeros((len(nl_arr), npts))
B00_all = np.zeros((len(nl_arr), npts))
Bpm_all = np.zeros((len(nl_arr), npts))

#some dummy n,l to get rho. I know its unclean.
n0 = nl_arr[0, 0]
l0 = nl_arr[0, 1]
omega_nl0 = omega_list[fn.find_nl(n0, l0)]

rho,__,__,__,__,_,_ = np.array(gkerns.Hkernels(n0,l0,m,n0,l0,m,s,r)\
                        .ret_kerns_axis_symm(a_coeffkerns = True))

for i in range(len(nl_arr)):
    nl = nl_arr[i]
    n = nl[0]
    l = nl[1]

    omega_nl = omega_list[fn.find_nl(n, l)]

    print(s, n, l)
    __, Bmm, B0m,B00, Bpm,_,_ = np.array(gkerns.Hkernels(n,l,m,n,l,m,s,r)\
                        .ret_kerns_axis_symm(a_coeffkerns = True))*plot_fac/(-2*omega_nl)

    Bmm_all[i, :] = Bmm
    B0m_all[i, :] = B0m
    B00_all[i, :] = B00