def drdpsiN_of_r(a,simul): print "++++++++++++++++++++++++++++" print "GENERATING PSI" print "++++++++++++++++++++++++++++" q95=simul.inputs.Miller_q kappa90=simul.inputs.Miller_kappa RBar=simul.RBar BBar=simul.BBar #rescale q_profile to fit whatever q95 we have in the simulation scale_q=q95/3.5 scale_kappa=kappa90/1.58 #actual profile has q95~3.5 kappay=scale_kappa*numpy.array([1.23,1.37,1.58]) kappax=numpy.array([0,0.5,0.9]) deg=2 #in what follows, rho=r/a kappa_rho=func_polyfit(kappax,kappay,deg) #kappa(rho) dkappadrho=func_polyfit_derivative(kappax,kappay,deg) #dkappadrho(rho) #generate the integrated B_T as function of minor radius of eliptical cross-section BT_r=lambda x: simul.BBar*1.0/simul.inputs.RHat(0.0) #should be B_T(r), here taken as constant and at theta=0 dBTdr=lambda x: 0 #dBTdr(r) #calculate radial derivative of toroidal flux Psi_T (assumes small theta dependence in B) dPsiTdr=toroidal_flux_derivative(a,kappa_rho,dkappadrho,BT_r,dBTdr) #calculate q profile q_rho=func_q(1.0,3.5*scale_q,0.6,1.6*scale_q) #q(rho) q_r=lambda r:q_rho(r/a) #q(rho=r/a) if Verbose: plotNum = 1 numRows = 1 numCols = 4 fig = plt.figure() xp=numpy.linspace(0,1) ax = fig.add_subplot(numRows, numCols, plotNum); plotNum += 1 ax.plot(xp, q_rho(xp)) ax = fig.add_subplot(numRows, numCols, plotNum); plotNum += 1 ax.plot(xp, kappa_rho(xp)) ax = fig.add_subplot(numRows, numCols, plotNum); plotNum += 1 ax.plot(xp, dPsiTdr(xp)) #calculate psi(r) psi_r=func_psi(q_r,dPsiTdr) #psi(r), will be in the same units as BBar and RBar psiAHat=psi_r(a)/(BBar*RBar**2) #translates to/from unitless psi to psi_N simul.inputs.changevar("physicsParameters","psiAHat",psiAHat) simul.inputs.read(simul.input_filename) #print drdPsiN_at_psiN_one(q_r,dPsiTdr,psi_r,a) if Verbose: print drdPsiN_at_psiN_one(q_r,dPsiTdr,psi_r,a)[0] ax = fig.add_subplot(numRows, numCols, plotNum); plotNum += 1 xr=numpy.linspace(0.1,0.7) psi_array=[psi_r(xxx) for xxx in xr] ax.plot(xr,psi_array) plt.show() return drdPsiN_at_psiN_one(q_r,dPsiTdr,psi_r,a)[0]
def psi_pedestal_width(deltar, q, dPsiTdr, psi, r_ped): drdpsi = drdPsiN_at_psiN_one(q, dPsiTdr, psi, r_ped)[0] return deltar / drdpsi if __name__ == "__main__": y = numpy.array([1.23, 1.37, 1.6]) x = numpy.array([0, 0.5, 0.9]) # flat profile # y=numpy.array([1.73,1.73,1.73]) # x=numpy.array([0,0.5,0.9]) deg = 2 kappa = func_polyfit(x, y, deg) dkappadrho = func_polyfit_derivative(x, y, deg) q_of_rho = func_q(1.0, 3.5, 0.6, 1.6) # flat profile # q=func_q(3.5,3.5,0.6,3.5) # does not actually matter in psiN since its normalized away # would matter if we calculated psi(r) BT = lambda x: 2.93 # Value for the average BT, taken from BBar in T for JETLike profile dBTdr = lambda x: 0 N = 100 rmin = 0 rmax = 0.7 q = lambda r: q_of_rho(r / rmax) dPsiTdr = toroidal_flux_derivative(rmax, kappa, dkappadrho, BT, dBTdr) psi = func_psi(q, dPsiTdr) r = numpy.linspace(rmin, rmax, N)