def set_optically_thin( self ): """ Set optically thin ionzation state """ # initialize a chemistry object #---------------------------------------- if self.rec_meth == 'fixed': self.fcA_H2 = np.ones(self.Nl) * self.fixed_fcA self.fcA_He2 = np.ones(self.Nl) * self.fixed_fcA self.fcA_He3 = np.ones(self.Nl) * self.fixed_fcA else: self.fcA_H2 = np.ones(self.Nl) self.fcA_He2 = np.ones(self.Nl) self.fcA_He3 = np.ones(self.Nl) kchem = chemistry.ChemistryRates( self.T, self.fcA_H2, self.fcA_He2, self.fcA_He3, H1i = np.ones(self.Nl) * self.rad_src.thin.H1i, He1i = np.ones(self.Nl) * self.rad_src.thin.He1i, He2i = np.ones(self.Nl) * self.rad_src.thin.He2i, fit_name = self.atomic_fit_name, ) kcool = cooling.CoolingRates( self.T, self.fcA_H2, self.fcA_He2, self.fcA_He3, H1h = np.ones(self.Nl) * self.rad_src.thin.H1h, He1h = np.ones(self.Nl) * self.rad_src.thin.He1h, He2h = np.ones(self.Nl) * self.rad_src.thin.He2h, fit_name = self.atomic_fit_name, ) if self.find_Teq: x = ozn.Solve_PCTE( self.nH, self.nHe, kchem, kcool, self.z, self.tol ) self.T = x.Teq else: x = ozn.Solve_PCE( self.nH, self.nHe, kchem, self.tol ) self.xH1 = x.H1 self.xH2 = x.H2 self.xHe1 = x.He1 self.xHe2 = x.He2 self.xHe3 = x.He3 # summarize #---------------------------------------- self.dNH1 = self.dNH * self.xH1 self.dNHe1 = self.dNHe * self.xHe1 self.dNHe2 = self.dNHe * self.xHe2 self.dtauH1_th = self.dNH1 * self.rad_src.th.sigma_H1 self.dtauHe1_th = self.dNHe1 * self.rad_src.th.sigma_He1 self.dtauHe2_th = self.dNHe2 * self.rad_src.th.sigma_He2 self.ne = self.xH2 * self.nH + \ ( self.xHe2 + 2.0 * self.xHe3 ) * self.nHe
def sweep_sphere(self): """ Performs one sweep through sphere. """ for i in xrange(self.Nl): if self.verbose: print 'i = ', i # calc tauXX above and below this layer # (constant during iterations) #---------------------------------------- self.set_taus(i) # set fcA #---------------------------------------- self.fcA_H2 = np.ones(self.Nl) * self.fixed_fcA self.fcA_He2 = np.ones(self.Nl) * self.fixed_fcA self.fcA_He3 = np.ones(self.Nl) * self.fixed_fcA # iterate until we have convergence in the optical # depth through this layer #-------------------------------------------------- conv_old = self.dtauH1_th[i] + \ self.dtauHe1_th[i] + self.dtauHe2_th[i] not_converged = True itr = 0 while not_converged: # calculate photoion / chemistry rates #---------------------------------------- self.set_photoion_rates(i) self.kchem.set(self.T[i], self.fcA_H2[i], self.fcA_He2[i], self.fcA_He3[i], H1i=self.H1i[i], He1i=self.He1i[i], He2i=self.He2i[i]) # calculate photoheat / cooling rates #---------------------------------------- self.set_photoheat_rates(i) self.kcool.set(self.T[i], self.fcA_H2[i], self.fcA_He2[i], self.fcA_He3[i], H1h=self.H1h[i], He1h=self.He1h[i], He2h=self.He2h[i]) # if we are finding the equilibrium temperature # we need to call IonTemp_Eq #---------------------------------------- if self.find_Teq: x = ozn.Solve_PCTE( np.ones(1) * self.nH[i], np.ones(1) * self.nHe[i], self.kchem, self.kcool, self.z, self.tol) self.T[i] = x.Teq # otherwise we call Ion_Eq #---------------------------------------- else: x = ozn.Solve_PCE( np.ones(1) * self.nH[i], np.ones(1) * self.nHe[i], self.kchem, self.tol) # set the ionization fraction in the object #---------------------------------------- self.xH1[i] = x.H1 self.xH2[i] = x.H2 self.xHe1[i] = x.He1 self.xHe2[i] = x.He2 self.xHe3[i] = x.He3 # calculate heating rates in layer #---------------------------------------- self.heatH1[i] = self.H1h[i] * self.nH[i] * self.xH1[i] self.heatHe1[i] = self.He1h[i] * self.nHe[i] * self.xHe1[i] self.heatHe2[i] = self.He2h[i] * self.nHe[i] * self.xHe2[i] self.heat[i] = self.heatH1[i] + \ self.heatHe1[i] + self.heatHe2[i] # calculate electron density in layer #---------------------------------------- self.ne[i] = self.xH2[i] * self.nH[i] + \ ( self.xHe2[i] + 2 * self.xHe3[i] ) * self.nHe[i] # calculate tauXX through layer #---------------------------------------- self.dNH1[i] = self.dNH[i] * self.xH1[i] self.dNHe1[i] = self.dNHe[i] * self.xHe1[i] self.dNHe2[i] = self.dNHe[i] * self.xHe2[i] self.dtauH1_th[i] = self.dNH1[i] * self.rad_src.th.sigma_H1 self.dtauHe1_th[i] = self.dNHe1[i] * self.rad_src.th.sigma_He1 self.dtauHe2_th[i] = self.dNHe2[i] * self.rad_src.th.sigma_He2 # check convergence #---------------------------------------- conv_new = self.dtauH1_th[i] + \ self.dtauHe1_th[i] + self.dtauHe2_th[i] if np.abs(conv_new / conv_old - 1.0) < self.tol: not_converged = False conv_old = conv_new itr += 1
def set_optically_thin(self): """ Set optically thin ionzation state at input temperature. Adjustments will be made during the sweeps. """ # initialize a chemistry object #---------------------------------------- fcA_H2 = self.fixed_fcA fcA_He2 = self.fixed_fcA fcA_He3 = self.fixed_fcA kchem = chemistry.ChemistryRates( self.T[0], fcA_H2, fcA_He2, fcA_He3, H1i=self.rad_src.thin.H1i(self.r_c[0]), He1i=self.rad_src.thin.He1i(self.r_c[0]), He2i=self.rad_src.thin.He2i(self.r_c[0]), fit_name=self.atomic_fit_name, ) kcool = cooling.CoolingRates( self.T[0], fcA_H2, fcA_He2, fcA_He3, H1h=self.rad_src.thin.H1h(self.r_c[0]), He1h=self.rad_src.thin.He1h(self.r_c[0]), He2h=self.rad_src.thin.He2h(self.r_c[0]), fit_name=self.atomic_fit_name, ) # loop through layers and set x #---------------------------------------- for i in range(self.Nl): H1i = self.rad_src.thin.H1i(self.r_c[i]) He1i = self.rad_src.thin.He1i(self.r_c[i]) He2i = self.rad_src.thin.He2i(self.r_c[i]) kchem.set(self.T[i], fcA_H2, fcA_He2, fcA_He3, H1i=H1i, He1i=He1i, He2i=He2i) H1h = self.rad_src.thin.H1h(self.r_c[i]) He1h = self.rad_src.thin.He1h(self.r_c[i]) He2h = self.rad_src.thin.He2h(self.r_c[i]) kcool.set(self.T[i], fcA_H2, fcA_He2, fcA_He3, H1h=H1h, He1h=He1h, He2h=He2h) if self.find_Teq: x = ozn.Solve_PCTE(self.nH[i], self.nHe[i], kchem, kcool, self.z, self.tol) self.T[i] = x.Teq else: x = ozn.Solve_PCE(self.nH[i], self.nHe[i], kchem, self.tol) self.xH1[i] = x.H1 self.xH2[i] = x.H2 self.xHe1[i] = x.He1 self.xHe2[i] = x.He2 self.xHe3[i] = x.He3 # summarize #---------------------------------------- self.dNH1 = self.dNH * self.xH1 self.dNHe1 = self.dNHe * self.xHe1 self.dNHe2 = self.dNHe * self.xHe2 self.dtauH1_th = self.dNH1 * self.rad_src.th.sigma_H1 self.dtauHe1_th = self.dNHe1 * self.rad_src.th.sigma_He1 self.dtauHe2_th = self.dNHe2 * self.rad_src.th.sigma_He2 self.ne = self.xH2 * self.nH + \ ( self.xHe2 + 2 * self.xHe3 ) * self.nHe