Commit 943e2e5f authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Code formatting

parent 6d0cfd1c
......@@ -20,7 +20,7 @@
#ifndef SWIFT_CONST_H
#define SWIFT_CONST_H
#include "physical_constants_cgs.h"
#include "physical_constants_cgs.h"
/* Hydrodynamical constants. */
#define const_hydro_gamma (5.0f / 3.0f)
......@@ -75,13 +75,16 @@
/* valid choices EXTERNAL_POTENTIAL_POINTMASS */
#define EXTERNAL_POTENTIAL_POINTMASS
/* System of units */
#define const_unit_length_in_cgs (1000.*PARSEC_IN_CGS) /* kpc */
#define const_unit_mass_in_cgs (SOLAR_MASS_IN_CGS) /* solar mass */
#define const_unit_velocity_in_cgs (1e5) /* km/s */
#define const_unit_length_in_cgs (1000. * PARSEC_IN_CGS) /* kpc */
#define const_unit_mass_in_cgs (SOLAR_MASS_IN_CGS) /* solar mass */
#define const_unit_velocity_in_cgs (1e5) /* km/s */
/* Derived constants */
#define const_unit_time_in_cgs (const_unit_length_in_cgs / const_unit_velocity_in_cgs)
#define const_G ((NEWTON_GRAVITY_CGS*const_unit_mass_in_cgs/(const_unit_velocity_in_cgs*const_unit_velocity_in_cgs*const_unit_length_in_cgs)))
#define const_unit_time_in_cgs \
(const_unit_length_in_cgs / const_unit_velocity_in_cgs)
#define const_G \
((NEWTON_GRAVITY_CGS* const_unit_mass_in_cgs / \
(const_unit_velocity_in_cgs* const_unit_velocity_in_cgs* \
const_unit_length_in_cgs)))
#endif /* SWIFT_CONST_H */
......@@ -110,15 +110,15 @@ void engine_make_ghost_tasks(struct engine *e, struct cell *c,
/* Local tasks only... */
if (c->nodeID == e->nodeID) {
if(c->count > 0) {
if (c->count > 0) {
/* Generate the ghost task. */
c->ghost = scheduler_addtask(s, task_type_ghost, task_subtype_none, 0, 0,
c, NULL, 0);
c->ghost = scheduler_addtask(s, task_type_ghost, task_subtype_none, 0,
0, c, NULL, 0);
}
/* Add the init task. */
c->init = scheduler_addtask(s, task_type_init, task_subtype_none, 0, 0, c,
NULL, 0);
/* Add the init task. */
c->init = scheduler_addtask(s, task_type_init, task_subtype_none, 0, 0, c,
NULL, 0);
/* Add the drift task. */
c->drift = scheduler_addtask(s, task_type_drift, task_subtype_none, 0, 0,
......@@ -128,17 +128,16 @@ void engine_make_ghost_tasks(struct engine *e, struct cell *c,
c->kick = scheduler_addtask(s, task_type_kick, task_subtype_none, 0, 0, c,
NULL, 0);
if(c->gcount > 0) {
if (c->gcount > 0) {
/* Add the gravity tasks */
c->grav_external = scheduler_addtask(s, task_type_grav_external, task_subtype_none, 0, 0,
c, NULL, 0);
c->grav_external = scheduler_addtask(
s, task_type_grav_external, task_subtype_none, 0, 0, c, NULL, 0);
/* Enforce gravity calculated before kick */
scheduler_addunlock(s, c->grav_external, c->kick);
/* Enforce gravity calculated after init */
scheduler_addunlock(s, c->init, c->grav_external);
/* Enforce gravity calculated after init */
scheduler_addunlock(s, c->init, c->grav_external);
}
}
}
......@@ -1910,7 +1909,8 @@ void engine_init_particles(struct engine *e) {
/* Add the tasks corresponding to external gravity to the masks */
if ((e->policy & engine_policy_external_gravity) ==
engine_policy_external_gravity) {
printf("%s: JR: Excellent lets add the external gravity tasks here.....\n", __FUNCTION__);
printf("%s: JR: Excellent lets add the external gravity tasks here.....\n",
__FUNCTION__);
mask |= 1 << task_type_grav_external;
}
......@@ -2343,7 +2343,8 @@ static bool hyperthreads_present(void) {
void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
int nr_queues, int nr_nodes, int nodeID, int policy,
float timeBegin, float timeEnd, float dt_min, float dt_max,
int verbose, const struct phys_const* physical_constants, const struct external_potential* potential) {
int verbose, const struct phys_const *physical_constants,
const struct external_potential *potential) {
/* Store the values. */
e->s = s;
......@@ -2375,7 +2376,7 @@ void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
e->physical_constants = physical_constants;
e->potential = potential;
engine_rank = nodeID;
/* Make the space link back to the engine. */
s->e = e;
......
......@@ -166,11 +166,10 @@ struct engine {
int verbose;
/* Physical constants definition */
const struct phys_const* physical_constants;
const struct phys_const *physical_constants;
/* Properties of external gravitational potential */
const struct external_potential* potential;
const struct external_potential *potential;
};
/* Function prototypes. */
......@@ -178,7 +177,8 @@ void engine_barrier(struct engine *e, int tid);
void engine_init(struct engine *e, struct space *s, float dt, int nr_threads,
int nr_queues, int nr_nodes, int nodeID, int policy,
float timeBegin, float timeEnd, float dt_min, float dt_max,
int verbose, const struct phys_const* physical_constants, const struct external_potential* potential);
int verbose, const struct phys_const *physical_constants,
const struct external_potential *potential);
void engine_launch(struct engine *e, int nr_runners, unsigned int mask,
unsigned int submask);
void engine_prepare(struct engine *e);
......
......@@ -18,14 +18,13 @@
*
******************************************************************************/
#include "physical_constants_cgs.h"
#include "physical_constants.h"
void initPhysicalConstants(struct UnitSystem* us, struct phys_const* prog_const)
{
float dimension[5] = {1, -3, 2, 0, 0};
prog_const->newton_gravity = NEWTON_GRAVITY_CGS * generalConversionFactor(us, dimension);
void initPhysicalConstants(struct UnitSystem* us,
struct phys_const* prog_const) {
float dimension[5] = {1, -3, 2, 0, 0};
prog_const->newton_gravity =
NEWTON_GRAVITY_CGS * generalConversionFactor(us, dimension);
}
......@@ -23,16 +23,14 @@
#include "units.h"
/* physical constants in in defined programme units */
struct phys_const{
struct phys_const {
double newton_gravity;
};
/**
* @brief Converts physical constants to the internal unit system
*/
void initPhysicalConstants(struct UnitSystem* us, struct phys_const* prog_const);
void initPhysicalConstants(struct UnitSystem* us,
struct phys_const* prog_const);
#endif /* SWIFT_PHYSICAL_CONSTANTS_H */
......@@ -21,14 +21,13 @@
#define SWIFT_PHYSICAL_CONSTANTS_CGS_H
/* physical constants in cgs */
#define NEWTON_GRAVITY_CGS 6.672e-8f
#define SOLAR_MASS_IN_CGS 1.989e33f
#define PARSEC_IN_CGS 3.086e18f
#define PROTON_MASS_IN_CGS 1.6726231e24f
#define YEAR_IN_CGS 3.154e+7f
#define NEWTON_GRAVITY_CGS 6.672e-8f
#define SOLAR_MASS_IN_CGS 1.989e33f
#define PARSEC_IN_CGS 3.086e18f
#define PROTON_MASS_IN_CGS 1.6726231e24f
#define YEAR_IN_CGS 3.154e+7f
/* Hydrodynamical constants. */
#define const_hydro_gamma (5.0f / 3.0f)
#endif /* SWIFT_PHYSICAL_CONSTANTS_CGS_H */
......@@ -2,10 +2,14 @@
#include "potentials.h"
#include "physical_constants.h"
void initPotentialProperties(struct UnitSystem *us, struct external_potential* potential)
{
potential-> point_mass.x = 50000 * PARSEC_IN_CGS / conversionFactor(us, UNIT_CONV_LENGTH);
potential-> point_mass.y = 50000 * PARSEC_IN_CGS / conversionFactor(us, UNIT_CONV_LENGTH);
potential-> point_mass.z = 50000 * PARSEC_IN_CGS / conversionFactor(us, UNIT_CONV_LENGTH);
potential-> point_mass.mass = 1e10 * SOLAR_MASS_IN_CGS / conversionFactor(us, UNIT_CONV_MASS);
void initPotentialProperties(struct UnitSystem* us,
struct external_potential* potential) {
potential->point_mass.x =
50000 * PARSEC_IN_CGS / conversionFactor(us, UNIT_CONV_LENGTH);
potential->point_mass.y =
50000 * PARSEC_IN_CGS / conversionFactor(us, UNIT_CONV_LENGTH);
potential->point_mass.z =
50000 * PARSEC_IN_CGS / conversionFactor(us, UNIT_CONV_LENGTH);
potential->point_mass.mass =
1e10 * SOLAR_MASS_IN_CGS / conversionFactor(us, UNIT_CONV_MASS);
}
......@@ -5,57 +5,62 @@
#include "physical_constants.h"
#include "units.h"
/* External Potential Constants */
struct external_potential{
struct
{
double x, y, z;
double mass;
struct external_potential {
struct {
double x, y, z;
double mass;
} point_mass;
};
/* Properties of Point Mass */
#ifdef EXTERNAL_POTENTIAL_POINTMASS
#define External_Potential_X (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Y (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Z (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Mass (1e10 * SOLAR_MASS_IN_CGS / const_unit_mass_in_cgs)
#define External_Potential_X (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Y (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Z (50000 * PARSEC_IN_CGS / const_unit_length_in_cgs)
#define External_Potential_Mass \
(1e10 * SOLAR_MASS_IN_CGS / const_unit_mass_in_cgs)
__attribute__((always_inline)) INLINE static float external_gravity_pointmass_timestep(const struct phys_const* phys_const, struct gpart* g) {
__attribute__((always_inline))
INLINE static float external_gravity_pointmass_timestep(
const struct phys_const* phys_const, struct gpart* g) {
const double G_newton = phys_const->newton_gravity;
const double G_newton = phys_const->newton_gravity;
/* Currently no limit is imposed */
const float dx = g->x[0]-External_Potential_X;
const float dy = g->x[1]-External_Potential_Y;
const float dz = g->x[2]-External_Potential_Z;
const float rinv = 1.f / sqrtf(dx*dx + dy*dy + dz*dz);
const float drdv = (g->x[0]-External_Potential_X) * (g->v_full[0]) + (g->x[1]-External_Potential_Y) * (g->v_full[1]) + (g->x[2]-External_Potential_Z) * (g->v_full[2]);
const float dota_x = G_newton * External_Potential_Mass * rinv * rinv * rinv * (-g->v_full[0] + 3.f * rinv * rinv * drdv * dx);
const float dota_y = G_newton * External_Potential_Mass * rinv * rinv * rinv * (-g->v_full[1] + 3.f * rinv * rinv * drdv * dy);
const float dota_z = G_newton * External_Potential_Mass * rinv * rinv * rinv * (-g->v_full[2] + 3.f * rinv * rinv * drdv * dz);
const float dx = g->x[0] - External_Potential_X;
const float dy = g->x[1] - External_Potential_Y;
const float dz = g->x[2] - External_Potential_Z;
const float rinv = 1.f / sqrtf(dx * dx + dy * dy + dz * dz);
const float drdv = (g->x[0] - External_Potential_X) * (g->v_full[0]) +
(g->x[1] - External_Potential_Y) * (g->v_full[1]) +
(g->x[2] - External_Potential_Z) * (g->v_full[2]);
const float dota_x = G_newton * External_Potential_Mass * rinv * rinv * rinv *
(-g->v_full[0] + 3.f * rinv * rinv * drdv * dx);
const float dota_y = G_newton * External_Potential_Mass * rinv * rinv * rinv *
(-g->v_full[1] + 3.f * rinv * rinv * drdv * dy);
const float dota_z = G_newton * External_Potential_Mass * rinv * rinv * rinv *
(-g->v_full[2] + 3.f * rinv * rinv * drdv * dz);
const float dota_2 = dota_x * dota_x + dota_y * dota_y + dota_z * dota_z;
const float a_2 = g->a_grav[0] * g->a_grav[0] + g->a_grav[1] * g->a_grav[1] + g->a_grav[2] * g->a_grav[2];
return 0.03f * sqrtf(a_2/dota_2);
const float a_2 = g->a_grav[0] * g->a_grav[0] + g->a_grav[1] * g->a_grav[1] +
g->a_grav[2] * g->a_grav[2];
return 0.03f * sqrtf(a_2 / dota_2);
}
__attribute__((always_inline)) INLINE static void external_gravity_pointmass(const struct phys_const* phys_const, struct gpart *g)
{
const double G_newton = phys_const->newton_gravity;
const float dx = g->x[0]-External_Potential_X;
const float dy = g->x[1]-External_Potential_Y;
const float dz = g->x[2]-External_Potential_Z;
const float rinv = 1.f / sqrtf(dx*dx + dy*dy + dz*dz);
g->a_grav[0] += - G_newton * External_Potential_Mass * dx * rinv * rinv * rinv;
g->a_grav[1] += - G_newton * External_Potential_Mass * dy * rinv * rinv * rinv;
g->a_grav[2] += - G_newton * External_Potential_Mass * dz * rinv * rinv * rinv;
__attribute__((always_inline)) INLINE static void external_gravity_pointmass(
const struct phys_const* phys_const, struct gpart* g) {
const double G_newton = phys_const->newton_gravity;
const float dx = g->x[0] - External_Potential_X;
const float dy = g->x[1] - External_Potential_Y;
const float dz = g->x[2] - External_Potential_Z;
const float rinv = 1.f / sqrtf(dx * dx + dy * dy + dz * dz);
g->a_grav[0] += -G_newton * External_Potential_Mass * dx * rinv * rinv * rinv;
g->a_grav[1] += -G_newton * External_Potential_Mass * dy * rinv * rinv * rinv;
g->a_grav[2] += -G_newton * External_Potential_Mass * dz * rinv * rinv * rinv;
}
#endif /* EXTERNAL_POTENTIAL_POINTMASS */
void initPotentialProperties(struct UnitSystem *us, struct external_potential* potential);
void initPotentialProperties(struct UnitSystem* us,
struct external_potential* potential);
#endif /* SWIFT_POTENTIALS_H */
......@@ -1074,10 +1074,10 @@ void runner_dokick(struct runner *r, struct cell *c, int timer) {
p->ti_begin = p->ti_end;
p->ti_end = p->ti_begin + new_dti;
if (p->gpart != NULL) {
p->gpart->ti_begin = p->ti_begin;
p->gpart->ti_end = p->ti_end;
}
p->gpart->ti_begin = p->ti_begin;
p->gpart->ti_end = p->ti_end;
}
/* Get the acceleration */
float a_tot[3] = {p->a_hydro[0], p->a_hydro[1], p->a_hydro[2]};
if (p->gpart != NULL) {
......
......@@ -162,21 +162,21 @@ void space_regrid(struct space *s, double cell_max, int verbose) {
/* Run through the parts and get the current h_max. */
// tic = getticks();
if(nr_parts) {
if (nr_parts) {
if (s->cells != NULL) {
for (int k = 0; k < s->nr_cells; k++) {
if (s->cells[k].h_max > h_max) h_max = s->cells[k].h_max;
if (s->cells[k].h_max > h_max) h_max = s->cells[k].h_max;
}
} else {
for (int k = 0; k < nr_parts; k++) {
if (s->parts[k].h > h_max) h_max = s->parts[k].h;
if (s->parts[k].h > h_max) h_max = s->parts[k].h;
}
s->h_max = h_max;
}
}
else {
/* It would be nice to replace this with something more physical or meaningful */
h_max = s->dim[0]/16.0;
} else {
/* It would be nice to replace this with something more physical or
* meaningful */
h_max = s->dim[0] / 16.0;
s->h_max = h_max;
}
......@@ -315,7 +315,8 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
const ticks tic = getticks();
/* Be verbose about this. */
message( "re)building space..." ); fflush(stdout);
message("re)building space...");
fflush(stdout);
/* Re-grid if necessary, or just re-set the cell data. */
space_regrid(s, cell_max, verbose);
......@@ -343,7 +344,7 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
p->x[j] -= dim[j];
ind[k] =
cell_getid(cdim, p->x[0] * ih[0], p->x[1] * ih[1], p->x[2] * ih[2]);
cells[ind[k]].count++;
cells[ind[k]].count++;
}
// message( "getting particle indices took %.3f %s." ,
// clocks_from_ticks(getticks() - tic), clocks_getunit()):
......@@ -502,7 +503,6 @@ void space_rebuild(struct space *s, double cell_max, int verbose) {
for (int k = 0; k < nr_gparts; k++)
if (s->gparts[k].id > 0) s->gparts[k].part->gpart = &s->gparts[k];
/* We no longer need the indices as of here. */
free(gind);
......@@ -1308,7 +1308,6 @@ void space_init(struct space *s, double dim[3], struct part *parts,
s->size_parts_foreign = 0;
/* Check that all the gas particle positions are reasonable, wrap if periodic.
*/
if (periodic) {
......
......@@ -43,9 +43,10 @@
/* Task type names. */
const char *taskID_names[task_type_count] = {
"none", "sort", "self", "pair", "sub", "init",
"ghost", "drift", "kick", "send", "recv", "grav_pp",
"grav_mm", "grav_up", "grav_down", "grav_external", "psort", "split_cell", "rewait"};
"none", "sort", "self", "pair", "sub",
"init", "ghost", "drift", "kick", "send",
"recv", "grav_pp", "grav_mm", "grav_up", "grav_down",
"grav_external", "psort", "split_cell", "rewait"};
const char *subtaskID_names[task_type_count] = {"none", "density",
"force", "grav"};
......
......@@ -443,4 +443,3 @@ void generalConversionString(char* buffer, struct UnitSystem* us,
strncat(buffer, "]", 2);
}
......@@ -155,5 +155,4 @@ void generalConversionString(char* buffer, struct UnitSystem* us,
void conversionString(char* buffer, struct UnitSystem* us,
enum UnitConversionFactor unit);
#endif /* SWIFT_UNITS_H */
Markdown is supported
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