Refactored code according to language server

This commit is contained in:
Aditya Ujeniya 2023-10-28 12:20:04 +02:00
parent 120be69102
commit 1987056dce
18 changed files with 1520 additions and 1397 deletions

View File

@ -11,9 +11,9 @@
#include <unistd.h>
#include "parameter.h"
#include "particletracing.h"
#include "progress.h"
#include "solver.h"
#include "particletracing.h"
#include "timing.h"
#include "vtkWriter.h"
@ -36,8 +36,7 @@ int main (int argc, char** argv)
}
readParameter(&params, argv[1]);
if (argc == 3)
{
if (argc == 3) {
variant = atoi(argv[2]);
}
@ -63,8 +62,7 @@ int main (int argc, char** argv)
S = getTimeStamp();
while (t <= te)
{
while (t <= te) {
if (tau > 0.0) computeTimestep(&solver);
setBoundaryConditions(&solver);
setSpecialBoundaryCondition(&solver);
@ -76,14 +74,13 @@ int main (int argc, char** argv)
solver_generic[variant - 1](&solver);
adaptUV(&solver);
/* Added function for particle tracing. Will inject and advance particles as per timePeriod */
/* Added function for particle tracing. Will inject and advance particles as per
* timePeriod */
trace(&particletracer, solver.u, solver.v, solver.s, t);
t += solver.dt;
nt++;
#ifdef VERBOSE
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
#else

View File

@ -98,7 +98,6 @@ void readParameter(Parameter* param, const char* filename)
PARSE_REAL(xRectLength);
PARSE_REAL(yRectLength);
PARSE_REAL(circleRadius);
}
}
@ -132,10 +131,14 @@ void printParameter(Parameter* param)
printf("\trho (SOR relaxation): %f\n", param->rho);
printf("Particle Tracing data:\n");
printf("\tNumber of particles : %d being injected for every period of %.2f\n", param->numberOfParticles, param->injectTimePeriod);
printf("\tNumber of particles : %d being injected for every period of %.2f\n",
param->numberOfParticles,
param->injectTimePeriod);
printf("\tstartTime : %.2f\n", param->startTime);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : %.2f, x2 : %.2f, y2 : %.2f\n", param->x1, param->y1, param->x2, param->y2);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : "
"%.2f, x2 : %.2f, y2 : %.2f\n",
param->x1,
param->y1,
param->x2,
param->y2);
}

View File

@ -19,41 +19,43 @@
static int ts = 0;
void printParticles(ParticleTracer* particletracer)
{
for(int i = 0; i < particletracer->totalParticles; ++i)
{
printf("Particle position X : %.2f, Y : %.2f, flag : %d\n", particletracer->particlePool[i].x,
for (int i = 0; i < particletracer->totalParticles; ++i) {
printf("Particle position X : %.2f, Y : %.2f, flag : %d\n",
particletracer->particlePool[i].x,
particletracer->particlePool[i].y,
particletracer->particlePool[i].flag);
}
}
void injectParticles(ParticleTracer* particletracer)
{
for(int i = 0; i < particletracer->numberOfParticles; ++i)
{
particletracer->particlePool[particletracer->pointer].x = particletracer->linSpaceLine[i].x;
particletracer->particlePool[particletracer->pointer].y = particletracer->linSpaceLine[i].y;
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
particletracer->particlePool[particletracer->pointer]
.x = particletracer->linSpaceLine[i].x;
particletracer->particlePool[particletracer->pointer]
.y = particletracer->linSpaceLine[i].y;
particletracer->particlePool[particletracer->pointer].flag = true;
++(particletracer->pointer);
++(particletracer->totalParticles);
}
}
void advanceParticles(ParticleTracer* particletracer, double* restrict u, double* restrict v, int* restrict s, double time)
void advanceParticles(ParticleTracer* particletracer,
double* restrict u,
double* restrict v,
int* restrict s,
double time)
{
int imax = particletracer->imax;
int jmax = particletracer->jmax;
double dx = particletracer->dx;
double dy = particletracer->dy;
double xlength = particletracer->xlength;
double ylength = particletracer->ylength;
for(int i = 0; i < particletracer->totalParticles; ++i)
{
if(particletracer->particlePool[i].flag == true)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
if (particletracer->particlePool[i].flag == true) {
double x = particletracer->particlePool[i].x;
double y = particletracer->particlePool[i].y;
@ -91,20 +93,25 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
double new_y = y + particletracer->dt * v_n;
particletracer->particlePool[i].y = new_y;
// printf("\tOld X : %.2f, New X : %.2f, iCoord : %d\n\tOld Y : %.2f, New Y : %.2f, jCoord : %d\n\n", x, new_x, iCoord, y, new_y, jCoord);
// printf("\tU(iCoord - 1, jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f, U(iCoord - 1, jCoord) : %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1, jCoord - 1), U(iCoord, jCoord - 1), U(iCoord - 1, jCoord), U(iCoord, jCoord));
// printf("\tV(iCoord - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1) : %.2f, V(iCoord - 1, jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n", V(iCoord - 1, jCoord - 1), V(iCoord, jCoord - 1), V(iCoord - 1, jCoord), V(iCoord, jCoord));
// printf("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
// printf("\t j-1 * (imax + 2) + i-1 = %d with element from U : %.2f", (jCoord - 1) * (200 + 2) + (iCoord - 1), u[(jCoord - 1) * (imax + 2) + (iCoord - 1)]);
// printf("\nimax : %d, jmax : %d\n", imax, jmax);
// printf("\tOld X : %.2f, New X : %.2f, iCoord : %d\n\tOld Y : %.2f, New Y :
// %.2f, jCoord : %d\n\n", x, new_x, iCoord, y, new_y, jCoord);
// printf("\tU(iCoord - 1, jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f,
// U(iCoord - 1, jCoord) : %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1,
// jCoord - 1), U(iCoord, jCoord - 1), U(iCoord - 1, jCoord), U(iCoord,
// jCoord)); printf("\tV(iCoord - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1)
// : %.2f, V(iCoord - 1, jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n",
// V(iCoord - 1, jCoord - 1), V(iCoord, jCoord - 1), V(iCoord - 1, jCoord),
// V(iCoord, jCoord)); printf("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
// printf("\t j-1 * (imax + 2) + i-1 = %d with element from U : %.2f", (jCoord
// - 1) * (200 + 2) + (iCoord - 1), u[(jCoord - 1) * (imax + 2) + (iCoord -
// 1)]); printf("\nimax : %d, jmax : %d\n", imax, jmax);
if (((new_x < 0.0) || (new_x > xlength) || (new_y < 0.0) || (new_y > ylength)))
{
if (((new_x < 0.0) || (new_x > xlength) || (new_y < 0.0) ||
(new_y > ylength))) {
particletracer->particlePool[i].flag = false;
}
int i_new = new_x / dx, j_new = new_y / dy;
if(S(i_new, j_new) != NONE)
{
if (S(i_new, j_new) != NONE) {
particletracer->particlePool[i].flag = false;
}
}
@ -138,8 +145,7 @@ void writeParticles(ParticleTracer* particletracer)
exit(EXIT_FAILURE);
}
for (int i = 0; i < particletracer->totalParticles; ++i)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
double x = particlePool[i].x;
double y = particlePool[i].y;
fprintf(fp, "%f %f\n", x, y);
@ -178,47 +184,57 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params)
particletracer->imax = params->imax;
particletracer->jmax = params->jmax;
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2 ) * params->numberOfParticles;
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2) *
params->numberOfParticles;
particletracer->particlePool = malloc(sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->linSpaceLine = malloc(sizeof(Particle) * particletracer->numberOfParticles);
particletracer->particlePool = malloc(
sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->linSpaceLine = malloc(
sizeof(Particle) * particletracer->numberOfParticles);
for (int i = 0; i < particletracer->numberOfParticles; ++i)
{
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
double spacing = (double)i / (double)(particletracer->numberOfParticles - 1);
particletracer->linSpaceLine[i].x = spacing * particletracer->x1 + (1.0 - spacing) * particletracer->x2;
particletracer->linSpaceLine[i].y = spacing * particletracer->y1 + (1.0 - spacing) * particletracer->y2;
particletracer->linSpaceLine[i].x = spacing * particletracer->x1 +
(1.0 - spacing) * particletracer->x2;
particletracer->linSpaceLine[i].y = spacing * particletracer->y1 +
(1.0 - spacing) * particletracer->y2;
particletracer->linSpaceLine[i].flag = true;
}
}
void printParticleTracerParameters(ParticleTracer* particletracer)
{
printf("Particle Tracing data:\n");
printf("\tNumber of particles : %d being injected for every period of %.2f\n", particletracer->numberOfParticles, particletracer->injectTimePeriod);
printf("\tNumber of particles : %d being injected for every period of %.2f\n",
particletracer->numberOfParticles,
particletracer->injectTimePeriod);
printf("\tstartTime : %.2f\n", particletracer->startTime);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : %.2f, x2 : %.2f, y2 : %.2f\n", particletracer->x1, particletracer->y1, particletracer->x2, particletracer->y2);
printf("\tPointer : %d, TotalParticles : %d\n", particletracer->pointer, particletracer->totalParticles);
printf("\tdt : %.2f, dx : %.2f, dy : %.2f\n", particletracer->dt, particletracer->dx, particletracer->dy);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : "
"%.2f, x2 : %.2f, y2 : %.2f\n",
particletracer->x1,
particletracer->y1,
particletracer->x2,
particletracer->y2);
printf("\tPointer : %d, TotalParticles : %d\n",
particletracer->pointer,
particletracer->totalParticles);
printf("\tdt : %.2f, dx : %.2f, dy : %.2f\n",
particletracer->dt,
particletracer->dx,
particletracer->dy);
}
void trace(ParticleTracer* particletracer, double* u, double* v, int* s, double time)
{
if (time >= particletracer->startTime)
{
if (time >= particletracer->startTime) {
// printParticles(particletracer);
if( (time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod)
{
if ((time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod) {
injectParticles(particletracer);
particletracer->lastInjectTime = time;
}
if( (time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod)
{
if ((time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod) {
writeParticles(particletracer);
particletracer->lastWriteTime = time;
}
advanceParticles(particletracer, u, v, s, time);
compress(particletracer);
@ -232,10 +248,8 @@ void compress(ParticleTracer* particletracer)
Particle tempPool[particletracer->totalParticles];
int totalParticles = 0;
for(int i=0; i < particletracer->totalParticles; ++i)
{
if(memPool[i].flag == 1)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
if (memPool[i].flag == 1) {
tempPool[totalParticles].x = memPool[i].x;
tempPool[totalParticles].y = memPool[i].y;
tempPool[totalParticles].flag = memPool[i].flag;

View File

@ -8,20 +8,20 @@
#define __PARTICLETRACING_H_
#include "allocate.h"
#include "parameter.h"
#include "solver.h"
#include "particletracing.h"
#include "solver.h"
#include <stdbool.h>
typedef enum COORD { X = 0, Y, NCOORD } COORD;
typedef struct
{
typedef struct {
double x, y;
bool flag;
} Particle;
typedef struct {
int numberOfParticles, totalParticles;
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime, lastWriteTime;
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime,
lastWriteTime;
int estimatedNumParticles;

View File

@ -71,27 +71,24 @@ void vtkParticle(VtkOptions* o, char* name)
fprintf(o->fh, "POINTS %d float\n", o->particletracer->totalParticles);
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
double x = particlePool[i].x;
double y = particlePool[i].y;
fprintf(o->fh, "%.2f %.2f 0.0\n", x, y);
}
fprintf(o->fh, "CELLS %d %d\n", o->particletracer->totalParticles, 2 * o->particletracer->totalParticles);
fprintf(o->fh,
"CELLS %d %d\n",
o->particletracer->totalParticles,
2 * o->particletracer->totalParticles);
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
fprintf(o->fh, "1 %d\n", i);
}
fprintf(o->fh, "CELL_TYPES %d\n", o->particletracer->totalParticles);
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
fprintf(o->fh, "1\n");
}

View File

@ -508,17 +508,18 @@ void commInit(Comm* c, int kmax, int jmax, int imax)
MPI_Cart_get(c->comm, NCORDS, c->dims, periods, c->coords);
c->imaxLocal = sizeOfRank(c->coords[KDIM], dims[ICORD], imax);
//printf("\nRank : %d\nimaxLocal : %d -> c->coords[IDIM] : %d , dims[ICORD] : %d, imax : %d\n", c->rank, c->imaxLocal, c->coords[IDIM], dims[ICORD], imax);
// printf("\nRank : %d\nimaxLocal : %d -> c->coords[IDIM] : %d , dims[ICORD] : %d,
// imax : %d\n", c->rank, c->imaxLocal, c->coords[IDIM], dims[ICORD], imax);
c->jmaxLocal = sizeOfRank(c->coords[JDIM], dims[JCORD], jmax);
//printf("jmaxLocal : %d -> c->coords[JDIM] : %d , dims[JCORD] : %d, imax : %d\n", c->jmaxLocal, c->coords[JDIM], dims[JCORD], jmax);
// printf("jmaxLocal : %d -> c->coords[JDIM] : %d , dims[JCORD] : %d, imax : %d\n",
// c->jmaxLocal, c->coords[JDIM], dims[JCORD], jmax);
c->kmaxLocal = sizeOfRank(c->coords[IDIM], dims[KCORD], kmax);
//printf("kmaxLocal : %d -> c->coords[KDIM] : %d , dims[KCORD] : %d, imax : %d\n", c->kmaxLocal, c->coords[KDIM], dims[KCORD], kmax);
// printf("kmaxLocal : %d -> c->coords[KDIM] : %d , dims[KCORD] : %d, imax : %d\n",
// c->kmaxLocal, c->coords[KDIM], dims[KCORD], kmax);
// sizeOfRank(int rank, int size, int N)
// { return N / size + ((N % size > rank) ? 1 : 0); }
// setup buffer types for communication
setupCommunication(c, LEFT, BULK);
setupCommunication(c, LEFT, HALO);

View File

@ -13,11 +13,11 @@
#include "allocate.h"
#include "parameter.h"
#include "particletracing.h"
#include "progress.h"
#include "solver.h"
#include "test.h"
#include "timing.h"
#include "particletracing.h"
#include "vtkWriter.h"
enum VARIANT { SOR = 1, RB, RBA };
@ -42,8 +42,7 @@ int main(int argc, char** argv)
}
readParameter(&params, argv[1]);
if (argc == 3)
{
if (argc == 3) {
variant = atoi(argv[2]);
}
if (commIsMaster(&solver.comm)) {
@ -73,7 +72,6 @@ int main(int argc, char** argv)
setSpecialBoundaryCondition(&solver);
setObjectBoundaryCondition(&solver);
computeFG(&solver);
computeRHS(&solver);
// if (nt % 100 == 0) normalizePressure(&solver);
@ -94,8 +92,6 @@ int main(int argc, char** argv)
#endif
}
timeStop = getTimeStamp();
stopProgress();
if (commIsMaster(&solver.comm)) {

View File

@ -27,7 +27,6 @@ void initParameter(Parameter* param)
param->gamma = 0.9;
param->tau = 0.5;
param->rho = 0.99;
}
void readParameter(Parameter* param, const char* filename)
@ -111,7 +110,6 @@ void readParameter(Parameter* param, const char* filename)
PARSE_REAL(yRectLength);
PARSE_REAL(zRectLength);
PARSE_REAL(circleRadius);
}
}

View File

@ -25,7 +25,8 @@ typedef struct {
double x1, y1, z1, x2, y2, z2;
int shape;
double xCenter, yCenter, zCenter, xRectLength, yRectLength, zRectLength, circleRadius;} Parameter;
double xCenter, yCenter, zCenter, xRectLength, yRectLength, zRectLength, circleRadius;
} Parameter;
void initParameter(Parameter*);
void readParameter(Parameter*, const char*);

View File

@ -13,10 +13,14 @@
#include "particletracing.h"
#include "solver.h"
#define U(i, j, k) u[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define V(i, j, k) v[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define W(i, j, k) w[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define S(i, j, k) seg[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define U(i, j, k) \
u[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define V(i, j, k) \
v[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define W(i, j, k) \
w[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define S(i, j, k) \
seg[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
static int ts = 0;
@ -31,8 +35,7 @@ static double sum(int* sizes, int size)
{
double sum = 0;
for (int i = 0; i < size; ++i)
{
for (int i = 0; i < size; ++i) {
sum += sizes[i];
}
@ -43,28 +46,29 @@ static double sumOffset(double* sizes, int init, int offset, int coord)
{
double sum = 0;
for (int i = init - offset; coord > 0; i-=offset, --coord)
{
for (int i = init - offset; coord > 0; i -= offset, --coord) {
sum += sizes[i];
}
return sum;
}
void printParticles(ParticleTracer* particletracer)
{
for(int i = 0; i < particletracer->totalParticles; ++i)
{
printf("Rank : %d Particle position X : %.2f, Y : %.2f, flag : %d, total pt : %d, pointer : %d, xOffset : %.2f, yOffset : %.2f, xOffsetEnd : %.2f, yOffsetEnd : %.2f\n",
for (int i = 0; i < particletracer->totalParticles; ++i) {
printf("Rank : %d Particle position X : %.2f, Y : %.2f, flag : %d, total pt : "
"%d, pointer : %d, xOffset : %.2f, yOffset : %.2f, xOffsetEnd : %.2f, "
"yOffsetEnd : %.2f\n",
particletracer->rank,
particletracer->particlePool[i].x,
particletracer->particlePool[i].y,
particletracer->particlePool[i].flag,
particletracer->totalParticles,
particletracer->pointer,
particletracer->xOffset, particletracer->yOffset,
particletracer->xOffsetEnd, particletracer->yOffsetEnd);
particletracer->xOffset,
particletracer->yOffset,
particletracer->xOffsetEnd,
particletracer->yOffsetEnd);
}
}
void injectParticles(ParticleTracer* particletracer, int* restrict seg)
@ -73,25 +77,29 @@ void injectParticles(ParticleTracer* particletracer,int* restrict seg)
int imaxLocal = particletracer->imaxLocal;
int jmaxLocal = particletracer->jmaxLocal;
int kmaxLocal = particletracer->kmaxLocal;
for(int i = 0; i < particletracer->numberOfParticles; ++i)
{
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
x = particletracer->linSpaceLine[i].x;
y = particletracer->linSpaceLine[i].y;
z = particletracer->linSpaceLine[i].z;
if(x >= particletracer->xOffset && y >= particletracer->yOffset && z >= particletracer->zOffset && x <= particletracer->xOffsetEnd && y <= particletracer->yOffsetEnd && y <= particletracer->zOffsetEnd )
{
if (x >= particletracer->xOffset && y >= particletracer->yOffset &&
z >= particletracer->zOffset && x <= particletracer->xOffsetEnd &&
y <= particletracer->yOffsetEnd && y <= particletracer->zOffsetEnd) {
// printf("\nRank : %d\n", particletracer->rank);
// printf("\t%.2f >= %.2f && %.2f >= %.2f && %.2f <= %.2f && %.2f <= %.2f\n",x , particletracer->xOffset ,y , particletracer->yOffset, x , particletracer->xOffsetEnd ,y , particletracer->yOffsetEnd);
// printf("\t%.2f >= %.2f && %.2f >= %.2f && %.2f <= %.2f && %.2f <= %.2f\n",x
// , particletracer->xOffset ,y , particletracer->yOffset, x ,
// particletracer->xOffsetEnd ,y , particletracer->yOffsetEnd);
particletracer->particlePool[particletracer->pointer].x = x;
particletracer->particlePool[particletracer->pointer].y = y;
particletracer->particlePool[particletracer->pointer].z = z;
int i = particletracer->particlePool[particletracer->pointer].x / particletracer->dx;
int j = particletracer->particlePool[particletracer->pointer].y / particletracer->dy;
int k = particletracer->particlePool[particletracer->pointer].z / particletracer->dz;
if(S(i,j,k) == NONE)
{
int i = particletracer->particlePool[particletracer->pointer].x /
particletracer->dx;
int j = particletracer->particlePool[particletracer->pointer].y /
particletracer->dy;
int k = particletracer->particlePool[particletracer->pointer].z /
particletracer->dz;
if (S(i, j, k) == NONE) {
particletracer->particlePool[particletracer->pointer].flag = true;
++(particletracer->pointer);
++(particletracer->totalParticles);
@ -100,7 +108,12 @@ void injectParticles(ParticleTracer* particletracer,int* restrict seg)
}
}
void advanceParticles(ParticleTracer* particletracer, double* restrict u, double* restrict v, double* restrict w, int* restrict seg, double time)
void advanceParticles(ParticleTracer* particletracer,
double* restrict u,
double* restrict v,
double* restrict w,
int* restrict seg,
double time)
{
int imax = particletracer->imax;
int jmax = particletracer->jmax;
@ -109,7 +122,6 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
int jmaxLocal = particletracer->jmaxLocal;
int kmaxLocal = particletracer->kmaxLocal;
double dx = particletracer->dx;
double dy = particletracer->dy;
double dz = particletracer->dz;
@ -118,13 +130,10 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
double ylength = particletracer->ylength;
double zlength = particletracer->zlength;
Particle buff[particletracer->size][100];
for(int i = 0; i < particletracer->size; ++i)
{
for(int j = 0; j < 100; ++j)
{
for (int i = 0; i < particletracer->size; ++i) {
for (int j = 0; j < 100; ++j) {
buff[i][j].x = 0.0;
buff[i][j].y = 0.0;
buff[i][j].z = 0.0;
@ -135,16 +144,12 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
memset(particleBufIndex, 0, sizeof(particleBufIndex));
for(int i = 0; i < particletracer->totalParticles; ++i)
{
if(particletracer->particlePool[i].flag == true)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
if (particletracer->particlePool[i].flag == true) {
double xTemp = particletracer->particlePool[i].x;
double yTemp = particletracer->particlePool[i].y;
double zTemp = particletracer->particlePool[i].z;
double x = xTemp - particletracer->xOffset;
double y = yTemp - particletracer->yOffset;
double z = zTemp - particletracer->zOffset;
@ -153,7 +158,6 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
int jCoord = (int)((y + 0.5 * dy) / dy) + 1;
int kCoord = (int)((z + 0.5 * dz) / dz) + 1;
double x1 = (double)(iCoord - 1) * dx;
double y1 = ((double)(jCoord - 1) - 0.5) * dy;
double z1 = ((double)(kCoord - 1) - 0.5) * dz;
@ -162,18 +166,16 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
double y2 = ((double)jCoord - 0.5) * dy;
double z2 = ((double)kCoord - 0.5) * dz;
double u_n = (1.0 / (dx * dy * dz)) *
(
(x2 - x) * (y2 - y) * (z2 - z) * U(iCoord - 1, jCoord - 1, kCoord - 1) +
double u_n =
(1.0 / (dx * dy * dz)) *
((x2 - x) * (y2 - y) * (z2 - z) * U(iCoord - 1, jCoord - 1, kCoord - 1) +
(x - x1) * (y2 - y) * (z2 - z) * U(iCoord, jCoord - 1, kCoord - 1) +
(x2 - x) * (y - y1) * (z2 - z) * U(iCoord - 1, jCoord, kCoord - 1) +
(x - x1) * (y - y1) * (z2 - z) * U(iCoord, jCoord, kCoord - 1) +
(x2 - x) * (y2 - y) * (z - z1) * U(iCoord - 1, jCoord - 1, kCoord) +
(x - x1) * (y2 - y) * (z - z1) * U(iCoord, jCoord - 1, kCoord) +
(x2 - x) * (y - y1) * (z - z1) * U(iCoord - 1, jCoord, kCoord) +
(x - x1) * (y - y1) * (z - z1) * U(iCoord, jCoord, kCoord)
);
(x - x1) * (y - y1) * (z - z1) * U(iCoord, jCoord, kCoord));
double new_x = (x + particletracer->xOffset) + particletracer->dt * u_n;
particletracer->particlePool[i].x = new_x;
@ -190,17 +192,16 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
y2 = (double)jCoord * dy;
z2 = ((double)kCoord - 0.5) * dz;
double v_n = (1.0 / (dx * dy * dz)) *
(
(x2 - x) * (y2 - y) * (z2 - z) * V(iCoord - 1, jCoord - 1, kCoord - 1) +
double v_n =
(1.0 / (dx * dy * dz)) *
((x2 - x) * (y2 - y) * (z2 - z) * V(iCoord - 1, jCoord - 1, kCoord - 1) +
(x - x1) * (y2 - y) * (z2 - z) * V(iCoord, jCoord - 1, kCoord - 1) +
(x2 - x) * (y - y1) * (z2 - z) * V(iCoord - 1, jCoord, kCoord - 1) +
(x - x1) * (y - y1) * (z2 - z) * V(iCoord, jCoord, kCoord - 1) +
(x2 - x) * (y2 - y) * (z - z1) * V(iCoord - 1, jCoord - 1, kCoord) +
(x - x1) * (y2 - y) * (z - z1) * V(iCoord, jCoord - 1, kCoord) +
(x2 - x) * (y - y1) * (z - z1) * V(iCoord - 1, jCoord, kCoord) +
(x - x1) * (y - y1) * (z - z1) * V(iCoord, jCoord, kCoord)
);
(x - x1) * (y - y1) * (z - z1) * V(iCoord, jCoord, kCoord));
double new_y = (y + particletracer->yOffset) + particletracer->dt * v_n;
particletracer->particlePool[i].y = new_y;
@ -217,43 +218,56 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
y2 = ((double)jCoord - 0.5) * dy;
z2 = (double)kCoord * dz;
double w_n = (1.0 / (dx * dy * dz)) *
(
(x2 - x) * (y2 - y) * (z2 - z) * W(iCoord - 1, jCoord - 1, kCoord - 1) +
double w_n =
(1.0 / (dx * dy * dz)) *
((x2 - x) * (y2 - y) * (z2 - z) * W(iCoord - 1, jCoord - 1, kCoord - 1) +
(x - x1) * (y2 - y) * (z2 - z) * W(iCoord, jCoord - 1, kCoord - 1) +
(x2 - x) * (y - y1) * (z2 - z) * W(iCoord - 1, jCoord, kCoord - 1) +
(x - x1) * (y - y1) * (z2 - z) * W(iCoord, jCoord, kCoord - 1) +
(x2 - x) * (y2 - y) * (z - z1) * W(iCoord - 1, jCoord - 1, kCoord) +
(x - x1) * (y2 - y) * (z - z1) * W(iCoord, jCoord - 1, kCoord) +
(x2 - x) * (y - y1) * (z - z1) * W(iCoord - 1, jCoord, kCoord) +
(x - x1) * (y - y1) * (z - z1) * W(iCoord, jCoord, kCoord)
);
(x - x1) * (y - y1) * (z - z1) * W(iCoord, jCoord, kCoord));
double new_z = (z + particletracer->zOffset) + particletracer->dt * w_n;
particletracer->particlePool[i].z = new_z;
// printf("Rank : %d\n", particletracer->rank);
// printf("\tOld X : %.2f, translated X : %.2f, xOffset : %.2f, New X : %.2f, iCoord : %d\n\tOld Y : %.2f, translated X : %.2f, yOffset : %.2f, New Y : %.2f, jCoord : %d\n\n",xTemp, x, particletracer->xOffset, new_x, iCoord, yTemp, y, particletracer->yOffset , new_y, jCoord);
// printf("\tU(iCoord - 1, jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f, U(iCoord - 1, jCoord) : %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1, jCoord - 1), U(iCoord, jCoord - 1), U(iCoord - 1, jCoord), U(iCoord, jCoord));
// printf("\tV(iCoord - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1) : %.2f, V(iCoord - 1, jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n", V(iCoord - 1, jCoord - 1), V(iCoord, jCoord - 1), V(iCoord - 1, jCoord), V(iCoord, jCoord));
// printf("\tOld X : %.2f, translated X : %.2f, xOffset : %.2f, New X : %.2f,
// iCoord : %d\n\tOld Y : %.2f, translated X : %.2f, yOffset : %.2f, New Y :
// %.2f, jCoord : %d\n\n",xTemp, x, particletracer->xOffset, new_x, iCoord,
// yTemp, y, particletracer->yOffset , new_y, jCoord); printf("\tU(iCoord - 1,
// jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f, U(iCoord - 1, jCoord) :
// %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1, jCoord - 1), U(iCoord,
// jCoord - 1), U(iCoord - 1, jCoord), U(iCoord, jCoord)); printf("\tV(iCoord
// - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1) : %.2f, V(iCoord - 1,
// jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n", V(iCoord - 1, jCoord - 1),
// V(iCoord, jCoord - 1), V(iCoord - 1, jCoord), V(iCoord, jCoord));
// printf("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
if (((new_x < particletracer->xOffset) || (new_x >= particletracer->xOffsetEnd) ||
(new_y < particletracer->yOffset) || (new_y >= particletracer->yOffsetEnd) ||
(new_z < particletracer->zOffset) || (new_z >= particletracer->zOffsetEnd)))
{
//New logic to transfer particles to neighbouring ranks or discard the particle.
if (((new_x < particletracer->xOffset) ||
(new_x >= particletracer->xOffsetEnd) ||
(new_y < particletracer->yOffset) ||
(new_y >= particletracer->yOffsetEnd) ||
(new_z < particletracer->zOffset) ||
(new_z >= particletracer->zOffsetEnd))) {
// New logic to transfer particles to neighbouring ranks or discard the
// particle.
for(int i = 0; i < particletracer->size; ++i)
{
if((new_x >= particletracer->offset[i + particletracer->size * XOFFSET]) &&
(new_x <= particletracer->offset[i + particletracer->size * XOFFSETEND]) &&
(new_y >= particletracer->offset[i + particletracer->size * YOFFSET]) &&
(new_y <= particletracer->offset[i + particletracer->size * YOFFSETEND]) &&
(new_z >= particletracer->offset[i + particletracer->size * ZOFFSET]) &&
(new_z <= particletracer->offset[i + particletracer->size * ZOFFSETEND]) &&
i != particletracer->rank)
{
for (int i = 0; i < particletracer->size; ++i) {
if ((new_x >=
particletracer->offset[i + particletracer->size * XOFFSET]) &&
(new_x <= particletracer
->offset[i + particletracer->size * XOFFSETEND]) &&
(new_y >=
particletracer->offset[i + particletracer->size * YOFFSET]) &&
(new_y <= particletracer
->offset[i + particletracer->size * YOFFSETEND]) &&
(new_z >=
particletracer->offset[i + particletracer->size * ZOFFSET]) &&
(new_z <= particletracer
->offset[i + particletracer->size * ZOFFSETEND]) &&
i != particletracer->rank) {
buff[i][particleBufIndex[i]].x = new_x;
buff[i][particleBufIndex[i]].y = new_y;
buff[i][particleBufIndex[i]].z = new_z;
@ -268,39 +282,44 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
int iOffset = particletracer->xOffset / dx,
jOffset = particletracer->yOffset / dy,
kOffset = particletracer->zOffset / dz;
if(S(i_new - iOffset, j_new - jOffset, k_new - kOffset) != NONE)
{
if (S(i_new - iOffset, j_new - jOffset, k_new - kOffset) != NONE) {
particletracer->particlePool[i].flag = false;
}
}
}
}
for(int i = 0; i < particletracer->size; ++i)
{
if(i != particletracer->rank)
{
MPI_Send(buff[i], 100, particletracer->mpi_particle, i, 0, particletracer->comm);
for (int i = 0; i < particletracer->size; ++i) {
if (i != particletracer->rank) {
MPI_Send(buff[i],
100,
particletracer->mpi_particle,
i,
0,
particletracer->comm);
}
}
for(int i = 0; i < particletracer->size; ++i)
{
if(i != particletracer->rank)
{
MPI_Recv(buff[i], 100, particletracer->mpi_particle, i, 0, particletracer->comm, MPI_STATUS_IGNORE);
for (int i = 0; i < particletracer->size; ++i) {
if (i != particletracer->rank) {
MPI_Recv(buff[i],
100,
particletracer->mpi_particle,
i,
0,
particletracer->comm,
MPI_STATUS_IGNORE);
}
}
for(int i = 0; i < particletracer->size; ++i)
{
if(i != particletracer->rank)
{
for(int j = 0; j < 100; ++j)
{
if(buff[i][j].flag == true)
{
particletracer->particlePool[particletracer->pointer].x = buff[i][j].x;
particletracer->particlePool[particletracer->pointer].y = buff[i][j].y;
particletracer->particlePool[particletracer->pointer].z = buff[i][j].z;
for (int i = 0; i < particletracer->size; ++i) {
if (i != particletracer->rank) {
for (int j = 0; j < 100; ++j) {
if (buff[i][j].flag == true) {
particletracer->particlePool[particletracer->pointer].x = buff[i][j]
.x;
particletracer->particlePool[particletracer->pointer].y = buff[i][j]
.y;
particletracer->particlePool[particletracer->pointer].z = buff[i][j]
.z;
particletracer->particlePool[particletracer->pointer].flag = true;
++(particletracer->pointer);
++(particletracer->totalParticles);
@ -321,23 +340,34 @@ void writeParticles(ParticleTracer* particletracer)
{
int collectedBuffIndex[particletracer->size];
MPI_Gather(&particletracer->totalParticles, 1, MPI_INT, collectedBuffIndex, 1, MPI_INT, 0, particletracer->comm);
MPI_Gather(&particletracer->totalParticles,
1,
MPI_INT,
collectedBuffIndex,
1,
MPI_INT,
0,
particletracer->comm);
if(particletracer->rank != 0)
{
if (particletracer->rank != 0) {
Particle buff[particletracer->totalParticles];
for(int i = 0; i < particletracer->totalParticles; ++i)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
buff[i].x = particletracer->particlePool[i].x;
buff[i].y = particletracer->particlePool[i].y;
buff[i].z = particletracer->particlePool[i].z;
buff[i].flag = particletracer->particlePool[i].flag;
//printf("Rank : %d sending to rank 0 X : %.2f, Y : %.2f with totalpt : %d\n", particletracer->rank, buff[i].x, buff[i].y, particletracer->totalParticles);
// printf("Rank : %d sending to rank 0 X : %.2f, Y : %.2f with totalpt :
// %d\n", particletracer->rank, buff[i].x, buff[i].y,
// particletracer->totalParticles);
}
MPI_Send(buff, particletracer->totalParticles, particletracer->mpi_particle, 0, 1, particletracer->comm);
MPI_Send(buff,
particletracer->totalParticles,
particletracer->mpi_particle,
0,
1,
particletracer->comm);
}
if(particletracer->rank == 0)
{
if (particletracer->rank == 0) {
char filename[50];
FILE* fp;
@ -352,7 +382,6 @@ void writeParticles(ParticleTracer* particletracer)
fprintf(fp, "PAMPI cfd solver particle tracing file\n");
fprintf(fp, "ASCII\n");
fprintf(fp, "DATASET UNSTRUCTURED_GRID\n");
fprintf(fp, "FIELD FieldData 2\n");
fprintf(fp, "TIME 1 1 double\n");
@ -366,24 +395,26 @@ void writeParticles(ParticleTracer* particletracer)
printf("Total particles : %d\n", overallTotalParticles);
for (int i = 1; i < particletracer->size; ++i)
{
for (int i = 1; i < particletracer->size; ++i) {
Particle recvBuff[collectedBuffIndex[i]];
MPI_Recv(&recvBuff, collectedBuffIndex[i], particletracer->mpi_particle, i, 1, particletracer->comm, MPI_STATUS_IGNORE);
MPI_Recv(&recvBuff,
collectedBuffIndex[i],
particletracer->mpi_particle,
i,
1,
particletracer->comm,
MPI_STATUS_IGNORE);
for (int j = 0; j < collectedBuffIndex[i]; ++j)
{
for (int j = 0; j < collectedBuffIndex[i]; ++j) {
double x = recvBuff[j].x;
double y = recvBuff[j].y;
double z = recvBuff[j].z;
fprintf(fp, "%f %f %f\n", x, y, z);
//printf("Rank : 0 receiving from rank %d X : %.2f, Y : %.2f with totalpt : %d\n", i, x, y, particletracer->totalParticles);
// printf("Rank : 0 receiving from rank %d X : %.2f, Y : %.2f with totalpt
// : %d\n", i, x, y, particletracer->totalParticles);
}
}
for (int i = 0; i < particletracer->totalParticles; ++i)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
double x = particletracer->particlePool[i].x;
double y = particletracer->particlePool[i].y;
double z = particletracer->particlePool[i].z;
@ -392,17 +423,13 @@ void writeParticles(ParticleTracer* particletracer)
fprintf(fp, "CELLS %d %d\n", overallTotalParticles, 2 * overallTotalParticles);
for (int i = 0; i < overallTotalParticles; ++i)
{
for (int i = 0; i < overallTotalParticles; ++i) {
fprintf(fp, "1 %d\n", i);
}
fprintf(fp, "CELL_TYPES %d\n", overallTotalParticles);
for (int i = 0; i < overallTotalParticles; ++i)
{
for (int i = 0; i < overallTotalParticles; ++i) {
fprintf(fp, "1\n");
}
@ -452,19 +479,22 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solv
particletracer->jmaxLocal = solver->comm.jmaxLocal;
particletracer->kmaxLocal = solver->comm.kmaxLocal;
particletracer->estimatedNumParticles = (particletracer->imaxLocal * particletracer->jmaxLocal * particletracer->kmaxLocal);
particletracer->estimatedNumParticles = (particletracer->imaxLocal *
particletracer->jmaxLocal *
particletracer->kmaxLocal);
particletracer->particlePool = malloc(sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->particlePool = malloc(
sizeof(Particle) * particletracer->estimatedNumParticles);
for(int i = 0; i < particletracer->estimatedNumParticles; ++i)
{
for (int i = 0; i < particletracer->estimatedNumParticles; ++i) {
particletracer->particlePool[i].x = 0.0;
particletracer->particlePool[i].y = 0.0;
particletracer->particlePool[i].z = 0.0;
particletracer->particlePool[i].flag = false;
}
particletracer->linSpaceLine = malloc(sizeof(Particle) * particletracer->numberOfParticles);
particletracer->linSpaceLine = malloc(
sizeof(Particle) * particletracer->numberOfParticles);
/* duplicating communication from solver */
MPI_Comm_dup(solver->comm.comm, &particletracer->comm);
@ -474,13 +504,10 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solv
particletracer->offset = (double*)malloc(sizeof(double) * 4 * particletracer->size);
memcpy(particletracer->dims, solver->comm.dims, sizeof(solver->comm.dims));
memcpy(particletracer->coords, solver->comm.coords, sizeof(solver->comm.coords));
double offset[6][particletracer->size];
particletracer->xOffset = solver->xOffset;
@ -490,49 +517,95 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solv
particletracer->yOffsetEnd = solver->yOffsetEnd;
particletracer->zOffsetEnd = solver->zOffsetEnd;
//printf("Rank : %d, xOffset : %.2f, yOffset : %.2f, zOffset : %.2f, xOffsetEnd : %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n", particletracer->rank, particletracer->xOffset, particletracer->yOffset, particletracer->zOffset, particletracer->xOffsetEnd, particletracer->yOffsetEnd, particletracer->zOffsetEnd);
// printf("Rank : %d, xOffset : %.2f, yOffset : %.2f, zOffset : %.2f, xOffsetEnd :
// %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n", particletracer->rank,
// particletracer->xOffset, particletracer->yOffset, particletracer->zOffset,
// particletracer->xOffsetEnd, particletracer->yOffsetEnd,
// particletracer->zOffsetEnd);
MPI_Allgather(&particletracer->xOffset, 1, MPI_DOUBLE, offset[0], 1, MPI_DOUBLE, particletracer->comm);
MPI_Allgather(&particletracer->yOffset, 1, MPI_DOUBLE, offset[1], 1, MPI_DOUBLE, particletracer->comm);
MPI_Allgather(&particletracer->zOffset, 1, MPI_DOUBLE, offset[2], 1, MPI_DOUBLE, particletracer->comm);
MPI_Allgather(&particletracer->xOffsetEnd, 1, MPI_DOUBLE, offset[3], 1, MPI_DOUBLE, particletracer->comm);
MPI_Allgather(&particletracer->yOffsetEnd, 1, MPI_DOUBLE, offset[4], 1, MPI_DOUBLE, particletracer->comm);
MPI_Allgather(&particletracer->zOffsetEnd, 1, MPI_DOUBLE, offset[5], 1, MPI_DOUBLE, particletracer->comm);
MPI_Allgather(&particletracer->xOffset,
1,
MPI_DOUBLE,
offset[0],
1,
MPI_DOUBLE,
particletracer->comm);
MPI_Allgather(&particletracer->yOffset,
1,
MPI_DOUBLE,
offset[1],
1,
MPI_DOUBLE,
particletracer->comm);
MPI_Allgather(&particletracer->zOffset,
1,
MPI_DOUBLE,
offset[2],
1,
MPI_DOUBLE,
particletracer->comm);
MPI_Allgather(&particletracer->xOffsetEnd,
1,
MPI_DOUBLE,
offset[3],
1,
MPI_DOUBLE,
particletracer->comm);
MPI_Allgather(&particletracer->yOffsetEnd,
1,
MPI_DOUBLE,
offset[4],
1,
MPI_DOUBLE,
particletracer->comm);
MPI_Allgather(&particletracer->zOffsetEnd,
1,
MPI_DOUBLE,
offset[5],
1,
MPI_DOUBLE,
particletracer->comm);
memcpy(particletracer->offset, offset, sizeof(offset));
// if(particletracer->rank == 0)
// {
// for(int i = 0;i < particletracer->size; ++i)
// {
// printf("Rank : %d, xLocal : %.2f, yLocal : %.2f, zLocal : %.2f\n", i, xLocal[i], yLocal[i], zLocal[i]);
// printf("Rank : %d, xLocal : %.2f, yLocal : %.2f, zLocal : %.2f\n", i,
// xLocal[i], yLocal[i], zLocal[i]);
// }
// for(int i = 0;i < particletracer->size; ++i)
// {
// printf("Rank : %d and its xOffset : %.2f, yOffset : %.2f, zOffset : %.2f,xOffsetEnd : %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n",
// i, particletracer->offset[i + particletracer->size * XOFFSET],
// particletracer->offset[i + particletracer->size * YOFFSET], particletracer->offset[i + particletracer->size * ZOFFSET]
// , particletracer->offset[i + particletracer->size * XOFFSETEND],
// particletracer->offset[i + particletracer->size * YOFFSETEND], particletracer->offset[i + particletracer->size * ZOFFSETEND]);
// printf("Rank : %d and its xOffset : %.2f, yOffset : %.2f, zOffset :
// %.2f,xOffsetEnd : %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n", i,
// particletracer->offset[i + particletracer->size * XOFFSET],
// particletracer->offset[i + particletracer->size * YOFFSET],
// particletracer->offset[i + particletracer->size * ZOFFSET] ,
// particletracer->offset[i + particletracer->size * XOFFSETEND],
// particletracer->offset[i + particletracer->size * YOFFSETEND],
// particletracer->offset[i + particletracer->size * ZOFFSETEND]);
// }
// }
for (int i = 0; i < particletracer->numberOfParticles; ++i)
{
// double spacing = (double)i / (double)(particletracer->numberOfParticles - 1);
// particletracer->linSpaceLine[i].x = spacing * particletracer->x1 + (1.0 - spacing) * particletracer->x2;
// particletracer->linSpaceLine[i].y = spacing * particletracer->y1 + (1.0 - spacing) * particletracer->y2;
// particletracer->linSpaceLine[i].z = spacing * particletracer->z1 + (1.0 - spacing) * particletracer->z2;
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
// double spacing = (double)i /
// (double)(particletracer->numberOfParticles - 1);
// particletracer->linSpaceLine[i].x = spacing * particletracer->x1 + (1.0 -
// spacing) * particletracer->x2; particletracer->linSpaceLine[i].y = spacing *
// particletracer->y1 + (1.0 - spacing) * particletracer->y2;
// particletracer->linSpaceLine[i].z = spacing * particletracer->z1 + (1.0 -
// spacing) * particletracer->z2;
particletracer->linSpaceLine[i].x = particletracer->x1;
particletracer->linSpaceLine[i].y = (double) rand() / RAND_MAX * particletracer->ylength;
particletracer->linSpaceLine[i].z = (double) rand() / RAND_MAX * particletracer->zlength;
particletracer->linSpaceLine[i].y = (double)rand() / RAND_MAX *
particletracer->ylength;
particletracer->linSpaceLine[i].z = (double)rand() / RAND_MAX *
particletracer->zlength;
particletracer->linSpaceLine[i].flag = true;
}
// Create the mpi_particle datatype
MPI_Datatype mpi_particle;
int lengths[4] = { 1, 1, 1, 1 };
@ -550,37 +623,69 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solv
displacements[2] = MPI_Aint_diff(displacements[2], base_address);
displacements[3] = MPI_Aint_diff(displacements[3], base_address);
MPI_Datatype types[4] = { MPI_DOUBLE, MPI_DOUBLE, MPI_DOUBLE, MPI_C_BOOL };
MPI_Type_create_struct(4, lengths, displacements, types, &particletracer->mpi_particle);
MPI_Type_create_struct(4,
lengths,
displacements,
types,
&particletracer->mpi_particle);
MPI_Type_commit(&particletracer->mpi_particle);
}
void printParticleTracerParameters(ParticleTracer* particletracer)
{
printf("Particle Tracing data:\n");
printf("Rank : %d\n", particletracer->rank);
printf("\tNumber of particles : %d being injected for every period of %.2f\n", particletracer->numberOfParticles, particletracer->injectTimePeriod);
printf("\tNumber of particles : %d being injected for every period of %.2f\n",
particletracer->numberOfParticles,
particletracer->injectTimePeriod);
printf("\tstartTime : %.2f\n", particletracer->startTime);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : %.2f, z1 : %.2f, x2 : %.2f, y2 : %.2f, z2 : %.2f\n", particletracer->x1, particletracer->y1, particletracer->z1, particletracer->x2, particletracer->y2, particletracer->z2);
printf("\tPointer : %d, TotalParticles : %d\n", particletracer->pointer, particletracer->totalParticles);
printf("\tdt : %.2f, dx : %.2f, dy : %.2f, dz : %.2f\n", particletracer->dt, particletracer->dx, particletracer->dy, particletracer->dz);
printf("\tcoord[0] : %d, coord[1] : %d, coord[2] : %d\n", particletracer->coords[IDIM], particletracer->coords[JDIM], particletracer->coords[KDIM]);
printf("\txOffset : %.2f, yOffset : %.2f, zOffset : %.2f\n", particletracer->xOffset, particletracer->yOffset, particletracer->zOffset);
printf("\txOffsetEnd : %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n", particletracer->xOffsetEnd, particletracer->yOffsetEnd, particletracer->zOffsetEnd);
printf("\txLocal : %.2f, yLocal : %.2f, zLocal : %.2f\n", particletracer->xLocal, particletracer->yLocal, particletracer->zLocal);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : "
"%.2f, z1 : %.2f, x2 : %.2f, y2 : %.2f, z2 : %.2f\n",
particletracer->x1,
particletracer->y1,
particletracer->z1,
particletracer->x2,
particletracer->y2,
particletracer->z2);
printf("\tPointer : %d, TotalParticles : %d\n",
particletracer->pointer,
particletracer->totalParticles);
printf("\tdt : %.2f, dx : %.2f, dy : %.2f, dz : %.2f\n",
particletracer->dt,
particletracer->dx,
particletracer->dy,
particletracer->dz);
printf("\tcoord[0] : %d, coord[1] : %d, coord[2] : %d\n",
particletracer->coords[IDIM],
particletracer->coords[JDIM],
particletracer->coords[KDIM]);
printf("\txOffset : %.2f, yOffset : %.2f, zOffset : %.2f\n",
particletracer->xOffset,
particletracer->yOffset,
particletracer->zOffset);
printf("\txOffsetEnd : %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n",
particletracer->xOffsetEnd,
particletracer->yOffsetEnd,
particletracer->zOffsetEnd);
printf("\txLocal : %.2f, yLocal : %.2f, zLocal : %.2f\n",
particletracer->xLocal,
particletracer->yLocal,
particletracer->zLocal);
}
void trace(ParticleTracer* particletracer, double* restrict u, double* restrict v, double* restrict w, int* restrict seg,double time)
{
if (time >= particletracer->startTime)
{
if( (time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod)
void trace(ParticleTracer* particletracer,
double* restrict u,
double* restrict v,
double* restrict w,
int* restrict seg,
double time)
{
if (time >= particletracer->startTime) {
if ((time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod) {
injectParticles(particletracer, seg);
particletracer->lastInjectTime = time;
}
if( (time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod)
{
if ((time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod) {
writeParticles(particletracer);
particletracer->lastWriteTime = time;
}
@ -595,8 +700,7 @@ void compress(ParticleTracer* particletracer)
Particle* memPool = particletracer->particlePool;
Particle tempPool[particletracer->totalParticles];
for(int i = 0; i < particletracer->totalParticles; ++i)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
tempPool[i].x = 0.0;
tempPool[i].y = 0.0;
tempPool[i].z = 0.0;
@ -604,10 +708,8 @@ void compress(ParticleTracer* particletracer)
}
int totalParticles = 0;
for(int i=0; i < particletracer->totalParticles; ++i)
{
if(memPool[i].flag == true)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
if (memPool[i].flag == true) {
tempPool[totalParticles].x = memPool[i].x;
tempPool[totalParticles].y = memPool[i].y;
tempPool[totalParticles].z = memPool[i].z;

View File

@ -9,21 +9,21 @@
#include "allocate.h"
#include "parameter.h"
#include "solver.h"
#include <stdbool.h>
#include <mpi.h>
#include <stdbool.h>
#define NDIMS 3
typedef enum COORD { X = 0, Y, NCOORD } COORD;
typedef struct
{
typedef struct {
double x, y, z;
bool flag;
} Particle;
typedef struct {
int numberOfParticles, totalParticles;
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime, lastWriteTime;
double startTime, injectTimePeriod, writeTimePeriod, lastInjectTime, lastUpdateTime,
lastWriteTime;
int estimatedNumParticles;
@ -43,7 +43,8 @@ typedef struct {
int rank, size;
int coords[NDIMS], dims[NDIMS];
double xLocal, yLocal, zLocal, xOffset, yOffset, zOffset, xOffsetEnd, yOffsetEnd, zOffsetEnd;
double xLocal, yLocal, zLocal, xOffset, yOffset, zOffset, xOffsetEnd, yOffsetEnd,
zOffsetEnd;
double* offset;

View File

@ -32,7 +32,8 @@
w[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define RHS(i, j, k) \
rhs[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define S(i, j, k) seg[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
#define S(i, j, k) \
seg[(k) * (imaxLocal + 2) * (jmaxLocal + 2) + (j) * (imaxLocal + 2) + (i)]
static double distance(
double i, double j, double k, double iCenter, double jCenter, double kCenter)
@ -79,13 +80,11 @@ static void printConfig(Solver* s)
commPrintConfig(&s->comm);
}
static double sumOffset(double* sizes, int init, int offset, int coord)
{
double sum = 0;
for (int i = init - offset; coord > 0; i-=offset, --coord)
{
for (int i = init - offset; coord > 0; i -= offset, --coord) {
sum += sizes[i];
}
@ -231,7 +230,6 @@ void initSolver(Solver* s, Parameter* params)
s->gamma = params->gamma;
s->rho = params->rho;
commInit(&s->comm, s->grid.kmax, s->grid.jmax, s->grid.imax);
/* allocate arrays */
int imaxLocal = s->comm.imaxLocal;
@ -249,7 +247,6 @@ void initSolver(Solver* s, Parameter* params)
s->h = allocate(64, size * sizeof(double));
s->seg = allocate(64, size * sizeof(int));
for (int i = 0; i < size; i++) {
s->u[i] = params->u_init;
s->v[i] = params->v_init;
@ -260,7 +257,6 @@ void initSolver(Solver* s, Parameter* params)
s->g[i] = 0.0;
s->h[i] = 0.0;
s->seg[i] = NONE;
}
double dx = s->grid.dx;
@ -286,14 +282,19 @@ void initSolver(Solver* s, Parameter* params)
MPI_Allgather(&s->yLocal, 1, MPI_DOUBLE, yLocal, 1, MPI_DOUBLE, s->comm.comm);
MPI_Allgather(&s->zLocal, 1, MPI_DOUBLE, zLocal, 1, MPI_DOUBLE, s->comm.comm);
s->xOffset = sumOffset(xLocal, s->comm.rank, (s->comm.dims[1] * s->comm.dims[2]), s->comm.coords[0]);
s->xOffset = sumOffset(xLocal,
s->comm.rank,
(s->comm.dims[1] * s->comm.dims[2]),
s->comm.coords[0]);
s->yOffset = sumOffset(yLocal, s->comm.rank, s->comm.dims[2], s->comm.coords[1]);
s->zOffset = sumOffset(zLocal, s->comm.rank, 1, s->comm.coords[2]);
s->xOffsetEnd = s->xOffset + s->xLocal;
s->yOffsetEnd = s->yOffset + s->yLocal;
s->zOffsetEnd = s->zOffset + s->zLocal;
// printf("Rank : %d, xOffset : %.2f, yOffset : %.2f, zOffset : %.2f, xOffsetEnd : %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n", s->comm.rank, s->xOffset, s->yOffset, s->zOffset, s->xOffsetEnd, s->yOffsetEnd, s->zOffsetEnd);
// printf("Rank : %d, xOffset : %.2f, yOffset : %.2f, zOffset : %.2f, xOffsetEnd :
// %.2f, yOffsetEnd : %.2f, zOffsetEnd : %.2f\n", s->comm.rank, s->xOffset,
// s->yOffset, s->zOffset, s->xOffsetEnd, s->yOffsetEnd, s->zOffsetEnd);
// exit(0);
@ -317,8 +318,9 @@ void initSolver(Solver* s, Parameter* params)
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
if ((x1 <= ((i + iOffset) * dx)) && (((i + iOffset) * dx) <= x2) && (y1 <= ((j +jOffset) * dy)) &&
(((j+ jOffset) * dy) <= y2) && ((z1 <= ((k + kOffset) * dz)) && (((k + kOffset)* dz) <= z2))) {
if ((x1 <= ((i + iOffset) * dx)) && (((i + iOffset) * dx) <= x2) &&
(y1 <= ((j + jOffset) * dy)) && (((j + jOffset) * dy) <= y2) &&
((z1 <= ((k + kOffset) * dz)) && (((k + kOffset) * dz) <= z2))) {
S(i, j, k) = LOCAL;
}
}
@ -353,7 +355,6 @@ void initSolver(Solver* s, Parameter* params)
commExchangeInt(&s->comm, seg);
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
@ -516,8 +517,7 @@ void computeRHS(Solver* s)
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
RHS(i, j, k) = ((F(i, j, k) - F(i - 1, j, k)) * idx +
(G(i, j, k) - G(i, j - 1, k)) * idy +
(H(i, j, k) - H(i, j, k - 1)) * idz) *
@ -557,7 +557,6 @@ void solveRB(Solver* s)
int pass, ksw, jsw, isw;
int* seg = s->seg;
while ((res >= epssq) && (it < itermax)) {
res = 0.0;
ksw = 1;
@ -566,16 +565,15 @@ void solveRB(Solver* s)
jsw = ksw;
commExchange(&s->comm, p);
for (int k = 1; k < kmaxLocal + 1; k++) {
isw = jsw;
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = isw; i < imaxLocal + 1; i += 2) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
double r =
RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 +
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
idy2 +
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
@ -659,7 +657,6 @@ void solveRB(Solver* s)
#endif
}
void solve(Solver* s)
{
int imaxLocal = s->comm.imaxLocal;
@ -692,15 +689,13 @@ void solve(Solver* s)
res = 0.0;
commExchange(&s->comm, p);
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
if(S(i,j,k) == NONE)
{
double r = RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 +
if (S(i, j, k) == NONE) {
double r =
RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
idy2 +
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
@ -780,7 +775,6 @@ void solve(Solver* s)
#endif
}
void solveRBA(Solver* s)
{
int imaxLocal = s->comm.imaxLocal;
@ -800,8 +794,7 @@ void solveRBA(Solver* s)
double idy2 = 1.0 / dy2;
double idz2 = 1.0 / dz2;
double factor = 0.5 * (dx2 * dy2 * dz2) /
(dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
double factor = 0.5 * (dx2 * dy2 * dz2) / (dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
double* p = s->p;
double* rhs = s->rhs;
double epssq = eps * eps;
@ -820,16 +813,15 @@ void solveRBA(Solver* s)
jsw = ksw;
commExchange(&s->comm, p);
for (int k = 1; k < kmaxLocal + 1; k++) {
isw = jsw;
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = isw; i < imaxLocal + 1; i += 2) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
double r =
RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 +
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
idy2 +
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
@ -915,7 +907,6 @@ void solveRBA(Solver* s)
#endif
}
static double maxElement(Solver* s, double* m)
{
int size = (s->comm.imaxLocal + 2) * (s->comm.jmaxLocal + 2) *
@ -1260,8 +1251,7 @@ void computeFG(Solver* s)
for (int k = 1; k < kmaxLocal + 1; k++) {
for (int j = 1; j < jmaxLocal + 1; j++) {
for (int i = 1; i < imaxLocal + 1; i++) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
du2dx = inverseDx * 0.25 *
((U(i, j, k) + U(i + 1, j, k)) *
(U(i, j, k) + U(i + 1, j, k)) -
@ -1301,8 +1291,9 @@ void computeFG(Solver* s)
(U(i, j + 1, k) - 2.0 * U(i, j, k) + U(i, j - 1, k));
du2dz2 = inverseDz * inverseDz *
(U(i, j, k + 1) - 2.0 * U(i, j, k) + U(i, j, k - 1));
F(i, j, k) = U(i, j, k) + dt * (inverseRe * (du2dx2 + du2dy2 + du2dz2) -
du2dx - duvdy - duwdz + gx);
F(i, j, k) = U(i, j, k) +
dt * (inverseRe * (du2dx2 + du2dy2 + du2dz2) - du2dx -
duvdy - duwdz + gx);
duvdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j + 1, k)) *
@ -1343,8 +1334,9 @@ void computeFG(Solver* s)
(V(i, j + 1, k) - 2.0 * V(i, j, k) + V(i, j - 1, k));
dv2dz2 = inverseDz * inverseDz *
(V(i, j, k + 1) - 2.0 * V(i, j, k) + V(i, j, k - 1));
G(i, j, k) = V(i, j, k) + dt * (inverseRe * (dv2dx2 + dv2dy2 + dv2dz2) -
duvdx - dv2dy - dvwdz + gy);
G(i, j, k) = V(i, j, k) +
dt * (inverseRe * (dv2dx2 + dv2dy2 + dv2dz2) - duvdx -
dv2dy - dvwdz + gy);
duwdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j, k + 1)) *
@ -1385,10 +1377,10 @@ void computeFG(Solver* s)
(W(i, j + 1, k) - 2.0 * W(i, j, k) + W(i, j - 1, k));
dw2dz2 = inverseDz * inverseDz *
(W(i, j, k + 1) - 2.0 * W(i, j, k) + W(i, j, k - 1));
H(i, j, k) = W(i, j, k) + dt * (inverseRe * (dw2dx2 + dw2dy2 + dw2dz2) -
duwdx - dvwdy - dw2dz + gz);
}
else{
H(i, j, k) = W(i, j, k) +
dt * (inverseRe * (dw2dx2 + dw2dy2 + dw2dz2) - duwdx -
dvwdy - dw2dz + gz);
} else {
switch (S(i, j, k)) {
case TOPFACE:
G(i, j, k) = V(i, j, k);
@ -1602,7 +1594,8 @@ void setObjectBoundaryCondition(Solver* s)
case TOPFACE:
U(i, j, k) = -U(i, j + 1, k);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j+1, k);;
W(i, j, k) = -W(i, j + 1, k);
;
break;
case BOTTOMFACE:
U(i, j, k) = -U(i, j - 1, k);

View File

@ -59,7 +59,8 @@ typedef struct {
double *f, *g, *h;
double *u, *v, *w;
int* seg;
double xLocal, yLocal, zLocal, xOffset, yOffset, zOffset, xOffsetEnd, yOffsetEnd, zOffsetEnd;
double xLocal, yLocal, zLocal, xOffset, yOffset, zOffset, xOffsetEnd, yOffsetEnd,
zOffsetEnd;
/* parameters */
double eps, omega, rho;
double re, tau, gamma;

View File

@ -21,9 +21,9 @@ static int ts = 0;
unsigned int seed = 32767;
void printParticles(ParticleTracer* particletracer)
{
for(int i = 0; i < particletracer->totalParticles; ++i)
{
printf("Particle position X : %.2f, Y : %.2f, flag : %d\n", particletracer->particlePool[i].x,
for (int i = 0; i < particletracer->totalParticles; ++i) {
printf("Particle position X : %.2f, Y : %.2f, flag : %d\n",
particletracer->particlePool[i].x,
particletracer->particlePool[i].y,
particletracer->particlePool[i].flag);
}
@ -34,23 +34,31 @@ void injectParticles(ParticleTracer* particletracer, int* seg)
int imax = particletracer->imax;
int jmax = particletracer->jmax;
int kmax = particletracer->kmax;
for(int i = 0; i < particletracer->numberOfParticles; ++i)
{
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
// particletracer->particlePool[particletracer->pointer].x = particletracer->linSpaceLine[i].x;
// particletracer->particlePool[particletracer->pointer].y = particletracer->linSpaceLine[i].y;
// particletracer->particlePool[particletracer->pointer].z = particletracer->linSpaceLine[i].z;
// particletracer->particlePool[particletracer->pointer].x =
// particletracer->linSpaceLine[i].x;
// particletracer->particlePool[particletracer->pointer].y =
// particletracer->linSpaceLine[i].y;
// particletracer->particlePool[particletracer->pointer].z =
// particletracer->linSpaceLine[i].z;
particletracer->particlePool[particletracer->pointer].x = particletracer->x1;
particletracer->particlePool[particletracer->pointer].y = (double) rand() / RAND_MAX * particletracer->ylength;
particletracer->particlePool[particletracer->pointer].z = (double) rand() / RAND_MAX * particletracer->zlength;
particletracer->particlePool[particletracer->pointer].y = (double)rand() /
RAND_MAX *
particletracer->ylength;
particletracer->particlePool[particletracer->pointer].z = (double)rand() /
RAND_MAX *
particletracer->zlength;
int i = particletracer->particlePool[particletracer->pointer].x / particletracer->dx;
int j = particletracer->particlePool[particletracer->pointer].y / particletracer->dy;
int k = particletracer->particlePool[particletracer->pointer].z / particletracer->dz;
int i = particletracer->particlePool[particletracer->pointer].x /
particletracer->dx;
int j = particletracer->particlePool[particletracer->pointer].y /
particletracer->dy;
int k = particletracer->particlePool[particletracer->pointer].z /
particletracer->dz;
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
particletracer->particlePool[particletracer->pointer].flag = true;
++(particletracer->pointer);
++(particletracer->totalParticles);
@ -58,28 +66,27 @@ void injectParticles(ParticleTracer* particletracer, int* seg)
}
}
void advanceParticles(ParticleTracer* particletracer, double* restrict u, double* restrict v, double* restrict w, int* restrict seg, double time)
void advanceParticles(ParticleTracer* particletracer,
double* restrict u,
double* restrict v,
double* restrict w,
int* restrict seg,
double time)
{
int imax = particletracer->imax;
int jmax = particletracer->jmax;
int kmax = particletracer->kmax;
double dx = particletracer->dx;
double dy = particletracer->dy;
double dz = particletracer->dz;
double xlength = particletracer->xlength;
double ylength = particletracer->ylength;
double zlength = particletracer->zlength;
for(int i = 0; i < particletracer->totalParticles; ++i)
{
if(particletracer->particlePool[i].flag == true)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
if (particletracer->particlePool[i].flag == true) {
double x = particletracer->particlePool[i].x;
double y = particletracer->particlePool[i].y;
double z = particletracer->particlePool[i].z;
@ -88,7 +95,6 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
int jCoord = (int)((y + 0.5 * dy) / dy) + 1;
int kCoord = (int)((z + 0.5 * dz) / dz) + 1;
double x1 = (double)(iCoord - 1) * dx;
double y1 = ((double)(jCoord - 1) - 0.5) * dy;
double z1 = ((double)(kCoord - 1) - 0.5) * dz;
@ -97,18 +103,16 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
double y2 = ((double)jCoord - 0.5) * dy;
double z2 = ((double)kCoord - 0.5) * dz;
double u_n = (1.0 / (dx * dy * dz)) *
(
(x2 - x) * (y2 - y) * (z2 - z) * U(iCoord - 1, jCoord - 1, kCoord - 1) +
double u_n =
(1.0 / (dx * dy * dz)) *
((x2 - x) * (y2 - y) * (z2 - z) * U(iCoord - 1, jCoord - 1, kCoord - 1) +
(x - x1) * (y2 - y) * (z2 - z) * U(iCoord, jCoord - 1, kCoord - 1) +
(x2 - x) * (y - y1) * (z2 - z) * U(iCoord - 1, jCoord, kCoord - 1) +
(x - x1) * (y - y1) * (z2 - z) * U(iCoord, jCoord, kCoord - 1) +
(x2 - x) * (y2 - y) * (z - z1) * U(iCoord - 1, jCoord - 1, kCoord) +
(x - x1) * (y2 - y) * (z - z1) * U(iCoord, jCoord - 1, kCoord) +
(x2 - x) * (y - y1) * (z - z1) * U(iCoord - 1, jCoord, kCoord) +
(x - x1) * (y - y1) * (z - z1) * U(iCoord, jCoord, kCoord)
);
(x - x1) * (y - y1) * (z - z1) * U(iCoord, jCoord, kCoord));
double new_x = x + particletracer->dt * u_n;
particletracer->particlePool[i].x = new_x;
@ -125,17 +129,16 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
y2 = (double)jCoord * dy;
z2 = ((double)kCoord - 0.5) * dz;
double v_n = (1.0 / (dx * dy * dz)) *
(
(x2 - x) * (y2 - y) * (z2 - z) * V(iCoord - 1, jCoord - 1, kCoord - 1) +
double v_n =
(1.0 / (dx * dy * dz)) *
((x2 - x) * (y2 - y) * (z2 - z) * V(iCoord - 1, jCoord - 1, kCoord - 1) +
(x - x1) * (y2 - y) * (z2 - z) * V(iCoord, jCoord - 1, kCoord - 1) +
(x2 - x) * (y - y1) * (z2 - z) * V(iCoord - 1, jCoord, kCoord - 1) +
(x - x1) * (y - y1) * (z2 - z) * V(iCoord, jCoord, kCoord - 1) +
(x2 - x) * (y2 - y) * (z - z1) * V(iCoord - 1, jCoord - 1, kCoord) +
(x - x1) * (y2 - y) * (z - z1) * V(iCoord, jCoord - 1, kCoord) +
(x2 - x) * (y - y1) * (z - z1) * V(iCoord - 1, jCoord, kCoord) +
(x - x1) * (y - y1) * (z - z1) * V(iCoord, jCoord, kCoord)
);
(x - x1) * (y - y1) * (z - z1) * V(iCoord, jCoord, kCoord));
double new_y = y + particletracer->dt * v_n;
particletracer->particlePool[i].y = new_y;
@ -152,36 +155,40 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
y2 = ((double)jCoord - 0.5) * dy;
z2 = (double)kCoord * dz;
double w_n = (1.0 / (dx * dy * dz)) *
(
(x2 - x) * (y2 - y) * (z2 - z) * W(iCoord - 1, jCoord - 1, kCoord - 1) +
double w_n =
(1.0 / (dx * dy * dz)) *
((x2 - x) * (y2 - y) * (z2 - z) * W(iCoord - 1, jCoord - 1, kCoord - 1) +
(x - x1) * (y2 - y) * (z2 - z) * W(iCoord, jCoord - 1, kCoord - 1) +
(x2 - x) * (y - y1) * (z2 - z) * W(iCoord - 1, jCoord, kCoord - 1) +
(x - x1) * (y - y1) * (z2 - z) * W(iCoord, jCoord, kCoord - 1) +
(x2 - x) * (y2 - y) * (z - z1) * W(iCoord - 1, jCoord - 1, kCoord) +
(x - x1) * (y2 - y) * (z - z1) * W(iCoord, jCoord - 1, kCoord) +
(x2 - x) * (y - y1) * (z - z1) * W(iCoord - 1, jCoord, kCoord) +
(x - x1) * (y - y1) * (z - z1) * W(iCoord, jCoord, kCoord)
);
(x - x1) * (y - y1) * (z - z1) * W(iCoord, jCoord, kCoord));
double new_z = z + particletracer->dt * w_n;
particletracer->particlePool[i].z = new_z;
// printf("\tOld X : %.2f, New X : %.2f, iCoord : %d\n\tOld Y : %.2f, New Y : %.2f, jCoord : %d\n\n", x, new_x, iCoord, y, new_y, jCoord);
// printf("\tU(iCoord - 1, jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f, U(iCoord - 1, jCoord) : %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1, jCoord - 1), U(iCoord, jCoord - 1), U(iCoord - 1, jCoord), U(iCoord, jCoord));
// printf("\tV(iCoord - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1) : %.2f, V(iCoord - 1, jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n", V(iCoord - 1, jCoord - 1), V(iCoord, jCoord - 1), V(iCoord - 1, jCoord), V(iCoord, jCoord));
// printf("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
// printf("\t j-1 * (imax + 2) + i-1 = %d with element from U : %.2f", (jCoord - 1) * (200 + 2) + (iCoord - 1), u[(jCoord - 1) * (imax + 2) + (iCoord - 1)]);
// printf("\nimax : %d, jmax : %d\n", imax, jmax);
// printf("\tOld X : %.2f, New X : %.2f, iCoord : %d\n\tOld Y : %.2f, New Y :
// %.2f, jCoord : %d\n\n", x, new_x, iCoord, y, new_y, jCoord);
// printf("\tU(iCoord - 1, jCoord - 1) : %.2f, U(iCoord, jCoord - 1) : %.2f,
// U(iCoord - 1, jCoord) : %.2f, U(iCoord, jCoord) : %.2f\n", U(iCoord - 1,
// jCoord - 1), U(iCoord, jCoord - 1), U(iCoord - 1, jCoord), U(iCoord,
// jCoord)); printf("\tV(iCoord - 1, jCoord - 1) : %.2f, V(iCoord, jCoord - 1)
// : %.2f, V(iCoord - 1, jCoord) : %.2f, V(iCoord, jCoord) : %.2f\n\n",
// V(iCoord - 1, jCoord - 1), V(iCoord, jCoord - 1), V(iCoord - 1, jCoord),
// V(iCoord, jCoord)); printf("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
// printf("\t j-1 * (imax + 2) + i-1 = %d with element from U : %.2f", (jCoord
// - 1) * (200 + 2) + (iCoord - 1), u[(jCoord - 1) * (imax + 2) + (iCoord -
// 1)]); printf("\nimax : %d, jmax : %d\n", imax, jmax);
if (((new_x < 0.0) || (new_x > xlength) || (new_y < 0.0) || (new_y > ylength) || (new_z < 0.0) || (new_z > zlength)))
{
if (((new_x < 0.0) || (new_x > xlength) || (new_y < 0.0) ||
(new_y > ylength) || (new_z < 0.0) || (new_z > zlength))) {
particletracer->particlePool[i].flag = false;
}
int i_new = new_x / dx, j_new = new_y / dy, k_new = new_z / dz;
if(S(i_new, j_new, k_new) != NONE)
{
if (S(i_new, j_new, k_new) != NONE) {
particletracer->particlePool[i].flag = false;
}
}
@ -218,12 +225,10 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params)
particletracer->dy = params->ylength / params->jmax;
particletracer->dz = params->zlength / params->kmax;
particletracer->xlength = params->xlength;
particletracer->ylength = params->ylength;
particletracer->zlength = params->zlength;
particletracer->x1 = params->x1;
particletracer->y1 = params->y1;
particletracer->z1 = params->z1;
@ -242,52 +247,74 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params)
particletracer->jmax = params->jmax;
particletracer->kmax = params->kmax;
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2 ) * params->numberOfParticles;
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2) *
params->numberOfParticles;
particletracer->particlePool = malloc(sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->linSpaceLine = malloc(sizeof(Particle) * particletracer->numberOfParticles);
particletracer->particlePool = malloc(
sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->linSpaceLine = malloc(
sizeof(Particle) * particletracer->numberOfParticles);
for (int i = 0; i < particletracer->numberOfParticles; ++i)
{
// double spacing = (double)i / (double)(particletracer->numberOfParticles - 1);
// particletracer->linSpaceLine[i].x = spacing * particletracer->x1 + (1.0 - spacing) * particletracer->x2;
// particletracer->linSpaceLine[i].y = spacing * particletracer->y1 + (1.0 - spacing) * particletracer->y2;
// particletracer->linSpaceLine[i].z = spacing * particletracer->z1 + (1.0 - spacing) * particletracer->z2;
for (int i = 0; i < particletracer->numberOfParticles; ++i) {
// double spacing = (double)i /
// (double)(particletracer->numberOfParticles - 1);
// particletracer->linSpaceLine[i].x = spacing * particletracer->x1 + (1.0 -
// spacing) * particletracer->x2; particletracer->linSpaceLine[i].y = spacing *
// particletracer->y1 + (1.0 - spacing) * particletracer->y2;
// particletracer->linSpaceLine[i].z = spacing * particletracer->z1 + (1.0 -
// spacing) * particletracer->z2;
particletracer->linSpaceLine[i].x = particletracer->x1;
particletracer->linSpaceLine[i].y = (double) rand() / RAND_MAX * particletracer->ylength;
particletracer->linSpaceLine[i].z = (double) rand() / RAND_MAX * particletracer->zlength;
particletracer->linSpaceLine[i].y = (double)rand() / RAND_MAX *
particletracer->ylength;
particletracer->linSpaceLine[i].z = (double)rand() / RAND_MAX *
particletracer->zlength;
particletracer->linSpaceLine[i].flag = true;
}
}
void printParticleTracerParameters(ParticleTracer* particletracer)
{
printf("Particle Tracing data:\n");
printf("\tNumber of particles : %d being injected for every period of %.2f\n", particletracer->numberOfParticles, particletracer->injectTimePeriod);
printf("\tNumber of particles : %d being injected for every period of %.2f\n",
particletracer->numberOfParticles,
particletracer->injectTimePeriod);
printf("\tstartTime : %.2f\n", particletracer->startTime);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : %.2f, z1 : %.2f, x2 : %.2f, y2 : %.2f, z2 : %.2f\n", particletracer->x1, particletracer->y1, particletracer->z1, particletracer->x2, particletracer->y2, particletracer->z2);
printf("\tPointer : %d, TotalParticles : %d\n", particletracer->pointer, particletracer->totalParticles);
printf("\tdt : %.2f, dx : %.2f, dy : %.2f, dz : %.2f\n", particletracer->dt, particletracer->dx, particletracer->dy, particletracer->dz);
printf("\t(Line along which the particles are to be injected) \n\tx1 : %.2f, y1 : "
"%.2f, z1 : %.2f, x2 : %.2f, y2 : %.2f, z2 : %.2f\n",
particletracer->x1,
particletracer->y1,
particletracer->z1,
particletracer->x2,
particletracer->y2,
particletracer->z2);
printf("\tPointer : %d, TotalParticles : %d\n",
particletracer->pointer,
particletracer->totalParticles);
printf("\tdt : %.2f, dx : %.2f, dy : %.2f, dz : %.2f\n",
particletracer->dt,
particletracer->dx,
particletracer->dy,
particletracer->dz);
}
void trace(ParticleTracer* particletracer, double* u, double* v, double* w, int* seg, double time)
{
if (time >= particletracer->startTime)
void trace(ParticleTracer* particletracer,
double* u,
double* v,
double* w,
int* seg,
double time)
{
if (time >= particletracer->startTime) {
// printParticles(particletracer);
if( (time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod)
{
if ((time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod) {
injectParticles(particletracer, seg);
particletracer->lastInjectTime = time;
}
if( (time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod)
{
if ((time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod) {
writeParticles(particletracer);
particletracer->lastWriteTime = time;
}
advanceParticles(particletracer, u, v, w, seg, time);
compress(particletracer);
@ -301,10 +328,8 @@ void compress(ParticleTracer* particletracer)
Particle tempPool[particletracer->totalParticles];
int totalParticles = 0;
for(int i=0; i < particletracer->totalParticles; ++i)
{
if(memPool[i].flag == 1)
{
for (int i = 0; i < particletracer->totalParticles; ++i) {
if (memPool[i].flag == 1) {
tempPool[totalParticles].x = memPool[i].x;
tempPool[totalParticles].y = memPool[i].y;
tempPool[totalParticles].z = memPool[i].z;

View File

@ -443,8 +443,7 @@ void computeRHS(Solver* s)
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
RHS(i, j, k) = ((F(i, j, k) - F(i - 1, j, k)) * idx +
(G(i, j, k) - G(i, j - 1, k)) * idy +
(H(i, j, k) - H(i, j, k - 1)) * idz) *
@ -483,11 +482,10 @@ void solve(Solver* s)
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
if(S(i,j,k) == NONE)
{
double r = RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 +
if (S(i, j, k) == NONE) {
double r =
RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
idy2 +
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
@ -591,11 +589,11 @@ void solveRB(Solver* s)
isw = jsw;
for (int j = 1; j < jmax + 1; j++) {
for (int i = isw; i < imax + 1; i += 2) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
double r =
RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 +
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
idy2 +
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
@ -612,7 +610,6 @@ void solveRB(Solver* s)
ksw = 3 - ksw;
}
res = res / (double)(imax * jmax * kmax);
#ifdef DEBUG
printf("%d Residuum: %e\n", it, res);
@ -649,7 +646,6 @@ void solveRBA(Solver* s)
int pass, ksw, jsw, isw;
int* seg = s->seg;
while ((res >= epssq) && (it < itermax)) {
res = 0.0;
ksw = 1;
@ -661,11 +657,11 @@ void solveRBA(Solver* s)
isw = jsw;
for (int j = 1; j < jmax + 1; j++) {
for (int i = isw; i < imax + 1; i += 2) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
double r =
RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 +
(P(i, j + 1, k) - 2.0 * P(i, j, k) + P(i, j - 1, k)) *
idy2 +
(P(i, j, k + 1) - 2.0 * P(i, j, k) + P(i, j, k - 1)) *
@ -1028,7 +1024,6 @@ void computeFG(Solver* s)
double* h = s->h;
int* seg = s->seg;
double gx = s->gx;
double gy = s->gy;
double gz = s->gz;
@ -1049,8 +1044,7 @@ void computeFG(Solver* s)
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
if(S(i,j,k) == NONE)
{
if (S(i, j, k) == NONE) {
du2dx = inverseDx * 0.25 *
((U(i, j, k) + U(i + 1, j, k)) *
(U(i, j, k) + U(i + 1, j, k)) -
@ -1090,8 +1084,9 @@ void computeFG(Solver* s)
(U(i, j + 1, k) - 2.0 * U(i, j, k) + U(i, j - 1, k));
du2dz2 = inverseDz * inverseDz *
(U(i, j, k + 1) - 2.0 * U(i, j, k) + U(i, j, k - 1));
F(i, j, k) = U(i, j, k) + dt * (inverseRe * (du2dx2 + du2dy2 + du2dz2) -
du2dx - duvdy - duwdz + gx);
F(i, j, k) = U(i, j, k) +
dt * (inverseRe * (du2dx2 + du2dy2 + du2dz2) - du2dx -
duvdy - duwdz + gx);
duvdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j + 1, k)) *
@ -1132,8 +1127,9 @@ void computeFG(Solver* s)
(V(i, j + 1, k) - 2.0 * V(i, j, k) + V(i, j - 1, k));
dv2dz2 = inverseDz * inverseDz *
(V(i, j, k + 1) - 2.0 * V(i, j, k) + V(i, j, k - 1));
G(i, j, k) = V(i, j, k) + dt * (inverseRe * (dv2dx2 + dv2dy2 + dv2dz2) -
duvdx - dv2dy - dvwdz + gy);
G(i, j, k) = V(i, j, k) +
dt * (inverseRe * (dv2dx2 + dv2dy2 + dv2dz2) - duvdx -
dv2dy - dvwdz + gy);
duwdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j, k + 1)) *
@ -1174,10 +1170,10 @@ void computeFG(Solver* s)
(W(i, j + 1, k) - 2.0 * W(i, j, k) + W(i, j - 1, k));
dw2dz2 = inverseDz * inverseDz *
(W(i, j, k + 1) - 2.0 * W(i, j, k) + W(i, j, k - 1));
H(i, j, k) = W(i, j, k) + dt * (inverseRe * (dw2dx2 + dw2dy2 + dw2dz2) -
duwdx - dvwdy - dw2dz + gz);
}
else{
H(i, j, k) = W(i, j, k) +
dt * (inverseRe * (dw2dx2 + dw2dy2 + dw2dz2) - duwdx -
dvwdy - dw2dz + gz);
} else {
switch (S(i, j, k)) {
case TOPFACE:
G(i, j, k) = V(i, j, k);
@ -1364,7 +1360,8 @@ void setObjectBoundaryCondition(Solver* s)
case TOPFACE:
U(i, j, k) = -U(i, j + 1, k);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j+1, k);;
W(i, j, k) = -W(i, j + 1, k);
;
break;
case BOTTOMFACE:
U(i, j, k) = -U(i, j - 1, k);

View File

@ -174,28 +174,25 @@ void vtkParticle(VtkOptions* o, char* name)
fprintf(o->fh, "POINTS %d float\n", o->particletracer->totalParticles);
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
double x = particlePool[i].x;
double y = particlePool[i].y;
double z = particlePool[i].z;
fprintf(o->fh, "%.2f %.2f %.2f\n", x, y, z);
}
fprintf(o->fh, "CELLS %d %d\n", o->particletracer->totalParticles, 2 * o->particletracer->totalParticles);
fprintf(o->fh,
"CELLS %d %d\n",
o->particletracer->totalParticles,
2 * o->particletracer->totalParticles);
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
fprintf(o->fh, "1 %d\n", i);
}
fprintf(o->fh, "CELL_TYPES %d\n", o->particletracer->totalParticles);
for (int i = 0; i < o->particletracer->totalParticles; ++i)
{
for (int i = 0; i < o->particletracer->totalParticles; ++i) {
fprintf(o->fh, "1\n");
}
}