12 #include "bigfile-mpi.h"
32 MPI_Comm_rank(MPI_COMM_WORLD, &
ThisTask);
40 big_file_open(bf, filename);
41 if(0 != big_file_open_block(bf, bb, dataset)) {
42 endrun(1,
"Cannot open %s %s: %s\n", filename, dataset, big_file_get_error_message());
47 if(dtype_itemsize(bb->dtype) !=
sizeof(
double))
48 endrun(1,
"UVflucatuation file %s should contain double-precision data, contains %s\n", filename, bb->dtype);
50 buffer = (
double *)
mymalloc(
"cooling_data", N * dtype_itemsize(bb->dtype) * bb->nmemb);
54 big_array_init(array, buffer, bb->dtype, 2, dims, NULL);
55 if(0 != big_block_seek(bb, &ptr, 0))
56 endrun(1,
"Failed to seek block %s %s: %s\n", filename, dataset, big_file_get_error_message());
58 if(0 != big_block_read(bb, &ptr, array))
59 endrun(1,
"Failed to read %s %s: %s", filename, dataset, big_file_get_error_message());
65 MPI_Bcast(&N, 1, MPI_INT, 0, MPI_COMM_WORLD);
67 buffer = (
double *)
mymalloc(
"cooling_data",N *
sizeof(
double));
69 MPI_Bcast(buffer, N, MPI_DOUBLE, 0, MPI_COMM_WORLD);
93 if(strnlen(UVFluctuationFile, UVFlucLen) == 0) {
101 if(0 != big_file_mpi_open(&bf, UVFluctuationFile, MPI_COMM_WORLD)) {
102 endrun(0,
"Failed to open snapshot at %s:%s\n", UVFluctuationFile,
103 big_file_get_error_message());
106 if(0 != big_file_mpi_open_block(&bf, &bh,
"Zreion_Table", MPI_COMM_WORLD)) {
107 endrun(0,
"Failed to create block at %s:%s\n",
"Header",
108 big_file_get_error_message());
111 double ReionRedshift;
112 if ((0 != big_block_get_attr(&bh,
"Nmesh", &
UVF.Nside,
"u8", 1)) ||
113 (0 != big_block_get_attr(&bh,
"BoxSize", &TableBoxSize,
"f8", 1)) ||
114 (0 != big_block_get_attr(&bh,
"Redshift", &ReionRedshift,
"f8", 1)) ||
115 (0 != big_block_mpi_close(&bh, MPI_COMM_WORLD))) {
116 endrun(0,
"Failed to close block: %s\n",
117 big_file_get_error_message());
119 big_file_mpi_close(&bf, MPI_COMM_WORLD);
121 if(fabs(TableBoxSize - BoxMpc) > BoxMpc * 1e-5)
122 endrun(0,
"Wrong UV fluctuation file! %s is for box size %g Mpc/h, but current box is %g Mpc/h\n", UVFluctuationFile, TableBoxSize, BoxMpc);
124 message(0,
"Using NON-UNIFORM UV BG fluctuations from %s. Median reionization redshift is %g\n", UVFluctuationFile, ReionRedshift);
130 if(
UVF.Nside *
UVF.Nside *
UVF.Nside != size)
131 endrun(0,
"Corrupt UV Fluctuation table: Nside = %ld, but table is %ld != %ld^3\n",
UVF.Nside, size,
UVF.Nside);
133 int64_t dims[] = {
UVF.Nside,
UVF.Nside,
UVF.Nside};
139 if(
UVF.Table[0] < 0.01 ||
UVF.Table[0] > 100.0) {
140 endrun(0,
"UV Fluctuation out of range: %g\n",
UVF.Table[0]);
149 struct UVBG get_local_UVBG(double redshift, const struct
UVBG *
const GlobalUVBG,
const double *
const Pos,
const double *
const PosOffset)
156 struct UVBG uvbg = {0};
162 for(i = 0; i < 3; i++)
163 corrpos[i] = Pos[i] - PosOffset[i];
169 memcpy(&uvbg, GlobalUVBG,
sizeof(
struct UVBG));
203 if(strlen(MetalCoolFile) == 0) {
212 double * tabbedmet =
read_big_array(MetalCoolFile,
"MetallicityInSolar_bins", &size);
214 if(size != 1 || tabbedmet[0] != 0.0) {
215 endrun(123,
"MetalCool file %s is wrongly tabulated\n", MetalCoolFile);
240 double lognH = log10(nHcgs);
241 double logT = log10(temp);
243 double x[] = {redshift, lognH, logT};
int NHydrogenNumberDensity_bins
void init_uvf_table(const char *UVFluctuationFile, const int UVFlucLen, const double BoxSize, const double UnitLength_in_cm)
double * HydrogenNumberDensity_bins
void InitMetalCooling(const char *MetalCoolFile)
struct UVBG get_local_UVBG(double redshift, const struct UVBG *const GlobalUVBG, const double *const Pos, const double *const PosOffset)
double TableMetalCoolingRate(double redshift, double temp, double nHcgs)
double * Temperature_bins
static double * read_big_array(const char *filename, const char *dataset, int *Nread)
void message(int where, const char *fmt,...)
void endrun(int where, const char *fmt,...)
double interp_eval(Interp *obj, double *x, double *ydata, int *status)
void interp_init(Interp *obj, int Ndim, int64_t *dims)
void interp_init_dim(Interp *obj, int d, double Min, double Max)
double interp_eval_periodic(Interp *obj, double *x, double *ydata)
#define mymalloc(name, size)
static double UnitLength_in_cm