Cooling and Heating Functions of Photoionized Gas
Nickolay Y. Gnedin, Nicholas Hollon
Last updated: 20120621
Paper
Downloadable data and the reader
(A smaller, 68MB, slightly less accurate table is available upon request.)
Test driver for validation
- test.f Test driver (compile and link it together with frt_cf3.F)
- test.c Test driver in C (compile and link it together with frt_cf3.F), written by Martin.Krause
- test.res Result of running test, for validation
Usage instructions
The reader is written in fortran, because it is easier to call fortran from C rather than C from fortran.
The table is loaded in the code by calling
call frtInitCF(mode,path)
where path is the path to the data file and mode is the flag that specifies what is returned:
- mode=0 for the full cooling and heating functions;
- mode=1 for the metal-dependent part of the cooling and heating functions only.
The table persists for the rest of the simulation and cannot be unloaded.
Parameter mode also serves as an error code - it is reset to zero if the loading of the data is successfull, and is set to -1 if there is an error opening the file or the data file is corrupted.
The reader uses internally the fortran unit number 97. If this conflicts with other parts of your code, it can be changed manually in frt_cf3.inc.
The reader offers a two-level interface. In the higher level interface, for each set of values for the gas temperature Tem (in K), baryon density Den≈ρ/mp (in cm-3), metallicity Z (in solar units), Lyman-Werner band H2 photo-desctruction rate PLW, and photo-ionization rates for HI (PHI), HeI (PHeI), and CVI (PCVI - all in s-1), the cooling and heating rates per baryon cfun and hfun (in erg cm3/s) can be returned by calling
call frtGetCF(Tem,Den,Z,PLW,PHI,PHeI,PCVI,cfun,hfun,ierr)
and the error flag ierr is set to zero if the call is successfull. The call may be unsuccessfull if the values of the parameters are such that the table needs to be sampled outside of its current range. In that case, the absolute value of the flag returns the dimension of the table along which the out-of-bound error occur, and the sign is -1 or +1 depending on whether the lower or the upper boundary of the table is crossed. The reader then returns the value from the table at the boundary, which may be highly imprecise.
In the lower-level interface, some of the table data can be pre-cached with a call
call frtCFCache(Den,Z,PLW,PHI,PHeI,PCVI,icache,rcache,ierr)
where icache and rcache are integer and real arrays declared as
dimension icache(12), rcache(13)
The cooling and heating rates per baryon cfun and hfun as functions of gas temperature (at fixed density, metallicity, and radiation field) can then be returned by successfully calling
call frtCFGetLn(log(Tem),icache,rcache,cfun,hfun)
for different values of the gas temperature Tem.
The low-level interface is intended to be used in simulation codes with sub-cycling - for each hydrodynamic step you need to call frtCFCache once per cell/particle, but then a sub-cycler can call frtCFGetLn multiple times to update the internal energy efficiently (a call to frtCFGetLn is much faster than a call to frtGetCF).
Given the cooling and heating rates per baryon cfun and hfun, the change in the internal energy of the gas is
For C/C++ codes, all one needs to do is to declare these prototypes:
void frtinitcf_(const int *mode, const char *path, int len);
void frtcfcache_(const float *Den, const float *Z, const float *Plw, const float *Ph1, const float *Pg1, const float *Pc6, int *icache, float *rcache, int *err);
void frtcfgetln_(const float *alt, int *icache, float *rcache, float *cfun, float *hfun);
void frtgetcf_(const float *Tem, const float *Den, const float *Z, const float *Plw, const float *Ph1, const float *Pg1, const float *Pc6, float *cfun, float *hfun, int *err);
and in C++ they need to be wrapped into
declaration wrapper.
Please e-mail Nick Gnedin is anything is not working right with this code or you find that its cache performance is poor.