19#ifndef SWIFT_MINIMAL_HYDRO_H
20#define SWIFT_MINIMAL_HYDRO_H
57hydro_get_comoving_internal_energy(
const struct part *restrict p,
72hydro_get_physical_internal_energy(
const struct part *restrict p,
73 const struct xpart *restrict
xp,
86hydro_get_drifted_comoving_internal_energy(
const struct part *restrict p) {
99hydro_get_drifted_physical_internal_energy(
const struct part *restrict p,
102 return p->u *
cosmo->a_factor_internal_energy;
113 const struct part *restrict p) {
115 return gas_pressure_from_internal_energy(
p->rho,
p->u);
130 return cosmo->a_factor_pressure *
131 gas_pressure_from_internal_energy(
p->rho,
p->u);
142 const struct part *restrict p,
const struct xpart *restrict
xp) {
144 return gas_entropy_from_internal_energy(
p->rho,
xp->
u_full);
156 const struct part *restrict p,
const struct xpart *restrict
xp,
161 return gas_entropy_from_internal_energy(
p->rho,
xp->
u_full);
171hydro_get_drifted_comoving_entropy(
const struct part *restrict p) {
173 return gas_entropy_from_internal_energy(
p->rho,
p->u);
184hydro_get_drifted_physical_entropy(
const struct part *restrict p,
189 return gas_entropy_from_internal_energy(
p->rho,
p->u);
198hydro_get_comoving_soundspeed(
const struct part *restrict p) {
200 return p->force.soundspeed;
210hydro_get_physical_soundspeed(
const struct part *restrict p,
213 return cosmo->a_factor_sound_speed *
p->force.soundspeed;
222 const struct part *restrict p) {
236 return cosmo->a3_inv *
p->rho;
245 const struct part *restrict p) {
270hydro_get_comoving_internal_energy_dt(
const struct part *restrict p) {
284hydro_get_physical_internal_energy_dt(
const struct part *restrict p,
287 return p->u_dt *
cosmo->a_factor_internal_energy;
300hydro_set_comoving_internal_energy_dt(
struct part *restrict p,
float du_dt) {
315hydro_set_physical_internal_energy_dt(
struct part *restrict p,
335 const float comoving_entropy =
entropy;
336 xp->
u_full = gas_internal_energy_from_entropy(p->rho, comoving_entropy);
348hydro_set_physical_internal_energy(
struct part *p,
struct xpart *
xp,
363hydro_set_drifted_physical_internal_energy(
367 p->u =
u /
cosmo->a_factor_internal_energy;
372 const float pressure = gas_pressure_from_internal_energy(p->rho, p->u);
392hydro_set_v_sig_based_on_velocity_kick(
struct part *p,
400 const float soundspeed = hydro_get_comoving_soundspeed(p);
414 struct part *restrict p,
float alpha) {
425hydro_diffusive_feedback_reset(
struct part *restrict p) {
441 const struct part *restrict p,
const struct xpart *restrict
xp,
442 const struct hydro_props *restrict hydro_properties,
445 const float CFL_condition = hydro_properties->CFL_condition;
448 const float dt_cfl = 2.f * kernel_gamma * CFL_condition *
cosmo->a *
p->h /
449 (
cosmo->a_factor_sound_speed *
p->force.v_sig);
467 const float dx[3],
const struct part *restrict pi,
470 const float ci = pi->force.soundspeed;
482 const struct part *restrict p) {
484 return p->force.v_sig;
492 const struct part *restrict p) {
494 return p->density.div_v;
505 struct part *p,
float dt) {}
518 struct part *restrict p,
const struct hydro_space *hs) {
520 p->density.wcount = 0.f;
521 p->density.wcount_dh = 0.f;
523 p->density.rho_dh = 0.f;
524 p->density.div_v = 0.f;
525 p->density.rot_v[0] = 0.f;
526 p->density.rot_v[1] = 0.f;
527 p->density.rot_v[2] = 0.f;
547 const float h =
p->h;
548 const float h_inv = 1.0f /
h;
550 const float h_inv_dim_plus_one = h_inv_dim *
h_inv;
554 p->density.rho_dh -= hydro_dimension *
p->mass *
kernel_root;
560 p->density.rho_dh *= h_inv_dim_plus_one;
561 p->density.wcount *= h_inv_dim;
562 p->density.wcount_dh *= h_inv_dim_plus_one;
564 const float rho_inv = 1.f /
p->rho;
565 const float a_inv2 =
cosmo->a2_inv;
568 p->density.rot_v[0] *= h_inv_dim_plus_one * a_inv2 * rho_inv;
569 p->density.rot_v[1] *= h_inv_dim_plus_one * a_inv2 * rho_inv;
570 p->density.rot_v[2] *= h_inv_dim_plus_one * a_inv2 * rho_inv;
573 p->density.div_v *= h_inv_dim_plus_one * a_inv2 * rho_inv;
588 struct part *restrict p,
struct xpart *restrict
xp,
603 struct part *restrict p) {}
627 struct part *restrict p,
struct xpart *restrict
xp,
631 const float h =
p->h;
632 const float h_inv = 1.0f /
h;
636 "Gas particle with ID %lld treated as having no neighbours (h: %g, "
638 p->id, h,
p->density.wcount);
643 p->density.rho_dh = 0.f;
644 p->density.wcount_dh = 0.f;
645 p->density.div_v = 0.f;
646 p->density.rot_v[0] = 0.f;
647 p->density.rot_v[1] = 0.f;
648 p->density.rot_v[2] = 0.f;
670 struct part *restrict p,
struct xpart *restrict
xp,
672 const struct pressure_floor_props *
pressure_floor,
const float dt_alpha,
675 const float fac_Balsara_eps =
cosmo->a_factor_Balsara_eps;
678 const float h_inv = 1.f /
p->h;
681 const float curl_v = sqrtf(
p->density.rot_v[0] *
p->density.rot_v[0] +
682 p->density.rot_v[1] *
p->density.rot_v[1] +
683 p->density.rot_v[2] *
p->density.rot_v[2]);
686 const float div_physical_v =
p->density.div_v + hydro_dimension *
cosmo->H;
687 const float abs_div_physical_v = fabsf(div_physical_v);
690 const float pressure = gas_pressure_from_internal_energy(
p->rho,
p->u);
701 const float common_factor =
p->h * hydro_dimension_inv /
p->density.wcount;
707 printf(
"h ~ h_max for particle with ID %lld (h: %g)",
p->id,
p->h);
709 const float grad_W_term = common_factor *
p->density.wcount_dh;
710 if (grad_W_term < -0.9999f) {
719 "grad_W_term very small for particle with ID %lld (h: %g, wcount: "
720 "%g, wcount_dh: %g).",
721 p->id,
p->h,
p->density.wcount,
p->density.wcount_dh);
723 grad_h_term = common_factor *
p->density.rho_dh / (1.f + grad_W_term);
731 (abs_div_physical_v + curl_v +
735 p->force.f = grad_h_term;
738 p->force.balsara = balsara;
750 struct part *restrict p) {
753 p->a_hydro[0] = 0.0f;
754 p->a_hydro[1] = 0.0f;
755 p->a_hydro[2] = 0.0f;
759 p->force.h_dt = 0.0f;
760 p->force.v_sig = 2.f *
p->force.soundspeed;
772 struct part *restrict p,
const struct xpart *restrict
xp,
785 const float pressure = gas_pressure_from_internal_energy(
p->rho,
p->u);
816 struct part *restrict p,
const struct xpart *restrict
xp,
float dt_drift,
825 const float h_inv = 1.f /
p->h;
828 const float w1 =
p->force.h_dt *
h_inv * dt_drift;
829 if (fabsf(w1) < 0.2f) {
830 p->h *= approx_expf(w1);
836 const float w2 = -hydro_dimension * w1;
837 if (fabsf(w2) < 0.2f) {
838 p->rho *= approx_expf(w2);
845 const float floor_u = gas_internal_energy_from_entropy(
p->rho, floor_A);
851 p->u =
MAX(
p->u, floor_u);
852 p->u =
MAX(
p->u, min_u);
855 const float pressure = gas_pressure_from_internal_energy(
p->rho,
p->u);
881 p->force.h_dt *=
p->h * hydro_dimension_inv;
903 float dt_grav,
float dt_grav_mesh,
float dt_hydro,
float dt_kick_corr,
908 const float delta_u =
p->u_dt *
dt_therm;
915 const float floor_u = gas_internal_energy_from_entropy(
p->rho, floor_A);
922 const float energy_min =
MAX(min_u, floor_u);
944 struct part *restrict p,
struct xpart *restrict
xp,
950 const float factor = 1.f /
cosmo->a_factor_internal_energy;
955 const float min_comoving_energy =
957 if (
xp->
u_full < min_comoving_energy) {
959 p->u = min_comoving_energy;
964 const float pressure = gas_pressure_from_internal_energy(
p->rho,
p->u);
967 const float soundspeed = gas_soundspeed_from_internal_energy(
p->rho,
p->u);
984 struct part *restrict p,
struct xpart *restrict
xp) {
993 hydro_init_part(p, NULL);
1008hydro_set_init_internal_energy(
struct part *p,
float u_init) {
1022 const struct part *p,
const struct xpart *
xp,
const double time) {}
Defines the adiabatic index (polytropix index) of the problem and (fast) mathematical functions invo...
Kernel functions for SPH (scalar and vector version).
Defines the dimensionality of the problem and (fast) mathematical functions involving it.
static INLINE float entropy_floor(const struct part *p, const struct cosmology *cosmo, const struct entropy_floor_properties *props)
Compute the entropy floor of a given part.
const struct xpart *restrict const struct cosmology * cosmo
const struct cosmology const struct pressure_floor_props * pressure_floor
struct xpart const struct cosmology const float entropy
__attribute__((always_inline)) INLINE static float hydro_get_comoving_internal_energy(const struct part *restrict p
Returns the comoving internal energy of a particle at the last time the particle was kicked.
const struct cosmology const float dv_phys
const struct xpart *restrict xp
struct xpart const struct cosmology const float u
const float const float const float struct part *restrict struct part *restrict pj
#define const_viscosity_beta
Contains all the constants and parameters of the hydro scheme.
#define INLINE
Defines inline.
#define MAX(a, b)
Maximum of two numbers.
InlineMethod T pow_dimension(T x)
returns x^ndim
double hydro_compute_timestep(Particle *particle)
Computes the SPH time step size.
void hydro_reset_acceleration(Particle *localParticle)
Reset acceleration fields of a particle.
void hydro_predict_extra(Particle *localParticle)
Predict additional particle fields forward in time when drifting.
void hydro_end_force(Particle *localParticle)
Finishes the force calculation.
void hydro_reset_predicted_values(Particle *localParticle)
Sets the values to be predicted in the drifts to their values at a kick time.
void hydro_end_density(Particle *localParticle)
Finishes the density calculation.
void hydro_prepare_force(Particle *localParticle)
Prepare a particle for the force calculation.
const struct part *restrict const struct part *restrict const float const float beta
const struct part *restrict const struct part *restrict const float mu_ij
Properties of the entropy floor.
Contains all the constants and parameters of the hydro scheme.
float minimal_internal_energy
struct viscosity_global_data viscosity
Particle fields for the SPH particles.
struct part::@3::@6 force
Structure for the variables only used in the force loop over neighbours.
Particle fields not needed during the SPH loops over neighbours.