def causality_p3(pressure3, pressure1, pressure2): args = [ baryon_density0, pressure1, baryon_density1, pressure2, baryon_density2, pressure3, baryon_density3 ] a = EOS_BPSwithPoly(args) density3=(a.eosPiecewisePoly.density2-pressure2/(a.eosPiecewisePoly.gamma3-1))\ *(pressure3/pressure2)**(1./a.eosPiecewisePoly.gamma3)\ +pressure3/(a.eosPiecewisePoly.gamma3-1) return a.eosPiecewisePoly.gamma3 * pressure3 / (density3 + pressure3) - 1.
def beta6lambda_ofmass(p1,ofmass): eos=EOS_BPSwithPoly([baryon_density0, p1, baryon_density1, func(p1,*fit_result_p2[0]), baryon_density2, func(p1,*fit_result_p3[0]), baryon_density3]) ofmass_result=Properity_ofmass(ofmass,p1,func(p1,*fit_result_pc_maxmass[0]),MassRadius,Preset_Pressure_final,Preset_rtol,1.0,eos) print p1,(ofmass_result[3])**6*ofmass_result[7] return (ofmass_result[3])**6*ofmass_result[7]
def Ofmass(pressure_center, ofmass, MassRadius_function, Preset_Pressure_final, Preset_rtol): pressure1 = pressure1_max gamma2 = opt.newton(causality_trans, 10, args=(pressure_center, )) pressure2 = pressure1 * (baryon_density2 / baryon_density1)**gamma2 eos = EOS_BPSwithPoly([ baryon_density0, pressure1, baryon_density1, pressure2, baryon_density2, pressure3, baryon_density3 ]) return -ofmass + MassRadius_function( pressure_center, Preset_Pressure_final, Preset_rtol, 'M', eos)
def stable_final_data_BPSwithPolyCSS(final_data): stable_parameter = [] for i in range(final_data.N): eos = EOS_BPSwithPoly(final_data.parameter[i].args[0:7]) pressure_trans = final_data.parameter[i].args[7] det_density = final_data.parameter[i].args[8] cs2 = final_data.parameter[i].args[9] density_trans = eos.eosDensity(pressure_trans) baryondensity_trans = eos.eosBaryonDensity(pressure_trans) chempo = (density_trans + pressure_trans) / baryondensity_trans if (1 - cs2 - 4. * A0 * ((chempo / m0)**2 - 1)**2.5 / (45 * chempo * (density_trans + det_density + pressure_trans) / m0) > 0): stable_parameter.append(final_data.parameter[i]) return final_data_BPSwithPolyCSS(stable_parameter)
def bound_upper(pressure1, m1, m2): #pressure2,pressure3,pressure_center_maxmass = p2p3_ofmaxmass(ofmaxmass,105,Maxmass,Preset_Pressure_final,Preset_rtol,pressure1) pressure2 = func(pressure1, *fit_result_p2[0]) pressure3 = func(pressure1, *fit_result_p3[0]) #pressure_center_maxmass=func(pressure1,*fit_result_pc_maxmass[0]) args = [ baryon_density0, pressure1, baryon_density1, pressure2, baryon_density2, pressure3, baryon_density3 ] a = EOS_BPSwithPoly(args) print pressure1, pressure3, m1, m2 tidal1 = Properity_ofmass(m1, 0.5 * pressure1, pressure3, MassRadius, Preset_Pressure_final, Preset_rtol, 1, a)[7] tidal2 = Properity_ofmass(m2, 0.5 * pressure1, pressure3, MassRadius, Preset_Pressure_final, Preset_rtol, 1, a)[7] print pressure1, tidal1 / tidal2 return tidal1 / tidal2, tidal1, tidal2, args
def Ofmaxmass(p2, ofmaxmass, Maxmass_function, Preset_Pressure_final, Preset_rtol, args_p1): print '==================Finding p3 at p2=%f' % p2 pressure3 = opt.newton(caulality_central_pressure_at_peak, trial_p3(p2), tol=0.1, args=(args_p1, p2, Preset_Pressure_final, Preset_rtol)) pressure3_result[0] = pressure3 args = [ baryon_density0, args_p1, baryon_density1, p2, baryon_density2, pressure3, baryon_density3 ] eos = EOS_BPSwithPoly(args) maxmass_result = Maxmass_function(Preset_Pressure_final, Preset_rtol, eos) pressure_center_maxmass[0] = maxmass_result[1] print 'maxmass=%f' % maxmass_result[2] return -ofmaxmass + maxmass_result[2]
def Properity_ofmass_at_transition(ofmass, Preset_pressure_center_low, MaximumMass_pressure_center, MassRadius_function, Preset_Pressure_final, Preset_rtol, Preset_Pressure_final_index): pressure1 = pressure1_max pressure_center = pressure_center_ofmass( ofmass, Preset_pressure_center_low, MaximumMass_pressure_center, MassRadius_function, Preset_Pressure_final, Preset_rtol) gamma2 = opt.newton(causality_trans, 10, args=(pressure_center, )) pressure2 = pressure1 * (baryon_density2 / baryon_density1)**gamma2 eos = EOS_BPSwithPoly([ baryon_density0, pressure1, baryon_density1, pressure2, baryon_density2, pressure3, baryon_density3 ]) [M, R, beta, M_binding, momentofinertia, yR, tidal] = MassRadius_function( pressure_center, Preset_Pressure_final**Preset_Pressure_final_index, Preset_rtol, 'MRBIT', eos) return [ pressure_center, M, R, beta, M_binding, momentofinertia, yR, tidal, pressure2 ]
def get_bound(m1_grid, m2_grid, upper_or_lower, p1_lower_bound=None): tidal1 = m1_grid.copy() tidal2 = m1_grid.copy() eos_args = [] if (upper_or_lower == 'upper'): for i in range(len(m1_grid)): print i eos_args.append([]) for j in range(len(m1_grid[0])): eos_args[i].append([]) tidal1[i, j], tidal2[i, j], eos_args[i][j] = get_bound_upper( m1_grid[i, j], m2_grid[i, j]) elif (upper_or_lower == 'lower'): p2_causal = opt.newton(causality_p2, 100., args=(p1_lower_bound, )) p3_causal = opt.newton(causality_p3, 800., args=(p1_lower_bound, p2_causal)) print p1_lower_bound, p2_causal p3_causal = opt.newton(caulality_central_pressure_at_peak, p3_causal, tol=0.1, args=(p1_lower_bound, p2_causal, Preset_Pressure_final, Preset_rtol)) print p3_causal args_lower_bound = [ baryon_density0, p1_lower_bound, baryon_density1, p2_causal, baryon_density2, p3_causal, baryon_density3 ] for i in range(len(m1_grid)): print i eos_args.append([]) for j in range(len(m1_grid[0])): eos_args[i].append([]) tidal1[i, j], tidal2[i, j], eos_args[i][j] = get_bound_lower( m1_grid[i, j], m2_grid[i, j], EOS_BPSwithPoly(args_lower_bound)) return tidal1, tidal2, eos_args
def causality_center(p3,p1,p2): a=EOS_BPSwithPoly([baryon_density0,p1,baryon_density1,p2,baryon_density2,p3,baryon_density3]) return a.eosCs2(Maxmass(Preset_Pressure_final,Preset_rtol,a)[1])-1
# ============================================================================= # eos.append(EOS_BPSwithPoly([0.059259259259259255, # p1[j], # 0.29600000000000004, # func(p1[j],*fit_result_p2[0]), # 0.5984, # func(p1[j],*fit_result_p3[0]), # 1.1840000000000002])) # pc_eos.append(Maxmass(Preset_Pressure_final,Preset_rtol,eos[j])[1]) # ============================================================================= p2=causality_p2(p1[j]) eos.append(EOS_BPSwithPoly([0.059259259259259255, p1[j], baryon_density1, p2, baryon_density2, 1.2*p2, baryon_density3])) pc_eos.append(1.5*p2) for i in range(len(pc_list)): result_upper_bound_no_maxmass=MassRadius(pc_eos[j]*pc_list[i],Preset_Pressure_final,Preset_rtol,'MRBIT',eos[j]) mass[j].append(result_upper_bound_no_maxmass[0]) Lambda[j].append(result_upper_bound_no_maxmass[6]) beta_no_correction[j].append(result_upper_bound_no_maxmass[2]) beta[j].append(result_upper_bound_no_maxmass[2]/Radius_correction_ratio(pc_eos[j]*pc_list[i],Preset_Pressure_final,result_upper_bound_no_maxmass[2],eos[j])) beta_no_correction=np.array(beta_no_correction) beta=np.array(beta) Lambda=np.array(Lambda) mass=np.array(mass)
args.append([ 0.059259259259259255, p1[i], 0.29600000000000004, p2[i], 0.5984, p3[i], 1.1840000000000002 ]) args.append([ 0.059259259259259255, 3.75, 0.29600000000000004, 144.85571948688346, 0.5984, 951.205339935, 1.1840000000000002 ]) N = 500 pressure_eos = np.linspace(0.1, 1000, N) pressure_center = np.linspace(10, 1000, N) mass_radius = [] for i in range(len(args)): a = EOS_BPSwithPoly(args[i]) mass_radius.append(calculate_mass_radius(pressure_center, a, MassRadius)) # ============================================================================= # a=EOS_BPSwithPoly(args[-1]) # mass_radius.append(calculate_mass_radius(pressure_center,a,MassRadius)) # ============================================================================= f, axs = plt.subplots(1, 3, sharex=False, figsize=(15, 5)) maxmass_min = 2.0 pressure1_min = 3.75 for i in range(3, len(args)): a = EOS_BPSwithPoly(args[i]) if (i == len(args) - 1): plot_eos_mass_radius( pressure_eos, a, mass_radius[i], axs, '-', '$p_1>%.2f$ MeV fm$^{-3}$ lower bound' % (pressure1_min))
p1 = 30. p2 = [ 298.98747443548757, 280.42619530917631, 246.62329988651169, 217.41984574618286, 191.78867337011866, 169.14667443229015 ] pc = [ 438.7646484375, 280.42619530917631, 246.62329988651169, 217.41984574618286, 191.78867337011866, 169.14667443229015 ] eos = [] for i in range(len(p2)): eos.append( EOS_BPSwithPoly([ baryon_density0, p1, baryon_density1, p2[i], baryon_density2, 932.73761329707713, baryon_density3 ])) def Calculation_maxmass(eos, i): maxmass_result = Maxmass(Preset_Pressure_final, Preset_rtol, eos[i])[1:3] return maxmass_result + [eos[i].eosCs2(maxmass_result[0])] def Calculation_onepointfour(args_list, i): eos = args_list[:, 0] maxmass_result = args_list[:, 1] Properity_onepointfour = Properity_ofmass(1.4, 10, maxmass_result[i][0], MassRadius, Preset_Pressure_final, Preset_rtol, 1, eos[i])
def __init__(self, parameter): self.parameter = parameter self.N = np.size(parameter) args_matrix = list() properity_matrix = list() stars_type0 = list() stars_type1 = list() stars_type2 = list() stars_type3 = list() binaries_matrix = list() tidal_binary_matrix = list() density_trans = list() baryondensity_trans = list() gamma2 = list() for i in range(self.N): eos = EOS_BPSwithPoly(parameter[i].args[0:7]) gamma2.append(eos.eosPiecewisePoly.gamma2) if (len(parameter[0].args) > 7): density_trans.append(eos.eosDensity(parameter[i].args[7])) baryondensity_trans.append( eos.eosBaryonDensity(parameter[i].args[7])) else: density_trans = [] baryondensity_trans = [] tidal_binary_matrix.append([ parameter[i].stars[0][-1], parameter[i].stars[1][-1], parameter[i].stars[2][-1], parameter[i].stars[3][-1], parameter[i].stars[4][-1] ]) args_matrix.append(parameter[i].args) properity_matrix.append(parameter[i].properity) for j in range(np.size(parameter[i].stars) / 9 - 5): if (parameter[i].stars[j + 5][0] == 0): stars_type0.append(parameter[i].stars[j + 5]) if (parameter[i].stars[j + 5][0] == 1): stars_type1.append(parameter[i].stars[j + 5]) if (parameter[i].stars[j + 5][0] == 2): stars_type2.append(parameter[i].stars[j + 5]) if (parameter[i].stars[j + 5][0] == 3): stars_type3.append(parameter[i].stars[j + 5]) binaries_matrix += parameter[i].binaries args_matrix = np.array(args_matrix) self.args_matrix = args_matrix.transpose() properity_matrix = np.array(properity_matrix) self.properity_matrix = properity_matrix.transpose() binaries_matrix = np.array(binaries_matrix) self.binaries_matrix = binaries_matrix.transpose() stars_type0 = np.array(stars_type0) self.stars_type0 = stars_type0.transpose() stars_type1 = np.array(stars_type1) self.stars_type1 = stars_type1.transpose() stars_type2 = np.array(stars_type2) self.stars_type2 = stars_type2.transpose() stars_type3 = np.array(stars_type3) self.stars_type3 = stars_type3.transpose() tidal_binary_matrix = np.array(tidal_binary_matrix) tidal_binary_matrix = tidal_binary_matrix.transpose() self.density_trans = np.array(density_trans) self.baryondensity_trans = np.array(baryondensity_trans) self.gamma2 = np.array(gamma2) if (self.N > 0): self.tidal_binary1 = tidal_binary(1.364653646, 1.364653646, tidal_binary_matrix[2], tidal_binary_matrix[2]) self.tidal_binary2 = tidal_binary(1.243697915, 1.5, tidal_binary_matrix[1], tidal_binary_matrix[3]) self.tidal_binary3 = tidal_binary(1.049578992, 1.8, tidal_binary_matrix[0], tidal_binary_matrix[4]) tidal_binay123 = np.array( [self.tidal_binary1, self.tidal_binary2, self.tidal_binary3]) self.tidal_binary_max = tidal_binay123.max(0) self.tidal_binary_min = tidal_binay123.min(0) self.pressure2 = self.args_matrix[3] self.Maximum_mass = self.properity_matrix[2] if (len(parameter[0].args) > 7): self.pressure_trans = self.args_matrix[7] self.det_density = self.args_matrix[8] [ self.R_opf_quark, self.beta_opf_quark, self.M_binding_opf_quark, self.momentofinertia_opf_quark, self.yR_opf_quark, self.tidal_opf_quark ] = self.properity_matrix[13:19] else: self.pressure_trans = [] self.det_density = [] [ self.R_opf_quark, self.beta_opf_quark, self.M_binding_opf_quark, self.momentofinertia_opf_quark, self.yR_opf_quark, self.tidal_opf_quark ] = [[], [], [], [], [], []] [ self.R_opf_quark, self.beta_opf_quark, self.M_binding_opf_quark, self.momentofinertia_opf_quark, self.yR_opf_quark, self.tidal_opf_quark ] = [[], [], [], [], [], []] else: self.tidal_binary1 = [] self.tidal_binary2 = [] self.tidal_binary3 = [] self.tidal_binary_max = [] self.tidal_binary_min = [] self.pressure2 = [] self.pressure_trans = [] self.det_density = [] self.Maximum_mass = [] [ self.R_opf, self.beta_opf, self.M_binding_opf, self.momentofinertia_opf, self.yR_opf, self.tidal_opf ] = [[], [], [], [], [], []] [ self.R_opf_quark, self.beta_opf_quark, self.M_binding_opf_quark, self.momentofinertia_opf_quark, self.yR_opf_quark, self.tidal_opf_quark ] = [[], [], [], [], [], []]
lower_bound_pc = [] baryon_density1 = 1.85 * 0.16 baryon_density2 = 3.2 * 0.16 pressure1 = 30 pressure2 = causality_p2(pressure1) Preset_Pressure_final = 1e-8 Preset_rtol = 1e-6 pressure3 = opt.newton(caulality_central_pressure_at_peak, trial_p3(pressure1, pressure2), tol=0.1, args=(pressure1, pressure2, Preset_Pressure_final, Preset_rtol)) upper_bound_eos.append( EOS_BPSwithPoly([ baryon_density0, pressure1, baryon_density1, pressure2, baryon_density2, pressure3, baryon_density3 ])) upper_bound_pc.append( Maxmass(Preset_Pressure_final, 1e-4, upper_bound_eos[-1])[1]) print upper_bound_eos[-1].args pressure1 = 8.4 pressure2, pressure3, pressure_center = p2p3_ofmaxmass(2.0, Maxmass, Preset_Pressure_final, Preset_rtol, pressure1) lower_bound_eos.append( EOS_BPSwithPoly([ baryon_density0, pressure1, baryon_density1, pressure2, baryon_density2, pressure3, baryon_density3 ])) lower_bound_pc.append( Maxmass(Preset_Pressure_final, 1e-4, lower_bound_eos[-1])[1])
def causality_p3(p1,p2): p3=opt.newton(causality_center,p2*6.5,tol=1e-1,args=(p1,p2)) a=EOS_BPSwithPoly([baryon_density0,p1,baryon_density1,p2,baryon_density2,p3,baryon_density3]) pc_max=Maxmass(Preset_Pressure_final,Preset_rtol,a)[1] return p3,pc_max
mass_rand = [] for i in range(np.shape(ijk_rand)[0]): for j in range(np.shape(ijk_rand)[1]): for k in range(np.shape(ijk_rand)[2]): mass_rand.append(1 + np.min([maxmass_result[i][j][k][1] - 1, 1]) * np.random.rand()) p1, p2, p3 = get_p1p2p3(*ijk_rand[i, j, k]) print ijk_rand[i, j, k] print p1, p2, p3, mass_rand[-1] log_lambda_exact.append( np.log( Properity_ofmass( mass_rand[-1], 10, maxmass_result[i][j][k][0], MassRadius, Preset_Pressure_final, Preset_rtol, 1, EOS_BPSwithPoly([ baryon_density0, p1, baryon_density1, p2, baryon_density2, p3, baryon_density3 ]))[-1])) log_lambda_int.append( log_Lambda_mass_grid_int([ ijk_rand[i, j, k, 0], ijk_rand[i, j, k, 1], ijk_rand[i, j, k, 2], mass_rand[-1] ])[0]) print(log_lambda_exact[-1], log_lambda_int[-1]) log_lambda_exact = np.array(log_lambda_exact) log_lambda_int = np.array(log_lambda_int) mass_rand = np.array(mass_rand) import matplotlib.pyplot as plt plt.plot(mass_rand, (log_lambda_int - log_lambda_exact) / log_lambda_exact) #log_Lambda_mass_grid=[]
gamma3_max=1+density2/p2[i][j] p3_max= p2[i][j]*(baryon_density3/baryon_density2)**gamma3_max p3[i][j]=np.exp(np.linspace(np.log(np.max([1.2*p2[i][j],250])),np.log(p3_max),N3)) eos=[] p1p2p3=[] for i in range(N1): eos.append([]) p1p2p3.append([]) for j in range(N2): eos[i].append([]) p1p2p3[i].append([]) for k in range(N3): eos[i][j].append([]) eos[i][j][k].append(EOS_BPSwithPoly([baryon_density0,p1[i],baryon_density1,p2[i][j],baryon_density2,p3[i][j][k],baryon_density3])) p1p2p3[i][j].append([]) p1p2p3[i][j][k].append([p1[i],p2[i][j],p3[i][j][k]]) from Parallel_process import main_parallel import cPickle dir_name='Lambda_hadronic_calculation' f_file=open('./'+dir_name+'/Lambda_hadronic_calculation_p1p2p3_eos.dat','wb') cPickle.dump([p1p2p3,eos],f_file) f_file.close() f_file=open('./'+dir_name+'/Lambda_hadronic_calculation_p1p2p3_eos.dat','rb') p1p2p3,eos=np.array(cPickle.load(f_file)) f_file.close() eos_flat=np.array(eos).flatten() p1p2p3_flat=np.array(p1p2p3).flatten()