def return_structure(r, theta, phi, bs, pot_range, le, chi_interp, S_interp, I_interp, arg, scale): if r[0] == 0.0 and r[1] == 0.0 and r[2] == 0.0: pot = le['pot_max'] else: pot = potentials.compute_diffrot_potential(r, pot_range[0], bs, scale) if pot > le['pot_max']: pot = le['pot_max'] if np.round(pot, 14) < np.round(pot_range[0], 14): return pot, 0., 0., 0. elif pot <= pot_range[1]: if pot < pot_range[0]: pot = pot_range[0] return pot, float(chi_interp( (pot, theta, phi))), float(S_interp( (pot, theta, phi))), float(I_interp[arg]((pot, theta, phi))) # return pot, float(chi_interp(pot)), float(S_interp(pot)), float(I_interp[arg](pot)) else: T = le['Tc'] * le['theta_interp_func'](1. / pot) rho = le['rhoc'] * le['theta_interp_func'](1. / pot)**le['n'] rho_cgs = (rho * const.M_sun / (const.R_sun)**3).value * 1e-3 opac_si = polytropes.opal_sun(T, rho_cgs)[0] # this opac is in m^2/kg opac = (opac_si * const.M_sun / const.R_sun**2).value S = (stefb / const.L_sun.value * const.R_sun.value**2) * T**4 return pot, opac * rho, S, S
def conserve_energy(self, I_new, points): J = np.zeros(len(points)) I_em = np.zeros(len(points)) F = np.zeros(len(points)) T = np.zeros(len(points)) chi = np.zeros(len(points)) # rhos = np.load(self.directory + 'rho.npy') rhos = self.mesh['rhos'] ws = self.sc_params['ws'] for i, indx in enumerate(points): J[i] = np.sum(ws * I_new[i]) cond_out = self.sc_params['thetas'] <= np.pi / 2 cond_in = self.sc_params['thetas'] >= np.pi / 2 #I_em[i] = 0.5*np.pi*np.sum(ws[cond_out] * I_new[i][cond_out]) F[i] = 4*np.pi*np.sum(ws[cond_out]*I_new[i][cond_out]*np.cos(self.sc_params['thetas'][cond_out])) - \ 4*np.pi*np.sum(ws[cond_in]*I_new[i][cond_in]*np.cos(self.sc_params['thetas'][cond_in])) rho = rhos[indx] T[i] = self.teff * (F[i] / self.flux)**0.25 rho_cgs = (rho * const.M_sun / (const.R_sun)**3).value * 1e-3 opac_si = polytropes.opal_sun(T[i], rho_cgs)[0] # this opac is in m^2/kg opac_new = (opac_si * const.M_sun / const.R_sun**2).value chi[i] = opac_new * rho return J, T, chi
def return_structure(r,theta,phi,q,nekmin,angle_breaks,pot_range,les,chis_interp,Ss_interp,Is_interp,arg,scale,r0_scales): if np.all(r == 0.0): pot = les[0]['pots_max'] T = les[0]['Tc'] rho = les[0]['rhoc'] rho_cgs = (rho * const.M_sun / (const.R_sun) ** 3).value * 1e-3 opac_si = polytropes.opal_sun(T, rho_cgs)[0] # this opac is in m^2/kg opac = (opac_si * const.M_sun / const.R_sun ** 2).value S = (stefb / const.L_sun.value * const.R_sun.value ** 2) * T ** 4 return pot, opac * rho, S, S else: # r_abs = np.sqrt(r[0] ** 2 + r[1] ** 2 + r[2] ** 2) if r[0] <= nekmin: comp = 0 pot = potentials.BinaryRoche(r / scale, q) le = les[0] r0_scale = r0_scales[0] chi_interp = chis_interp[0] S_interp = Ss_interp[0] I_interp = Is_interp[0] breaks = angle_breaks[0] pot_limits = np.array(pot_range).copy() q_compute=q else: comp = 1 rnew = r.copy() rnew[0] = scale - rnew[0] pot = potentials.BinaryRoche(rnew / scale, 1. / q) theta = np.arccos(rnew[2] / np.sqrt(np.sum(rnew ** 2))) phi = np.abs(np.arctan2(rnew[1] / np.sqrt(np.sum(rnew ** 2)), rnew[0] / np.sqrt(np.sum(rnew ** 2)))) if theta > np.pi / 2: theta = rot_theta(theta) le = les[1] r0_scale = r0_scales[1] chi_interp = chis_interp[1] S_interp = Ss_interp[1] I_interp = Is_interp[1] breaks = angle_breaks[1] # pot_limits = np.array([float(pot_range[0] / q + 0.5 * (q - 1) / q), float(pot_range[1] / q + 0.5 * (q - 1) / q)]) pot_limits = np.array(pot_range).copy()/q + 0.5 * (q - 1) / q # pot_range[0] = pot_range[0] / q + 0.5 * (q - 1) / q # pot_range[1] = pot_range[1] / q + 0.5 * (q - 1) / q # print 'secondary pot_range:', pot_limits q_compute = 1./q chi, S, I = return_values(pot,theta,phi,arg,le,r0_scale,q_compute,pot_limits,breaks,chi_interp,S_interp,I_interp) if comp == 0: return pot, chi, S, I elif comp ==1: q = 1./q return pot * q - 0.5 * (q - 1), chi, S, I
def return_le(pot,le,r0_scale,q): T = le['Tc'] * le['theta_interp_func'](r0_scale / (pot - q)) rho = le['rhoc'] * le['theta_interp_func'](r0_scale / (pot - q)) ** le['n'] rho_cgs = (rho * const.M_sun / (const.R_sun) ** 3).value * 1e-3 opac_si = polytropes.opal_sun(T, rho_cgs)[0] # this opac is in m^2/kg opac = (opac_si * const.M_sun / const.R_sun ** 2).value S = (stefb / const.L_sun.value * const.R_sun.value ** 2) * T ** 4 return opac * rho, S
def structure_per_point(self, pot, theta_pot): T = self.le['Tc'] * theta_pot rho = self.le['rhoc'] * theta_pot**self.polytropic_index rho_cgs = (rho * const.M_sun / (const.R_sun)**3).value * 1e-3 opac_si = polytropes.opal_sun(T, rho_cgs)[0] # this opac is in m^2/kg opac = (opac_si * const.M_sun / const.R_sun**2).value chi = opac * rho J = (1. / np.pi) * (stefb / const.L_sun.value * const.R_sun.value**2) * T**4 I = J return T, chi, rho, J, I
def structure_per_point(self, theta_pot, n, Tc, rhoc): T = Tc * theta_pot rho = rhoc * theta_pot**n rho_cgs = (rho * const.M_sun / (const.R_sun)**3).value * 1e-3 opac_si = polytropes.opal_sun(T, rho_cgs)[0] # this opac is in m^2/kg opac = (opac_si * const.M_sun / const.R_sun**2).value chi = opac * rho J = (1. / np.pi) * (stefb / const.L_sun.value * const.R_sun.value**2) * T**4 I = J return T, chi, rho, J, I
def conserve_energy(self, I_new, points): J = np.zeros(len(points)) I_em = np.zeros(len(points)) F = np.zeros(len(points)) T = np.zeros(len(points)) chi = np.zeros(len(points)) ws = self.sc_params['ws'] for i, indx in enumerate(points): J[i] = np.sum(ws * I_new[i]) cond_out = self.sc_params['thetas'] <= np.pi / 2 cond_in = self.sc_params['thetas'] > np.pi / 2 #I_em[i] = 0.5*np.pi*np.sum(ws[cond_out] * I_new[i][cond_out]) F[i] = 2 * np.pi *np.sum(ws[cond_out]*I_new[i][cond_out]*np.cos(self.sc_params['thetas'][cond_out])) - \ 2 * np.pi *np.sum(ws[cond_in]*I_new[i][cond_in]*np.cos(self.sc_params['thetas'][cond_in])) # F[i] = np.sum(ws[cond_out] * I_new[i][cond_out]) - np.sum(ws[cond_in] * I_new[i][cond_in]) rho = self.mesh['rhos'][indx] # T[i] = (F[i]/stefb_sol)**0.25 # T[i] = self.teff_cb * (F[i] / self.flux) ** 0.25 T[i] = (J[i] * np.pi / (stefb / const.L_sun.value * const.R_sun.value**2))**0.25 if T[i] == 0.0: chi[i] = 0.0 else: rho_cgs = (rho * const.M_sun / (const.R_sun)**3).value * 1e-3 opac_si = polytropes.opal_sun( T[i], rho_cgs)[0] # this opac is in m^2/kg opac_new = (opac_si * const.M_sun / const.R_sun**2).value chi[i] = opac_new * rho return J, T, chi