Skip to content
Snippets Groups Projects
Commit e47db28b authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Updated the definition of Lambda in the const-lambda cooling model to have the right units.

parent a868520d
No related branches found
No related tags found
No related merge requests found
...@@ -49,7 +49,7 @@ InitialConditions: ...@@ -49,7 +49,7 @@ InitialConditions:
# Dimensionless pre-factor for the time-step condition # Dimensionless pre-factor for the time-step condition
LambdaCooling: LambdaCooling:
lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) lambda_nH2_cgs: 1e-22 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3])
cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition
# Cooling with Grackle 2.0 # Cooling with Grackle 2.0
......
...@@ -35,7 +35,7 @@ InitialConditions: ...@@ -35,7 +35,7 @@ InitialConditions:
# Dimensionless pre-factor for the time-step condition # Dimensionless pre-factor for the time-step condition
LambdaCooling: LambdaCooling:
lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) lambda_nH2_cgs: 1e-22 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3])
cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition
# Cooling with Grackle 2.0 # Cooling with Grackle 2.0
......
...@@ -41,5 +41,5 @@ IsothermalPotential: ...@@ -41,5 +41,5 @@ IsothermalPotential:
# Cooling parameters # Cooling parameters
LambdaCooling: LambdaCooling:
lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) lambda_nH2_cgs: 1e-22 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3])
cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition cooling_tstep_mult: 1.0 # Dimensionless pre-factor for the time-step condition
...@@ -41,5 +41,5 @@ IsothermalPotential: ...@@ -41,5 +41,5 @@ IsothermalPotential:
# Cooling parameters # Cooling parameters
LambdaCooling: LambdaCooling:
lambda_cgs: 1.0e-22 # Cooling rate (in cgs units) lambda_nH2_cgs: 1e-22 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3])
cooling_tstep_mult: 0.1 # Dimensionless pre-factor for the time-step condition cooling_tstep_mult: 0.1 # Dimensionless pre-factor for the time-step condition
...@@ -71,7 +71,7 @@ git = sim["Code"].attrs["Git Revision"] ...@@ -71,7 +71,7 @@ git = sim["Code"].attrs["Git Revision"]
cooling_model = sim["/SubgridScheme"].attrs["Cooling Model"] cooling_model = sim["/SubgridScheme"].attrs["Cooling Model"]
if cooling_model == "Constant Lambda": if cooling_model == "Constant Lambda":
Lambda = sim["/SubgridScheme"].attrs["Lambda [cgs]"][0] Lambda = sim["/SubgridScheme"].attrs["Lambda/n_H^2 [cgs]"][0]
# Cosmological parameters # Cosmological parameters
H_0 = sim["/Cosmology"].attrs["H0 [internal units]"][0] H_0 = sim["/Cosmology"].attrs["H0 [internal units]"][0]
......
...@@ -59,4 +59,4 @@ InitialConditions: ...@@ -59,4 +59,4 @@ InitialConditions:
# Constant lambda cooling function # Constant lambda cooling function
LambdaCooling: LambdaCooling:
lambda_cgs: 1e-26 # Cooling rate (in cgs units [erg * s^-1 * cm^-3]) lambda_nH2_cgs: 1e-26 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3])
...@@ -198,7 +198,7 @@ ConstCooling: ...@@ -198,7 +198,7 @@ ConstCooling:
# Constant lambda cooling function # Constant lambda cooling function
LambdaCooling: LambdaCooling:
lambda_cgs: 1e-22 # Cooling rate (in cgs units [erg * s^-1 * cm^-3]) lambda_nH2_cgs: 1e-22 # Cooling rate divided by square Hydrogen number density (in cgs units [erg * s^-1 * cm^3])
cooling_tstep_mult: 1.0 # (Optional) 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 # Cooling with Grackle 3.0
......
...@@ -47,8 +47,10 @@ ...@@ -47,8 +47,10 @@
/** /**
* @brief Calculates du/dt in CGS units for a particle. * @brief Calculates du/dt in CGS units for a particle.
* *
* The cooling rate is \f$\frac{du}{dt} = -\Lambda \frac{n_H^2}{\rho} \f$ and * The cooling rate is \f$\frac{du}{dt} = -\frac{\Lambda}{n_H^2}
* the returned value is in physical [erg * g^-1 * s^-1]. * \frac{n_H^2}{\rho} \f$, where \f$ \frac{\Lambda}{n_H^2} \f$ is a constant in
* this model (lambda_nH2_cgs in #cooling_function_data).
* The returned value is in physical [erg * g^-1 * s^-1].
* *
* @param cosmo The current cosmological model. * @param cosmo The current cosmological model.
* @param hydro_props The properties of the hydro scheme. * @param hydro_props The properties of the hydro scheme.
...@@ -61,18 +63,19 @@ __attribute__((always_inline)) INLINE static double cooling_rate_cgs( ...@@ -61,18 +63,19 @@ __attribute__((always_inline)) INLINE static double cooling_rate_cgs(
const struct cosmology* cosmo, const struct hydro_props* hydro_props, const struct cosmology* cosmo, const struct hydro_props* hydro_props,
const struct cooling_function_data* cooling, const struct part* p) { const struct cooling_function_data* cooling, const struct part* p) {
/* Get particle density */ /* Get particle density [g * cm^-3] */
const double rho = hydro_get_physical_density(p, cosmo); const double rho = hydro_get_physical_density(p, cosmo);
const double rho_cgs = rho * cooling->conv_factor_density_to_cgs; const double rho_cgs = rho * cooling->conv_factor_density_to_cgs;
/* Get Hydrogen mass fraction */ /* Get Hydrogen mass fraction */
const double X_H = hydro_props->hydrogen_mass_fraction; const double X_H = hydro_props->hydrogen_mass_fraction;
/* Hydrogen number density (X_H * rho / m_p) */ /* Hydrogen number density (X_H * rho / m_p) [cm^-3] */
const double n_H_cgs = X_H * rho_cgs * cooling->proton_mass_cgs_inv; const double n_H_cgs = X_H * rho_cgs * cooling->proton_mass_cgs_inv;
/* Calculate du_dt (Lambda * n_H^2 / rho) */ /* Calculate du_dt ((Lambda / n_H^2) * n_H^2 / rho) */
const double du_dt_cgs = -cooling->lambda_cgs * n_H_cgs * n_H_cgs / rho_cgs; const double du_dt_cgs =
-cooling->lambda_nH2_cgs * n_H_cgs * n_H_cgs / rho_cgs;
return du_dt_cgs; return du_dt_cgs;
} }
...@@ -238,8 +241,8 @@ static INLINE void cooling_init_backend(struct swift_params* parameter_file, ...@@ -238,8 +241,8 @@ static INLINE void cooling_init_backend(struct swift_params* parameter_file,
struct cooling_function_data* cooling) { struct cooling_function_data* cooling) {
/* Read in the cooling parameters */ /* Read in the cooling parameters */
cooling->lambda_cgs = cooling->lambda_nH2_cgs =
parser_get_param_double(parameter_file, "LambdaCooling:lambda_cgs"); parser_get_param_double(parameter_file, "LambdaCooling:lambda_nH2_cgs");
cooling->cooling_tstep_mult = parser_get_opt_param_float( cooling->cooling_tstep_mult = parser_get_opt_param_float(
parameter_file, "LambdaCooling:cooling_tstep_mult", FLT_MAX); parameter_file, "LambdaCooling:cooling_tstep_mult", FLT_MAX);
...@@ -265,9 +268,10 @@ static INLINE void cooling_print_backend( ...@@ -265,9 +268,10 @@ static INLINE void cooling_print_backend(
const struct cooling_function_data* cooling) { const struct cooling_function_data* cooling) {
message( message(
"Cooling function is 'Constant lambda' with Lambda=%g [erg * s^-1 * " "Cooling function is 'Constant lambda' with Lambda/n_H^2=%g [erg * s^-1 "
"cm^-3]", "* "
cooling->lambda_cgs); "cm^3]",
cooling->lambda_nH2_cgs);
if (cooling->cooling_tstep_mult == FLT_MAX) if (cooling->cooling_tstep_mult == FLT_MAX)
message("Cooling function time-step size is unlimited"); message("Cooling function time-step size is unlimited");
......
...@@ -45,7 +45,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour( ...@@ -45,7 +45,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
hid_t h_grp, const struct cooling_function_data* cooling) { hid_t h_grp, const struct cooling_function_data* cooling) {
io_write_attribute_s(h_grp, "Cooling Model", "Constant Lambda"); io_write_attribute_s(h_grp, "Cooling Model", "Constant Lambda");
io_write_attribute_d(h_grp, "Lambda [cgs]", cooling->lambda_cgs); io_write_attribute_d(h_grp, "Lambda/n_H^2 [cgs]", cooling->lambda_nH2_cgs);
} }
#endif #endif
......
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
*/ */
struct cooling_function_data { struct cooling_function_data {
/*! Cooling rate in physical cgs units [erg * s^-1 * cm^-3] */ /*! Cooling rate / nH^2 in physical cgs units [erg * s^-1 * cm^3] */
double lambda_cgs; double lambda_nH2_cgs;
/*! Conversion factor from internal units to cgs for density */ /*! Conversion factor from internal units to cgs for density */
double conv_factor_density_to_cgs; double conv_factor_density_to_cgs;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment