def deriv(rm_vector, enthalpy, eos): ''' The TOV equations in terms of pseudoenthalpy. Derivatives of vector (radius, mass) as a function of enthalpy for given eos.''' (rad, mass) = rm_vector drdenth = - rad * (rad - 2 * mass) \ / (mass + 4 * np.pi * rad **3 * eos.pressure(enthalpy)*Gcc) dmdenth = 4 * np.pi * eos.energy(enthalpy) * Gcc * rad**2 * drdenth return np.array([drdenth, dmdenth])
def deriv(rm_vector, enthalpy, eos): ''' The TOV equations in terms of pseudoenthalpy. Derivatives of vector (radius, mass) as a function of enthalpy for given eos.''' (rad, mass) = rm_vector drdenth = - rad * (rad - 2 * mass) \ / (mass + 4 * np.pi * rad **3 * eos.pressure(enthalpy)*Gcc) dmdenth = 4 * np.pi * eos.energy(enthalpy)*Gcc * rad **2 * drdenth return np.array([drdenth,dmdenth])
def rotderiv(rm_vector, enthalpy, eos): ''' The TOV equations augmented for a linearly perturbed, slowly rotating neutron star. Also includes rest mass of star.''' (rad, mass, restmass, alpha, omega) = rm_vector pr = eos.pressure(enthalpy) * Gcc en = eos.energy(enthalpy) * Gcc rho = eos.density(enthalpy)**Gcc factor = rad - 2 * mass coef = 4.0 * np.pi drdenth = -rad * factor / (mass + coef * rad**3 * pr) dmdenth = coef * en * rad**2 * drdenth dmadenth = coef * rho * rad**2 * drdenth / (factor / rad)**0.5 domega = alpha * drdenth dalpha = drdenth * (- 4.0 * alpha / rad \ + coef * rad * (pr + en) * (4.0 * omega + rad * alpha ) / factor ) return np.array([drdenth, dmdenth, dmadenth, dalpha, domega])
def rotderiv(rm_vector, enthalpy, eos): ''' The TOV equations augmented for a linearly perturbed, slowly rotating neutron star. Also includes rest mass of star.''' (rad, mass, restmass, alpha, omega) = rm_vector pr = eos.pressure(enthalpy) * Gcc en = eos.energy(enthalpy) * Gcc rho = eos.density(enthalpy) ** Gcc factor = rad - 2 * mass coef = 4.0 * np.pi drdenth = - rad * factor / (mass + coef * rad**3 * pr) dmdenth = coef * en * rad**2 * drdenth dmadenth = coef * rho * rad**2 * drdenth / ( factor / rad )**0.5 domega = alpha * drdenth dalpha = drdenth * (- 4.0 * alpha / rad \ + coef * rad * (pr + en) * (4.0 * omega + rad * alpha ) / factor ) return np.array([drdenth,dmdenth, dmadenth, dalpha, domega])
def tidederiv(rm_vector, enthalpy, eos): (rad, mass, restmass, beta, h) = rm_vector pr = eos.pressure(enthalpy) * Gcc en = eos.energy(enthalpy) * Gcc func = 1.0 / eos.dprden(enthalpy) factor = rad - 2 * mass coef = 4.0 * np.pi drdenth = -rad * factor / (mass + coef * rad**3 * pr) dmdenth = coef * en * rad**2 * drdenth dbeta = 2 * drdenth *\ ( h * ( \ (- 2. * np.pi * func * rad * (pr + en))/ factor + \ (2. * mass**2 + \ rad**2 * (3.0 + 2.0 * np.pi * rad**2 * \ ( pr * (16.0 * np.pi * pr * rad**2 - 9.0 ) - 5. * en ))\ + mass * ( - 6 * rad + 4 * np.pi * rad**3 * (13 *pr + 5*en) ) )\ / rad**2 / factor**2 ) + beta / rad / factor * ( mass - rad + 2 * np.pi * rad**3 * (en - pr))) dh = beta * drdenth return np.array([drdenth, dmdenth, dbeta, dh])
def tidederiv(rm_vector, enthalpy, eos): (rad, mass, restmass, beta, h) = rm_vector pr = eos.pressure(enthalpy) * Gcc en = eos.energy(enthalpy) * Gcc func = 1.0/eos.dprden(enthalpy) factor = rad - 2 * mass coef = 4.0*np.pi drdenth = - rad * factor / (mass + coef * rad**3 * pr) dmdenth = coef * en * rad**2 * drdenth dbeta = 2 * drdenth *\ ( h * ( \ (- 2. * np.pi * func * rad * (pr + en))/ factor + \ (2. * mass**2 + \ rad**2 * (3.0 + 2.0 * np.pi * rad**2 * \ ( pr * (16.0 * np.pi * pr * rad**2 - 9.0 ) - 5. * en ))\ + mass * ( - 6 * rad + 4 * np.pi * rad**3 * (13 *pr + 5*en) ) )\ / rad**2 / factor**2 ) + beta / rad / factor * ( mass - rad + 2 * np.pi * rad**3 * (en - pr))) dh = beta * drdenth return np.array([drdenth,dmdenth, dbeta, dh])
def diff_Pr(): return eos.pressure(alpha, rho_n, self.params, order) - eos.pressure( 0.0, rho_i, self.params, order)
def find_coex(self, rho_i=0.01, rho_n=4.0, order=2, n_max=1000, tol=1e-10, updates=False): for i in range(2, order + 1): Bi = "B" + str(i) if not Bi in self.params.keys(): return "Error: function not fitted for " + Bi + ": can't find coexistence" from scipy.optimize import minimize_scalar def diff_Pr(): return eos.pressure(alpha, rho_n, self.params, order) - eos.pressure( 0.0, rho_i, self.params, order) def diff_mu(): return eos.chemical_potential(alpha, rho_n, self.params, order) - eos.chemical_potential( 0.0, rho_i, self.params, order) for i in range(n_max): alpha = (minimize_scalar(eos.free_energy, args=(rho_n, self.params, order), bounds=(-1e-10, 2e3), method='bounded')).x dPnn = eos.d_pr(alpha, rho_n, self.params, order) dPii = eos.d_pr(0.0, rho_i, self.params, order) dmnn = eos.d_mu(alpha, rho_n, self.params, order) dmii = eos.d_mu(0.0, rho_i, self.params, order) F1 = diff_Pr() F2 = diff_mu() dF11 = dPnn dF12 = -dPii dF21 = dmnn dF22 = -dmii det = dF22 * dF11 - dF12 * dF21 if updates: print('loop: ', i) print('rho_i: ', rho_i, ' delta_i:', (F2 * dF11 - F1 * dF21) / det, ' Pr_i: ', eos.pressure(0.0, rho_i, self.params, order)) print('rho_n: ', rho_n, ' delta_n:', (F1 * dF22 - F2 * dF12) / det, ' Pr_n: ', eos.pressure(alpha, rho_n, self.params, order)) print('alpha: ', alpha) print('') rho_n1 = rho_n - (F1 * dF22 - F2 * dF12) / det rho_i1 = rho_i - (F2 * dF11 - F1 * dF21) / det if (rho_n1 < 0.0) or (rho_i1 < 0.0): return 'Error: try changing the guesses rho_i and rho_n' if i > 0: if (np.absolute(rho_n1 - rho_n) / rho_n < tol) & (np.absolute(rho_i1 - rho_i) / rho_i < tol): coex = {} coex['rho_i'] = rho_i1 coex['rho_n'] = rho_n1 coex['Pr_i'] = eos.pressure(0.0, rho_i1, self.params, order) coex['Pr_n'] = eos.pressure(alpha, rho_n1, self.params, order) coex['mu_i'] = eos.chemical_potential( 0.0, rho_i1, self.params, order) coex['mu_n'] = eos.chemical_potential( alpha, rho_n1, self.params, order) coex['fe_i'] = eos.free_energy(0.0, rho_i1, self.params, order) coex['fe_n'] = eos.free_energy(alpha, rho_n1, self.params, order) coex['S2'] = eos.nematic_order(alpha) cols = [ 'rho_i', 'rho_n', 'S2', 'Pr_i', 'Pr_n', 'mu_i', 'mu_n', 'fe_i', 'fe_n' ] coex = pd.DataFrame( coex, index=np.arange(1) )[cols] # pd.DataFrame(coex, index=['B'+str(order)])[cols] self.coex.loc['B' + str(order), :] = coex.iloc[ 0, :] #pd.DataFrame(coex, index=np.arange(1))[cols] return rho_n = rho_n1 rho_i = rho_i1 return 'Did not converge: try increasing n_max'