density_norm = m / vol_mass dens_norm = g.scratch_array() dens_norm[mask_mass] = density_norm ''' # analytical potential of a spheroid at y surface phi_anal = g.scratch_y_plane_array() for i in range(g.nx): for j in range(g.nz): spheroid_V = ap.Ana_Mac_pot(a1, a3, g.x[i], g.y[8], g.z[j], density) phi_anal[i, j] = spheroid_V.potential ''' lmax = 30 center = (0, 0, 0) # m = multipole.Multipole(g, dens, lmax, 0.3*g.dr, center=center) m = multipole.Multipole(g, dens_norm, lmax, 0.3 * g.dr, center=center) phi = m.Phi() ''' phi = m.PhiY(8) plt.imshow(np.log10(np.abs(np.transpose(phi))), origin="lower", interpolation="nearest", extent=[g.xlim[0], g.xlim[1], g.zlim[0], g.zlim[1]]) plt.colorbar() ax = plt.gca() ax.set_aspect("equal") plt.savefig("lmax=0.png") diff = comdf.comp_diff(phi_anal, phi)
""" """ center = (0, 0) n_moments = 0 m = multipole.Multipole(g, n_moments, 2*g.dr, center=center) m.compute_expansion(dens) phi = g.scratch_array() for i in range(g.nr): for j in range(g.nz): phi[i, j] = m.phi_point(g.r[i], g.z[j]) """ # test brute force version Multipole center = (0, 0) n_moments = 0 m = multipole.Multipole(g, n_moments, center=center) m.compute_expansion(dens) phi = m.phi() phi_norm = np.sqrt(np.sum(phi**2 / phi.size)) L2normerr = L2.L2_diff(phi_anal, phi, g.scratch_array()) # L2normerr = L2.L2_diff(phi_anal, phi, g) # normalized L2 norm error L2normerr = L2normerr / phi_norm print("lmax=", n_moments) print(L2normerr)
""" plt.imshow(np.log10(np.abs(np.transpose(phi_mac))), origin="lower", interpolation="nearest", extent=[g.rlim[0], g.rlim[1], g.zlim[0], g.zlim[1]]) plt.colorbar() ax = plt.gca() ax.set_aspect("equal") plt.savefig("anal_phi.png") """ # create a multipole object center = (0.0, 0.0) n_moments = 1 m = multipole.Multipole(g, n_moments, 1.2 * g.dr, center=center) # calculate the multipole for l in range(n_moments): m.compute_expansion(dens, l) """ phi = g.scratch_array() for i in range(g.nr): for j in range(g.nz): phi[i, j] = m.phi(g.r[i], g.z[j]) """ # evaluate eq.20 at the surface # the surface coodinates satisfy: # r_surface = r_grid_center - dr/2 phi = g.scratch_array() for i in range(g.nr):
plt.colorbar() ax = plt.gca() ax.set_aspect("equal") plt.savefig("lmax=0.png") L2normerr = L2.L2_diff(V_cube, phi, g.scratch_array()) print("resolution", nx) print("lmax =", n_moments) print(L2normerr) """ # test brute force codes n_moments = 0 # center = (a/2, b/2, c/2) center = (0.5, 0.5, 0.5) # multipole expansion with concentric sphere moment = multipole.Multipole(g, dens, n_moments, 2 * g.dr, center=center) ''' # with azumuthal for l in range(n_moments): for m in range(-l, l+1): moment.compute_expansion(dens, l, m) ''' phi = g.y_plane_array() for i in range(g.nx): for j in range(g.nz): phi[i, j] = moment.phi(g.x[i], g.y[0], g.z[j]) # phi[i, j] = moment.phi_point(g.x[i], g.y[0], g.z[j]) plt.imshow(np.log10(np.abs(np.transpose(phi))),