diff --git a/src/hydro/Default/hydro.h b/src/hydro/Default/hydro.h index e14fc29aefccf8643c19c342ca9ebe645a323db1..f5e71a8762c54faca7d165eb26199d0e30b486ac 100644 --- a/src/hydro/Default/hydro.h +++ b/src/hydro/Default/hydro.h @@ -351,16 +351,22 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( /** * @brief Prepare a particle for the force calculation. * - * Computes viscosity term, conduction term and smoothing length gradient terms. + * This function is called in the ghost task to convert some quantities coming + * from the density loop over neighbours into quantities ready to be used in the + * force loop over neighbours. Quantities are typically read from the density + * sub-structure and written to the force sub-structure. + * Examples of calculations done here include the calculation of viscosity term + * constants, thermal conduction terms, hydro conversions, etc. * * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part *restrict p, struct xpart *restrict xp, - const struct cosmology *cosmo) { - + const struct cosmology *cosmo, const float dt_alpha) { const float fac_mu = cosmo->a_factor_mu; /* Some smoothing length multiples. */ diff --git a/src/hydro/Gadget2/hydro.h b/src/hydro/Gadget2/hydro.h index ec46b93f51804b28ce2cb71c134f8c643301e272..0dcd2cf01e9d3b93194fab96af836b6dd045d1f9 100644 --- a/src/hydro/Gadget2/hydro.h +++ b/src/hydro/Gadget2/hydro.h @@ -361,15 +361,22 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( /** * @brief Prepare a particle for the force calculation. * - * Computes viscosity term, conduction term and smoothing length gradient terms. + * This function is called in the ghost task to convert some quantities coming + * from the density loop over neighbours into quantities ready to be used in the + * force loop over neighbours. Quantities are typically read from the density + * sub-structure and written to the force sub-structure. + * Examples of calculations done here include the calculation of viscosity term + * constants, thermal conduction terms, hydro conversions, etc. * * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part *restrict p, struct xpart *restrict xp, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, const float dt_alpha) { const float fac_mu = cosmo->a_factor_mu; diff --git a/src/hydro/GizmoMFM/hydro.h b/src/hydro/GizmoMFM/hydro.h index e8f116efb30de769acdfd764b7f4dbd03dc91c31..d6b44e19899fdb74ee32f699665ec6e706d718b1 100644 --- a/src/hydro/GizmoMFM/hydro.h +++ b/src/hydro/GizmoMFM/hydro.h @@ -441,17 +441,22 @@ __attribute__((always_inline)) INLINE static void hydro_end_gradient( /** * @brief Prepare a particle for the force calculation. * - * This function is called in the extra_ghost task to convert some quantities - * coming from the gradient loop over neighbours into quantities ready to be - * used in the force loop over neighbours. + * This function is called in the ghost task to convert some quantities coming + * from the density loop over neighbours into quantities ready to be used in the + * force loop over neighbours. Quantities are typically read from the density + * sub-structure and written to the force sub-structure. + * Examples of calculations done here include the calculation of viscosity term + * constants, thermal conduction terms, hydro conversions, etc. * * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part* restrict p, struct xpart* restrict xp, - const struct cosmology* cosmo) { + const struct cosmology* cosmo, const float dt_alpha) { /* Initialise values that are used in the force loop */ p->flux.momentum[0] = 0.0f; diff --git a/src/hydro/GizmoMFV/hydro.h b/src/hydro/GizmoMFV/hydro.h index 98296a1a0d4fd5917c0f3cf4e492ac1c9916b360..24456b7bdf65acb516630d587e1319e58c96e2fe 100644 --- a/src/hydro/GizmoMFV/hydro.h +++ b/src/hydro/GizmoMFV/hydro.h @@ -466,17 +466,22 @@ __attribute__((always_inline)) INLINE static void hydro_end_gradient( /** * @brief Prepare a particle for the force calculation. * - * This function is called in the extra_ghost task to convert some quantities - * coming from the gradient loop over neighbours into quantities ready to be - * used in the force loop over neighbours. + * This function is called in the ghost task to convert some quantities coming + * from the density loop over neighbours into quantities ready to be used in the + * force loop over neighbours. Quantities are typically read from the density + * sub-structure and written to the force sub-structure. + * Examples of calculations done here include the calculation of viscosity term + * constants, thermal conduction terms, hydro conversions, etc. * * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part* restrict p, struct xpart* restrict xp, - const struct cosmology* cosmo) { + const struct cosmology* cosmo, const float dt_alpha) { /* Initialise values that are used in the force loop */ p->gravity.mflux[0] = 0.0f; diff --git a/src/hydro/Minimal/hydro.h b/src/hydro/Minimal/hydro.h index acac81ecdf435af02a15f89a13d689b043f26f96..cf629814817064c109f7f016f81b6c621b087436 100644 --- a/src/hydro/Minimal/hydro.h +++ b/src/hydro/Minimal/hydro.h @@ -385,10 +385,12 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part *restrict p, struct xpart *restrict xp, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, const float dt_alpha) { /* Compute the pressure */ const float pressure = gas_pressure_from_internal_energy(p->rho, p->u); diff --git a/src/hydro/Planetary/hydro.h b/src/hydro/Planetary/hydro.h index b7cd16d3773c1ab538636d143d9488576a33ebb1..57025b17e106ae4b71f150d2c2d319e92752ec9e 100644 --- a/src/hydro/Planetary/hydro.h +++ b/src/hydro/Planetary/hydro.h @@ -393,10 +393,12 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part *restrict p, struct xpart *restrict xp, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, const float dt_alpha) { #ifdef PLANETARY_SPH_BALSARA const float fac_mu = cosmo->a_factor_mu; diff --git a/src/hydro/PressureEnergy/hydro.h b/src/hydro/PressureEnergy/hydro.h index 32075481be7cadc08bad01fe13f4d9d3f5a24b0e..0ee25c3adbe8d3f46a461692f26ccccf0390b338 100644 --- a/src/hydro/PressureEnergy/hydro.h +++ b/src/hydro/PressureEnergy/hydro.h @@ -427,10 +427,12 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part *restrict p, struct xpart *restrict xp, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, const float dt_alpha) { const float fac_mu = cosmo->a_factor_mu; diff --git a/src/hydro/PressureEntropy/hydro.h b/src/hydro/PressureEntropy/hydro.h index 95608b5538be5fe46094209b12ec416582396431..a5c0c62c385a2304adb27ccbad4b7f6769d8b5d0 100644 --- a/src/hydro/PressureEntropy/hydro.h +++ b/src/hydro/PressureEntropy/hydro.h @@ -370,15 +370,22 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( /** * @brief Prepare a particle for the force calculation. * - * Computes viscosity term, conduction term and smoothing length gradient terms. + * This function is called in the ghost task to convert some quantities coming + * from the density loop over neighbours into quantities ready to be used in the + * force loop over neighbours. Quantities are typically read from the density + * sub-structure and written to the force sub-structure. + * Examples of calculations done here include the calculation of viscosity term + * constants, thermal conduction terms, hydro conversions, etc. * * @param p The particle to act upon * @param xp The extended particle data to act upon * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part *restrict p, struct xpart *restrict xp, - const struct cosmology *cosmo) { + const struct cosmology *cosmo, const float dt_alpha) { const float fac_mu = cosmo->a_factor_mu; diff --git a/src/hydro/Shadowswift/hydro.h b/src/hydro/Shadowswift/hydro.h index 6b8046bac8210e6edd8c3bbbf5e8310e401e4c06..0715223850023be90294e5ccaa43c197c8eab2d4 100644 --- a/src/hydro/Shadowswift/hydro.h +++ b/src/hydro/Shadowswift/hydro.h @@ -283,22 +283,24 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours( } /** - * @brief Prepare a particle for the gradient calculation. - * - * The name of this method is confusing, as this method is really called after - * the density loop and before the gradient loop. + * @brief Prepare a particle for the force calculation. * - * We use it to set the physical timestep for the particle and to copy the - * actual velocities, which we need to boost our interfaces during the flux - * calculation. We also initialize the variables used for the time step - * calculation. + * This function is called in the ghost task to convert some quantities coming + * from the density loop over neighbours into quantities ready to be used in the + * force loop over neighbours. Quantities are typically read from the density + * sub-structure and written to the force sub-structure. + * Examples of calculations done here include the calculation of viscosity term + * constants, thermal conduction terms, hydro conversions, etc. * - * @param p The particle to act upon. - * @param xp The extended particle data to act upon. + * @param p The particle to act upon + * @param xp The extended particle data to act upon + * @param cosmo The current cosmological model. + * @param dt_alpha The time-step used to evolve non-cosmological quantities such + * as the artificial viscosity. */ __attribute__((always_inline)) INLINE static void hydro_prepare_force( struct part* restrict p, struct xpart* restrict xp, - const struct cosmology* cosmo) { + const struct cosmology* cosmo, const float dt_alpha) { /* Initialize time step criterion variables */ p->timestepvars.vmax = 0.0f; diff --git a/src/runner.c b/src/runner.c index 0be6288cbcc0b77fbe9ba3128d820b82a8943480..828adc4185e2050fee2c48fa31b7af3ad7962f7e 100644 --- a/src/runner.c +++ b/src/runner.c @@ -642,6 +642,8 @@ void runner_do_extra_ghost(struct runner *r, struct cell *c, int timer) { struct xpart *restrict xparts = c->xparts; const int count = c->count; const struct engine *e = r->e; + const integertime_t ti_end = e->ti_current; + const double time_base = e->time_base; const struct cosmology *cosmo = e->cosmology; TIMER_TIC; @@ -663,6 +665,16 @@ void runner_do_extra_ghost(struct runner *r, struct cell *c, int timer) { struct xpart *restrict xp = &xparts[i]; if (part_is_active(p, e)) { + /* Calculate the time-step for passing to hydro_prepare_force, used for + * the evolution of alpha factors (i.e. those involved in the artificial + * viscosity and thermal conduction terms) */ + double dt_alpha; + if (with_cosmology) { + const integertime_t ti_step = get_integer_timestep(p->time_bin); + dt_alpha = cosmology_get_delta_time(cosmo, ti_end - ti_step, ti_end); + } else { + dt_alpha = get_timestep(p->time_bin, time_base); + } /* Finish the gradient calculation */ hydro_end_gradient(p); @@ -670,7 +682,7 @@ void runner_do_extra_ghost(struct runner *r, struct cell *c, int timer) { /* As of here, particle force variables will be set. */ /* Compute variables required for the force loop */ - hydro_prepare_force(p, xp, cosmo); + hydro_prepare_force(p, xp, cosmo, dt_alpha); /* The particle force values are now set. Do _NOT_ try to read any particle density variables! */ @@ -705,10 +717,13 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { const struct hydro_space *hs = &s->hs; const struct cosmology *cosmo = e->cosmology; const struct chemistry_global_data *chemistry = e->chemistry; + const double time_base = e->time_base; + const integertime_t ti_end = e->ti_current; const float hydro_h_max = e->hydro_properties->h_max; const float eps = e->hydro_properties->h_tolerance; const float hydro_eta_dim = pow_dimension(e->hydro_properties->eta_neighbours); + const int with_cosmology = (e->policy & engine_policy_cosmology); const int max_smoothing_iter = e->hydro_properties->max_smoothing_iterations; int redo = 0, count = 0; @@ -759,6 +774,17 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { float h_new; int has_no_neighbours = 0; + /* Calculate the time-step for passing to hydro_prepare_force, used for + * the evolution of alpha factors (i.e. those involved in the artificial + * viscosity and thermal conduction terms) */ + double dt_alpha; + if (with_cosmology) { + const integertime_t ti_step = get_integer_timestep(p->time_bin); + dt_alpha = cosmology_get_delta_time(cosmo, ti_end - ti_step, ti_end); + } else { + dt_alpha = get_timestep(p->time_bin, time_base); + } + if (p->density.wcount == 0.f) { /* No neighbours case */ /* Flag that there were no neighbours */ @@ -784,9 +810,9 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* Skip if h is already h_max and we don't have enough neighbours */ if ((p->h >= hydro_h_max) && (f < 0.f)) { - /* We have a particle whose smoothing length is already set (wants to - * be larger but has already hit the maximum). So, just tidy up as if - * the smoothing length had converged correctly */ + /* We have a particle whose smoothing length is already set (wants + * to be larger but has already hit the maximum). So, just tidy up + * as if the smoothing length had converged correctly */ #ifdef EXTRA_HYDRO_LOOP @@ -806,7 +832,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* As of here, particle force variables will be set. */ /* Compute variables required for the force loop */ - hydro_prepare_force(p, xp, cosmo); + hydro_prepare_force(p, xp, cosmo, dt_alpha); /* The particle force values are now set. Do _NOT_ try to read any particle density variables! */ @@ -888,7 +914,7 @@ void runner_do_ghost(struct runner *r, struct cell *c, int timer) { /* As of here, particle force variables will be set. */ /* Compute variables required for the force loop */ - hydro_prepare_force(p, xp, cosmo); + hydro_prepare_force(p, xp, cosmo, dt_alpha); /* The particle force values are now set. Do _NOT_ try to read any particle density variables! */