Commit a1784eb7 authored by Josh Borrow's avatar Josh Borrow Committed by Matthieu Schaller
Browse files

Add viscosity to parameterfile

parent 78a4dbbc
......@@ -28,3 +28,9 @@ scheme it includes a Monaghan AV scheme and a Balsara switch.
.. code-block:: bash
./configure --with-hydro="pressure-energy"
Both of the above schemes use a very simple, fixed artificial viscosity, only
the ``SPH:viscosity_alpha`` parameter has any effect for this scheme. This will
change the strength of the artificial viscosity throughout the simulation, and
has a default of 0.8.
......@@ -10,11 +10,17 @@ Minimal (Density-Energy) SPH
:caption: Contents:
This scheme is a textbook implementation of Density-Energy SPH, and can be used
as a pedagogical example. It also implements a Monaghan AV scheme, like the
GADGET-2 scheme. It uses very similar equations, but differs in implementation
details; namely it tracks the internal energy \(u\) as the thermodynamic
variable, rather than entropy \(A\). To use the minimal scheme, use
as a pedagogical example. It also implements a Monaghan AV scheme with a
Balsara switch, like the GADGET-2 scheme. It uses very similar equations, but
differs in implementation details; namely it tracks the internal energy \(u\)
as the thermodynamic variable, rather than entropy \(A\). To use the minimal
scheme, use
.. code-block:: bash
./configure --with-hydro="minimal"
As it uses a very simple, fixed artificial viscosity, only the
``SPH:viscosity_alpha`` parameter has any effect for this scheme. This will
change the strength of the artificial viscosity throughout the simulation,
and has a default of 0.8.
......@@ -15,3 +15,8 @@ a Monaghan artificial viscosity scheme and Balsara switch.
To use this hydro scheme, you need no extra configuration options -- it is the
default!
As it uses a very simple, fixed artificial viscosity, only the
``SPH:viscosity_alpha`` parameter has any effect for this scheme. This will
change the strength of the artificial viscosity throughout the simulation,
and has a default of 0.8.
......@@ -34,6 +34,10 @@ SPH:
minimal_temperature: 0 # (Optional) Minimal temperature (in internal units) allowed for the gas particles. Value is ignored if set to 0.
H_mass_fraction: 0.755 # (Optional) Hydrogen mass fraction used for initial conversion from temp to internal energy. Default value is derived from the physical constants.
H_ionization_temperature: 1e4 # (Optional) Temperature of the transition from neutral to ionized Hydrogen for primoridal gas.
viscosity_alpha: 0.8 # (Optional) Override for the initial value of the artificial viscosity. In schemes that have a fixed AV, this remains as alpha throughout the run.
viscosity_alpha_max: 2.0 # (Optional) Maximal value for the artificial viscosity in schemes that allow alpha to vary
viscosity_alpha_min: 0.1 # (Optional) Minimal value for the artificial viscosity in schemes that allow alpha to vary
viscosity_length: 0.1 # (Optional) Decay length for the artificial viscosity in schemes that allow alpha to vary
# Parameters for the self-gravity scheme
Gravity:
......
......@@ -21,18 +21,11 @@
#define SWIFT_CONST_H
/* SPH Viscosity constants. */
/* Cosmology defaults: a=0.8, b=3.0. Planetary defaults: a=1.5, b=4.0
/* Cosmology default beta=3.0. Planetary default beta=4.0
* Alpha can be set in the parameter file.
* Beta is defined as in e.g. Price (2010) Eqn (103) */
#define const_viscosity_alpha 0.8f
#define const_viscosity_beta 3.0f
#define const_viscosity_alpha_min \
0.1f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_alpha_max \
2.0f /* Values taken from (Price,2004), not used in legacy gadget mode */
#define const_viscosity_length \
0.1f /* Values taken from (Price,2004), not used in legacy gadget mode */
/* SPH Thermal conductivity constants. */
#define const_conductivity_alpha \
1.f /* Value taken from (Price,2008), not used in legacy gadget mode */
......
......@@ -458,12 +458,14 @@ __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 hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
const float fac_mu = cosmo->a_factor_mu;
/* Some smoothing length multiples. */
......@@ -492,6 +494,9 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
p->force.balsara =
normDiv_v / (normDiv_v + normRot_v + 0.0001f * fac_mu * fc * h_inv);
/* Set the AV property */
p->alpha = hydro_props->viscosity.alpha;
/* Viscosity parameter decay time */
/* const float tau = h / (2.f * const_viscosity_length * p->force.soundspeed);
*/
......@@ -500,8 +505,8 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
/* const float S = max(-normDiv_v, 0.f); */
/* Compute the particle's viscosity parameter time derivative */
/* const float alpha_dot = (const_viscosity_alpha_min - p->alpha) / tau + */
/* (const_viscosity_alpha_max - p->alpha) * S; */
/* const float alpha_dot = (hydro_props->viscosity.alpha_max) - p->alpha) / tau + */
/* (hydro_props->viscosity.alpha_max - p->alpha) * S; */
/* Update particle's viscosity paramter */
/* p->alpha += alpha_dot * (p->ti_end - p->ti_begin) * timeBase; */ // MATTHIEU
......
......@@ -183,13 +183,6 @@ INLINE static void hydro_write_flavour(hid_t h_grpsph) {
h_grpsph, "Viscosity Model",
"Morris & Monaghan (1997), Rosswog, Davies, Thielemann & "
"Piran (2000) with additional Balsara (1995) switch");
io_write_attribute_f(h_grpsph, "Viscosity alpha_min",
const_viscosity_alpha_min);
io_write_attribute_f(h_grpsph, "Viscosity alpha_max",
const_viscosity_alpha_max);
io_write_attribute_f(h_grpsph, "Viscosity beta", 2.f);
io_write_attribute_f(h_grpsph, "Viscosity decay length",
const_viscosity_length);
/* Time integration properties */
io_write_attribute_f(h_grpsph, "Maximal Delta u change over dt",
......
......@@ -472,12 +472,14 @@ __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 hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
const float fac_mu = cosmo->a_factor_mu;
......@@ -502,8 +504,10 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
const float P_over_rho2 = pressure * rho_inv * rho_inv;
/* Compute the Balsara switch */
/* Pre-multiply in the AV factor; hydro_props are not passed to the iact functions */
const float balsara =
abs_div_v / (abs_div_v + curl_v + 0.0001f * fac_mu * soundspeed / p->h);
hydro_props->viscosity.alpha * abs_div_v /
(abs_div_v + curl_v + 0.0001f * fac_mu * soundspeed / p->h);
/* Compute the "grad h" term */
const float omega_inv =
......
......@@ -497,8 +497,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
/* Now construct the full viscosity term */
const float rho_ij = 0.5f * (rhoi + rhoj);
const float visc = -0.25f * const_viscosity_alpha * v_sig * mu_ij *
(balsara_i + balsara_j) / rho_ij;
const float visc = -0.25f * v_sig * mu_ij * (balsara_i + balsara_j) / rho_ij;
/* Now, convolve with the kernel */
const float visc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
......@@ -620,8 +619,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
/* Now construct the full viscosity term */
const float rho_ij = 0.5f * (rhoi + rhoj);
const float visc = -0.25f * const_viscosity_alpha * v_sig * mu_ij *
(balsara_i + balsara_j) / rho_ij;
const float visc = -0.25f * v_sig * mu_ij * (balsara_i + balsara_j) / rho_ij;
/* Now, convolve with the kernel */
const float visc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
......@@ -654,8 +652,6 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
}
#ifdef WITH_VECTORIZATION
static const vector const_viscosity_alpha_fac =
FILL_VEC(-0.25f * const_viscosity_alpha);
/**
* @brief Force interaction computed using 1 vector
......@@ -746,7 +742,7 @@ runner_iact_nonsym_1_vec_force(
/* Now construct the full viscosity term */
rho_ij.v = vec_mul(vec_set1(0.5f), vec_add(pirho.v, pjrho.v));
visc.v = vec_div(vec_mul(const_viscosity_alpha_fac.v,
visc.v = vec_div(vec_mul(vec_set1(-0.25f),
vec_mul(v_sig.v, vec_mul(mu_ij.v, balsara.v))),
rho_ij.v);
......@@ -937,11 +933,11 @@ runner_iact_nonsym_2_vec_force(
rho_ij.v = vec_mul(vec_set1(0.5f), vec_add(pirho.v, pjrho.v));
rho_ij_2.v = vec_mul(vec_set1(0.5f), vec_add(pirho.v, pjrho_2.v));
visc.v = vec_div(vec_mul(const_viscosity_alpha_fac.v,
visc.v = vec_div(vec_mul(vec_set1(-0.25f),
vec_mul(v_sig.v, vec_mul(mu_ij.v, balsara.v))),
rho_ij.v);
visc_2.v =
vec_div(vec_mul(const_viscosity_alpha_fac.v,
vec_div(vec_mul(vec_set1(-0.25f),
vec_mul(v_sig_2.v, vec_mul(mu_ij_2.v, balsara_2.v))),
rho_ij_2.v);
......
......@@ -200,8 +200,6 @@ INLINE static void hydro_write_flavour(hid_t h_grpsph) {
io_write_attribute_s(
h_grpsph, "Viscosity Model",
"as in Springel (2005), i.e. Monaghan (1992) with Balsara (1995) switch");
io_write_attribute_f(h_grpsph, "Viscosity alpha", const_viscosity_alpha);
io_write_attribute_f(h_grpsph, "Viscosity beta", 3.f);
}
/**
......
......@@ -451,12 +451,14 @@ __attribute__((always_inline)) INLINE static void hydro_end_gradient(
* @param p The particle to act upon
* @param xp The extended particle data to act upon
* @param cosmo The current cosmological model.
* @param hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
struct part *restrict p, struct xpart *restrict xp,
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
/* Initialise values that are used in the force loop */
p->flux.momentum[0] = 0.0f;
......
......@@ -476,12 +476,14 @@ __attribute__((always_inline)) INLINE static void hydro_end_gradient(
* @param p The particle to act upon
* @param xp The extended particle data to act upon
* @param cosmo The current cosmological model.
* @param hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
struct part *restrict p, struct xpart *restrict xp,
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
/* Initialise values that are used in the force loop */
p->gravity.mflux[0] = 0.0f;
......
......@@ -389,6 +389,10 @@ __attribute__((always_inline)) INLINE static void hydro_init_part(
p->density.wcount_dh = 0.f;
p->rho = 0.f;
p->density.rho_dh = 0.f;
p->density.div_v = 0.f;
p->density.rot_v[0] = 0.f;
p->density.rot_v[1] = 0.f;
p->density.rot_v[2] = 0.f;
}
/**
......@@ -424,6 +428,17 @@ __attribute__((always_inline)) INLINE static void hydro_end_density(
p->density.rho_dh *= h_inv_dim_plus_one;
p->density.wcount *= h_inv_dim;
p->density.wcount_dh *= h_inv_dim_plus_one;
const float rho_inv = 1.f / p->rho;
const float a_inv2 = cosmo->a2_inv;
/* Finish calculation of the (physical) velocity curl components */
p->density.rot_v[0] *= h_inv_dim_plus_one * a_inv2 * rho_inv;
p->density.rot_v[1] *= h_inv_dim_plus_one * a_inv2 * rho_inv;
p->density.rot_v[2] *= h_inv_dim_plus_one * a_inv2 * rho_inv;
/* Finish calculation of the (physical) velocity divergence */
p->density.div_v *= h_inv_dim_plus_one * a_inv2 * rho_inv;
}
/**
......@@ -451,6 +466,10 @@ __attribute__((always_inline)) INLINE static void hydro_part_has_no_neighbours(
p->density.wcount = kernel_root * h_inv_dim;
p->density.rho_dh = 0.f;
p->density.wcount_dh = 0.f;
p->density.div_v = 0.f;
p->density.rot_v[0] = 0.f;
p->density.rot_v[1] = 0.f;
p->density.rot_v[2] = 0.f;
}
/**
......@@ -466,12 +485,24 @@ __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 hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
const float fac_mu = cosmo->a_factor_mu;
/* Compute the norm of the curl */
const float curl_v = sqrtf(p->density.rot_v[0] * p->density.rot_v[0] +
p->density.rot_v[1] * p->density.rot_v[1] +
p->density.rot_v[2] * p->density.rot_v[2]);
/* Compute the norm of div v */
const float abs_div_v = fabsf(p->density.div_v);
/* Compute the pressure */
const float pressure = gas_pressure_from_internal_energy(p->rho, p->u);
......@@ -484,10 +515,17 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
const float grad_h_term =
1.f / (1.f + hydro_dimension_inv * p->h * p->density.rho_dh * rho_inv);
/* Compute the Balsara switch */
/* Pre-multiply in the AV factor; hydro_props are not passed to the iact functions */
const float balsara =
hydro_props->viscosity.alpha * abs_div_v /
(abs_div_v + curl_v + 0.0001f * fac_mu * soundspeed / p->h);
/* Update variables. */
p->force.f = grad_h_term;
p->force.pressure = pressure;
p->force.soundspeed = soundspeed;
p->force.balsara = balsara;
}
/**
......
......@@ -80,6 +80,33 @@ __attribute__((always_inline)) INLINE static void runner_iact_density(
pj->density.rho_dh -= mi * (hydro_dimension * wj + uj * wj_dx);
pj->density.wcount += wj;
pj->density.wcount_dh -= (hydro_dimension * wj + uj * wj_dx);
/* Compute dv dot r */
float dv[3], curlvr[3];
const float faci = mj * wi_dx * r_inv;
const float facj = mi * wj_dx * r_inv;
dv[0] = pi->v[0] - pj->v[0];
dv[1] = pi->v[1] - pj->v[1];
dv[2] = pi->v[2] - pj->v[2];
const float dvdr = dv[0] * dx[0] + dv[1] * dx[1] + dv[2] * dx[2];
pi->density.div_v -= faci * dvdr;
pj->density.div_v -= facj * dvdr;
/* Compute dv cross r */
curlvr[0] = dv[1] * dx[2] - dv[2] * dx[1];
curlvr[1] = dv[2] * dx[0] - dv[0] * dx[2];
curlvr[2] = dv[0] * dx[1] - dv[1] * dx[0];
pi->density.rot_v[0] += faci * curlvr[0];
pi->density.rot_v[1] += faci * curlvr[1];
pi->density.rot_v[2] += faci * curlvr[2];
pj->density.rot_v[0] += facj * curlvr[0];
pj->density.rot_v[1] += facj * curlvr[1];
pj->density.rot_v[2] += facj * curlvr[2];
}
/**
......@@ -115,6 +142,27 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_density(
pi->density.rho_dh -= mj * (hydro_dimension * wi + ui * wi_dx);
pi->density.wcount += wi;
pi->density.wcount_dh -= (hydro_dimension * wi + ui * wi_dx);
/* Compute dv dot r */
float dv[3], curlvr[3];
const float faci = mj * wi_dx * r_inv;
dv[0] = pi->v[0] - pj->v[0];
dv[1] = pi->v[1] - pj->v[1];
dv[2] = pi->v[2] - pj->v[2];
const float dvdr = dv[0] * dx[0] + dv[1] * dx[1] + dv[2] * dx[2];
pi->density.div_v -= faci * dvdr;
/* Compute dv cross r */
curlvr[0] = dv[1] * dx[2] - dv[2] * dx[1];
curlvr[1] = dv[2] * dx[0] - dv[0] * dx[2];
curlvr[2] = dv[0] * dx[1] - dv[1] * dx[0];
pi->density.rot_v[0] += faci * curlvr[0];
pi->density.rot_v[1] += faci * curlvr[1];
pi->density.rot_v[2] += faci * curlvr[2];
}
/**
......@@ -186,9 +234,13 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
const float cj = pj->force.soundspeed;
const float v_sig = ci + cj - const_viscosity_beta * mu_ij;
/* Grab balsara switches */
const float balsara_i = pi->force.balsara;
const float balsara_j = pj->force.balsara;
/* Construct the full viscosity term */
const float rho_ij = 0.5f * (rhoi + rhoj);
const float visc = -0.5f * const_viscosity_alpha * v_sig * mu_ij / rho_ij;
const float visc = -0.25f * v_sig * (balsara_i + balsara_j) * mu_ij / rho_ij;
/* Convolve with the kernel */
const float visc_acc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
......@@ -302,9 +354,13 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
const float cj = pj->force.soundspeed;
const float v_sig = ci + cj - const_viscosity_beta * mu_ij;
/* Grab balsara switches */
const float balsara_i = pi->force.balsara;
const float balsara_j = pj->force.balsara;
/* Construct the full viscosity term */
const float rho_ij = 0.5f * (rhoi + rhoj);
const float visc = -0.5f * const_viscosity_alpha * v_sig * mu_ij / rho_ij;
const float visc = -0.25f * v_sig * (balsara_i + balsara_j) * mu_ij / rho_ij;
/* Convolve with the kernel */
const float visc_acc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
......
......@@ -124,6 +124,12 @@ struct part {
/*! Derivative of density with respect to h */
float rho_dh;
/*! Velocity divergence */
float div_v;
/*! Velocity curl */
float rot_v[3];
} density;
/**
......@@ -150,6 +156,9 @@ struct part {
/*! Time derivative of smoothing length */
float h_dt;
/*! Balsara switch */
float balsara;
} force;
};
......
......@@ -488,14 +488,15 @@ __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 hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
#ifndef PLANETARY_SPH_NO_BALSARA
const float fac_mu = cosmo->a_factor_mu;
/* Compute the norm of the curl */
......@@ -505,7 +506,6 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
/* Compute the norm of div v */
const float abs_div_v = fabsf(p->density.div_v);
#endif
/* Compute the pressure */
const float pressure =
......@@ -527,20 +527,20 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
grad_h_term = 0.f;
}
#ifndef PLANETARY_SPH_NO_BALSARA
/* Compute the Balsara switch */
#ifdef PLANETARY_SPH_NO_BALSARA
const float balsara = hydro_props->viscosity.alpha;
#else
const float balsara =
abs_div_v / (abs_div_v + curl_v + 0.0001f * fac_mu * soundspeed / p->h);
hydro_props->viscosity.alpha * abs_div_v /
(abs_div_v + curl_v + 0.0001f * fac_mu * soundspeed / p->h);
#endif
/* Update variables. */
p->force.f = grad_h_term;
p->force.pressure = pressure;
p->force.soundspeed = soundspeed;
#ifndef PLANETARY_SPH_NO_BALSARA
p->force.balsara = balsara;
#endif
}
/**
......
......@@ -176,11 +176,9 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
(pi->v[1] - pj->v[1]) * dx[1] +
(pi->v[2] - pj->v[2]) * dx[2] + a2_Hubble * r2;
#ifndef PLANETARY_SPH_NO_BALSARA
/* Balsara term */
const float balsara_i = pi->force.balsara;
const float balsara_j = pj->force.balsara;
#endif
/* Are the particles moving towards each other? */
const float omega_ij = min(dvdr, 0.f);
......@@ -193,12 +191,7 @@ __attribute__((always_inline)) INLINE static void runner_iact_force(
/* Now construct the full viscosity term */
const float rho_ij = 0.5f * (rhoi + rhoj);
#ifdef PLANETARY_SPH_NO_BALSARA
const float visc = -0.5f * const_viscosity_alpha * v_sig * mu_ij / rho_ij;
#else
const float visc = -0.25f * const_viscosity_alpha * v_sig * mu_ij *
(balsara_i + balsara_j) / rho_ij;
#endif
const float visc = -0.25f * v_sig * mu_ij * (balsara_i + balsara_j) / rho_ij;
/* Convolve with the kernel */
const float visc_acc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
......@@ -300,11 +293,9 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
(pi->v[1] - pj->v[1]) * dx[1] +
(pi->v[2] - pj->v[2]) * dx[2] + a2_Hubble * r2;
#ifndef PLANETARY_SPH_NO_BALSARA
/* Balsara term */
const float balsara_i = pi->force.balsara;
const float balsara_j = pj->force.balsara;
#endif
/* Are the particles moving towards each other? */
const float omega_ij = min(dvdr, 0.f);
......@@ -319,12 +310,8 @@ __attribute__((always_inline)) INLINE static void runner_iact_nonsym_force(
/* Construct the full viscosity term */
const float rho_ij = 0.5f * (rhoi + rhoj);
#ifdef PLANETARY_SPH_NO_BALSARA
const float visc = -0.5f * const_viscosity_alpha * v_sig * mu_ij / rho_ij;
#else
const float visc = -0.25f * const_viscosity_alpha * v_sig * mu_ij *
const float visc = -0.25f * v_sig * mu_ij *
(balsara_i + balsara_j) / rho_ij;
#endif
/* Convolve with the kernel */
const float visc_acc_term = 0.5f * visc * (wi_dr + wj_dr) * r_inv;
......
......@@ -126,13 +126,11 @@ struct part {
/*! Derivative of density with respect to h */
float rho_dh;
#ifndef PLANETARY_SPH_NO_BALSARA
/*! Velocity divergence. */
float div_v;
/*! Velocity curl. */
float rot_v[3];
#endif
} density;
......@@ -160,10 +158,8 @@ struct part {
/*! Time derivative of smoothing length */
float h_dt;
#ifndef PLANETARY_SPH_NO_BALSARA
/*! Balsara switch */
float balsara;
#endif
} force;
};
......
......@@ -524,12 +524,14 @@ __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 hydro_props Hydrodynamic properties.
* @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 float dt_alpha) {
const struct cosmology *cosmo, const struct hydro_props *hydro_props,
const float dt_alpha) {
const float fac_mu = cosmo->a_factor_mu;
......@@ -546,7 +548,8 @@ __attribute__((always_inline)) INLINE static void hydro_prepare_force(
/* Compute the Balsara switch */
const float balsara =
abs_div_v / (abs_div_v + curl_v + 0.0001f * soundspeed * fac_mu / p->h);
hydro_props->viscosity.alpha * abs_div_v /
(abs_div_v + curl_v + 0.0001f * soundspeed * fac_mu / p->h);