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

Code formatting

parent d12fde95
......@@ -38,7 +38,6 @@
#error "Invalid choice of SPH variant"
#endif
/**
* @brief Looks for the particle with the given id and prints its information to
*the standard output.
......
......@@ -31,9 +31,9 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
const float dt_cfl = 2.f * const_cfl * kernel_gamma * p->h / p->force.v_sig;
/* Limit change in u */
const float dt_u_change = (p->force.u_dt != 0.0f)
? fabsf(const_max_u_change * p->u / p->force.u_dt)
: FLT_MAX;
const float dt_u_change =
(p->force.u_dt != 0.0f) ? fabsf(const_max_u_change * p->u / p->force.u_dt)
: FLT_MAX;
return fminf(dt_cfl, dt_u_change);
}
......@@ -48,7 +48,8 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
* @param xp The extended particle data to act upon
*/
__attribute__((always_inline))
INLINE static void hydro_first_init_part(struct part* p, struct xpart* xp) {}
INLINE static void hydro_first_init_part(struct part* p, struct xpart* xp) {
}
/**
* @brief Prepares a particle for the density calculation.
......@@ -106,8 +107,8 @@ __attribute__((always_inline))
* @param xp The extended particle data to act upon
* @param time The current time
*/
__attribute__((always_inline))
INLINE static void hydro_prepare_force(struct part* p, struct xpart* xp, float time) {
__attribute__((always_inline)) INLINE static void hydro_prepare_force(
struct part* p, struct xpart* xp, float time) {
/* Some smoothing length multiples. */
const float h = p->h;
......@@ -206,15 +207,13 @@ __attribute__((always_inline)) INLINE static void hydro_predict_extra(
__attribute__((always_inline))
INLINE static void hydro_end_force(struct part* p) {}
/**
* @brief Kick the additional variables
*
* @param p The particle to act upon
*/
__attribute__((always_inline))
INLINE static void hydro_kick_extra(struct part* p, float dt) {}
INLINE static void hydro_kick_extra(struct part* p, float dt) {}
/**
* @brief Converts hydro quantity of a particle
......
......@@ -28,9 +28,9 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
struct part* p, struct xpart* xp) {
/* Acceleration */
float ac = sqrtf(p->a_hydro[0] * p->a_hydro[0] +
p->a_hydro[1] * p->a_hydro[1] +
p->a_hydro[2] * p->a_hydro[2]);
float ac =
sqrtf(p->a_hydro[0] * p->a_hydro[0] + p->a_hydro[1] * p->a_hydro[1] +
p->a_hydro[2] * p->a_hydro[2]);
ac = fmaxf(ac, 1e-30);
const float dt_accel = sqrtf(2.f); // MATTHIEU
......@@ -51,7 +51,8 @@ __attribute__((always_inline)) INLINE static float hydro_compute_timestep(
* @param xp The extended particle data to act upon
*/
__attribute__((always_inline))
INLINE static void hydro_first_init_part(struct part* p, struct xpart* xp) {}
INLINE static void hydro_first_init_part(struct part* p, struct xpart* xp) {
}
/**
* @brief Prepares a particle for the density calculation.
......@@ -103,7 +104,7 @@ __attribute__((always_inline))
p->density.wcount_dh *= ih * (4.0f / 3.0f * M_PI * kernel_gamma3);
const float irho = 1.f / p->rho;
/* Compute the derivative term */
p->rho_dh = 1.f / (1.f + 0.33333333f * p->h * p->rho_dh * irho);
......@@ -125,14 +126,13 @@ __attribute__((always_inline))
* @param xp The extended particle data to act upon
* @param time The current time
*/
__attribute__((always_inline))
INLINE static void hydro_prepare_force(struct part* p, struct xpart* xp, float time) {
__attribute__((always_inline)) INLINE static void hydro_prepare_force(
struct part* p, struct xpart* xp, float time) {
/* Compute the norm of the curl */
p->force.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]);
p->density.rot_v[1] * p->density.rot_v[1] +
p->density.rot_v[2] * p->density.rot_v[2]);
/* Compute the pressure */
const float dt = time - 0.5f * (p->t_begin + p->t_end);
......@@ -202,7 +202,6 @@ __attribute__((always_inline))
(const_hydro_gamma - 1.f) * powf(p->rho, -(const_hydro_gamma - 1.f));
}
/**
* @brief Kick the additional variables
*
......@@ -211,16 +210,15 @@ __attribute__((always_inline))
* @param dt The time-step for this kick
* @param half_dt The half time-step for this kick
*/
__attribute__((always_inline))
INLINE static void hydro_kick_extra(struct part* p, struct xpart* xp,
float dt, float half_dt) {
__attribute__((always_inline)) INLINE static void hydro_kick_extra(
struct part* p, struct xpart* xp, float dt, float half_dt) {
/* Do not decrease the entropy (temperature) by more than a factor of 2*/
const float entropy_change = p->entropy_dt * dt;
if (entropy_change > -0.5f * p->entropy)
p->entropy += entropy_change;
else
p->entropy *= 0.5f;
p->entropy *= 0.5f;
/* Do not 'overcool' when timestep increases */
if (p->entropy + 0.5f * p->entropy_dt * dt < 0.5f * p->entropy)
......@@ -238,5 +236,5 @@ __attribute__((always_inline))
INLINE static void hydro_convert_quantities(struct part* p) {
p->entropy = (const_hydro_gamma - 1.f) * p->entropy *
powf(p->rho, -(const_hydro_gamma - 1.f));
powf(p->rho, -(const_hydro_gamma - 1.f));
}
......@@ -29,9 +29,8 @@ __attribute__((always_inline))
"v_sig=%e dh/dt=%.3e t_begin=%.3e, t_end=%.3e\n",
p->x[0], p->x[1], p->x[2], p->v[0], p->v[1], p->v[2], xp->v_full[0],
xp->v_full[1], xp->v_full[2], p->a_hydro[0], p->a_hydro[1], p->a_hydro[2],
p->h, (int)p->density.wcount, p->mass, p->rho_dh, p->rho, p->force.pressure,
p->entropy, p->entropy_dt, p->force.soundspeed,
p->div_v, p->force.curl_v, p->density.rot_v[0],
p->density.rot_v[1], p->density.rot_v[2], p->force.v_sig, p->h_dt,
p->t_begin, p->t_end);
p->h, (int)p->density.wcount, p->mass, p->rho_dh, p->rho,
p->force.pressure, p->entropy, p->entropy_dt, p->force.soundspeed,
p->div_v, p->force.curl_v, p->density.rot_v[0], p->density.rot_v[1],
p->density.rot_v[2], p->force.v_sig, p->h_dt, p->t_begin, p->t_end);
}
......@@ -17,7 +17,6 @@
*
******************************************************************************/
/* Extra particle data not needed during the SPH loops over neighbours. */
struct xpart {
......@@ -26,7 +25,7 @@ struct xpart {
/* Velocity at the last full step. */
float v_full[3];
} __attribute__((aligned(xpart_align)));
/* Data of a single particle. */
......@@ -65,43 +64,42 @@ struct part {
/* Entropy time derivative */
float entropy_dt;
/* Particle mass. */
float mass;
union{
union {
struct {
/* Number of neighbours */
float wcount;
/* Number of neighbours spatial derivative */
float wcount_dh;
/* Velocity curl components */
float rot_v[3];
} density;
struct {
/* Velocity curl norm*/
float curl_v;
/* Signal velocity */
float v_sig;
/* Particle pressure */
float pressure;
/* Particle sound speed */
float soundspeed;
} force;
};
/* Velocity divergence */
float div_v;
......
......@@ -28,8 +28,8 @@
/**
* @brief Minimal conservative implementation of SPH
*
* The thermal variable is the internal energy (u). No viscosity nor
* thermal conduction terms are implemented.
* The thermal variable is the internal energy (u). No viscosity nor
* thermal conduction terms are implemented.
*/
/**
......
......@@ -241,10 +241,10 @@ void prepareArray(hid_t grp, char* fileName, FILE* xmfFile, char* name,
*
* Calls #error() if an error occurs.
*/
void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
enum DATA_TYPE type, int N, int dim, long long N_total,
int mpi_rank, long long offset, char* part_c,
struct UnitSystem* us,
void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
enum DATA_TYPE type, int N, int dim, long long N_total,
int mpi_rank, long long offset, char* part_c,
struct UnitSystem* us,
enum UnitConversionFactor convFactor) {
hid_t h_data = 0, h_err = 0, h_memspace = 0, h_filespace = 0;
......@@ -259,11 +259,10 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
/* message("Writing '%s' array...", name); */
/* Prepare the arrays in the file */
if(mpi_rank == 0)
prepareArray(grp, fileName, xmfFile, name, type, N_total, dim,
us, convFactor);
if (mpi_rank == 0)
prepareArray(grp, fileName, xmfFile, name, type, N_total, dim, us,
convFactor);
/* Allocate temporary buffer */
temp = malloc(N * dim * sizeOfType(type));
if (temp == NULL) error("Unable to allocate memory for temporary buffer");
......@@ -359,9 +358,9 @@ void writeArrayBackEnd(hid_t grp, char* fileName, FILE* xmfFile, char* name,
*/
#define writeArray(grp, fileName, xmfFile, name, type, N, dim, part, N_total, \
mpi_rank, offset, field, us, convFactor) \
writeArrayBackEnd(grp, fileName, xmfFile, name, type, N, dim, N_total, \
mpi_rank, offset, (char*)(&(part[0]).field), \
us, convFactor)
writeArrayBackEnd(grp, fileName, xmfFile, name, type, N, dim, N_total, \
mpi_rank, offset, (char*)(&(part[0]).field), us, \
convFactor)
/* Import the right hydro definition */
#include "hydro_io.h"
......@@ -639,8 +638,8 @@ void write_output_serial(struct engine* e, struct UnitSystem* us, int mpi_rank,
error("Error while opening particle group on rank %d.\n", mpi_rank);
/* Write particle fields from the particle structure */
hydro_write_particles(h_grp, fileName, xmfFile, N, N_total, mpi_rank, offset,
parts, us);
hydro_write_particles(h_grp, fileName, xmfFile, N, N_total, mpi_rank,
offset, parts, us);
/* Close particle group */
H5Gclose(h_grp);
......
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