Commit 1da94574 authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Also updated the Pressure-Entropy and Pressure-Energy schemes.

parent d949f23a
......@@ -69,6 +69,7 @@ __attribute__((always_inline)) INLINE static float
hydro_get_physical_internal_energy(const struct part *restrict p,
const struct xpart *restrict xp,
const struct cosmology *cosmo) {
return xp->u_full * cosmo->a_factor_internal_energy;
}
......@@ -141,7 +142,7 @@ __attribute__((always_inline)) INLINE static float hydro_get_comoving_entropy(
}
/**
* @brief Returns the physical entropy of a particl at the last
* @brief Returns the physical entropy of a particle at the last
* time the particle was kicked.
*
* @param p The particle of interest.
......
......@@ -49,22 +49,26 @@
#include <float.h>
/**
* @brief Returns the comoving internal energy of a particle
* @brief Returns the comoving internal energy of a particle at the last
* time the particle was kicked.
*
* For implementations where the main thermodynamic variable
* is not internal energy, this function computes the internal
* energy from the thermodynamic variable.
*
* @param p The particle of interest
* @param xp The extended data of the particle of interest.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_comoving_internal_energy(const struct part *restrict p) {
hydro_get_comoving_internal_energy(const struct part *restrict p,
const struct xpart *restrict xp) {
return p->u;
return xp->u_full;
}
/**
* @brief Returns the physical internal energy of a particle
* @brief Returns the physical internal energy of a particle at the last
* time the particle was kicked.
*
* For implementations where the main thermodynamic variable
* is not internal energy, this function computes the internal
......@@ -72,12 +76,40 @@ hydro_get_comoving_internal_energy(const struct part *restrict p) {
* physical coordinates.
*
* @param p The particle of interest.
* @param xp The extended data of the particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_physical_internal_energy(const struct part *restrict p,
const struct xpart *restrict xp,
const struct cosmology *cosmo) {
return xp->u_full * cosmo->a_factor_internal_energy;
}
/**
* @brief Returns the comoving internal energy of a particle drifted to the
* current time.
*
* @param p The particle of interest
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_comoving_internal_energy(const struct part *restrict p) {
return p->u;
}
/**
* @brief Returns the physical internal energy of a particle drifted to the
* current time.
*
* @param p The particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_physical_internal_energy(const struct part *restrict p,
const struct cosmology *cosmo) {
return p->u * cosmo->a_factor_internal_energy;
}
......@@ -110,33 +142,66 @@ __attribute__((always_inline)) INLINE static float hydro_get_physical_pressure(
}
/**
* @brief Returns the comoving entropy of a particle
* @brief Returns the comoving entropy of a particle at the last
* time the particle was kicked.
*
* For implementations where the main thermodynamic variable
* is not entropy, this function computes the entropy from
* the thermodynamic variable.
*
* @param p The particle of interest
* @param xp The extended data of the particle of interest.
*/
__attribute__((always_inline)) INLINE static float hydro_get_comoving_entropy(
const struct part *restrict p) {
const struct part *restrict p, const struct xpart *restrict xp) {
return gas_entropy_from_internal_energy(p->rho, p->u);
return gas_entropy_from_internal_energy(p->rho, xp->u_full);
}
/**
* @brief Returns the physical entropy of a particle
* @brief Returns the physical entropy of a particle at the last
* time the particle was kicked.
*
* For implementations where the main thermodynamic variable
* is not entropy, this function computes the entropy from
* the thermodynamic variable and converts it to
* physical coordinates.
*
* @param p The particle of interest
* @param p The particle of interest.
* @param xp The extended data of the particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float hydro_get_physical_entropy(
const struct part *restrict p, const struct cosmology *cosmo) {
const struct part *restrict p, const struct xpart *restrict xp,
const struct cosmology *cosmo) {
/* Note: no cosmological conversion required here with our choice of
* coordinates. */
return gas_entropy_from_internal_energy(p->rho, xp->u_full);
}
/**
* @brief Returns the comoving entropy of a particle drifted to the
* current time.
*
* @param p The particle of interest.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_comoving_entropy(const struct part *restrict p) {
return gas_entropy_from_internal_energy(p->rho, p->u);
}
/**
* @brief Returns the physical entropy of a particle drifted to the
* current time.
*
* @param p The particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_physical_entropy(const struct part *restrict p,
const struct cosmology *cosmo) {
/* Note: no cosmological conversion required here with our choice of
* coordinates. */
......@@ -245,12 +310,27 @@ __attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities(
*
* @param p The particle of interest
*/
__attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt(
const struct part *restrict p) {
__attribute__((always_inline)) INLINE static float
hydro_get_comoving_internal_energy_dt(const struct part *restrict p) {
return p->u_dt;
}
/**
* @brief Returns the time derivative of internal energy of a particle
*
* We assume a constant density.
*
* @param p The particle of interest
* @param cosmo Cosmology data structure
*/
__attribute__((always_inline)) INLINE static float
hydro_get_physical_internal_energy_dt(const struct part *restrict p,
const struct cosmology *cosmo) {
return p->u_dt * cosmo->a_factor_internal_energy;
}
/**
* @brief Sets the time derivative of internal energy of a particle
*
......@@ -259,12 +339,29 @@ __attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt(
* @param p The particle of interest.
* @param du_dt The new time derivative of the internal energy.
*/
__attribute__((always_inline)) INLINE static void hydro_set_internal_energy_dt(
struct part *restrict p, float du_dt) {
__attribute__((always_inline)) INLINE static void
hydro_set_comoving_internal_energy_dt(struct part *restrict p, float du_dt) {
p->u_dt = du_dt;
}
/**
* @brief Returns the time derivative of internal energy of a particle
*
* We assume a constant density.
*
* @param p The particle of interest.
* @param cosmo Cosmology data structure
* @param du_dt The new time derivative of the internal energy.
*/
__attribute__((always_inline)) INLINE static void
hydro_set_physical_internal_energy_dt(struct part *restrict p,
const struct cosmology *cosmo,
float du_dt) {
p->u_dt = du_dt * cosmo->a_factor_internal_energy;
}
/**
* @brief Computes the hydro time-step of a given particle
*
......
......@@ -68,16 +68,10 @@ INLINE static void hydro_read_particles(struct part* parts,
UNIT_CONV_DENSITY, parts, rho);
}
INLINE static void convert_u(const struct engine* e, const struct part* p,
const struct xpart* xp, float* ret) {
ret[0] = hydro_get_comoving_internal_energy(p);
}
INLINE static void convert_S(const struct engine* e, const struct part* p,
const struct xpart* xp, float* ret) {
ret[0] = hydro_get_comoving_entropy(p);
ret[0] = hydro_get_comoving_entropy(p, xp);
}
INLINE static void convert_P(const struct engine* e, const struct part* p,
......@@ -169,9 +163,8 @@ INLINE static void hydro_write_particles(const struct part* parts,
io_make_output_field("Masses", FLOAT, 1, UNIT_CONV_MASS, parts, mass);
list[3] = io_make_output_field("SmoothingLength", FLOAT, 1, UNIT_CONV_LENGTH,
parts, h);
list[4] = io_make_output_field_convert_part("InternalEnergy", FLOAT, 1,
UNIT_CONV_ENERGY_PER_UNIT_MASS,
parts, xparts, convert_u);
list[4] = io_make_output_field("InternalEnergy", FLOAT, 1,
UNIT_CONV_ENERGY_PER_UNIT_MASS, parts, u);
list[5] = io_make_output_field("ParticleIDs", ULONGLONG, 1,
UNIT_CONV_NO_UNITS, parts, id);
list[6] =
......
......@@ -42,28 +42,59 @@
#include "minmax.h"
/**
* @brief Returns the comoving internal energy of a particle
* @brief Returns the comoving internal energy of a particle at the last
* time the particle was kicked.
*
* @param p The particle of interest
* @param xp The extended data of the particle of interest.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_comoving_internal_energy(const struct part *restrict p) {
hydro_get_comoving_internal_energy(const struct part *restrict p,
const struct xpart *restrict xp) {
return gas_internal_energy_from_entropy(p->rho_bar, p->entropy);
return gas_internal_energy_from_entropy(p->rho_bar, xp->entropy_full);
}
/**
* @brief Returns the physical internal energy of a particle
* @brief Returns the physical internal energy of a particle at the last
* time the particle was kicked.
*
* @param p The particle of interest
* @param p The particle of interest.
* @param xp The extended data of the particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_physical_internal_energy(const struct part *restrict p,
const struct xpart *restrict xp,
const struct cosmology *cosmo) {
return gas_internal_energy_from_entropy(p->rho_bar * cosmo->a3_inv,
p->entropy);
xp->entropy_full);
}
/**
* @brief Returns the comoving internal energy of a particle drifted to the
* current time.
*
* @param p The particle of interest
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_comoving_internal_energy(const struct part *restrict p) {
return gas_internal_energy_from_entropy(p->rho_bar, p->entropy);
}
/**
* @brief Returns the physical internal energy of a particle drifted to the
* current time.
*
* @param p The particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_physical_internal_energy(const struct part *restrict p,
const struct cosmology *cosmo) {
return gas_internal_energy_from_entropy(p->rho_bar * cosmo->a3_inv, p->entropy);
}
/**
......@@ -89,24 +120,57 @@ __attribute__((always_inline)) INLINE static float hydro_get_physical_pressure(
}
/**
* @brief Returns the comoving entropy of a particle
* @brief Returns the comoving entropy of a particle at the last
* time the particle was kicked.
*
* @param p The particle of interest
* @param p The particle of interest.
* @param xp The extended data of the particle of interest.
*/
__attribute__((always_inline)) INLINE static float hydro_get_comoving_entropy(
const struct part *restrict p) {
const struct part *restrict p, const struct xpart *restrict xp) {
return p->entropy;
return xp->entropy_full;
}
/**
* @brief Returns the physical entropy of a particle
* @brief Returns the physical entropy of a particl at the last
* time the particle was kicked.
*
* @param p The particle of interest.
* @param xp The extended data of the particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float hydro_get_physical_entropy(
const struct part *restrict p, const struct cosmology *cosmo) {
const struct part *restrict p, const struct xpart *restrict xp,
const struct cosmology *cosmo) {
/* Note: no cosmological conversion required here with our choice of
* coordinates. */
return xp->entropy_full;
}
/**
* @brief Returns the comoving entropy of a particle drifted to the
* current time.
*
* @param p The particle of interest.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_comoving_entropy(const struct part *restrict p) {
return p->entropy;
}
/**
* @brief Returns the physical entropy of a particle drifted to the
* current time.
*
* @param p The particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_drifted_physical_entropy(const struct part *restrict p,
const struct cosmology *cosmo) {
/* Note: no cosmological conversion required here with our choice of
* coordinates. */
......@@ -210,12 +274,28 @@ __attribute__((always_inline)) INLINE static void hydro_get_drifted_velocities(
*
* @param p The particle of interest
*/
__attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt(
__attribute__((always_inline)) INLINE static float hydro_get_comoving_internal_energy_dt(
const struct part *restrict p) {
return gas_internal_energy_from_entropy(p->rho_bar, p->entropy_dt);
}
/**
* @brief Returns the time derivative of physical internal energy of a particle
*
* We assume a constant density.
*
* @param p The particle of interest.
* @param cosmo The cosmological model.
*/
__attribute__((always_inline)) INLINE static float
hydro_get_physical_internal_energy_dt(const struct part *restrict p,
const struct cosmology *cosmo) {
return gas_internal_energy_from_entropy(p->rho_bar * cosmo->a3_inv,
p->entropy_dt);
}
/**
* @brief Returns the time derivative of internal energy of a particle
*
......@@ -224,12 +304,29 @@ __attribute__((always_inline)) INLINE static float hydro_get_internal_energy_dt(
* @param p The particle of interest.
* @param du_dt The new time derivative of the internal energy.
*/
__attribute__((always_inline)) INLINE static void hydro_set_internal_energy_dt(
__attribute__((always_inline)) INLINE static void hydro_set_comoving_internal_energy_dt(
struct part *restrict p, float du_dt) {
p->entropy_dt = gas_entropy_from_internal_energy(p->rho_bar, du_dt);
}
/**
* @brief Sets the time derivative of the physical internal energy of a particle
*
* We assume a constant density for the conversion to entropy.
*
* @param p The particle of interest.
* @param cosmo Cosmology data structure
* @param du_dt The time derivative of the internal energy.
*/
__attribute__((always_inline)) INLINE static void
hydro_set_physical_internal_energy_dt(struct part *restrict p,
const struct cosmology *restrict cosmo,
float du_dt) {
p->entropy_dt =
gas_entropy_from_internal_energy(p->rho_bar * cosmo->a3_inv, du_dt);
}
/**
* @brief Computes the hydro time-step of a given particle
*
......
......@@ -71,7 +71,7 @@ INLINE static void hydro_read_particles(struct part* parts,
INLINE static void convert_u(const struct engine* e, const struct part* p,
const struct xpart* xp, float* ret) {
ret[0] = hydro_get_comoving_internal_energy(p);
ret[0] = hydro_get_comoving_internal_energy(p, xp);
}
INLINE static void convert_P(const struct engine* e, const struct part* p,
......
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