Removed d'Alembert force and chaned halo model to NFW

This commit is contained in:
Yohai Meiron 2020-05-04 21:31:01 -04:00
parent f8eae117dd
commit 8cb62ac88c
7 changed files with 316 additions and 73 deletions

View file

@ -15,8 +15,8 @@ file_name = 'data/subhalo_411321.hdf5'
# centers_file_name = 'data/centers_411321.hdf5'
### Snapshot parameters ###
snapshot = 99
a = 1.0 # Should read this value from somewhere!
snapshot = 25
a = 0.2494928434225328 # Should read this value from somewhere!
# Read the centre from separate file
# DISABLED: we calculate on our own.
@ -32,6 +32,48 @@ particle_types['dm'] = '1'
particle_types['stars'] = '4'
particle_types['bhs'] = '5'
# Read DM
particle_type = 'dm'
with h5py.File(file_name, 'r') as f:
m = f[str(snapshot)][particle_types[particle_type]]['Masses'][...]
X = f[str(snapshot)][particle_types[particle_type]]['Coordinates'][...] * a / h0
V = f[str(snapshot)][particle_types[particle_type]]['Velocities'][...] * sqrt(a)
M_tot = sum(m)
# Calculate density centre and shift appropriately
X_center_new, V_center_new = def_dc(m, X, V)
X -= X_center_new
V -= V_center_new
r = linalg.norm(X, axis=1)
i = r.argsort()
rr = r[i]
m_cumulative = cumsum(m[i])/sum(m)
nfw_cumulative_mass = lambda rho_0, b, r: 4*pi*rho_0*b**3*(log(1+r/b) - r/(b+r))
cost = lambda args: sum((nfw_cumulative_mass(*args, rr) - m_cumulative)**2)
res = scipy.optimize.minimize(cost, [0.001, 30.], method='Nelder-Mead')
print(res)
rho_0_nfw, b_nfw = res.x
plot(rr, m_cumulative*sum(m))
plot(rr, nfw_cumulative_mass(*res.x, rr)*sum(m))
figure()
counts, bin_edges = histogram(r, logspace(-2, 2, 65))
volumes = 4*pi/3*(bin_edges[1:]**3 - bin_edges[:-1]**3)
means = lambda arr: 0.5*(arr[:-1]+arr[1:])
bins = means(bin_edges)
density = counts*m[0]/volumes
loglog(bins, density)
nfw_density = lambda rho_0, b, r: rho_0/((r/b) * (1 + r/b)**2)
loglog(bins, nfw_density(*res.x, bins)*sum(m))
show()
raise SystemExit
# Read stars
particle_type = 'stars'
with h5py.File(file_name, 'r') as f: