Commit bccd9547 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Pass the cosmological model to the cooling function and get the physcial...

Pass the cosmological model to the cooling function and get the physcial density and internal energy.
parent fe5c53a1
......@@ -52,6 +52,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data.
* @param xp Pointer to the extended particle data.
......@@ -60,6 +61,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {}
......@@ -69,11 +71,13 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
* @param cooling The #cooling_function_data used in the run.
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param p Pointer to the particle data.
*/
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct cosmology* restrict cosmo,
const struct unit_system* restrict us, const struct part* restrict p) {
return FLT_MAX;
......
......@@ -62,6 +62,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data.
* @param xp Pointer to the extended particle data.
......@@ -70,6 +71,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {
......@@ -77,7 +79,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
const float u_floor = cooling->min_energy;
/* Get current internal energy */
const float u_old = hydro_get_internal_energy(p);
const float u_old = hydro_get_physical_internal_energy(p, cosmo);
/* Current du_dt */
const float hydro_du_dt = hydro_get_internal_energy_dt(p);
......@@ -108,16 +110,18 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
*
* @param cooling The #cooling_function_data used in the run.
* @param phys_const The physical constants in internal units.
* @param cosmo The current cosmological model.
* @param us The internal system of units.
* @param p Pointer to the particle data.
*/
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct cosmology* restrict cosmo,
const struct unit_system* restrict us, const struct part* restrict p) {
const float cooling_rate = cooling->cooling_rate;
const float internal_energy = hydro_get_internal_energy(p);
const float internal_energy = hydro_get_physical_internal_energy(p, cosmo);
return cooling->cooling_tstep_mult * internal_energy / fabsf(cooling_rate);
}
......
......@@ -52,15 +52,17 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data..
*/
__attribute__((always_inline)) INLINE static float cooling_rate(
const struct phys_const* const phys_const, const struct unit_system* us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* cooling, const struct part* p) {
/* Get particle density */
const float rho = hydro_get_density(p);
const float rho = hydro_get_physical_density(p, cosmo);
/* Get cooling function properties */
const float X_H = cooling->hydrogen_mass_abundance;
......@@ -77,6 +79,7 @@ __attribute__((always_inline)) INLINE static float cooling_rate(
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data.
* @param dt The time-step of this particle.
......@@ -84,6 +87,7 @@ __attribute__((always_inline)) INLINE static float cooling_rate(
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {
......@@ -91,13 +95,13 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
const float u_floor = cooling->min_energy;
/* Current energy */
const float u_old = hydro_get_internal_energy(p);
const float u_old = hydro_get_physical_internal_energy(p, cosmo);
/* Current du_dt */
const float hydro_du_dt = hydro_get_internal_energy_dt(p);
/* Calculate cooling du_dt */
float cooling_du_dt = cooling_rate(phys_const, us, cooling, p);
float cooling_du_dt = cooling_rate(phys_const, us, cosmo, cooling, p);
/* Integrate cooling equation to enforce energy floor */
/* Factor of 1.5 included since timestep could potentially double */
......@@ -117,17 +121,19 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
*
* @param cooling The #cooling_function_data used in the run.
* @param phys_const The physical constants in internal units.
* @param cosmo The current cosmological model.
* @param us The internal system of units.
* @param p Pointer to the particle data.
*/
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct cosmology* restrict cosmo,
const struct unit_system* restrict us, const struct part* restrict p) {
/* Get current internal energy */
const float u = hydro_get_internal_energy(p);
const float du_dt = cooling_rate(phys_const, us, cooling, p);
const float u = hydro_get_physical_internal_energy(p, cosmo);
const float du_dt = cooling_rate(phys_const, us, cosmo, cooling, p);
/* If we are close to (or below) the energy floor, we ignore the condition */
if (u < 1.01f * cooling->min_energy)
......
......@@ -120,6 +120,7 @@ __attribute__((always_inline)) INLINE static void cooling_print_backend(
__attribute__((always_inline)) INLINE static double cooling_rate(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, float dt) {
......@@ -147,8 +148,8 @@ __attribute__((always_inline)) INLINE static double cooling_rate(
data.grid_end = grid_end;
/* general particle data */
gr_float density = hydro_get_density(p);
const double energy_before = hydro_get_internal_energy(p);
gr_float density = hydro_get_physical_density(p, cosmo);
const double energy_before = hydro_get_physical_internal_energy(p, cosmo);
gr_float energy = energy_before;
gr_float vx = 0;
gr_float vy = 0;
......@@ -221,6 +222,7 @@ __attribute__((always_inline)) INLINE static double cooling_rate(
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data.
* @param dt The time-step of this particle.
......@@ -228,6 +230,7 @@ __attribute__((always_inline)) INLINE static double cooling_rate(
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {
......@@ -237,7 +240,7 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
const float hydro_du_dt = hydro_get_internal_energy_dt(p);
/* compute cooling rate */
const float du_dt = cooling_rate(phys_const, us, cooling, p, dt);
const float du_dt = cooling_rate(phys_const, us, cosmo, cooling, p, dt);
/* record energy lost */
xp->cooling_data.radiated_energy += -du_dt * dt * hydro_get_mass(p);
......@@ -253,12 +256,14 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
*
* @param cooling The #cooling_function_data used in the run.
* @param phys_const The physical constants in internal units.
* @param cosmo The current cosmological model.
* @param us The internal system of units.
* @param p Pointer to the particle data.
*/
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct cosmology* restrict cosmo,
const struct unit_system* restrict us, const struct part* restrict p) {
return FLT_MAX;
......
......@@ -54,6 +54,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
*
* @param phys_const The physical constants in internal units.
* @param us The internal system of units.
* @param cosmo The current cosmological model.
* @param cooling The #cooling_function_data used in the run.
* @param p Pointer to the particle data.
* @param xp Pointer to the extended particle data.
......@@ -62,6 +63,7 @@ __attribute__((always_inline)) INLINE static void cooling_write_flavour(
__attribute__((always_inline)) INLINE static void cooling_cool_part(
const struct phys_const* restrict phys_const,
const struct unit_system* restrict us,
const struct cosmology* restrict cosmo,
const struct cooling_function_data* restrict cooling,
struct part* restrict p, struct xpart* restrict xp, float dt) {}
......@@ -72,12 +74,14 @@ __attribute__((always_inline)) INLINE static void cooling_cool_part(
*
* @param cooling The #cooling_function_data used in the run.
* @param phys_const The physical constants in internal units.
* @param cosmo The current cosmological model.
* @param us The internal system of units.
* @param p Pointer to the particle data.
*/
__attribute__((always_inline)) INLINE static float cooling_timestep(
const struct cooling_function_data* restrict cooling,
const struct phys_const* restrict phys_const,
const struct cosmology* restrict cosmo,
const struct unit_system* restrict us, const struct part* restrict p) {
return FLT_MAX;
......
......@@ -230,7 +230,7 @@ void runner_do_cooling(struct runner *r, struct cell *c, int timer) {
}
/* Let's cool ! */
cooling_cool_part(constants, us, cooling_func, p, xp, dt_cool);
cooling_cool_part(constants, us, cosmo, cooling_func, p, xp, dt_cool);
}
}
}
......
......@@ -119,7 +119,7 @@ __attribute__((always_inline)) INLINE static integertime_t get_part_timestep(
float new_dt_cooling = FLT_MAX;
if (e->policy & engine_policy_cooling)
new_dt_cooling = cooling_timestep(e->cooling_func, e->physical_constants,
e->internal_units, p);
e->cosmology, e->internal_units, p);
/* Compute the next timestep (gravity condition) */
float new_dt_grav = FLT_MAX, new_dt_self_grav = FLT_MAX,
......
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