diff --git a/examples/AgoraDisk/agora_disk.yml b/examples/AgoraDisk/agora_disk.yml index 7368700d8a2a5ca8de7d677e1da78be51d669835..4870d29a7b6caaaa8b574b16cd6b453b8d3b3dad 100644 --- a/examples/AgoraDisk/agora_disk.yml +++ b/examples/AgoraDisk/agora_disk.yml @@ -39,7 +39,7 @@ Gravity: SPH: resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel). CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. - minimal_temperature: 10 # (internal units) + minimal_temperature: 10. # Kelvin # Parameters related to the initial conditions InitialConditions: @@ -50,9 +50,6 @@ InitialConditions: # Dimensionless pre-factor for the time-step condition LambdaCooling: lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) - minimum_temperature: 1.0e2 # Minimal temperature (Kelvin) - mean_molecular_weight: 0.59 # Mean molecular weight - hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless) cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition # Cooling with Grackle 2.0 diff --git a/examples/CoolingBox/coolingBox.yml b/examples/CoolingBox/coolingBox.yml index 2bd2f19f6d78388ae638521f590255d410bc8697..510bcd63170206b71d8e2a63174da9e4abdbbccb 100644 --- a/examples/CoolingBox/coolingBox.yml +++ b/examples/CoolingBox/coolingBox.yml @@ -27,6 +27,7 @@ Statistics: SPH: resolution_eta: 1.2348 # Target smoothing length in units of the mean inter-particle separation (1.2348 == 48Ngbs with the cubic spline kernel). CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. + minimal_temperature: 100. # Kelvin # Parameters related to the initial conditions InitialConditions: @@ -35,9 +36,6 @@ InitialConditions: # Dimensionless pre-factor for the time-step condition LambdaCooling: lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) - minimum_temperature: 1.0e4 # Minimal temperature (Kelvin) - mean_molecular_weight: 0.59 # Mean molecular weight - hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless) cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition # Cooling with Grackle 2.0 diff --git a/examples/CoolingHalo/cooling_halo.yml b/examples/CoolingHalo/cooling_halo.yml index 68c3478b717261698ac175835fc246e134e3a6a7..2ae0c9ddd4e1bfaf5ce5686b28dca32a166b7d7b 100644 --- a/examples/CoolingHalo/cooling_halo.yml +++ b/examples/CoolingHalo/cooling_halo.yml @@ -27,7 +27,8 @@ Snapshots: SPH: resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel). CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. - + minimal_temperature: 1e4 # Kelvin + # Parameters related to the initial conditions InitialConditions: file_name: CoolingHalo.hdf5 # The file to read @@ -41,7 +42,4 @@ IsothermalPotential: # Cooling parameters LambdaCooling: lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) - minimum_temperature: 1.0e4 # Minimal temperature (Kelvin) - mean_molecular_weight: 0.59 # Mean molecular weight - hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless) cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition diff --git a/examples/CoolingHaloWithSpin/cooling_halo.yml b/examples/CoolingHaloWithSpin/cooling_halo.yml index f6e9fe3b124631fc2d5336db8a7ffb18f7b34a95..1b173dea8c30e7e9a75527d8fdbb76bc45997e89 100644 --- a/examples/CoolingHaloWithSpin/cooling_halo.yml +++ b/examples/CoolingHaloWithSpin/cooling_halo.yml @@ -27,6 +27,7 @@ Snapshots: SPH: resolution_eta: 1.2349 # Target smoothing length in units of the mean inter-particle separation (1.2349 == 48Ngbs with the cubic spline kernel). CFL_condition: 0.1 # Courant-Friedrich-Levy condition for time integration. + minimal_temperature: 1e4 # Kelvin # Parameters related to the initial conditions InitialConditions: @@ -41,7 +42,4 @@ IsothermalPotential: # Cooling parameters LambdaCooling: lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) - minimum_temperature: 1.0e4 # Minimal temperature (Kelvin) - mean_molecular_weight: 0.59 # Mean molecular weight - hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless) cooling_tstep_mult: 0.1 # Dimensionless pre-factor for the time-step condition diff --git a/examples/SmallCosmoVolume_cooling/README b/examples/SmallCosmoVolume_cooling/README index a0abad5f814f87133dccc31d414bdc546609df88..2ee364ca2f00a4280a492a11520bf7b9a1ac1f7d 100644 --- a/examples/SmallCosmoVolume_cooling/README +++ b/examples/SmallCosmoVolume_cooling/README @@ -7,6 +7,11 @@ on the options to cancel the h-factors and a-factors at reading time. We generate gas from the ICs using SWIFT's internal mechanism and set the temperature to the expected gas temperature at this redshift. +This example runs with cooling switch on. Depending on the cooling +model chosen at the time SWIFT was configured, the answer will be +different. Interesting cases to compare to the no-cooling case are +a constant cooling rate or Compton cooling. + The 'plotTempEvolution.py' plots the temperature evolution of the gas in the simulated volume. diff --git a/examples/SmallCosmoVolume_cooling/small_cosmo_volume.yml b/examples/SmallCosmoVolume_cooling/small_cosmo_volume.yml index 8f6a2f2ad6a972e6bc1523da80b4243495853ace..d087cac4e8ef01ca25c8d4329e1da92b4e38256a 100644 --- a/examples/SmallCosmoVolume_cooling/small_cosmo_volume.yml +++ b/examples/SmallCosmoVolume_cooling/small_cosmo_volume.yml @@ -59,5 +59,4 @@ InitialConditions: # Constant lambda cooling function LambdaCooling: - lambda_cgs: 1e-30 # Cooling rate (in cgs units) - cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition + lambda_cgs: 1e-26 # Cooling rate (in cgs units) diff --git a/examples/parameter_example.yml b/examples/parameter_example.yml index 0b0a1c50d73663e695571faa4e555c50d5bc242d..1f146d908521f298782eb0a81ebc804773ea625c 100644 --- a/examples/parameter_example.yml +++ b/examples/parameter_example.yml @@ -199,10 +199,7 @@ ConstCooling: # Constant lambda cooling function LambdaCooling: lambda_cgs: 2.0 # Cooling rate (in cgs units) - minimum_temperature: 1.0e4 # Minimal temperature (Kelvin) - mean_molecular_weight: 0.59 # Mean molecular weight - hydrogen_mass_abundance: 0.75 # Hydrogen mass abundance (dimensionless) - cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition + cooling_tstep_mult: 1.0 # (Optional) Dimensionless pre-factor for the time-step condition. # Cooling with Grackle 3.0 GrackleCooling: diff --git a/src/cooling/const_lambda/cooling.h b/src/cooling/const_lambda/cooling.h index 57b58fed798dd68b5d7438f836bc005191c785e7..c1f5d802e441b69988fb6401e9398a925d8f55d4 100644 --- a/src/cooling/const_lambda/cooling.h +++ b/src/cooling/const_lambda/cooling.h @@ -159,6 +159,11 @@ __attribute__((always_inline)) INLINE static float cooling_timestep( const struct unit_system* restrict us, const struct hydro_props* hydro_props, const struct part* restrict p) { + /* Start with the case where there is no limit */ + if (cooling->cooling_tstep_mult == FLT_MAX) { + return FLT_MAX; + } + /* Get current internal energy and cooling rate */ const float u = hydro_get_physical_internal_energy(p, cosmo); const double cooling_du_dt_cgs = @@ -225,8 +230,8 @@ static INLINE void cooling_init_backend(struct swift_params* parameter_file, /* Read in the cooling parameters */ cooling->lambda_cgs = parser_get_param_double(parameter_file, "LambdaCooling:lambda_cgs"); - cooling->cooling_tstep_mult = parser_get_param_double( - parameter_file, "LambdaCooling:cooling_tstep_mult"); + cooling->cooling_tstep_mult = parser_get_opt_param_float( + parameter_file, "LambdaCooling:cooling_tstep_mult", FLT_MAX); /* Some useful conversion values */ cooling->conv_factor_density_to_cgs = @@ -251,6 +256,12 @@ static INLINE void cooling_print_backend( message("Cooling function is 'Constant lambda' with Lambda=%g [cgs]", cooling->lambda_cgs); + + if (cooling->cooling_tstep_mult == FLT_MAX) + message("Cooling function time-step size is unlimited"); + else + message("Cooling function time-step size limited to %f of u/(du/dt)", + cooling->cooling_tstep_mult); } #endif /* SWIFT_COOLING_CONST_LAMBDA_H */ diff --git a/src/runner.c b/src/runner.c index 0cf5a5da4ae64504e89a2136ab6d8ec8a1a8d191..2cd978a0185484a0daf4275a6b7c98ab033b96a5 100644 --- a/src/runner.c +++ b/src/runner.c @@ -461,11 +461,11 @@ void runner_do_cooling(struct runner *r, struct cell *c, int timer) { if (part_is_active(p, e)) { double dt_cool, dt_therm; - ; if (with_cosmology) { const integertime_t ti_step = get_integer_timestep(p->time_bin); const integertime_t ti_begin = - get_integer_time_begin(ti_current + 1, p->time_bin); + get_integer_time_begin(ti_current - 1, p->time_bin); + dt_cool = cosmology_get_delta_time(cosmo, ti_begin, ti_begin + ti_step); dt_therm = cosmology_get_therm_kick_factor(e->cosmology, ti_begin,