Пример #1
0
def gridgen_coarse_UV_fine(q,
                           k_x,
                           Flag,
                           Nx,
                           Nt,
                           size_x,
                           ix,
                           ix_fine,
                           size_t,
                           it,
                           it_fine,
                           M_x_0,
                           boundary_function_map,
                           mykind='linear'):
    [U_x_coarse, V_x_coarse, d_coarse] = q2UV(q, size_x, size_t, k_x, Flag)
    [U_x_coarse, V_x_coarse] = UV_init_boundary(U_x_coarse, V_x_coarse,
                                                boundary_function_map)
    # Construction of fine grid from coarse grid bases
    U_xx = np.zeros((Nx, k_x))
    V_xx = np.zeros((k_x, Nt))
    for kcount in range(k_x):
        U_x_fun = interp1(ix, U_x_coarse[:, kcount], kind=mykind)
        #cubic, linear, quadratic
        U_xx[:, kcount] = U_x_fun(ix_fine)

        V_x_fun = interp1(it, V_x_coarse[kcount, :], kind=mykind)
        V_xx[kcount, :] = V_x_fun(it_fine)
    # Construction of fine grid deviation from Eulerian grid
    dx = np.dot(U_xx, V_xx)
    # Construction of fine grid
    M_x_ALE = dx + M_x_0

    return M_x_ALE, dx, U_xx, V_xx
Пример #2
0
    def _harmonic_number_approx(self):

        if self._harmonic is None:
            x = [1.001, 1.00125, 1.0025, 1.005, 1.01, 1.025, 1.05, 1.075, 1.1,
                 1.2, 1.3, 1.4, 1.5, 1.52753, 1.6, 1.7, 1.8, 1.9, 1.95, 2.0]
            y = [1000.58, 800.577, 400.577, 200.578, 100.578, 40.579, 20.5808,
                 13.916, 10.5844, 5.59158, 3.93195, 3.10555, 2.61238, 2.50988,
                 2.28577, 2.05429, 1.88223, 1.74975, 1.69443, 1.6449340668]

            f = interp1(x, y)

            self._harmonic = f(self.exponent)

        return self._harmonic
Пример #3
0
def interp1d_loop(M_x_in, X_in, M_x_Out, Nx, Nt, bc, mykind='linear'):
    X_out = np.zeros((Nx, Nt))
    for tcount in range(Nt):
        state_fun = interp1(M_x_in[:, tcount],
                            X_in[:, tcount],
                            kind=mykind,
                            fill_value=(bc, bc),
                            bounds_error=False)
        X_out[:, tcount] = state_fun(M_x_Out[:, tcount])

    #    state_fun = interp2(M_x_0, M_t_0, X_E_FOM,
    #                        kind = 'linear', fill_value=(bc,bc), bounds_error=False );
    #    M_w_ALE = state_fun( M_x_ALE, M_t_0)
    return X_out
Пример #4
0
    def _harmonic_number_approx(self):

        if self._harmonic is None:
            x = [1.001, 1.00125, 1.0025, 1.005, 1.01, 1.025, 1.05, 1.075, 1.1,
                 1.2, 1.3, 1.4, 1.5, 1.52753, 1.6, 1.7, 1.8, 1.9, 1.95, 2.0]
            y = [1000.58, 800.577, 400.577, 200.578, 100.578, 40.579, 20.5808,
                 13.916, 10.5844, 5.59158, 3.93195, 3.10555, 2.61238, 2.50988,
                 2.28577, 2.05429, 1.88223, 1.74975, 1.69443, 1.6449340668]

            f = interp1(x, y)

            self._harmonic = f(self.exponent)

        return self._harmonic
Пример #5
0
def XYLatLong(Origin,Points):
    
    phi=np.linspace(np.deg2rad(20),np.deg2rad(60),100);
    yphi=(111132-559*np.cos(2*phi)+1.175*np.cos(4*phi))*(np.rad2deg(phi)-Origin[1]);

    yInterp=interp1(yphi,phi);
    Lat=yInterp(Points[:,1]);
    a=6378137;
    b=6356752.3142;
    e2=(a**2-b**2)/(a**2);

    P=np.pi*a*np.cos(Lat)/(180*np.sqrt(1-e2*(np.sin(Lat)**2)));
    Lat=np.rad2deg(Lat);
    Long=Points[:,0]/P+Origin[0];
    
    LongLat=np.zeros([len(Lat),2]);
    LongLat[:,0]=Long;
    LongLat[:,1]=Lat;
    
    return LongLat;
Пример #6
0
def PixToLatLong(RParallel,xMeet,x49):
    MerLongs=np.genfromtxt('MeridianLongs.csv',skip_header=1,usecols=1,delimiter=',');
    PixTokm=PixelScale();
    
    MerLong1=MerLongs[0];
    MerLong2=MerLongs[-1];
    
    PixtoLong=(MerLong2-MerLong1)/(x49[1]-x49[0]);
    Pixb=MerLong2-PixtoLong*x49[1];
    
    Rkm=RParallel*PixTokm;
    phi=np.deg2rad(np.linspace(0,90,1000));
    yphi=-((111132-559*np.cos(2*phi)+1.175*np.cos(4*phi)))*1e-3*(np.rad2deg(phi)-49);
    yInterp=interp1(yphi,np.rad2deg(phi));
    Lat=yInterp(Rkm);
    
    Long=PixtoLong*xMeet+Pixb;
    LongLat=np.zeros([len(Long),2]);

    LongLat[:,0]=Long;
    LongLat[:,1]=Lat;
    
    return LongLat;
Пример #7
0
    sf.coil[name] = {'r':rcs_space[i],'z':zcs_space[i],'dr':1,
                     'dz':abs(np.diff(zcs_space))[0],'I':1}
'''    
   
rb = RB(conf,sf,Np=150)
eq = EQ([4,15.5],[-12,6.5],5e4,sf)
eq.get_plasma_coil()
#sf.plasma_coils(N=11,dL=0.25)
eq.coils(delta=0.25)  # multi-filiment coils 

r,z = sf.get_boundary(alpha=0.99)
L = sf.length(r,z)
Lc = np.linspace(0,1,1)[:-1]

fix = {}
fix['r'],fix['z'] = interp1(L,r)(Lc),interp1(L,z)(Lc)
fix['value'] = eq.psi_coil(fix['r'],fix['z'])
fix['BC'] = np.array(['psi']*len(fix['r'])) 
'''
r,z = sf.get_boundary(alpha=0.45)
L = sf.length(r,z)
Lc = np.linspace(0,1,31)[:-1]
fix['r'] = np.append(fix['r'],interp1(L,r)(Lc))
fix['z'] = np.append(fix['z'],interp1(L,z)(Lc))
fix['value'] = np.append(fix['value'],eq.psi_coil(interp1(L,r)(Lc),
                                               interp1(L,z)(Lc)))
fix['BC'] = np.append(fix['BC'],np.array(['psi']*len(Lc)))
'''


Пример #8
0
for shift, r in zip(rshift, rspace):
    R, Z = elipsoid(theta, ro + shift, zo, ro / r, k, delta)
    pl.plot(R, Z, 'k-')

Rc, Zc, nc = np.array([]), np.array([]), np.array([])
for shift, r in zip(rshift[:-1], rspace[:-1]):
    if r == 0.0:
        R, Z = ro + shift, zo
        Rc, Zc = np.append(Rc, R), np.append(Rc, Z)
        nc = np.append(nc, 1)
    else:
        R, Z = elipsoid(theta, ro + shift, zo, ro / r, k, delta)
        L = np.cumsum(np.sqrt(np.gradient(R)**2 + np.gradient(Z)**2))
        Linterp = np.linspace(L[0], L[-1], np.round(L[-1] / dcoil))
        Rc = np.append(Rc, interp1(L, R)(Linterp))
        Zc = np.append(Zc, interp1(L, Z)(Linterp))
        nc = np.append(nc, len(interp1(L, R)(Linterp)))

Ci = (1 - np.arange(N - 1) /
      (N - 1)) * nc  # I = Io*sum(Ci) = Io*sum(nci(1-xi/(N-1)))
Io = I / np.sum(Ci)
Ic = np.zeros(np.shape(Rc))
ncOld = 0
for i in range(len(nc)):
    ncSum = sum(nc[0:i + 1])
    Ic[ncOld:ncSum] = Io * (1 - i / (N - 1))
    ncOld = ncSum

print(sum(Ic))
Пример #9
0
        if L3D[-1] > 0:
            Dsol = np.append(Dsol, sf.Dsol[i])
            connect = np.append(connect, L3D[-1])

    imax = np.argmax(connect)
    pl.plot(1e3 * Dsol[1:], connect[1:], color=color)
    config_add = config.replace('m', '-')
    config_add = config_add.replace('p', '+')
    text.add(config_add + ' sm')

    if config in ['SN', 'SFm', 'SFp']:
        file = 'Louter_vs_rus_2015'
        with open(path + file + '_' + config + '.dat', 'rb') as f:
            seg = pk.load(f)
        Dsol_hr, connect_hr = seg[:, 0], seg[:, 1]
        connect = interp1(Dsol_hr, connect_hr)(Dsol[1:])
        #pl.plot(1e3*Dsol_hr,connect_hr,'--',color=color)
        pl.plot(1e3 * Dsol[1:], connect, '--', color=color)
        text.add(config_add + ' hr')

        file = 'CREATE'
        with open(path + file + '_' + config + '.dat',
                  'rb') as f:  # load segment geometory
            seg = pk.load(f)
        Dsol_vp, connect_vp = seg[:, 0], seg[:, 1]
        b = np.log10(10e3 / 10) / (10e3 - 10)
        a = 10e3 / 10**(b * 10e3)
        connect_vp = a * 10**(b * connect_vp)
        connect = interp1(Dsol_vp, connect_vp)(Dsol[1:])
        pl.plot(1e3 * Dsol[1:], connect, ':', color=color)
        text.add(config_add + ' vp')
Пример #10
0
    def plasma_coils(self,I,N):
        import numpy as np
        from scipy.interpolate import interp1d as interp1
        import scipy.optimize as op
        from itertools import count
        import pylab as pl
        index = count(0)
        delta = self.dr/N
    
        grid = 'elip'  # 'sq || rad
        
        if grid is 'elip':  # elipsoid
            zo=0
            ro=9.08
            A=3.89
            k=1.69
            tau=0.44
            f = 0.6  # edge current fraction Iedge = fIo
            self.xo = [zo,ro,A,k,tau]
            self.theta_elip = np.linspace(-np.pi,np.pi,100)
            #constraint = {'type':'ineq','fun':self.dot_r}
            par = op.minimize(self.min_r,self.xo,
                              options={'disp':True,'maxiter':500},
                              method='SLSQP',tol=1e-2)
            self.xo = par.x
            zo=self.xo[0]
            ro=self.xo[1]
            A=self.xo[2]
            k=self.xo[3]
            tau=self.xo[4]
            dcoil = 1.5*ro/(N*A)
            rshift = np.linspace(0.45,0,N)
            rmax = ro/A
            rspace = np.linspace(0,rmax,N)

            rp,zp,nc = np.array([]),np.array([]),np.array([])
            for shift,r in zip(rshift,rspace):
                if r  == 0.0:
                    R,Z = ro+shift,zo
                    rp,zp = np.append(rp,R),np.append(zp,Z)
                    nc = np.append(nc,1)
                else:
                    R,Z = self.elipsoid(zo,ro+shift,ro/r,k,tau)
                    L = np.cumsum(np.sqrt(np.gradient(R)**2+np.gradient(Z)**2))
                    Linterp = np.linspace(L[0],L[-1],np.round(L[-1]/dcoil))
                    rp = np.append(rp,interp1(L,R)(Linterp))
                    zp = np.append(zp,interp1(L,Z)(Linterp))
                    nc = np.append(nc,len(interp1(L,R)(Linterp)))
                    pl.plot(R,Z,'b-')

            Ci = (1-(1-f)*(np.arange(N)/(N-1))**2)*nc  # I = Io*sum(Ci) = Io*sum(nci(1-xi/(N-1)))
            Io = I/np.sum(Ci)
            Ip = np.zeros(np.shape(rp))
            ncOld = 0
            for i in range(len(nc)):
                ncSum = sum(nc[0:i+1])
                Ip[ncOld:ncSum] = Io*(1-(1-f)*(i/(N-1))**2)
                ncOld = ncSum

            delta = dcoil
            print(sum(Ip))
            
        elif grid == 'sq':
            nr, nz = (int(self.dr/delta), int(self.dz/delta))
            r,dr = np.linspace(self.rlim[0]-self.dr/2,
                               self.rlim[1]+self.dr/2, nr+1, retstep='true')
            z,dz = np.linspace(self.zlim[0]-self.dz/2,
                               self.zlim[1]+self.dz/2, nz+1, retstep='true')
            rm, zm = np.meshgrid(r, z)
            
            rp,zp = [],[]
            
            for i in range(nz):
                for j in range(nr):
                    if self.check([rm[i,j],zm[i,j]]):
                        rp.append(rm[i,j])
                        zp.append(zm[i,j])
        elif grid == 'rad':
            nr = np.int(np.max(self.radius)/delta)
            r_line = np.linspace(0,np.max(self.radius),nr)
    
            for rL in r_line:
                if rL == 0:
                    rm = np.array([self.rc])
                    zm = np.array([self.zc])
                    radius = np.zeros(1)
                    theta = np.zeros(1)
                else:
                    n_theta = np.int(2*np.pi*rL/delta)
                    thetaL = np.linspace(0,2*np.pi,n_theta,endpoint=False)
                    rm = np.append(rm,self.rc+rL*np.cos(thetaL))
                    zm = np.append(zm,self.zc+rL*np.sin(thetaL))
                    theta = np.append(theta, thetaL)
                    radius = np.append(radius, rL*np.ones(n_theta))
                  
            rp,zp,theta_p,radius_p = [],[],[],[]
            for r,z,rad,th in zip(rm,zm,radius,theta):
                if self.check_plasma([r,z]):
                    rp.append(r)
                    zp.append(z)
                    theta_p.append(th)
                    radius_p.append(rad)
                    
        plasma_name = []
        print('lenrp',len(rp))
        for r,z in zip(rp,zp):
            plasma_name.append('plasma-'+str(next(index)))
            self.coil[plasma_name[-1]] = {}
            self.coil[plasma_name[-1]]['r'] = r
            self.coil[plasma_name[-1]]['z'] = z
            self.coil[plasma_name[-1]]['rc'] = delta 
            
        if grid is 'elip':
            for name,ip in zip(plasma_name,Ip):
                self.coil[name]['I'] = ip
        else:
            self.current_profile(I,rp,radius_p,theta_p,plasma_name)
Пример #11
0
pl.figure(figsize=(9,12))

pl.axis('equal')
pl.xlim([5,12]),pl.ylim([-6,6])

conf = Config(config,inside=False)
sf = SF(conf,sample=1)

sf.contour()

N = 100
sf.get_boundary(alpha=1)
rb,zb = sf.eq['rbdry'],sf.eq['zbdry']
L = sf.length(rb,zb)
Lpoints = np.linspace(1/(2*(N-1)),1-1/(2*(N-1)),N)
R = interp1(L,rb)(Lpoints)
Z = interp1(L,zb)(Lpoints)

   
with open('../Data/SN_ref_bdry.txt','w') as f:
    f.write('Npoints = {:1.0f}\n\n'.format(N))
    f.write('R[m]\t\tZ[m]\n')
    for i in range(N):
        f.write('{:1.6f}\t{:1.6f}\n'.format(R[i],Z[i]))

pl.plot(rb,zb,'r')
pl.plot(R,Z,'bo')
pl.axis('off')
pl.savefig('../Figs/SN_bdry_image.png',dpi=200)

nf = 100