diff --git a/examples/EAGLE_ConstantCosmoVolumeNoGrav/eagle_cooling_box.yml b/examples/EAGLE_ConstantCosmoVolumeNoGrav/eagle_cooling_box.yml index 7d8215ec1983b69c7d288e54d98772a516b7c98e..5b59f5c14fd52903967928c92465ad6bfcc824bb 100644 --- a/examples/EAGLE_ConstantCosmoVolumeNoGrav/eagle_cooling_box.yml +++ b/examples/EAGLE_ConstantCosmoVolumeNoGrav/eagle_cooling_box.yml @@ -9,7 +9,7 @@ InternalUnitSystem: # Cosmological parameters Cosmology: h: 0.6777 # Reduced Hubble constant - a_begin: 0.0099 # Initial scale-factor of the simulation (z = 100.0) + a_begin: 0.0099 # Initial scale-factor of the simulation (z = 100.0) a_end: 1.0 # Final scale factor of the simulation Omega_m: 0.307 # Matter density parameter Omega_lambda: 0.693 # Dark-energy density parameter @@ -32,21 +32,12 @@ Statistics: scale_factor_first: 0.00991 delta_time: 1.1 -# Parameters for the self-gravity scheme -Gravity: - eta: 0.025 # Constant dimensionless multiplier for time integration. - theta: 0.7 # Opening angle (Multipole acceptance criterion) - comoving_softening: 0.0026994 # Comoving softening length (in internal units). - max_physical_softening: 0.0007 # Physical softening length (in internal units). - mesh_side_length: 16 - # Parameters for the hydrodynamics scheme SPH: resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel). - h_min_ratio: 0.1 # Minimal smoothing in units of softening. CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. - minimal_temperature: 100 # (internal units) - + minimal_temperature: 100 # K + # Parameters related to the initial conditions InitialConditions: file_name: ./constantBox.hdf5 # The file to read diff --git a/src/cooling/Compton/cooling.h b/src/cooling/Compton/cooling.h index a74399b3f91ebbc31ce62d53242caa001c092748..9e5a5ad34a9086152b98a1f1709e3755d875fb83 100644 --- a/src/cooling/Compton/cooling.h +++ b/src/cooling/Compton/cooling.h @@ -53,7 +53,7 @@ */ INLINE static void cooling_update(const struct cosmology* cosmo, struct cooling_function_data* cooling, - struct space *s) { + struct space* s) { // Add content if required. } diff --git a/src/cooling/EAGLE/cooling.c b/src/cooling/EAGLE/cooling.c index 1257eb1e172808d8391785b1223d2d8804d83870..72752df439e27448974265ce6d4585d1ee7b60bf 100644 --- a/src/cooling/EAGLE/cooling.c +++ b/src/cooling/EAGLE/cooling.c @@ -124,6 +124,8 @@ __attribute__((always_inline)) INLINE void get_redshift_index( * given time-step or redshift. Predominantly used to read cooling tables * above and below the current redshift, if not already read in. * + * Also calls the additional H reionisation energy injection if need be. + * * @param cosmo The current cosmological model. * @param cooling The #cooling_function_data used in the run. * @param s The space data, including a pointer to array of particles @@ -140,22 +142,19 @@ void cooling_update(const struct cosmology *cosmo, get_redshift_index(redshift, &z_index, &dz, cooling); cooling->dz = dz; - static int H_reion_happened = 0; /* Does this timestep straddle Hydrogen reionization? If so, we need to input * extra heat */ - if ((H_reion_happened == 0) && (redshift < cooling->H_reion_z)) { + if (!cooling->H_reion_done && (redshift < cooling->H_reion_z)) { - const float extra_heat = - cooling->H_reion_heat_cgs * cooling->internal_energy_from_cgs; + if (s == NULL) error("Trying to do H reionization on an empty space!"); - size_t i; + /* Inject energy to all particles */ + cooling_Hydrogen_reionization(cooling, cosmo, s); - /* Loop through particles and set new heat */ - for (i = 0; i < s->nr_parts; i++) { - hydro_reion_heating(&s->parts[i], &s->xparts[i], cosmo, extra_heat); - } - H_reion_happened = 1; + /* Flag that reionization happened */ + cooling->H_reion_done = 1; } + /* Do we already have the correct tables loaded? */ if (cooling->z_index == z_index) return; @@ -778,6 +777,23 @@ __attribute__((always_inline)) INLINE float cooling_get_radiated_energy( return xp->cooling_data.radiated_energy; } +void cooling_Hydrogen_reionization(const struct cooling_function_data *cooling, + const struct cosmology *cosmo, + struct space *s) { + + struct part *parts = s->parts; + struct xpart *xparts = s->xparts; + + /* Energy to inject in internal units */ + const float extra_heat = + cooling->H_reion_heat_cgs * cooling->internal_energy_from_cgs; + + /* Loop through particles and set new heat */ + for (size_t i = 0; i < s->nr_parts; i++) { + hydro_reion_heating(&parts[i], &xparts[i], cosmo, extra_heat); + } +} + /** * @brief Initialises properties stored in the cooling_function_data struct * @@ -799,6 +815,8 @@ void cooling_init_backend(struct swift_params *parameter_file, parser_get_param_string(parameter_file, "EAGLECooling:dir_name", cooling->cooling_table_path); + + cooling->H_reion_done = 0; cooling->H_reion_z = parser_get_param_float(parameter_file, "EAGLECooling:H_reion_z"); cooling->H_reion_heat_cgs = @@ -900,10 +918,9 @@ void cooling_init_backend(struct swift_params *parameter_file, * * @param cooling the #cooling_function_data structure * @param cosmo #cosmology structure - * @param s The space data, including a pointer to array of particles */ void cooling_restore_tables(struct cooling_function_data *cooling, - const struct cosmology *cosmo, struct space *s) { + const struct cosmology *cosmo) { /* Read redshifts */ get_cooling_redshifts(cooling); @@ -919,7 +936,7 @@ void cooling_restore_tables(struct cooling_function_data *cooling, /* Force a re-read of the cooling tables */ cooling->z_index = -10; cooling->previous_z_index = eagle_cooling_N_redshifts - 2; - cooling_update(cosmo, cooling, s); + cooling_update(cosmo, cooling, /*space=*/NULL); } /** @@ -998,12 +1015,11 @@ void cooling_struct_dump(const struct cooling_function_data *cooling, * @param cooling the struct * @param stream the file stream * @param cosmo #cosmology structure - * @param s The space data, including a pointer to array of particles */ void cooling_struct_restore(struct cooling_function_data *cooling, FILE *stream, - const struct cosmology *cosmo, struct space *s) { + const struct cosmology *cosmo) { restart_read_blocks((void *)cooling, sizeof(struct cooling_function_data), 1, stream, NULL, "cooling function"); - cooling_restore_tables(cooling, cosmo, s); + cooling_restore_tables(cooling, cosmo); } diff --git a/src/cooling/EAGLE/cooling.h b/src/cooling/EAGLE/cooling.h index b5df601835f8c0dab8cfc44d58e8cf52d660a68d..eac3425d25f5f4c8fd0a5ed7656423379a3ad3f9 100644 --- a/src/cooling/EAGLE/cooling.h +++ b/src/cooling/EAGLE/cooling.h @@ -71,14 +71,15 @@ float cooling_get_temperature( float cooling_get_radiated_energy(const struct xpart *restrict xp); +void cooling_Hydrogen_reionization(const struct cooling_function_data *cooling, + const struct cosmology *cosmo, + struct space *s); + void cooling_init_backend(struct swift_params *parameter_file, const struct unit_system *us, const struct phys_const *phys_const, struct cooling_function_data *cooling); -void cooling_restore_tables(struct cooling_function_data *cooling, - const struct cosmology *cosmo, struct space *s); - void cooling_print_backend(const struct cooling_function_data *cooling); void cooling_clean(struct cooling_function_data *data); diff --git a/src/cooling/EAGLE/cooling_struct.h b/src/cooling/EAGLE/cooling_struct.h index f84e3501300c40f3b0c9df5b0132d0b33bb6821c..88e49036f62962d35025f7fa81d5703a1245e3ce 100644 --- a/src/cooling/EAGLE/cooling_struct.h +++ b/src/cooling/EAGLE/cooling_struct.h @@ -80,6 +80,9 @@ struct cooling_function_data { /*! H reionization energy in CGS units */ float H_reion_heat_cgs; + /*! Have we already done H reioisation? */ + int H_reion_done; + /*! Ca over Si abundance divided by the solar ratio for these elements */ float Ca_over_Si_ratio_in_solar; diff --git a/src/cooling/const_du/cooling.h b/src/cooling/const_du/cooling.h index 76eb2ca0c8ce3c00b812d203b49d76a4ae635b2b..c57ef4a6874e0314bcea672cd514d1419b1acdd8 100644 --- a/src/cooling/const_du/cooling.h +++ b/src/cooling/const_du/cooling.h @@ -58,7 +58,7 @@ */ INLINE static void cooling_update(const struct cosmology* cosmo, struct cooling_function_data* cooling, - struct space *s) { + struct space* s) { // Add content if required. } diff --git a/src/cooling/const_lambda/cooling.h b/src/cooling/const_lambda/cooling.h index 63c93e162a3aa3e01de6ed584fa19f97fc91ba55..1e50c162d02e8c326f67978a7de73fda5c6aecd8 100644 --- a/src/cooling/const_lambda/cooling.h +++ b/src/cooling/const_lambda/cooling.h @@ -55,7 +55,7 @@ */ INLINE static void cooling_update(const struct cosmology* cosmo, struct cooling_function_data* cooling, - struct space *s) { + struct space* s) { // Add content if required. } diff --git a/src/cooling/grackle/cooling.h b/src/cooling/grackle/cooling.h index 04439e0852067ba3116c0e1a7db896f4828ba360..edf8f0ca50cc498b8d1b235196addb5a694a0b80 100644 --- a/src/cooling/grackle/cooling.h +++ b/src/cooling/grackle/cooling.h @@ -70,7 +70,7 @@ static gr_float cooling_new_energy( */ INLINE static void cooling_update(const struct cosmology* cosmo, struct cooling_function_data* cooling, - struct space *s) { + struct space* s) { /* set current time */ if (cooling->redshift == -1) cooling->units.a_value = cosmo->a; diff --git a/src/cooling/none/cooling.h b/src/cooling/none/cooling.h index cdc492ded771474d9e85c9776064911c1fbe4269..20aef187d912db379bb1c51ad9e8a4f16e47778c 100644 --- a/src/cooling/none/cooling.h +++ b/src/cooling/none/cooling.h @@ -47,7 +47,7 @@ */ INLINE static void cooling_update(const struct cosmology* cosmo, struct cooling_function_data* cooling, - struct space *s) { + struct space* s) { // Add content if required. }