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
......@@ -49,7 +49,7 @@ InitialConditions:
# Dimensionless pre-factor for the time-step condition
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 with Grackle 2.0
......
......@@ -35,7 +35,7 @@ InitialConditions:
# Dimensionless pre-factor for the time-step condition
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 with Grackle 2.0
......
......@@ -41,5 +41,5 @@ IsothermalPotential:
# Cooling parameters
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
......@@ -41,5 +41,5 @@ IsothermalPotential:
# Cooling parameters
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
......@@ -71,7 +71,7 @@ git = sim["Code"].attrs["Git Revision"]
cooling_model = sim["/SubgridScheme"].attrs["Cooling Model"]
if cooling_model == "Constant Lambda":
Lambda = sim["/SubgridScheme"].attrs["Lambda [cgs]"][0]
Lambda = sim["/SubgridScheme"].attrs["Lambda/n_H^2 [cgs]"][0]
# Cosmological parameters
H_0 = sim["/Cosmology"].attrs["H0 [internal units]"][0]
......
......@@ -59,4 +59,4 @@ InitialConditions:
# Constant lambda cooling function
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:
# Constant lambda cooling function
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 with Grackle 3.0
......
......@@ -47,8 +47,10 @@
/**
* @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 returned value is in physical [erg * g^-1 * s^-1].
* The cooling rate is \f$\frac{du}{dt} = -\frac{\Lambda}{n_H^2}
* \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 hydro_props The properties of the hydro scheme.
......@@ -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 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_cgs = rho * cooling->conv_factor_density_to_cgs;
/* Get 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;
/* Calculate du_dt (Lambda * n_H^2 / rho) */
const double du_dt_cgs = -cooling->lambda_cgs * n_H_cgs * n_H_cgs / rho_cgs;
/* Calculate du_dt ((Lambda / n_H^2) * n_H^2 / rho) */
const double du_dt_cgs =
-cooling->lambda_nH2_cgs * n_H_cgs * n_H_cgs / rho_cgs;
return du_dt_cgs;
}
......@@ -238,8 +241,8 @@ static INLINE void cooling_init_backend(struct swift_params* parameter_file,
struct cooling_function_data* cooling) {
/* Read in the cooling parameters */
cooling->lambda_cgs =
parser_get_param_double(parameter_file, "LambdaCooling:lambda_cgs");
cooling->lambda_nH2_cgs =
parser_get_param_double(parameter_file, "LambdaCooling:lambda_nH2_cgs");
cooling->cooling_tstep_mult = parser_get_opt_param_float(
parameter_file, "LambdaCooling:cooling_tstep_mult", FLT_MAX);
......@@ -265,9 +268,10 @@ static INLINE void cooling_print_backend(
const struct cooling_function_data* cooling) {
message(
"Cooling function is 'Constant lambda' with Lambda=%g [erg * s^-1 * "
"cm^-3]",
cooling->lambda_cgs);
"Cooling function is 'Constant lambda' with Lambda/n_H^2=%g [erg * s^-1 "
"* "
"cm^3]",
cooling->lambda_nH2_cgs);
if (cooling->cooling_tstep_mult == FLT_MAX)
message("Cooling function time-step size is unlimited");
......
......@@ -45,7 +45,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
hid_t h_grp, const struct cooling_function_data* cooling) {
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
......
......@@ -33,8 +33,8 @@
*/
struct cooling_function_data {
/*! Cooling rate in physical cgs units [erg * s^-1 * cm^-3] */
double lambda_cgs;
/*! Cooling rate / nH^2 in physical cgs units [erg * s^-1 * cm^3] */
double lambda_nH2_cgs;
/*! Conversion factor from internal units to cgs for density */
double conv_factor_density_to_cgs;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment