Beispiel #1
0
    def f(z0):
        z0 = np.array([z0])
        Nz0 = -np.array([0.03])
        #x0=-np.array([0.13])
        x0 = -np.array([0.20])

        r = np.array([z0, x0])
        X = p.X(r)
        Y = mf.Yabs(r)
        Nx0 = coldNx_Xm(X, Y, Nz0)
        data = X, Y, p.gamma(Te), Nz0

        Nx0 = fsolve(hot_disp_rel_wrapp, Nx0, args=data)

        N = np.array([Nz0, Nx0])
        nz, nx = ri.nz(r, N), ri.nx(r, N)

        init_cond = np.array([z0, x0, Nz0, Nx0])

        soln = hot.get_ray(init_cond, ncycle)
        #make gamma in the config!
        soln = {
            "init_cond": init_cond,
            "soln": soln,
            "ncycle": ncycle,
            "gamma": p.gamma(Te)
        }
        #make file exist check
        np.save(
            os.path.abspath("results/mirror/simple/gamma" + str(Te) +
                            "/soln_" + str(z0[0])), soln)
        return soln
Beispiel #2
0
    def f(q, t):
        z, x, Nz, Nx = q.reshape(4, Num)
        # all the variables are in global CS
        N = np.array([Nz, Nx])
        r = np.array([z, x])
        X = p.X(r)
        Y = mf.Yabs(r)

        dnz_dN = ri.dnz_dN(r, N)
        dnx_dN = ri.dnx_dN(r, N)
        dnz_dr = ri.dnz_dr(r, N)
        dnx_dr = ri.dnx_dr(r, N)
        dX_dr = p.dX_dr(r)
        dY_dr = mf.dY_dr(r)

        nz, nx = ri.nz(r, N), ri.nx(r, N)

        n = np.array([nz, nx])

        vg = -np.real(
            dD_dN(X, Y, nz, nx, dnz_dN, dnx_dN, m) / dD_dw(X, Y, nz, nx, m))

        a = np.real(
            dD_dr(X, Y, nz, nx, dnz_dr, dnx_dr, dX_dr, dY_dr, m) /
            dD_dw(X, Y, nz, nx, m))
        arr = np.array([vg, a])

        print(cold_disp_rel(X, Y, nz, nx, m), vg[0], vg[1])

        return arr.reshape(4 * Num)
Beispiel #3
0
    def f(z0):
        z0 = np.array([z0])
        x0 = np.array([0.01])
        r = np.array([z0, x0])
        X = p.X(r)
        Y = mf.Yabs(r)
        Nz0 = np.sqrt(Y / (1 + Y)) - 0.001
        print "Nz_opt", Nz0
        Nx0 = coldNx_Om(X, Y, Nz0)
        data = X, Y, p.gamma(10), Nz0
        Nx0 = fsolve(hot_disp_rel_wrapp, Nx0, args=data)
        print Nx0
        N = np.array([Nz0, Nx0])
        nz, nx = ri.nz(r, N), ri.nx(r, N)

        init_cond = np.array([z0, x0, Nz0, Nx0])
        print init_cond
        soln = hot.get_ray(init_cond, ncycle)
        #make gamma in the config!
        soln = {
            "init_cond": init_cond,
            "soln": soln,
            "ncycle": ncycle,
            "gamma": p.gamma(10)
        }
        #make file exist check

        #np.save(os.path.abspath("results/mirror/simple/Obeam/plasma_bvp/gamma10/soln_"+str(z0[0])),soln)

        return soln
Beispiel #4
0
    def f(Y):
        params.Y = Y
        X = p.X(r)
        Nz0 = np.array([np.sqrt(Y / (1 + Y))])

        Nx0 = -coldNx_Om(
            X, Y,
            Nz0)  #Om should be called "+" mode. we actually above the O-cutoff
        data = X, Y, p.gamma(Te), Nz0

        Nx0 = fsolve(hot_disp_rel_wrapp, Nx0, args=data)

        N = np.array([Nz0, Nx0])
        nz, nx = ri.nz(r, N), ri.nx(r, N)

        init_cond = np.array([z0, x0, Nz0, Nx0])

        print mf.Yabs(np.array([z0, x0])), init_cond
        soln = hot.get_ray(init_cond, ncycle)

        soln = {
            "init_cond": init_cond,
            "soln": soln,
            "Y": params.Y,
            "ncycle": ncycle
        }
Beispiel #5
0
    def f(delta_Nz0):

        z0 = np.array([0])
        x0 = np.array([1.05])

        r = np.array([z0, x0])
        X = p.X(r)
        Y = mf.Yabs(r)
        Nz0 = np.sqrt(Y / (1 + Y)) + delta_Nz0
        print "Nz_opt", X, Y
        Nx0 = coldNx_Om(X, Y, Nz0)

        data = X, Y, p.gamma(10), Nz0
        Nx0 = fsolve(hot_disp_rel_wrapp, Nx0, args=data)
        print Nx0
        N = np.array([Nz0, Nx0])
        nz, nx = ri.nz(r, N), ri.nx(r, N)

        init_cond = np.array([z0, x0, Nz0, Nx0])
        print init_cond
        soln = hot.get_ray(init_cond, ncycle)
        #make gamma in the config!
        print(init_cond)
        soln = {
            "init_cond": init_cond,
            "soln": soln,
            "ncycle": ncycle,
            "gamma": p.gamma(10)
        }
        #make file exist check

        return soln
Beispiel #6
0
    def f(q, t):
        z, x, Nz, Nx = q.reshape(4, Num)
        # all the variables are in global CS
        r = np.array([z, x])
        X = p.X(r)
        Y = mf.Yabs(r)
        gamma = p.gamma(Te)

        N = np.array([Nz, Nx])

        dnz_dN = ri.dnz_dN(r, N)
        dnx_dN = ri.dnx_dN(r, N)
        dnz_dr = ri.dnz_dr(r, N)
        dnx_dr = ri.dnx_dr(r, N)
        dX_dr = p.dX_dr(r)
        dY_dr = mf.dY_dr(r)
        dgamma_dr = p.dgamma_dr(r)
        nz, nx = ri.nz(r, N), ri.nx(r, N)

        n = np.array([nz, nx])

        if nx < 1:
            vg = -dD_dN(X, Y, gamma, nz, nx, dnz_dN, dnx_dN) / dD_dw(
                X, Y, gamma, nz, nx)

            a = dD_dr(X, Y, gamma, nz, nx, dnz_dr, dnx_dr, dX_dr, dY_dr,
                      dgamma_dr) / dD_dw(X, Y, gamma, nz, nx)
            if conf.verbose == True:
                print('disp rel cold:{}, disp rel:{},x:{} '.format(
                    cold_disp_rel(X, Y, nz, nx, "Xm"),
                    disp_rel(X, Y, gamma, nz, nx), x))
            #if disp_rel(X,Y,gamma,nz,nx)>0:
#break
        else:
            vg = -np.real(
                ebw.dD_dN(X, Y, gamma, nz, nx, dnz_dN, dnx_dN) /
                ebw.dD_dw(X, Y, gamma, nz, nx))

            if vg[0] > 1 or vg[1] > 1:
                print("vg", vg[0], vg[1])

            if conf.verbose == True:
                print(
                    "EBW", 'x:{},X:{},dispRel:{},nx:{},nz:{},'.format(
                        x, X, disp_rel_ebw(X, Y, gamma, nz, nx), nx, nz))

#if  np.abs(disp_rel_ebw(X,Y,gamma,nz,nx))>1e-4:
#break
            a = ebw.dD_dr(X, Y, gamma, nz, nx, dnz_dr, dnx_dr, dX_dr, dY_dr,
                          dgamma_dr) / ebw.dD_dw(X, Y, gamma, nz, nx)

        arr = np.array([vg, a])
        arr = np.real(np.real(arr.astype(np.complex64)))

        return arr.reshape(4 * Num)
Beispiel #7
0
    def f(q, t):
        z, x, Nz, Nx = q.reshape(4, Num)
        # all the variables are in global CS
        r = np.array([z, x])
        N = np.array([Nz, Nx])
        X = p.X(r)
        Y = mf.Yabs(r)
        gamma = p.gamma(10)
        """
        if localNx<1:
            vg = -np.real( dD_dN( X,Y,gamma,localNz,localNx,dNz_dN,dNx_dN  ) / dD_dw( X,Y,gamma,localNz,localNx  ) )

            a = np.real( dD_dr(X,Y,gamma,localNz,localNx,dNz_dr,dNx_dr,dX_dr,dY_dr,dgamma_dr) / dD_dw( X,Y,gamma,localNz,localNx  ) )
            A,B,C=get_ABC(X,Y,gamma,localNz,localNx)
            #print A*localNx**4
            arr = np.array([vg,a])
	"""

        dnz_dN = ri.dnz_dN(r, N)
        dnx_dN = ri.dnx_dN(r, N)
        dnz_dr = ri.dnz_dr(r, N)
        dnx_dr = ri.dnx_dr(r, N)
        dX_dr = p.dX_dr(r)
        dY_dr = mf.dY_dr(r)
        dgamma_dr = p.dgamma_dr(r)
        nz, nx = ri.nz(r, N), ri.nx(r, N)

        n = np.array([nz, nx])

        if nx < 1:
            vg = -np.real(dD_dN(X, Y, gamma, nz, nx, dnz_dN, dnx_dN))

            a = np.real(
                dD_dr(X, Y, gamma, nz, nx, dnz_dr, dnx_dr, dX_dr, dY_dr,
                      dgamma_dr))
            arr = np.array([vg, a])
            if conf.verbose == True:
                print "dr", disp_rel(X, Y, gamma, nz, nx), x
        else:
            vg = -np.real(ebw.dD_dN(X, Y, gamma, nz, nx, dnz_dN, dnx_dN))

            if vg[0] > 1 or vg[1] > 1:
                print "vg", vg[0], vg[1]

            if conf.verbose == True:
                print "EBW", x, X, disp_rel_ebw(X, Y, gamma, nz, nx), nx, nz

            a = np.real(
                ebw.dD_dr(X, Y, gamma, nz, nx, dnz_dr, dnx_dr, dX_dr, dY_dr,
                          dgamma_dr))
            arr = np.array([vg, a])
        return arr.reshape(4)
Beispiel #8
0
    def f(Y):
        params.Y = Y
        Nz0_opt = np.array([np.sqrt(Y / (1 + Y))])
        allSolns = []
        for Nz0 in np.linspace(Nz0_opt + 0.001, Nz0_opt + 0.001, 1):
            Nz0 = np.array([Nz0])
            #TODO: use the cold dispersion relation to find which refractive index to use, becasue I want to do the angular scan. We need to choose the proper branch
            if (Nz0 < Nz0_opt):
                #get the starting point of a ray
                x0 = np.array([brentq(cold_C_wrapp, 1.001, 40, args=(Y, Nz0))
                               ]) + 0.001
                print "x0", x0
            else:
                x0 = np.array([1.001])  #more or less arbitrary
            z0 = np.array([0])
            r = np.array([z0, x0])
            X = p.X(r)
            print r, X

            Nx0 = -coldNx_Om(X, Y, Nz0)
            print Nx0
            data = X, Y, p.gamma(10), Nz0

            Nx0 = fsolve(hot_disp_rel_wrapp, Nx0, args=data)

            N = np.array([Nz0, Nx0])
            nz, nx = ri.nz(r, N), ri.nx(r, N)

            init_cond = np.array([z0, x0, Nz0, Nx0])

            print mf.Yabs(np.array([z0, x0])), init_cond
            soln = hot.get_ray(init_cond, ncycle)

            soln = {
                "init_cond": init_cond,
                "soln": soln,
                "Y": params.Y,
                "ncycle": ncycle
            }
            allSolns.append(soln)
            #Idea: investigate vg_perp/v_parallel of as function of Nz in the slabb model. We willl find the that the dependy is weak! (hopefully) -> EBW is not affected much the injection angle
        #np.save(os.path.abspath("results/slab/Obeam/harm1/gamma10/NzScan/soln_"+str(params.Y)),allSolns)

        return np.array(allSolns)
Beispiel #9
0
def f(r,N):
	
	X=p.X(r)
	Y=mf.Yabs(r)
	gamma = p.gamma(10)


	"""
	if localNx<1:
	    vg = -np.real( dD_dN( X,Y,gamma,localNz,localNx,dNz_dN,dNx_dN  ) / dD_dw( X,Y,gamma,localNz,localNx  ) )

	    a = np.real( dD_dr(X,Y,gamma,localNz,localNx,dNz_dr,dNx_dr,dX_dr,dY_dr,dgamma_dr) / dD_dw( X,Y,gamma,localNz,localNx  ) )
	    A,B,C=get_ABC(X,Y,gamma,localNz,localNx)
	    #print A*localNx**4
	    arr = np.array([vg,a])
	"""

	dnz_dN=ri.dnz_dN(r,N)
	dnx_dN=ri.dnx_dN(r,N)
	dnz_dr=ri.dnz_dr(r,N)
	dnx_dr=ri.dnx_dr(r,N)
	dX_dr = p.dX_dr(r)
	dY_dr = mf.dY_dr(r)
	dgamma_dr = p.dgamma_dr(r)
	nz,nx=ri.nz(r,N),ri.nx(r,N)
	n = np.array([nz,nx])


	if nx<1:

	    a = np.real( dD_dr(X,Y,gamma,nz,nx,dnz_dr,dnx_dr,dX_dr,dY_dr,dgamma_dr) / dD_dw( X,Y,gamma,nz,nx  ) )
	else:


	  
	    a = np.real( ebw.dD_dr(X,Y,gamma,nz,nx,dnz_dr,dnx_dr,dX_dr,dY_dr,dgamma_dr) / ebw.dD_dw( X,Y,gamma,nz,nx  ) )
	return a
Beispiel #10
0
ncycle =params.ncycle
#type of simulation


####
#f for pool

Te = params.Te #set the the Te

z0 = np.array([0.001])
x0=np.array([-0.77])


r = np.array([z0,x0])
X = p.X(r)
Y = mf.Yabs(r)

data = X,Y,p.gamma(500),Nz0

Nx0 = coldNx_Xm(X,Y,Nz0)
Nx0=fsolve(hot_disp_rel_wrapp,Nx0,args=data)
print(Nx0)
N = np.array([Nz0,Nx0])
nz,nx=ri.nz(r,N),ri.nx(r,N)

init_cond=np.array([z0,x0,Nz0,Nx0])  
soln=hot.get_ray(init_cond,ncycle)	
#make gamma in the config!
print(init_cond)
soln = {"init_cond":init_cond,"soln":soln,"ncycle":ncycle,"gamma":p.gamma(500)}
Beispiel #11
0
def plot(soln):
    Num = 500

    Yz = np.zeros((500, 500))
    Yx = np.zeros((500, 500))
    X = np.zeros((500, 500))

    i = 0
    z = np.linspace(-2, 2, Num)
    r = np.linspace(-1, 1, Num)
    for x in r:
        x = x * np.ones(500)
        Yz[i, :] = mf.Yz((z, x))
        Yx[i, :] = mf.Yx((z, x))
        X[i, :] = p.X((z, x))
        i += 1

    fig, (ax1) = plt.subplots(1, 1)

    fig.set_size_inches(5.4, 5.5, forward=True)
    #fig.set_figwidth(5.4,forward=True)
    Y = np.sqrt(Yz**2 + Yx**2)

    im = ax1.imshow(X, cmap=plt.cm.Blues, extent=[-2, 2, -1, 1])

    cuhr = ax1.contour(z,
                       r,
                       np.sqrt(Y**2 + X),
                       np.array([1]),
                       linewidths=2,
                       colors="red")
    ax1.clabel(cuhr, inline=True, fmt="UHR", fontsize=12)

    cO = ax1.contour(z, r, X, np.array([1]), linewidths=2, colors="green")
    ax1.clabel(cO, inline=True, fmt="O-cutoff", fontsize=12)

    cR = ax1.contour(z,
                     r,
                     np.sqrt(0.25 * Y**2 + X) + 0.5 * Y,
                     np.array([1]),
                     linewidths=2,
                     colors="black")
    ax1.clabel(cR, inline=True, fmt='R', fontsize=12)

    cL = ax1.contour(z,
                     r,
                     np.sqrt(0.25 * Y**2 + X) - 0.5 * Y,
                     np.array([1]),
                     linewidths=2,
                     colors="black")
    ax1.clabel(cL, inline=True, fmt='L-cutoff', fontsize=12)

    ax1.streamplot(z, r, Yz, Yx, minlength=0.9, density=0.4, color="blue")

    ax1.set_xlabel("z || B_0", fontsize=12)
    ax1.set_ylabel("x", fontsize=12)
    ax1.set_aspect('equal')
    if len(soln) > 0:
        plt.plot(soln[:, 0], soln[:, 1])

    return X