def setup_predator_prey_network(): setup_predator_prey_rates() cN = ChemicalNetwork() cN.add_reaction("exp_growth_prey") cN.add_reaction("predation") cN.add_reaction("natural_death_predator") # this shouldnt be compulsory... cN.init_temperature((1e0, 1e8)) return cN
def __init__(self): primordial_simplified = ChemicalNetwork() primordial_simplified.add_reaction("k01") primordial_simplified.add_reaction("k22") primordial_simplified.add_cooling("h2formation") primordial_simplified.add_cooling("gloverabel08") self.network = primordial_simplified self.solution = TestChemicalNetworkSolution()
from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.primordial_rates, dengo.primordial_cooling from dengo.chemistry_constants import tiny, kboltz, mh # from dengo.known_species import * # If only a subset of species are wanted put them here # and change the commented lines below want = ("HI", "HII", "de", "ge") primordial = ChemicalNetwork() #primordial.add_energy_term() # Set to false if intermediate solution output is not wanted primordial.write_intermediate_solutions = True #for ca in cooling_registry.values(): #if not all(sp.name in want for sp in ca.species): continue # primordial.add_cooling(ca) for i, rname in enumerate(sorted(reaction_registry)): s = reaction_registry[rname] #if not all(sp.name in want for sp in s.species): continue primordial.add_reaction(s) # This defines the temperature range for the rate tables primordial.init_temperature((1e0, 1e8)) # Generate initial conditions (switch to False to disable this)
from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.primordial_rates, dengo.primordial_cooling import dengo.oxygen_rates, dengo.oxygen_cooling from dengo.chemistry_constants import tiny, kboltz, mh from dengo.known_species import * NCELLS = 4 density = 1.0 temperature = np.logspace(4, 6.7, NCELLS) temperature[:] = 1e7 X = 1e-3 oxygen = ChemicalNetwork() oxygen.add_energy_term() for ca in cooling_registry.values(): if ca.name.startswith("O"): oxygen.add_cooling(ca) for s in reaction_registry.values(): if s.name.startswith("O"): oxygen.add_reaction(s) # This defines the temperature range for the rate tables oxygen.init_temperature((1e0, 1e8)) tiny = 1e-10
from dengo.chemical_network import ChemicalNetwork, reaction_registry import dengo.primordial_rates primordial = ChemicalNetwork() for i in range(23): n = "k%02i" % (i+1) if n in reaction_registry: primordial.add_reaction(n) print "These species are required:" print "\n".join([s.name for s in sorted(primordial.required_species)]) for species in primordial.required_species: print "Querying: ", species for rxn in primordial.species_reactions(species): print " ", rxn for rxn in primordial: write_reaction(rxn) for species in primordial.required_species: write_species_deriv(species, primordial.species_reactions(species))
cooling_registry import dengo.new_rates from dengo.chemistry_constants import tiny, kboltz, mh #from dengo.known_species import * import os os.environ["HDF5_DIR"] = "/home/kwoksun2/anaconda3" NCELLS = 1 density = 1e0 temperature = np.logspace(2, 4, NCELLS) temperature[:] = 2e3 X = 0.5 dengo.new_rates.setup_new() new = ChemicalNetwork() new.add_reaction("I01") new.add_reaction("I01_re") new.add_reaction("I02") new.add_reaction("I03") new.add_reaction("I04") new.add_reaction("I05") new.add_reaction("C05") new.add_reaction("D01") # This defines the temperature range for the rate tables new.init_temperature((1e0, 1e8)) init_array = np.ones(NCELLS) * density init_values = dict() init_values["HOI_1"] = 8.0e-11 * init_array * (200)
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
from dengo.ion_by_ion import setup_ionization from dengo.chemistry_constants import tiny, kboltz, mh import numpy as np from dengo.reaction_classes import AtomicSpecies import os os.environ["HDF5_DIR"] = '/home/kwoksun2/anaconda3' NCELLS = 1 density = 1.0 #* 1.67e-24 temperature = np.logspace(2, 8, NCELLS) temperature[:] = 5e6 X = 1e-8 ion_by_ion = ChemicalNetwork(write_intermediate = False, stop_time = 3.1557e13) HI = AtomicSpecies("H", 0.0) HII = AtomicSpecies("H", 1.0) HeI = AtomicSpecies("He", 0.0) HeII = AtomicSpecies("He", 1.0) de = species_registry['de'] ion_by_ion.add_species(de) ion_by_ion.add_species(HI) ion_by_ion.add_species(HII) ion_by_ion.add_species(HeI) ion_by_ion.add_species(HeII) #ion_by_ion.add_species('O_1') #ion_by_ion.add_species('O_2') #ion_by_ion.add_species('O_3') #ion_by_ion.add_species('O_4')
from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.primordial_rates, dengo.primordial_cooling from dengo.chemistry_constants import tiny, kboltz, mh NCELLS = 4 density = 1e7 temperature = np.logspace(2, 4, NCELLS) temperature[:] = 2e3 X = 0.5 dengo.primordial_rates.setup_primordial() primordial = ChemicalNetwork() primordial.add_reaction("k01") primordial.add_reaction("k02") # This defines the temperature range for the rate tables primordial.init_temperature((1e0, 1e8)) tiny = 1e-10 init_array = np.ones(NCELLS) * density init_values = dict() init_values['HII'] = X * init_array init_values['de'] = init_array * 0.0 #total_density = primordial.calculate_total_density(init_values, ("HI",))
import numpy as np from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.primordial_rates, dengo.primordial_cooling from dengo.chemistry_constants import tiny, kboltz, mh from dengo.known_species import * NCELLS = 4 density = 1e7 temperature = np.logspace(2, 4, NCELLS) temperature[:] = 2e3 X = 0.5 primordial = ChemicalNetwork() primordial.add_energy_term() primordial.add_cooling("brem") primordial.add_cooling("reHII") primordial.add_cooling("reHeIII") primordial.add_cooling("gloverabel08") primordial.add_cooling("ceHI") primordial.add_cooling("h2formation") primordial.add_cooling("reHeII2") primordial.add_cooling("reHeII1") primordial.add_cooling("ciHeIS") primordial.add_cooling("ceHeII") primordial.add_cooling("ciHI") primordial.add_cooling("ceHeI") primordial.add_cooling("gammah")
import dengo.nitrogen_rates, dengo.nitrogen_cooling import dengo.oxygen_rates, dengo.oxygen_cooling import dengo.neon_rates, dengo.neon_cooling import dengo.magnesium_rates, dengo.magnesium_cooling import dengo.silicon_rates, dengo.silicon_cooling import dengo.sulfur_rates, dengo.sulfur_cooling from dengo.chemistry_constants import tiny, kboltz, mh import numpy as np NCELLS = 1 density = 1.0 temperature = np.logspace(4, 6.7, NCELLS) temperature[:] = 5e6 X = 1e-3 combined = ChemicalNetwork() combined.add_energy_term() for ca in cooling_registry.values(): if ca.name.startswith("C") \ or ca.name.startswith("N") \ or ca.name.startswith("O") \ or ca.name.startswith("Ne") \ or ca.name.startswith("Mg") \ or ca.name.startswith("Si") \ or ca.name.startswith("S"): combined.add_cooling(ca) combined.add_cooling("brem") combined.add_cooling("reHII") combined.add_cooling("reHeIII")
from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry from dengo.reaction_classes import index_i, count_m import dengo.primordial_rates, dengo.primordial_cooling import dengo.oxygen_rates, dengo.oxygen_cooling from dengo.write_rate_reader import create_rate_tables, create_rate_reader import sympy from sympy.printing import print_ccode oxygen = ChemicalNetwork() for ca in cooling_registry.values(): if ca.name.startswith("o_"): oxygen.add_cooling(ca) print "These species are required for cooling alone:" print "\n".join([s.name for s in sorted(oxygen.required_species)]) for s in reaction_registry.values(): if s.name.startswith("o_"): oxygen.add_reaction(s) print "These species are required for chemistry and cooling:" print "\n".join([s.name for s in sorted(oxygen.required_species)]) functions = [] cooling = sum(v.equation for n, v in sorted(oxygen.cooling_actions.items())) for species in oxygen.required_species:
from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.primordial_rates, dengo.primordial_cooling from dengo.chemistry_constants import tiny, kboltz, mh NCELLS = 4 density = 1e7 temperature = np.logspace(2, 4, NCELLS) temperature[:] = 2e3 X = 0.75 dengo.primordial_rates.setup_primordial() primordial = ChemicalNetwork() primordial.add_reaction("k01") primordial.add_reaction("k02") primordial.add_reaction("k03") primordial.add_reaction("k04") primordial.add_reaction("k05") primordial.add_reaction("k06") # This defines the temperature range for the rate tables primordial.init_temperature((1e0, 1e8)) tiny = 1e-10 init_array = np.ones(NCELLS) * density init_values = dict()
def setup_network(): """Initial a ChemicalNetwork object for primordial network 9-species model Return: primordial: ChemicalNetwork with primordial reactions and cooling """ # this register all the rates specified in `primordial_rates.py` dengo.primordial_rates.setup_primordial() # initialize the chmical network object primordial = ChemicalNetwork() # add all the reactions primordial.add_reaction("k01") primordial.add_reaction("k02") primordial.add_reaction("k03") primordial.add_reaction("k04") primordial.add_reaction("k05") primordial.add_reaction("k06") primordial.add_reaction("k07") primordial.add_reaction("k08") primordial.add_reaction("k09") primordial.add_reaction("k10") primordial.add_reaction("k11") primordial.add_reaction("k12") primordial.add_reaction("k13") primordial.add_reaction("k14") primordial.add_reaction("k15") primordial.add_reaction("k16") primordial.add_reaction("k17") primordial.add_reaction("k18") primordial.add_reaction("k19") primordial.add_reaction("k21") primordial.add_reaction("k22") primordial.add_reaction("k23") primordial.add_cooling("brem") primordial.add_cooling("reHII") primordial.add_cooling("reHeIII") primordial.add_cooling("gloverabel08") primordial.add_cooling("ceHI") primordial.add_cooling("h2formation") primordial.add_cooling("h2formation_extra") primordial.add_cooling("reHeII2") primordial.add_cooling("reHeII1") primordial.add_cooling("ciHeIS") primordial.add_cooling("ceHeII") primordial.add_cooling("ciHI") primordial.add_cooling("ceHeI") primordial.add_cooling("gammah") primordial.add_cooling("ciHeI") primordial.add_cooling("ciHeII") primordial.add_cooling("cie_cooling") primordial.add_cooling("compton") # This defines the temperature range for the rate tables primordial.init_temperature((1e0, 1e8)) primordial.enforce_conservation = True return primordial
ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.primordial_rates, dengo.primordial_cooling import dengo.carbon_rates, dengo.carbon_cooling from dengo.write_rate_reader import \ create_rate_tables, \ create_rate_reader, \ create_initial_conditions from dengo.chemistry_constants import tiny, kboltz, mh # If only a subset of species are wanted put them here # and change the commented lines below want = ('CIII', 'CIV', 'CV', 'de', 'ge') carbon = ChemicalNetwork() carbon.add_energy_term() # for ca in cooling_registry.values(): # # The following line can be used to specify a subset of species # #if all(sp.name in want for sp in ca.species): # if ca.name.startswith("C"): # carbon.add_cooling(ca) for s in reaction_registry.values(): # The following line can be used to specify a subset of species #if all(sp.name in want for sp in s.species): if s.name.startswith("C"): carbon.add_reaction(s) # This defines the temperature range for the rate tables
ChemicalNetwork, \ reaction_registry, \ cooling_registry from dengo.primordial_rates import setup_primordial import dengo.primordial_cooling from dengo.ion_by_ion import setup_ionization from dengo.chemistry_constants import tiny, kboltz, mh import numpy as np NCELLS = 1 density = 1e-3 * 1.67e-24 temperature = np.logspace(4, 6.7, NCELLS) temperature[:] = 5e6 X = 1e-3 ion_by_ion = ChemicalNetwork(write_intermediate=False, stop_time=3.1557e13) ion_by_ion.add_species("de") #for atom in ["O", "C", "Si", "Mg", "N", "S", "He", "Ne", "H"]: for atom in ["H", "O", "He"]: s, c, r = setup_ionization(atom) ion_by_ion.add_collection(s, c, r) #ion_by_ion.add_collection(s, [], r) # ion_by_ion.add_cooling('compton') #s, c, r = setup_primordial() #ion_by_ion.add_collection(s, c, r) # This defines the temperature range for the rate tables ion_by_ion.init_temperature((1e0, 1e12))
import numpy as np from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry import dengo.umist_rates from dengo.get_rates import setup_umist_species, setup_umist_reactions from dengo.chemistry_constants import tiny, kboltz, mh NCELLS = 4 density = 1.0 temperature = np.logspace(1, 3, NCELLS) temperature[:] = 1e2 X = 1e-3 umist = ChemicalNetwork() umist.skip_weight += ("us_e_0", ) # This defines the temperature range for the rate tables umist.init_temperature((1e0, 1e3)) # Get UMIST rates for a bunch of species for an example network desired_species = [("H", 1), ("H2", 2), ("e-", 1)] added_species = set([]) for name, weight in desired_species: s, c, r = setup_umist_species(name, weight) print "ADDED", s added_species.update(s) umist.add_collection(s, c, r)
import numpy as na import h5py from dengo.chemical_network import ChemicalNetwork from dengo.reaction_classes import Species, chianti_rate, reaction_registry, species_registry import dengo.primordial_rates import dengo.oxygen_rates from dengo.oxygen_cooling import cooling_rates_table, cooling_action_table oxygen_network = ChemicalNetwork() for rate in sorted(reaction_registry): if rate.startswith("o_"): oxygen_network.add_reaction(rate) print "These species are required:" print "\n".join([s.name for s in sorted(oxygen_network.required_species)]) for species in oxygen_network.required_species: print "Querying: ", species for rxn in oxygen_network.species_reactions(species): print " ", rxn for rxn in oxygen_network: write_reaction(rxn) for species in oxygen_network.required_species: print species.name write_species_deriv(species, oxygen_network.species_reactions(species)) # Define the temperature we want rate values for Tlog_bounds = (1, 9)
reaction_registry, \ cooling_registry import dengo.umist_rates from dengo.get_rates import setup_umist_species, setup_umist_reactions from dengo.chemistry_constants import tiny, kboltz, mh import os os.environ['HDF5_DIR'] = '/home/kwoksun2/anaconda2/' NCELLS = 1 density = 1.0e0 temperature = np.logspace(1, 3, NCELLS) temperature[:] = 1e3 X = 1e-2 umist = ChemicalNetwork() umist.skip_weight += ("us_e_0", ) # This defines the temperature range for the rate tables umist.init_temperature((1e0, 1e3)) # Get UMIST rates for a bunch of species for an example network desired_species = [("H", 1), ("H2", 2), ("e-", 1)] added_species = set([]) for name, weight in desired_species: s, c, r = setup_umist_species(name, weight) print("ADDED", s) added_species.update(s) umist.add_collection(s, c, r)
cooling_registry import dengo.primordial_rates, dengo.primordial_cooling from dengo.chemistry_constants import tiny, kboltz, mh import os # this is required to compiled cython os.environ["HDF5_DIR"] = "/home/kwoksun2/anaconda3" NCELLS = 4 density = 1e12 temperature = np.logspace(2, 4, NCELLS) temperature[:] = 2e3 X = 1.0e-4 dengo.primordial_rates.setup_primordial() primordial = ChemicalNetwork() #primordial.add_energy_term() # add the neccessary cooling and reactions primordial.add_reaction("k01") primordial.add_reaction("k02") primordial.add_reaction("k03") primordial.add_reaction("k04") primordial.add_reaction("k05") primordial.add_reaction("k06") primordial.add_reaction("k07") primordial.add_reaction("k08") primordial.add_reaction("k09") primordial.add_reaction("k10") primordial.add_reaction("k11") primordial.add_reaction("k12")
from dengo.chemical_network import \ ChemicalNetwork, \ reaction_registry, \ cooling_registry from dengo.reaction_classes import index_i, count_m import dengo.primordial_rates, dengo.primordial_cooling from dengo.write_rate_reader import create_rate_tables, create_rate_reader import sympy from sympy.utilities.codegen import codegen from sympy.printing import print_ccode primordial = ChemicalNetwork() for ca in cooling_registry.values(): primordial.add_cooling(ca) print "These species are required for cooling alone:" print "\n".join([s.name for s in sorted(primordial.required_species)]) for s in reaction_registry.values(): primordial.add_reaction(s) print "These species are required for chemistry and cooling:" print "\n".join([s.name for s in sorted(primordial.required_species)]) functions = [] cooling = sum(v.equation for n, v in sorted(primordial.cooling_actions.items())) for species in primordial.required_species: print