ion.ioneqOne() # this calcuate the equilirbium abundance @ T # however this attr is not defined for fully ionized species... # fix that later, take this as 1 for now first #ion_frac = ion.IoneqOne ion_frac = 1.0 # ion.Abundance is the elemental abundance relative to hydrogen init_values[s.name] = ion_frac * init_array * ion.Abundance # in case something is negative or super small: init_values[s.name][init_values[s.name] < tiny] = tiny init_values['de'] = init_array * 0.0 init_values = ion_by_ion.convert_to_mass_density(init_values) init_values['de'] = ion_by_ion.calculate_free_electrons(init_values) init_values['density'] = ion_by_ion.calculate_total_density(init_values) number_density = ion_by_ion.calculate_number_density(init_values) # calculate ge (very crudely) gamma = 5.0/3.0 init_values['ge'] = ((temperature * number_density * kboltz) / (init_values['density'] * mh * (gamma - 1))) # Write the initial conditions file # IF you need to use the Makefile, and c-library # you will have to specified the library_path library_path = {} library_path["CVODE_PATH"] = "/home/kwoksun2/cvode-3.1.0/instdir" library_path["HDF5_PATH"] = "/home/kwoksun2/anaconda3"
init_array = np.ones(NCELLS) * density init_values = dict() init_values["H_1"] = (1 - X) * init_array init_values['H_2'] = X * init_array init_values['H_m0'] = init_array * tiny init_values['He_1'] = init_array * tiny init_values['He_2'] = init_array * tiny init_values['He_3'] = init_array * tiny init_values['H2_1'] = init_array * tiny init_values['H2_2'] = init_array * tiny init_values['de'] = init_array * 0.0 # update and calculate electron density and etc with the handy functions total_density = primordial.calculate_total_density(init_values) init_values = primordial.convert_to_mass_density(init_values) init_values['de'] = primordial.calculate_free_electrons(init_values) init_values['density'] = primordial.calculate_total_density(init_values) number_density = primordial.calculate_number_density(init_values) # set up initial temperatures values used to define ge init_values['T'] = temperature # calculate ge (very crudely, no H2 help here) gamma = 5.0 / 3.0 init_values['ge'] = ((temperature * number_density * kboltz) / (init_values['density'] * mh * (gamma - 1))) # Write the initial conditions file # IF you need to use the Makefile, and c-library # you will have to specified the library_path library_path = {}
init_array = np.ones(NCELLS) * density init_values = dict() init_values['OII'] = X * init_array init_values['OIII'] = init_array * X init_values['OIV'] = init_array * X init_values['OV'] = init_array * X init_values['OVI'] = init_array * X init_values['OVII'] = init_array * X init_values['OVIII'] = init_array * X init_values['OIX'] = init_array * X init_values['de'] = init_array * 0.0 total_density = oxygen.calculate_total_density(init_values, ("OI", )) init_values["OI"] = init_array.copy() - total_density init_values = oxygen.convert_to_mass_density(init_values) init_values['de'] = oxygen.calculate_free_electrons(init_values) init_values['density'] = oxygen.calculate_total_density(init_values) number_density = oxygen.calculate_number_density(init_values) # set up initial temperatures values used to define ge init_values['T'] = temperature # calculate ge (very crudely, no H2 help here) gamma = 5.0 / 3.0 init_values['ge'] = ((temperature * number_density * kboltz) / (init_values['density'] * mh * (gamma - 1))) # Write the initial conditions file oxygen.write_solver("oxygen", output_dir=".") import pyximport
init_values['H2O_1'] = 1.0 * init_array * (18) init_values['HOIO_1'] = 9.0e-11 * init_array * (126 + 32 + 1) init_values['IO3m_0'] = 0.01 * init_array * (1 + 16 * 3) init_values['O2_1'] = 2.5e3 * init_array * (16 * 2) init_values['CH2_COOH2_1'] = 0.0015 * init_array * (12 + 2 + (12 + 16 * 2 + 1) * 2) init_values['CHI_COOH2_1'] = 1.0e-20 * init_array * (12 + 126 + (12 + 16 * 2 + 1) * 2) init_values["H2O2_1"] = 0.33 * init_array * (2 + 16) * 2 print(new.required_species) total_density = new.calculate_total_density(init_values) init_values = new.convert_to_mass_density(init_values) init_values['de'] = new.calculate_free_electrons(init_values) init_values['density'] = init_array # new.calculate_total_density(init_values) number_density = new.calculate_number_density(init_values) # set up initial temperatures values used to define ge init_values['T'] = temperature # calculate ge (very crudely, no H2 help here) gamma = 5.0 / 3.0 init_values['ge'] = ((temperature * number_density * kboltz) / (init_values['density'] * mh * (gamma - 1))) # Write the initial conditions file # IF you need to use the Makefile, and c-library # you will have to specified the library_path library_path = {}
init_array = np.ones(NCELLS) * density init_values = dict() init_values['us_H_1'] = init_array * X init_values['us_H2_1'] = init_array * X init_values['us_e_0'] = init_array * 0.0 print(init_values) #print sorted(umist.reactions.values()) for species in umist.required_species: if species.name not in init_values: init_values[species.name] = init_array * 0.0 total_density = umist.calculate_total_density(init_values) init_values = umist.convert_to_mass_density(init_values) init_values['us_e_0'] = umist.calculate_free_electrons(init_values) init_values['density'] = umist.calculate_total_density(init_values) number_density = umist.calculate_number_density(init_values) # set up initial temperatures values used to define ge init_values['T'] = temperature # calculate ge (very crudely, no H2 help here) gamma = 5.0 / 3.0 init_values['ge'] = ((temperature * number_density * kboltz) / (init_values['density'] * mh * (gamma - 1))) print(init_values) import pdb pdb.set_trace()
if s.name == 'de': continue else: print s.name, s.number, s.free_electrons + 1 ion_name = chu.zion2name(np.int(s.number), np.int(s.free_electrons + 1)) ion = ch.ion(ion_name, temperature=init_values['T']) ion.ioneqOne() ion_frac = ion.IoneqOne init_values[s.name] = ion_frac * init_array * ion.Abundance # in case something is negative or super small: init_values[s.name][init_values[s.name] < tiny] = tiny init_values['de'] = init_array * 0.0 # total_density = combined.calculate_total_density(init_values, ("OI",)) # init_values["OI"] = init_array.copy() - total_density init_values = combined.convert_to_mass_density(init_values) init_values['de'] = combined.calculate_free_electrons(init_values) init_values['density'] = combined.calculate_total_density(init_values) number_density = combined.calculate_number_density(init_values) # calculate ge (very crudely) gamma = 5.0 / 3.0 init_values['ge'] = ((temperature * number_density * kboltz) / (init_values['density'] * mh * (gamma - 1))) # Write the initial conditions file combined.write_solver("combined", output_dir=".", init_values=init_values)
def Init_values(temperature, density, n_species=9, cooling=True): """ Create a initial value dictionary, for a given temperature, density, number of species Args: temperature -- in Kelvin density -- in amu / cm**3 n_species -- number of species (6/9) cooling Returns: init_values: initial value dictionary with self-consistent energy/ electron density primordial : chemical_network classes """ # initialize and setup the network dengo.primordial_rates.setup_primordial() primordial = ChemicalNetwork() if n_species == 9: for i in range(23): try: primordial.add_reaction("k{0:02d}".format(i + 1)) except: pass else: for i in range(6): try: primordial.add_reaction("k{0:02d}".format(i + 1)) except: pass # the temperature array required to interpolates the rates primordial.init_temperature((1e0, 1e5)) tiny = 1.0e-20 # init_array are is in fractional abundances init_values = dict() if n_species == 6: # 6-species model init_values["He_1"] = density * (1.0 - 0.76) / 2. init_values["He_2"] = density * (1.0 - 0.76) / 2. init_values["He_3"] = np.array([tiny]) init_values["H_1"] = density * (0.76) / 2. init_values['H_2'] = density * (0.76) / 2. else: # 9-species model init_values["He_1"] = density * (1.0 - 0.76) / 2.0 init_values["He_2"] = density * (1.0 - 0.76) / 2.0 init_values["He_3"] = np.array([tiny]) init_values["H_1"] = density * (0.76) / 3. init_values['H_2'] = density * (0.76) / 3. init_values["H_m0"] = np.array([tiny]) init_values["H2_1"] = density * (0.76) / 3. init_values["H2_2"] = np.array([tiny]) # now everything in mass density init_values['de'] = primordial.calculate_free_electrons(init_values) # one signle value: again mass density init_values['density'] = primordial.calculate_total_density(init_values) num_den = {} for sp in primordial.required_species: try: num_den[sp.name] = init_values[sp.name] / sp.weight except: pass # set up initial temperatures values used to define ge init_values['T'] = temperature # calculate gammaH2 x = 6100.0 / temperature gammaH2 = 2.0 / (5.0 + 2.0 * x * x / (numpy.exp(x) - 1)**2.0) + 1 gamma_factor = primordial.gamma_factor().subs(num_den).subs({ 'gammaH2': gammaH2, 'gamma': 5. / 3., 'T': temperature }) ge = ((temperature * kboltz) * gamma_factor / (init_values['density'] * mh)) T = init_values['density'] * ge * mh / kboltz / gamma_factor print("difference in temperature:", T - temperature) init_values['ge'] = numpy.array([numpy.float64(ge)]) if cooling: for cooling_action in cooling_registry: k = cooling_registry[cooling_action] if (k.species).issubset(primordial.required_species): if k.name != "cie_cooling": print("adding:", k.name, k.equation) primordial.add_cooling(cooling_action) print('---------------------------') return init_values, primordial