def psi_term(r, z, *p): n1, a1, b1 = p if rt1.check_coilcase(r, z): return 0.0 else: return np.exp(-a1 * abs((rt1.psi(r, z, separatrix) - psix) / psi0)**2)
def B_term(r, z, *p): n1, a1, b1 = p br, bz = rt1.bvec(r, z, separatrix) bb = np.sqrt(br**2 + bz**2) if rt1.check_coilcase(r, z): return 0.0 else: return (bb / rt1.b0(r, z, separatrix))**(-b1)
def ne_single_gaussian(r, z, *p): n1, a1, b1, rm = p br, bz = rt1.bvec(r, z, separatrix) bb = np.sqrt(br**2 + bz**2) if r == 0.0: return n1 * np.exp(-a1 * abs((rt1.psi(r, 0.0, separatrix)-psix)/psi0)**2) if rt1.check_coilcase(r, z): return 0.0 else: return n1 * np.exp(-a1*abs((rt1.psi(r, z, separatrix) - psix)/psi0)**2) * (bb/rt1.b0(r, z, separatrix))**(-b1)
def view_profile(rm, p_opt): psix = rt1.psi(rm, 0.0, separatrix) # psi上のBが最小となる直線上の密度最大値 n1, a1, b1 = p_opt nl_y450 = 0.0 nl_z620 = 0.0 nl_z700 = 0.0 nl_y450 = 0.0 for i, x in enumerate(x450): nl_y450 = nl_y450 + np.exp(-a1 * abs( (psi_x450[i] - psix) / psi0)**2) * n1 * dx450 nl_y450 = 2.0 * nl_y450 error_y450 = (nl_y450 - nl_y450_mes)**2 / (nl_y450_mes)**2 # line integral along vertical y=60, 70 chord nl_z620 = 0.0 for j, z in enumerate(z620): nl_z620 = nl_z620 + n1 * np.exp(-a1 * abs( (psi_z620[j] - psix) / psi0)**2) * (bb620[j] / b0620[j])**(-b1) * dz620 error_z620 = (nl_z620 - nl_z620_mes)**2 / (nl_z620_mes)**2 nl_z700 = 0.0 for j, z in enumerate(z700): nl_z700 = nl_z700 + n1 * np.exp(-a1 * abs( (psi_z700[j] - psix) / psi0)**2) * (bb700[j] / b0700[j])**(-b1) * dz700 error_z700 = (nl_z700 - nl_z700_mes)**2 / (nl_z700_mes)**2 print('y450: ', nl_y450, '/', nl_y450_mes) print('z620: ', nl_z620, '/', nl_z620_mes) print('z700: ', nl_z700, '/', nl_z700_mes) print('error_y450: ', error_y450) print('error_z620: ', error_z620) print('error_z700: ', error_z700) # Export figure rs = np.linspace(0.1, 1.001, 200) zs = np.linspace(-0.4, 0.401, 200) r_mesh, z_mesh = np.meshgrid(rs, zs) ne_profile = np.array([ list( map(lambda r, z: ne_single_gaussian(r, z, *p_opt_best), r_mesh.ravel(), z_mesh.ravel())) ]).ravel().reshape(len(rs), len(zs)) psi_term_profile = np.array([ list( map(lambda r, z: psi_term(r, z, *p_opt_best), r_mesh.ravel(), z_mesh.ravel())) ]).ravel().reshape(len(rs), len(zs)) B_term_profile = np.array([ list( map(lambda r, z: B_term(r, z, *p_opt_best), r_mesh.ravel(), z_mesh.ravel())) ]).ravel().reshape(len(rs), len(zs)) psi = np.array([ list(map(lambda r, z: rt1.psi(r, z), r_mesh.ravel(), z_mesh.ravel())) ]).ravel().reshape(len(rs), len(zs)) coilcase_truth_table = np.array([ list( map(lambda r, z: rt1.check_coilcase(r, z), r_mesh.ravel(), z_mesh.ravel())) ]).ravel().reshape(len(rs), len(zs)) psi[coilcase_truth_table == True] = 0 np.save('ne2D_35_t20_r1', ne_profile) # density profileの表示 levels = [ 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.011, 0.012, 0.013, 0.014 ] plt.figure(figsize=(8, 5)) plt.subplot(111) img = plt.imshow(ne_profile, origin='lower', cmap='jet', extent=(rs.min(), rs.max(), zs.min(), zs.max())) plt.contour(r_mesh, z_mesh, ne_profile, colors=['k']) plt.contour(r_mesh, z_mesh, psi, colors=['white'], levels=levels) plt.title(r'$n_\mathrm{e}$') plt.xlabel(r'$r\mathrm{\ [m]}$') plt.ylabel(r'$z\mathrm{\ [m]}$') # plt.gca():現在のAxesオブジェクトを返す divider = make_axes_locatable(plt.gca()) # カラーバーの位置 cax = divider.append_axes("right", "5%", pad="3%") cb = plt.colorbar(img, cax=cax) #cb.set_clim(0,6.4) cb.set_label(r'$\mathrm{[10^{16}\,m^{-3}]}$') plt.tight_layout(pad=1.0, w_pad=2.0, h_pad=1.0) plt.show() # psi term profileの表示 plt.figure(figsize=(8, 5)) plt.subplot(111) img = plt.imshow(psi_term_profile, origin='lower', cmap='plasma', extent=(rs.min(), rs.max(), zs.min(), zs.max())) plt.contour(r_mesh, z_mesh, psi_term_profile, colors=['k']) plt.contour(r_mesh, z_mesh, psi, colors=['white'], levels=levels) plt.title(r'$\psi term$') plt.xlabel(r'$r\mathrm{\ [m]}$') plt.ylabel(r'$z\mathrm{\ [m]}$') # plt.gca():現在のAxesオブジェクトを返す divider = make_axes_locatable(plt.gca()) # カラーバーの位置 cax = divider.append_axes("right", "5%", pad="3%") cb = plt.colorbar(img, cax=cax) cb.set_clim(0, 6.4) cb.set_label(r'$\mathrm{[10^{16}\,m^{-3}]}$') plt.tight_layout(pad=1.0, w_pad=2.0, h_pad=1.0) plt.show() # B term profileの表示 plt.figure(figsize=(8, 5)) plt.subplot(111) img = plt.imshow(B_term_profile, origin='lower', cmap='plasma', extent=(rs.min(), rs.max(), zs.min(), zs.max())) plt.contour(r_mesh, z_mesh, B_term_profile, colors=['k']) plt.contour(r_mesh, z_mesh, psi, colors=['white'], levels=levels) plt.title(r'$B term$') plt.xlabel(r'$r\mathrm{\ [m]}$') plt.ylabel(r'$z\mathrm{\ [m]}$') # plt.gca():現在のAxesオブジェクトを返す divider = make_axes_locatable(plt.gca()) # カラーバーの位置 cax = divider.append_axes("right", "5%", pad="3%") cb = plt.colorbar(img, cax=cax) cb.set_clim(0, 6.4) cb.set_label(r'$\mathrm{[10^{16}\,m^{-3}]}$') plt.tight_layout(pad=1.0, w_pad=2.0, h_pad=1.0) plt.show() # profile_zでのdensity profileの表示 profile_z = 0.0 # プロファイルが見たい任意のz [m] profile_z_index = np.searchsorted(zs, profile_z) ne_profile_z0 = ne_profile[:][profile_z_index] fig, ax = plt.subplots(1) ax.plot(rs, ne_profile_z0) plt.draw() plt.show() #error at rms fig, ax = plt.subplots(1) ax.plot(rms, error_at_rms[:, 0]) ax.plot(rms, error_at_rms[:, 1]) plt.yscale('log') plt.xlabel('r [m]') plt.ylabel('Error at rm') plt.show()