#*************Loading the data****************************************** rhot0, te0, ti0, ne0, ni0, nz0, vrot0 = read_iterdb_file(iterdb_file_name) EFITdict = read_EFIT(geomfile) xgrid = EFITdict['psipn'] q = EFITdict['qpsi'] * q_scale uni_rhot = np.linspace(min(rhot0), max(rhot0), len(rhot0) * 10.) te_u = interp(rhot0, te0, uni_rhot) ne_u = interp(rhot0, ne0, uni_rhot) vrot_u = interp(rhot0, vrot0, uni_rhot) q = interp(xgrid, q, uni_rhot) tprime_e = -fd_d1_o4(te_u, uni_rhot) / te_u nprime_e = -fd_d1_o4(ne_u, uni_rhot) / ne_u midped, topped = find_pedestal(file_name=geomfile, path_name='', plot=False) x0_center = midped print('mid pedestal is at r/a = ' + str(x0_center)) Lref, Bref, R_major, q0, shat0 = get_geom_pars(geomfile, x0_center) index_begin = np.argmin(abs(uni_rhot - x0_center + 2 * (1 - x0_center))) te_u = te_u[index_begin:len(uni_rhot) - 1] ne_u = ne_u[index_begin:len(uni_rhot) - 1] vrot_u = vrot_u[index_begin:len(uni_rhot) - 1] q = q[index_begin:len(uni_rhot) - 1] tprime_e = tprime_e[index_begin:len(uni_rhot) - 1] nprime_e = nprime_e[index_begin:len(uni_rhot) - 1] uni_rhot = uni_rhot[index_begin:len(uni_rhot) - 1]
def Parameter_reader(profile_name, geomfile, q_scale, manual_ped, mid_ped0, plot, output_csv): n0 = 1. mref = 2. # mass of ion in proton mass rhot0, rhop0, te0, ti0, ne0, ni0, vrot0 = read_profile_file( profile_type, profile_name, geomfile_name) if geomfile_type == "gfile": xgrid, q = read_geom_file(geomfile_type, geomfile_name, suffix) elif geomfile_type == "GENE_tracor": xgrid, q, Lref, Bref, x0_from_para = read_geom_file( geomfile_type, geomfile_name, suffix) q = q * q_scale if geomfile_type == "GENE_tracor": rhot0_range_min = np.argmin(abs(rhot0 - xgrid[0])) rhot0_range_max = np.argmin(abs(rhot0 - xgrid[-1])) rhot0 = rhot0[rhot0_range_min:rhot0_range_max] rhop0 = rhop0[rhot0_range_min:rhot0_range_max] te0 = te0[rhot0_range_min:rhot0_range_max] ti0 = ti0[rhot0_range_min:rhot0_range_max] ne0 = ne0[rhot0_range_min:rhot0_range_max] ni0 = ni0[rhot0_range_min:rhot0_range_max] vrot0 = vrot0[rhot0_range_min:rhot0_range_max] uni_rhot = np.linspace(min(rhot0), max(rhot0), len(rhot0) * 10.) te_u = interp(rhot0, te0, uni_rhot) ne_u = interp(rhot0, ne0, uni_rhot) ni_u = interp(rhot0, ni0, uni_rhot) vrot_u = interp(rhot0, vrot0, uni_rhot) q = interp(xgrid, q, uni_rhot) tprime_e = -fd_d1_o4(te_u, uni_rhot) / te_u nprime_e = -fd_d1_o4(ne_u, uni_rhot) / ne_u qprime = fd_d1_o4(q, uni_rhot) / q #center_index = np.argmax((tprime_e*te_u+nprime_e*ne_u)[0:int(len(tprime_e)*0.99)]) if manual_ped == 1: x0_center = mid_ped0 else: if geomfile_type == "gfile": midped, topped = find_pedestal(file_name=geomfile_name, path_name='', plot=False) elif geomfile_type == "GENE_tracor": midped = x0_from_para x0_center = midped print('mid pedestal is at r/a = ' + str(x0_center)) if geomfile_type == "gfile": Lref, Bref, R_major, q0, shat0 = get_geom_pars(geomfile_name, x0_center) print("Lref=" + str(Lref)) print("x0_center=" + str(x0_center)) index_begin = np.argmin(abs(uni_rhot - x0_center + 2 * (1. - x0_center))) te_u = te_u[index_begin:len(uni_rhot) - 1] ne_u = ne_u[index_begin:len(uni_rhot) - 1] ni_u = ni_u[index_begin:len(uni_rhot) - 1] vrot_u = vrot_u[index_begin:len(uni_rhot) - 1] q = q[index_begin:len(uni_rhot) - 1] tprime_e = tprime_e[index_begin:len(uni_rhot) - 1] nprime_e = nprime_e[index_begin:len(uni_rhot) - 1] qprime = qprime[index_begin:len(uni_rhot) - 1] uni_rhot = uni_rhot[index_begin:len(uni_rhot) - 1] Lt = 1. / tprime_e Ln = 1. / nprime_e Lq = 1. / qprime center_index = np.argmin(abs(uni_rhot - x0_center)) q0 = q[center_index] ne = ne_u / (10.**19.) # in 10^19 /m^3 ni = ni_u / (10.**19.) # in 10^19 /m^3 te = te_u / 1000. #in keV m_SI = mref * 1.6726 * 10**(-27) me_SI = 9.11 * 10**(-31) c = 1. qref = 1.6 * 10**(-19) #refes to GENE manual coll_c = 2.3031 * 10**(-5) * Lref * ne / (te)**2 * ( 24 - np.log(np.sqrt(ne * 10**13) / (te * 1000))) coll_ei = 4 * (ni / ne) * coll_c * np.sqrt( te * 1000. * qref / me_SI) / Lref nuei = coll_ei beta = 403. * 10**(-5) * ne * te / Bref**2. nref = ne_u[center_index] te_mid = te_u[center_index] Tref = te_u[center_index] * qref cref = np.sqrt(Tref / m_SI) Omegaref = qref * Bref / m_SI / c rhoref = cref / Omegaref kymin = n0 * q0 * rhoref / (Lref * x0_center) kyGENE = kymin * (q / q0) * np.sqrt(te_u / te_mid) * ( x0_center / uni_rhot) #Add the effect of the q varying #from mtm_doppler omMTM = kyGENE * (tprime_e + nprime_e) gyroFreq = 9.79E3 / np.sqrt(mref) * np.sqrt(te_u) / Lref mtmFreq = omMTM * gyroFreq / (2. * np.pi * 1000.) omegaDoppler = abs(vrot_u * n0 / (2. * np.pi * 1000.)) omega = mtmFreq + omegaDoppler omega_n_GENE = kyGENE * (nprime_e) #in cs/a omega_n = omega_n_GENE * gyroFreq / (2. * np.pi * 1000.) #in kHz coll_ei = coll_ei / (1000.) #in kHz shat = Ln / Lq eta = Ln / Lt ky = kyGENE nu = (coll_ei) / (omega_n) mean_rho, xstar = omega_gaussian_fit(uni_rhot, mtmFreq, rhoref, Lref, plot) if plot == True: plt.clf() plt.xlabel('r/a') plt.ylabel('eta') plt.plot(uni_rhot, eta, label='eta') plt.show() plt.clf() #plt.title('mode number finder') plt.xlabel('r/a') plt.ylabel('omega*(Lab), kHz') plt.plot(uni_rhot, omega, label='omega*(Lab)') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('eta') plt.plot(uni_rhot, eta, label='eta') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('shat') plt.plot(uni_rhot, shat, label='shat') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('beta') plt.plot(uni_rhot, beta, label='beta') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('ky rhoi') plt.plot(uni_rhot, ky, label='ky') plt.show() if output_csv == True: with open('profile_output.csv', 'w') as csvfile: data = csv.writer(csvfile, delimiter=',') data.writerow([ 'x/a', 'nu_ei(kHz)', 'omega*n(kHz)', 'omega* plasma(kHz)', 'Doppler shift(kHz)', 'nu/omega*n', 'eta', 'shat', 'beta', 'ky rhoi(for n=1)' ]) for i in range(len(uni_rhot)): data.writerow([ uni_rhot[i], coll_ei[i], omega_n[i], mtmFreq[i], omegaDoppler[i], nu[i], eta[i], shat[i], beta[i], ky[i] ]) csvfile.close() return uni_rhot, nu, eta, shat, beta, ky, q, mtmFreq, omegaDoppler, omega_n, omega_n_GENE, xstar, Lref, rhoref
def Parameter_reader(path, profile_name, geomfile, q_scale, manual_ped, mid_ped0, plot, output_csv): n0 = 1. mref = 2. # mass of ion in proton mass if profile_type == "ITERDB": rhot0, rhop0, te0, ti0, ne0, ni0, nz0, vrot0 = read_profile_file( profile_type, path + '/' + profile_name, path + '/' + geomfile_name, suffix) elif profile_type == "pfile": rhot0, rhop0, te0, ti0, ne0, ni0, nz0, vrot0 = read_profile_file( profile_type, path + '/' + profile_name, path + '/' + geomfile_name, suffix) if geomfile_type == "gfile": xgrid, q, R_ref = read_geom_file(geomfile_type, path + '/' + geomfile_name, suffix) elif geomfile_type == "GENE_tracor": xgrid, q, Lref, R_ref, Bref, x0_from_para = read_geom_file( geomfile_type, path + '/' + geomfile_name, suffix) q = q * q_scale if geomfile_type == "GENE_tracor" and profile_type != "profile": rhot0_range_min = np.argmin(abs(rhot0 - xgrid[0])) rhot0_range_max = np.argmin(abs(rhot0 - xgrid[-1])) rhot0 = rhot0[rhot0_range_min:rhot0_range_max] rhop0 = rhop0[rhot0_range_min:rhot0_range_max] te0 = te0[rhot0_range_min:rhot0_range_max] ti0 = ti0[rhot0_range_min:rhot0_range_max] ne0 = ne0[rhot0_range_min:rhot0_range_max] ni0 = ni0[rhot0_range_min:rhot0_range_max] nz0 = nz0[rhot0_range_min:rhot0_range_max] vrot0 = vrot0[rhot0_range_min:rhot0_range_max] uni_rhot = np.linspace(min(rhot0), max(rhot0), len(rhot0) * 10) te_u = interp(rhot0, te0, uni_rhot) ne_u = interp(rhot0, ne0, uni_rhot) ni_u = interp(rhot0, ni0, uni_rhot) print(str((len(rhot0), len(nz0), len(uni_rhot)))) nz_u = interp(rhot0, nz0, uni_rhot) vrot_u = interp(rhot0, vrot0, uni_rhot) q = interp(xgrid, q, uni_rhot) tprime_e = -fd_d1_o4(te_u, uni_rhot) / te_u nprime_e = -fd_d1_o4(ne_u, uni_rhot) / ne_u qprime = fd_d1_o4(q, uni_rhot) / q #center_index = np.argmax((tprime_e*te_u+nprime_e*ne_u)[0:int(len(tprime_e)*0.99)]) if manual_ped == 1: x0_center = mid_ped0 else: if geomfile_type == "gfile": midped, topped = find_pedestal(file_name=path + '/' + geomfile_name, path_name='', plot=False) elif geomfile_type == "GENE_tracor": midped = x0_from_para x0_center = midped print('mid pedestal is at r/a = ' + str(x0_center)) if geomfile_type == "gfile": Lref, Bref, R_major, q0, shat0 = get_geom_pars( path + '/' + geomfile_name, x0_center) print("Lref=" + str(Lref)) print("x0_center=" + str(x0_center)) index_begin = np.argmin(abs(uni_rhot - x0_center + 2 * (1. - x0_center))) te_u = te_u[index_begin:len(uni_rhot) - 1] ne_u = ne_u[index_begin:len(uni_rhot) - 1] ni_u = ni_u[index_begin:len(uni_rhot) - 1] nz_u = nz_u[index_begin:len(uni_rhot) - 1] vrot_u = vrot_u[index_begin:len(uni_rhot) - 1] q = q[index_begin:len(uni_rhot) - 1] tprime_e = tprime_e[index_begin:len(uni_rhot) - 1] nprime_e = nprime_e[index_begin:len(uni_rhot) - 1] qprime = qprime[index_begin:len(uni_rhot) - 1] uni_rhot = uni_rhot[index_begin:len(uni_rhot) - 1] Lt = 1. / tprime_e Ln = 1. / nprime_e center_index = np.argmin(abs(uni_rhot - x0_center)) q0 = q[center_index] ne = ne_u / (10.**19.) # in 10^19 /m^3 ni = ni_u / (10.**19.) # in 10^19 /m^3 nz = nz_u / (10.**19.) # in 10^19 /m^3 te = te_u / 1000. #in keV m_SI = mref * 1.6726 * 10**(-27) me_SI = 9.11 * 10**(-31) c = 1. qref = 1.6 * 10**(-19) #refes to GENE manual coll_c = 2.3031 * 10**(-5) * Lref * ne / (te)**2 * ( 24 - np.log(np.sqrt(ne * 10**13) / (te * 1000))) coll_ei = 4. * coll_c * np.sqrt(te * 1000. * qref / me_SI) / Lref nuei = coll_ei beta = 403. * 10**(-5) * ne * te / Bref**2. nref = ne_u[center_index] te_mid = te_u[center_index] Tref = te_u[center_index] * qref cref = np.sqrt(Tref / m_SI) Omegaref = qref * Bref / m_SI / c rhoref = cref / Omegaref rhoref_temp = rhoref * np.sqrt(te_u / te_mid) kymin = n0 * q0 * rhoref / (Lref * x0_center) kyGENE = kymin * (q / q0) * np.sqrt(te_u / te_mid) * ( x0_center / uni_rhot) #Add the effect of the q varying #from mtm_doppler omMTM = kyGENE * (tprime_e + nprime_e) gyroFreq = 9.79E3 / np.sqrt(mref) * np.sqrt(te_u) / Lref mtmFreq = omMTM * gyroFreq / (2. * np.pi * 1000.) omegaDoppler = abs(vrot_u * n0 / (2. * np.pi * 1000.)) omega = mtmFreq + omegaDoppler global zeff zeff = ((ni + Z**2 * nz) / ne)[center_index] if zeff_manual != False: zeff = zeff_manual print('********zeff*********') print('zeff=' + str(zeff)) print('********zeff*********') omega_n_GENE = kyGENE * (nprime_e) #in cs/a print("*******************") print("*******************") print(np.max(omega_n_GENE)) print("*******************") print("*******************") omega_n = omega_n_GENE * gyroFreq / (2. * np.pi * 1000.) #in kHz #coll_ei=coll_ei/(1000.) #in kHz coll_ei = coll_ei / (2. * np.pi * 1000.) #in kHz Lq = 1. / (Lref / (R_ref * q) * qprime) shat = Ln / Lq eta = Ln / Lt ky = kyGENE * np.sqrt(2.) nu = (coll_ei) / (np.max(omega_n)) nuei = nu * omega_n_GENE / omega_n if plot == True: if profile_type == "ITERDB0": plt.clf() plt.plot(uni_rhot, nuei, label='nuei(cs/a)') plt.plot(uni_rhot, nuei * 2. * np.pi, label='nuei(cs/a)*2 pi') plt.plot(uni_rhot, nuei * zeff, label='nuei*zeff') plt.legend() plt.title('nuei') plt.axvline(0.96, color='red', alpha=1.) plt.show() index = np.argmin( abs(float(input("Enter location of interest:\n")) - uni_rhot)) print('zeff(x/r=' + str(uni_rhot[index]) + ')=' + str(zeff[index])) #print('id(x/r='+str(rho)+')='+str(id[index])) print('nuei*zeff(x/r=' + str(uni_rhot[index]) + ')=' + str((nuei * zeff)[index])) print('nuei*2 pi(x/r=' + str(uni_rhot[index]) + ')=' + str((nuei * 2. * np.pi)[index])) plt.clf() plt.xlabel('r/a') plt.ylabel('nuei(kHZ)') plt.plot(uni_rhot, nu * np.max(omega_n), label='coll') plt.show() d = {'uni_rhot': uni_rhot, 'nu*np.max(omega_n)': nu * np.max(omega_n)} df = pd.DataFrame(d, columns=['uni_rhot', 'nu*np.max(omega_n)']) df.to_csv('0nu_ei_smooth.csv', index=False) plt.clf() #plt.title('mode number finder') plt.xlabel('r/a') plt.ylabel('omega*, kHz') plt.plot(uni_rhot, mtmFreq, label='omega*p') plt.plot(uni_rhot, omega_n, label='omega*n') plt.axvline(uni_rhot[np.argmax(mtmFreq)], color='red', alpha=1., label='peak of omega*p') plt.axvline(uni_rhot[np.argmax(omega_n)], color='green', alpha=1., label='peak of omega*n') plt.plot(uni_rhot, rhoref_temp, color='purple', label='rhoref') plt.legend() plt.show() print("rho i for peak of omega*p: " + str(rhoref_temp[np.argmax(mtmFreq)])) print("rho i for peak of omega*n: " + str(rhoref_temp[np.argmax(omega_n)])) plt.clf() plt.xlabel('r/a') plt.ylabel('eta') plt.plot(uni_rhot, eta, label='eta') plt.show() plt.clf() #plt.title('mode number finder') plt.xlabel('r/a') plt.ylabel('omega*(Lab), kHz') plt.plot(uni_rhot, omega, label='omega*(Lab)') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('eta') plt.plot(uni_rhot, eta, label='eta') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('shat') plt.plot(uni_rhot, shat, label='shat') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('beta') plt.plot(uni_rhot, beta, label='beta') plt.show() plt.clf() plt.xlabel('r/a') plt.ylabel('ky rhoi') plt.plot(uni_rhot, ky, label='ky') plt.show() mean_rho, xstar = omega_gaussian_fit(uni_rhot, mtmFreq, rhoref * np.sqrt(2.), Lref, path, profile_name, plot) if abs(mean_rho) + abs(xstar) < 0.0001: quit() if output_csv == True: with open('profile_output.csv', 'w') as csvfile: data = csv.writer(csvfile, delimiter=',') data.writerow([ 'x/a', 'nu_ei(kHz)', 'omega*n(kHz)', 'omega* plasma(kHz)', 'Doppler shift(kHz)', 'nu/omega*n', 'eta', 'shat', 'beta', 'ky rhoi(for n=1)' ]) for i in range(len(uni_rhot)): data.writerow([ uni_rhot[i], coll_ei[i], omega_n[i], mtmFreq[i], omegaDoppler[i], nu[i], eta[i], shat[i], beta[i], ky[i] ]) csvfile.close() return uni_rhot, nu, eta, shat, beta, ky, q, mtmFreq, omegaDoppler, omega_n, omega_n_GENE, xstar, Lref, R_ref, rhoref