#include #include #include #define H5_USE_16_API 1 #include "hdf5.h" #include "nuc_eos.h" // Catch HDF5 errors #define HDF5_ERROR(fn_call) \ do { \ int _error_code = fn_call; \ if (_error_code < 0) { \ printf("HDF5 call '%s' returned error code %d", \ #fn_call, _error_code); \ } \ } while (0) static int file_is_readable(const char* filename); static int file_is_readable(const char* filename) { FILE* fp = NULL; fp = fopen(filename, "r"); if(fp != NULL) { fclose(fp); return 1; } return 0; } // define the variables //namespace nuc_eos { // double temp0, temp1; // double energy_shift; // // double eos_rhomax, eos_rhomin; // double eos_tempmin, eos_tempmax; // double eos_yemin, eos_yemax; // double eos_epsmin, eos_epsmax; // // double c2p_tempmin; // double c2p_tempmax; // //} //namespace nuc_eos_private { // int nrho; // int ntemp; // int nye; // // double * restrict alltables; // double * restrict epstable; // double * restrict logrho; // double * restrict logtemp; // double dlintemp, dlintempi; // double drholintempi; // double dlintempyei; // double drholintempyei; // double * restrict yes; // double dtemp, dtempi; // double drho, drhoi; // double dye, dyei; // double drhotempi; // double drhoyei; // double dtempyei; // double drhotempyei; //} // TODO: replace with version in ET EOS_Omni. NOTE: table arrangement changed. // Cactus calls this function. It reads in the table and calls a fortran // function to setup values for the fortran eos module void nuc_eos_C_ReadTable(char* nuceos_table_name) { // double temp0, temp1; // double energy_shift; // // double eos_rhomax, eos_rhomin; // double eos_tempmin, eos_tempmax; // double eos_yemin, eos_yemax; // double eos_epsmin, eos_epsmax; // // double c2p_tempmin; // double c2p_tempmax; // // int nrho; // int ntemp; // int nye; // // double * restrict alltables; // double * restrict epstable; // double * restrict logrho; // double * restrict logtemp; // double dlintemp, dlintempi; // double drholintempi; // double dlintempyei; // double drholintempyei; // double * restrict yes; // double dtemp, dtempi; // double drho, drhoi; // double dye, dyei; // double drhotempi; // double drhoyei; // double dtempyei; // double drhotempyei; printf("*******************************"); printf("Reading nuc_eos table file:"); printf("%s",nuceos_table_name); printf("*******************************"); hid_t file; if (!file_is_readable(nuceos_table_name)) { printf("Could not read nuceos_table_name %s \n", nuceos_table_name); } HDF5_ERROR(file = H5Fopen(nuceos_table_name, H5F_ACC_RDONLY, H5P_DEFAULT)); // Use these two defines to easily read in a lot of variables in the same way // The first reads in one variable of a given type completely #define READ_EOS_HDF5(NAME,VAR,TYPE,MEM) \ do { \ hid_t dataset; \ HDF5_ERROR(dataset = H5Dopen(file, NAME)); \ HDF5_ERROR(H5Dread(dataset, TYPE, MEM, H5S_ALL, H5P_DEFAULT, VAR)); \ HDF5_ERROR(H5Dclose(dataset)); \ } while (0) // The second reads a given variable into a hyperslab of the alltables_temp array #define READ_EOSTABLE_HDF5(NAME,OFF) \ do { \ hsize_t offset[2] = {OFF,0}; \ H5Sselect_hyperslab(mem3, H5S_SELECT_SET, offset, NULL, var3, NULL); \ READ_EOS_HDF5(NAME,alltables_temp,H5T_NATIVE_DOUBLE,mem3); \ } while (0) // Read size of tables READ_EOS_HDF5("pointsrho", &nrho, H5T_NATIVE_INT, H5S_ALL); READ_EOS_HDF5("pointstemp", &ntemp, H5T_NATIVE_INT, H5S_ALL); READ_EOS_HDF5("pointsye", &nye, H5T_NATIVE_INT, H5S_ALL); // Allocate memory for tables double* alltables_temp; if (!(alltables_temp = (double*)malloc(nrho * ntemp * nye * NTABLES * sizeof(double)))) { printf("Cannot allocate memory for EOS table"); } if (!(logrho = (double*)malloc(nrho * sizeof(double)))) { printf("Cannot allocate memory for EOS table"); } if (!(logtemp = (double*)malloc(ntemp * sizeof(double)))) { printf("Cannot allocate memory for EOS table"); } if (!(yes = (double*)malloc(nye * sizeof(double)))) { printf("Cannot allocate memory for EOS table"); } // Prepare HDF5 to read hyperslabs into alltables_temp hsize_t table_dims[2] = {NTABLES, (hsize_t)nrho * ntemp * nye}; hsize_t var3[2] = { 1, (hsize_t)nrho * ntemp * nye}; hid_t mem3 = H5Screate_simple(2, table_dims, NULL); // Read alltables_temp READ_EOSTABLE_HDF5("logpress", 0); READ_EOSTABLE_HDF5("logenergy", 1); READ_EOSTABLE_HDF5("entropy", 2); READ_EOSTABLE_HDF5("munu", 3); READ_EOSTABLE_HDF5("cs2", 4); READ_EOSTABLE_HDF5("dedt", 5); READ_EOSTABLE_HDF5("dpdrhoe", 6); READ_EOSTABLE_HDF5("dpderho", 7); // chemical potentials READ_EOSTABLE_HDF5("muhat", 8); READ_EOSTABLE_HDF5("mu_e", 9); READ_EOSTABLE_HDF5("mu_p", 10); READ_EOSTABLE_HDF5("mu_n", 11); // compositions READ_EOSTABLE_HDF5("Xa", 12); READ_EOSTABLE_HDF5("Xh", 13); READ_EOSTABLE_HDF5("Xn", 14); READ_EOSTABLE_HDF5("Xp", 15); // average nucleus READ_EOSTABLE_HDF5("Abar", 16); READ_EOSTABLE_HDF5("Zbar", 17); // Gamma READ_EOSTABLE_HDF5("gamma", 18); // Read additional tables and variables READ_EOS_HDF5("logrho", logrho, H5T_NATIVE_DOUBLE, H5S_ALL); READ_EOS_HDF5("logtemp", logtemp, H5T_NATIVE_DOUBLE, H5S_ALL); READ_EOS_HDF5("ye", yes, H5T_NATIVE_DOUBLE, H5S_ALL); READ_EOS_HDF5("energy_shift", &energy_shift, H5T_NATIVE_DOUBLE, H5S_ALL); HDF5_ERROR(H5Sclose(mem3)); HDF5_ERROR(H5Fclose(file)); // change ordering of alltables array so that // the table kind is the fastest changing index if (!(alltables = (double*)malloc(nrho * ntemp * nye * NTABLES * sizeof(double)))) { printf("Cannot allocate memory for EOS table"); } for(int iv = 0;iv epsmax) && (epstable[i] < 1.0e150)){ epsmax = epstable[i]; } if (epstable[i] < epsmin){ epsmin = epstable[i]; } } double pressmax = presstable[0]; double pressmin = presstable[0]; for(int i=1;i pressmax) && (presstable[i] < 1.0e150)){ pressmax = presstable[i]; } if (presstable[i] < pressmin){ pressmin = presstable[i]; } } eos_pressmax = pressmax; eos_pressmin = pressmin; eos_epsmax = epsmax; //- energy_shift; eos_epsmin = epsmin; //- energy_shift; eos_epsmax = epsmax- energy_shift; eos_epsmin = epsmin- energy_shift; } void nuc_eos_c_get_energy_shift(double *energy_shift_fortran, double *eos_tempmin_fortran, double *eos_tempmax_fortran, double *eos_yemin_fortran, double *eos_yemax_fortran, double *eos_rhomin_fortran, double *eos_rhomax_fortran, double *eos_epsmin_fortran, double *eos_epsmax_fortran) { double eos_rhomax, eos_rhomin; double eos_tempmin, eos_tempmax; double eos_yemin, eos_yemax; double eos_epsmin, eos_epsmax; *energy_shift_fortran = energy_shift; *eos_tempmin_fortran = eos_tempmin; *eos_tempmax_fortran = eos_tempmax; *eos_yemin_fortran = eos_yemin; *eos_yemax_fortran = eos_yemax; *eos_rhomin_fortran = eos_rhomin; *eos_rhomax_fortran = eos_rhomax; *eos_epsmin_fortran = eos_epsmin; *eos_epsmax_fortran = eos_epsmax; }