Wiki

Clone wiki

KROME / krome_user

3.5 The krome_user module

KROME has a user-friendly fortran module to help the user with common basic operations. Including this module to your code is very simple, you just need to add

use krome_user

to the Fortran file that needs the utility function(s). This module contains not only functions, but also constant values that are related to the problem (e.g. the total number of species) and the physical constants. All the possible functions and variables are listed in the next Subsections.

3.5.1 Common variables (parameters)

Species index

The user's module contains the index of the species employed in the network. If you want to know where a given molecule is stored within the array of the abundances, you do not need to remember the corresponding number, since this value is stored here. For example H2 is krome_idx_H2, while H2O is in krome_idx_H2O. Note that ions have j instead of + (e.g. H+ is krome_idx_Hj), while anions have k instead of - (e.g. C2- is krome_idx_C2k). Note: all these variables are integer values.

KROME's arrays size

In order to work with KROME you need to know the size of some arrays, for example the one that contains the abundances of the cheimical species. The size of these arrays are stored in the following variables:

Variable description
krome_nrea number of reactions
krome_nmols number of species in the krome array (i.e. the real number of species)
krome_nspec number of species in the krome internal array (for developers only!)
krome_ndust number dust bins per dust type (so, the total number is ndust*ndustTypes)
krome_ndustTypes number of dust types (e.g. if C- and Si-based then ndustTypes=2)

Note: these variables are integer values.

Physical constants

KROME contains a large number of physical constants. For example krome_boltzmann_erg is the Boltzmann constat in erg/K. For a complete list take look into the krome_user.f90 file. Note: all these variables are double values (real*8).

3.5.2 Utility functions

The functions included in the user's module are listed in this section. As this module is in continuous development we suggest the users to run the script list_user_functions.py which is provided in the buildfolder after the execution of KROME. The script will provide a complete list of all the available functions with a short description where available. Note also that the functions and subroutines stored in the module depend on the options employed, e.g. the photochemistry functions are only displayed when photochemistry is active. For this reason we again encourage to use list_user_functions.py.

krome_get_gamma_x(x(:), Tgas)

Returns the adiabatic index (gamma) as a real*8 value. Arguments are: an array (size krome_nmols) that contains the mass fractions of the species (real*8), and the gas temperature in K. The way in which this function computes gamma depends on what -gamma option you have used (if any).

krome_consistent_x(x(:))

This is a subroutine that normalizes the array x(:) (size krome_nmols) which contains the mass fractions of the species (real*8), and balances the total charge to zero by modifying electron abundance. It also contains a conservation check (not enabled by default) that verify that you are not too far from the normalization. Uncomment the source if you want this additional control.

krome_n2x(n(:),rhogas)

Convert from number densities to mass fractions. Returns an array (real*8, size krome_nmols) with the mass fractions. Arguments: n(:) is an array (real*8, size krome_nmols) containing the number densities of the species, while rhogas is the density in g/cm3.

krome_x2n(x(:),rhogas)

Convert from mass fractions to number densities. Returns an array (real*8, size krome_nmols) with the number densities. Arguments: x(:) is an array (real*8, size krome_nmols) containing the mass fractions of the species, while rhogas is the density in g/cm3.

krome_thermo(x(:),Tgas,dt)

Returns the \(\mathrm dT/\mathrm dt\) in K/s (as real*8) from the number densities (array x(:), size krome_nmols, real*8), the gas temperature in K (real*8), and the time-step in s (real*8).

krome_get_cooling(x(:),Tgas)

Returns a real*8 value which is the cooling in erg/s/cm3. Arguments are the number densities (array x(:), size krome_nmols, real*8), and the gas temperature in K (real*8).

krome_plot_cooling(n(:))

Prints the cooling function to KROME_cooling_plot.dat file. Functions are plotted in the range of temperature math:`10`K-:math:`10^8`K. The columns of the file are Tgas, total with H2,total with H2GP, H2, ATOMIC, HD, H2, Z, DH. See -cooling option for details. Arguments: number densities (array n(:), size krome_nmols, real*8).

krome_dump_cooling(n(:),Tgas,nfile)

Dump cooling to the file unit nfile (integer). Arguments are the number densities (array n(:), size krome_nmols, real*8), and the gas temperature in K (real*8). The order is Tgas, total, H2GP, ATOMIC, HD, Z, DH, DUST, COMPTON, CIE. See -cooling option for details.

krome_conserve(x(:),xi(:))

Force the conservation for the array x(:) (size krome_nmols, real*8), using the initial abundances contained in xi(:) (size krome_nmols, real*8). It tries to rescale the species in order to conserve the initial fraction of the atoms. Work exactly when hybdrid compounds with different atoms (e.g. OH) are not present, otherwise their precision is problem-depending. To be employed with attention! Returns a rescaled array (size krome_nmols, real*8).

krome_get_gamma(x(:),Tgas)

Returns the adiabatic index (gamma) as a real*8 value. Arguments are: an array (size krome_nmols) that contains the number densisties of the species (real*8), and the gas temperature in K. The way in which this function compute gamma depends on what -gamma option you have used (if any).

krome_get_zatoms()

Returns an array (size krome_nmols, integer) containing the atomic number Z of the species.

krome_get_mu(x(:))

Returns the mean molecular weight in amu as a real*8 computed with \(\mu = \frac{\sum_i n_i\,m_i}{m_p\sum_i ni}\), where \(n_i\) are the number densities, \(m_i\) are the corresponding masses in g, \(m_p\) the mass of the protons in g. Argument: an array (size krome_nmols) that contains the number densisties of the species (real*8).

krome_get_mass()

Returns the masses of the species in grams as a real*8 array of size krome_nmols.

krome_get_mass()

Returns the inverse of the masses of the species in 1/grams as a real*8 array of size krome_nmols.

krome_get_Hnuclei(x(:))

Returns a real*8 value that is the amount of H nuclei, from an array real*8 of size krome_nmols that contains the number densities of the species.

krome_get_charges()

Returns the charges of the species as a real*8 array of size krome_nmols. Ions are positive (e.g. Si++ returns +2.d0), while anions are negative (e.g. H- returns -1.d0).

krome_get_names()

Returns an array of krome_nmols character*16 elements containing the strings of the species (e.g. "HCO+").

krome_get_index(name)

Returns the index (integer) of the species that exact matches the name (character*). If the species is nont found stops and rise an error on stdout.

krome_get_rho(x(:))

Returns an the total density of the gas in g/cm3 (real*8) from a real*8 array of size krome_nmols that contains the number densitites of the species.

krome_scale_Z(n(:),Z)

A subroutine that scales the neutral metals in the array n(:) (size krome_nmols, real*8), using the metallicity Z (real*8). It uses \(n_x = n_H\,10^{Z+\log_{10}(n_{xO})}\), where \(n_x\) is the number density of the given metal, \(n_H\) is the amount of atomic hydrogen (following the definition), \(n_{xO}\) is the solar numerical density for the given metal.

krome_get_electrons(n(:))

Returns the number density of electrons (real*8) necessary to balance the positive charge of the remaining species. Argument: an array (size krome_nmols) that contains the number densisties of the species (real*8).

krome_print_best_flux(x(:),Tgas,nbest)

Print on screen the first nbest (integer) reactions sorted by flux, where the flux is defined as \(F=k(T)\prod_in_i\), where \(k(T)\) is the rate coefficient, and the product is on the number densities of the reactants, e.g. \(\mathrm H+ \mathrm{CO}->\mathrm{OH}+\mathrm C\) is \(f_1=k_1(T)\times n_{H}\times n_{CO}\), where \(k_1(T)\) is the corresponding reaction rate. Arguments: x(:) is an array (size krome_nmols) that contains the number densisties of the species (real*8), Tgas is the gas temperature (real*8), nbest is the number of reactions to be printed (integer). The fluxes are sorted with a bubble algorithm contained in the idx_sort() function in krome_subs.f90, which is not very efficient: change it with the one you prefer if needed. This funcion is bery useful for debugging chemical networks.

krome_get_flux(n(:), Tgas)

Returns an array (real*8, size krome_nmols) with the fluxes (see krome_print_best_flux for a definition). Arguments: n(:) is an array (size krome_nmols) that contains the number densisties of the species (real*8), and Tgas is the gas temperature (real*8).

krome_get_qeff()

Returns an array (real*8, size krome_nmols) with the effective nuclear momenta. Employed in thermochemical networks calculations.

krome_dump_flux(n(:),Tgas,nfile)

Dumps the fluxes to the file unit nfile (integer). See krome_print_best_flux for a definition. Arguments: n(:) is an array (size krome_nmols) that contains the number densisties of the species (real*8), and Tgas is the gas temperature (real*8).

krome_get_info(x(:), Tgas)

Prints on screen some information about the chemical species employed. Arguments: x(:) is an array (size krome_nmols) that contains the number densisties of the species (real*8), and Tgas is the gas temperature (real*8).

krome_get_free_fall_time_rho(rhogas)

Returns the free-fall time given the total mass density:

\(\tau_{ff} = \sqrt{\frac{3\pi}{32G\rho}}\)

krome_get_free_fall_time(x(:))

Returns the free-fall time given the number density.

Updated