Skip to content
Snippets Groups Projects
Commit 56aa3662 authored by James Willis's avatar James Willis
Browse files

Formatting.

parent 3acb789f
No related branches found
No related tags found
1 merge request!154Shuffle array
......@@ -59,7 +59,6 @@ void factor(int value, int *f1, int *f2) {
void pairs_n2(double *dim, struct part *__restrict__ parts, int N,
int periodic) {
int i, j, k, count = 0;
// int mj, mk;
// double maxratio = 1.0;
......@@ -124,7 +123,6 @@ void pairs_n2(double *dim, struct part *__restrict__ parts, int N,
void pairs_single_density(double *dim, long long int pid,
struct part *__restrict__ parts, int N,
int periodic) {
int i, k;
// int mj, mk;
// double maxratio = 1.0;
......@@ -177,19 +175,16 @@ void pairs_single_density(double *dim, long long int pid,
}
void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) {
float r2, hi, hj, hig2, hjg2, dx[3];
struct part *pi, *pj;
/* Implements a double-for loop and checks every interaction */
for (int i = 0; i < ci->count; ++i) {
pi = &ci->parts[i];
hi = pi->h;
hig2 = hi * hi * kernel_gamma2;
for (int j = 0; j < cj->count; ++j) {
pj = &cj->parts[j];
/* Pairwise distance */
......@@ -201,7 +196,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) {
/* Hit or miss? */
if (r2 < hig2) {
/* Interact */
runner_iact_nonsym_density(r2, dx, hi, pj->h, pi, pj);
}
......@@ -210,13 +204,11 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) {
/* Reverse double-for loop and checks every interaction */
for (int j = 0; j < cj->count; ++j) {
pj = &cj->parts[j];
hj = pj->h;
hjg2 = hj * hj * kernel_gamma2;
for (int i = 0; i < ci->count; ++i) {
pi = &ci->parts[i];
/* Pairwise distance */
......@@ -228,7 +220,6 @@ void pairs_all_density(struct runner *r, struct cell *ci, struct cell *cj) {
/* Hit or miss? */
if (r2 < hjg2) {
/* Interact */
runner_iact_nonsym_density(r2, dx, hj, pi->h, pj, pi);
}
......@@ -242,13 +233,11 @@ void self_all_density(struct runner *r, struct cell *ci) {
/* Implements a double-for loop and checks every interaction */
for (int i = 0; i < ci->count; ++i) {
pi = &ci->parts[i];
hi = pi->h;
hig2 = hi * hi * kernel_gamma2;
for (int j = i + 1; j < ci->count; ++j) {
pj = &ci->parts[j];
hj = pj->h;
hjg2 = hj * hj * kernel_gamma2;
......@@ -264,14 +253,12 @@ void self_all_density(struct runner *r, struct cell *ci) {
/* Hit or miss? */
if (r2 < hig2) {
/* Interact */
runner_iact_nonsym_density(r2, dxi, hi, hj, pi, pj);
}
/* Hit or miss? */
if (r2 < hjg2) {
dxi[0] = -dxi[0];
dxi[1] = -dxi[1];
dxi[2] = -dxi[2];
......@@ -285,7 +272,6 @@ void self_all_density(struct runner *r, struct cell *ci) {
void pairs_single_grav(double *dim, long long int pid,
struct gpart *__restrict__ parts, int N, int periodic) {
int i, k;
// int mj, mk;
// double maxratio = 1.0;
......@@ -344,7 +330,6 @@ void pairs_single_grav(double *dim, long long int pid,
*/
void density_dump(int N) {
int k;
float r2[4] = {0.0f, 0.0f, 0.0f, 0.0f}, hi[4], hj[4];
struct part /**pi[4], *pj[4],*/ Pi[4], Pj[4];
......@@ -382,7 +367,6 @@ void density_dump(int N) {
void engine_single_density(double *dim, long long int pid,
struct part *__restrict__ parts, int N,
int periodic) {
int i, k;
double r2, dx[3];
float fdx[3], ih;
......@@ -429,7 +413,6 @@ void engine_single_density(double *dim, long long int pid,
void engine_single_force(double *dim, long long int pid,
struct part *__restrict__ parts, int N, int periodic) {
int i, k;
double r2, dx[3];
float fdx[3];
......@@ -483,13 +466,10 @@ double random_uniform(double a, double b) {
* @brief Randomly shuffle an array of particles.
*/
void shuffle_particles(struct part *parts, const int count) {
if (count > 1) {
for (int i = 0; i < count - 1; i++) {
int j = i + random_uniform(0., (double)(count - 1 - i));
if(count > 1) {
for(int i=0; i<count - 1; i++) {
int j = i + random_uniform(0.,(double)(count - 1 - i));
struct part particle = parts[j];
parts[j] = parts[i];
......@@ -497,7 +477,6 @@ void shuffle_particles(struct part *parts, const int count) {
parts[i] = particle;
}
}
else error("Array not big enough to shuffle!");
} else
error("Array not big enough to shuffle!");
}
......@@ -38,10 +38,12 @@ enum velocity_types {
* @param n The cube root of the number of particles.
* @param offset The position of the cell offset from (0,0,0).
* @param size The cell size.
* @param h The smoothing length of the particles in units of the inter-particle separation.
* @param h The smoothing length of the particles in units of the inter-particle
*separation.
* @param density The density of the fluid.
* @param partId The running counter of IDs.
* @param pert The perturbation to apply to the particles in the cell in units of the inter-particle separation.
* @param pert The perturbation to apply to the particles in the cell in units
*of the inter-particle separation.
* @param vel The type of velocity field (0, random, divergent, rotating)
*/
struct cell *make_cell(size_t n, double *offset, double size, double h,
......@@ -119,7 +121,7 @@ struct cell *make_cell(size_t n, double *offset, double size, double h,
cell->ti_end_min = 1;
cell->ti_end_max = 1;
shuffle_particles(cell->parts,cell->count);
shuffle_particles(cell->parts, cell->count);
cell->sorted = 0;
cell->sort = NULL;
......@@ -139,7 +141,6 @@ void clean_up(struct cell *ci) {
* @brief Initializes all particles field to be ready for a density calculation
*/
void zero_particle_fields(struct cell *c) {
for (size_t pid = 0; pid < c->count; pid++) {
c->parts[pid].rho = 0.f;
c->parts[pid].rho_dh = 0.f;
......@@ -151,7 +152,6 @@ void zero_particle_fields(struct cell *c) {
* @brief Ends the loop by adding the appropriate coefficients
*/
void end_calculation(struct cell *c) {
for (size_t pid = 0; pid < c->count; pid++) {
hydro_end_density(&c->parts[pid], 1);
}
......@@ -162,7 +162,6 @@ void end_calculation(struct cell *c) {
*/
void dump_particle_fields(char *fileName, struct cell *main_cell,
struct cell **cells) {
FILE *file = fopen(fileName, "w");
/* Write header */
......@@ -199,7 +198,6 @@ void dump_particle_fields(char *fileName, struct cell *main_cell,
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
struct cell *cj = cells[i * 9 + j * 3 + k];
if (cj == main_cell) continue;
......@@ -236,7 +234,6 @@ void runner_doself1_density(struct runner *r, struct cell *ci);
/* And go... */
int main(int argc, char *argv[]) {
size_t runs = 0, particles = 0;
double h = 1.2348, size = 1., rho = 1.;
double perturbation = 0.;
......@@ -330,7 +327,6 @@ int main(int argc, char *argv[]) {
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
double offset[3] = {i * size, j * size, k * size};
cells[i * 9 + j * 3 + k] = make_cell(particles, offset, size, h, rho,
&partId, perturbation, vel);
......@@ -343,7 +339,6 @@ int main(int argc, char *argv[]) {
ticks time = 0;
for (size_t i = 0; i < runs; ++i) {
/* Zero the fields */
for (int j = 0; j < 27; ++j) zero_particle_fields(cells[j]);
......
......@@ -86,7 +86,7 @@ struct cell *make_cell(size_t n, double *offset, double size, double h,
cell->ti_end_min = 1;
cell->ti_end_max = 1;
shuffle_particles(cell->parts,cell->count);
shuffle_particles(cell->parts, cell->count);
cell->sorted = 0;
cell->sort = NULL;
......@@ -106,7 +106,6 @@ void clean_up(struct cell *ci) {
* @brief Initializes all particles field to be ready for a density calculation
*/
void zero_particle_fields(struct cell *c) {
for (size_t pid = 0; pid < c->count; pid++) {
c->parts[pid].rho = 0.f;
c->parts[pid].rho_dh = 0.f;
......@@ -118,7 +117,6 @@ void zero_particle_fields(struct cell *c) {
* @brief Dump all the particles to a file
*/
void dump_particle_fields(char *fileName, struct cell *ci, struct cell *cj) {
FILE *file = fopen(fileName, "w");
/* Write header */
......@@ -249,7 +247,6 @@ int main(int argc, char *argv[]) {
time = 0;
for (size_t i = 0; i < runs; ++i) {
/* Zero the fields */
zero_particle_fields(ci);
zero_particle_fields(cj);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment