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,15 +11,15 @@
#include <unistd.h>
#include "parameter.h"
#include "particletracing.h"
#include "progress.h"
#include "solver.h"
#include "particletracing.h"
#include "timing.h"
#include "vtkWriter.h"
enum VARIANT { SOR = 1, RB, RBA };
int main (int argc, char** argv)
int main(int argc, char** argv)
{
int rank;
int variant = RB;
@ -36,8 +36,7 @@ int main (int argc, char** argv)
}
readParameter(&params, argv[1]);
if (argc == 3)
{
if (argc == 3) {
variant = atoi(argv[2]);
}
@ -55,7 +54,7 @@ int main (int argc, char** argv)
double t = 0.0;
int nt = 0;
void (*solver_generic[])() = {solve, solveRB, solveRBA};
void (*solver_generic[])() = { solve, solveRB, solveRBA };
// printGrid(&solver, solver.s);
@ -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);
@ -75,15 +73,14 @@ int main (int argc, char** argv)
if (nt % 100 == 0) normalizePressure(&solver);
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
@ -92,7 +89,7 @@ int main (int argc, char** argv)
}
printf("Total particles : %d\n", particletracer.totalParticles);
//print(&solver, solver.p);
// print(&solver, solver.p);
E = getTimeStamp();
stopProgress();

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

@ -12,48 +12,50 @@
#include "vtkWriter.h"
#define U(i, j) u[(j) * (imax + 2) + (i)]
#define V(i, j) v[(j) * (imax + 2) + (i)]
#define S(i, j) s[(j) * (imax + 2) + (i)]
#define U(i, j) u[(j) * (imax + 2) + (i)]
#define V(i, j) v[(j) * (imax + 2) + (i)]
#define S(i, j) s[(j) * (imax + 2) + (i)]
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,
particletracer->particlePool[i].y,
particletracer->particlePool[i].flag);
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;
@ -66,12 +68,12 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
double y2 = ((double)jCoord - 0.5) * dy;
double u_n = (1.0 / (dx * dy)) *
((x2 - x) * (y2 - y) * U(iCoord - 1, jCoord - 1) +
(x - x1) * (y2 - y) * U(iCoord, jCoord - 1) +
(x2 - x) * (y - y1) * U(iCoord - 1, jCoord) +
(x - x1) * (y - y1) * U(iCoord, jCoord));
((x2 - x) * (y2 - y) * U(iCoord - 1, jCoord - 1) +
(x - x1) * (y2 - y) * U(iCoord, jCoord - 1) +
(x2 - x) * (y - y1) * U(iCoord - 1, jCoord) +
(x - x1) * (y - y1) * U(iCoord, jCoord));
double new_x = x + particletracer->dt * u_n;
double new_x = x + particletracer->dt * u_n;
particletracer->particlePool[i].x = new_x;
iCoord = (int)((x + 0.5 * dx) / dx) + 1;
@ -83,28 +85,33 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
y2 = (double)jCoord * dy;
double v_n = (1.0 / (dx * dy)) *
((x2 - x) * (y2 - y) * V(iCoord - 1, jCoord - 1) +
(x - x1) * (y2 - y) * V(iCoord, jCoord - 1) +
(x2 - x) * (y - y1) * V(iCoord - 1, jCoord) +
(x - x1) * (y - y1) * V(iCoord, jCoord));
((x2 - x) * (y2 - y) * V(iCoord - 1, jCoord - 1) +
(x - x1) * (y2 - y) * V(iCoord, jCoord - 1) +
(x2 - x) * (y - y1) * V(iCoord - 1, jCoord) +
(x - x1) * (y - y1) * V(iCoord, jCoord));
double new_y = y + particletracer->dt * v_n;
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)
{
int i_new = new_x / dx, j_new = new_y / dy;
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);
@ -156,73 +162,83 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params)
particletracer->injectTimePeriod = params->injectTimePeriod;
particletracer->writeTimePeriod = params->writeTimePeriod;
particletracer->dt = params->dt;
particletracer->dx = params->xlength / params->imax;
particletracer->dy = params->ylength / params->jmax;
particletracer->dt = params->dt;
particletracer->dx = params->xlength / params->imax;
particletracer->dy = params->ylength / params->jmax;
particletracer->xlength = params->xlength;
particletracer->ylength = params->ylength;
particletracer->x1 = params->x1;
particletracer->y1 = params->y1;
particletracer->x2 = params->x2;
particletracer->y2 = params->y2;
particletracer->xlength = params->xlength;
particletracer->ylength = params->ylength;
particletracer->lastInjectTime = params->startTime;
particletracer->lastUpdateTime = params->startTime;
particletracer->lastWriteTime = params->startTime;
particletracer->x1 = params->x1;
particletracer->y1 = params->y1;
particletracer->x2 = params->x2;
particletracer->y2 = params->y2;
particletracer->pointer = 0;
particletracer->totalParticles = 0;
particletracer->lastInjectTime = params->startTime;
particletracer->lastUpdateTime = params->startTime;
particletracer->lastWriteTime = params->startTime;
particletracer->imax = params->imax;
particletracer->jmax = params->jmax;
particletracer->pointer = 0;
particletracer->totalParticles = 0;
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2 ) * params->numberOfParticles;
particletracer->imax = params->imax;
particletracer->jmax = params->jmax;
particletracer->particlePool = malloc(sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->linSpaceLine = malloc(sizeof(Particle) * particletracer->numberOfParticles);
particletracer->estimatedNumParticles = ((params->te - params->startTime) + 2) *
params->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->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].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)
{
//printParticles(particletracer);
if( (time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod)
{
if (time >= particletracer->startTime) {
// printParticles(particletracer);
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);
particletracer->lastUpdateTime = time;
particletracer->lastUpdateTime = time;
}
}
@ -232,12 +248,10 @@ void compress(ParticleTracer* particletracer)
Particle tempPool[particletracer->totalParticles];
int totalParticles = 0;
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;
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;
++totalParticles;
}
@ -245,5 +259,5 @@ void compress(ParticleTracer* particletracer)
particletracer->totalParticles = totalParticles;
particletracer->pointer = totalParticles + 1;
memcpy(particletracer->particlePool, tempPool, totalParticles*sizeof(Particle));
memcpy(particletracer->particlePool, tempPool, totalParticles * sizeof(Particle));
}

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;
@ -30,7 +30,7 @@ typedef struct {
Particle* particlePool;
int pointer;
double imax, jmax, xlength, ylength;
double x1, y1, x2, y2;
@ -38,11 +38,11 @@ typedef struct {
void initParticleTracer(ParticleTracer*, Parameter*);
void injectParticles(ParticleTracer*);
void advanceParticles(ParticleTracer*, double* , double*, int*, double);
void advanceParticles(ParticleTracer*, double*, double*, int*, double);
void freeParticles(ParticleTracer*);
void writeParticles(ParticleTracer*);
void printParticleTracerParameters(ParticleTracer*);
void printParticles(ParticleTracer*);
void trace(ParticleTracer*, double* , double* , int* , double );
void compress(ParticleTracer* );
void trace(ParticleTracer*, double*, double*, int*, double);
void compress(ParticleTracer*);
#endif

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

@ -101,7 +101,7 @@ static void setupCommunication(Comm* c, Direction direction, int layer)
MPI_DOUBLE,
&c->rbufferTypes[direction]);
MPI_Type_commit(&c->rbufferTypes[direction]);
MPI_Type_create_subarray(NDIMS,
MPI_Type_create_subarray(NDIMS,
sizes,
subSizes,
starts,
@ -118,7 +118,7 @@ static void setupCommunication(Comm* c, Direction direction, int layer)
MPI_DOUBLE,
&c->sbufferTypes[direction]);
MPI_Type_commit(&c->sbufferTypes[direction]);
MPI_Type_create_subarray(NDIMS,
MPI_Type_create_subarray(NDIMS,
sizes,
subSizes,
starts,
@ -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)) {
@ -63,8 +62,8 @@ int main(int argc, char** argv)
double t = 0.0;
int nt = 0;
void (*solver_generic[])() = {solve, solveRB, solveRBA};
void (*solver_generic[])() = { solve, solveRB, solveRBA };
timeStart = getTimeStamp();
while (t <= te) {
@ -73,14 +72,13 @@ int main(int argc, char** argv)
setSpecialBoundaryCondition(&solver);
setObjectBoundaryCondition(&solver);
computeFG(&solver);
computeRHS(&solver);
// if (nt % 100 == 0) normalizePressure(&solver);
solver_generic[variant - 1](&solver);
adaptUV(&solver);
trace(&particletracer, solver.u, solver.v, solver.w, solver.seg, t);
trace(&particletracer, solver.u, solver.v, solver.w, solver.seg, t);
t += solver.dt;
nt++;
@ -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,16 +13,20 @@
#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;
#define XOFFSET 0
#define YOFFSET 1
#define ZOFFSET 2
#define XOFFSET 0
#define YOFFSET 1
#define ZOFFSET 2
#define XOFFSETEND 3
#define YOFFSETEND 4
#define ZOFFSETEND 5
@ -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,91 +46,97 @@ 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",
particletracer->rank,
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->particlePool[i].flag,
particletracer->totalParticles,
particletracer->pointer,
particletracer->xOffset,
particletracer->yOffset,
particletracer->xOffsetEnd,
particletracer->yOffsetEnd);
}
}
void injectParticles(ParticleTracer* particletracer,int* restrict seg)
void injectParticles(ParticleTracer* particletracer, int* restrict seg)
{
double x, y, z;
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)
{
particletracer->particlePool[particletracer->pointer].flag = true;
++(particletracer->pointer);
++(particletracer->totalParticles);
}
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);
}
}
}
}
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;
int imaxLocal = particletracer->imaxLocal;
int jmaxLocal = particletracer->jmaxLocal;
int kmaxLocal = particletracer->kmaxLocal;
int imax = particletracer->imax;
int jmax = particletracer->jmax;
int kmax = particletracer->kmax;
int imaxLocal = particletracer->imaxLocal;
int jmaxLocal = particletracer->jmaxLocal;
int kmaxLocal = particletracer->kmaxLocal;
double dx = particletracer->dx;
double dy = particletracer->dy;
double dz = particletracer->dz;
double dx = particletracer->dx;
double dy = particletracer->dy;
double dz = particletracer->dz;
double xlength = particletracer->xlength;
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)
{
buff[i][j].x = 0.0;
buff[i][j].y = 0.0;
buff[i][j].z = 0.0;
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;
buff[i][j].flag = false;
}
}
@ -135,25 +144,20 @@ 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;
double x = xTemp - particletracer->xOffset;
double y = yTemp - particletracer->yOffset;
double z = zTemp - particletracer->zOffset;
int iCoord = (int)(x / dx) + 1;
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) +
(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;
@ -189,18 +191,17 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
x2 = ((double)iCoord - 0.5) * dx;
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) +
(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)
);
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));
double new_y = (y + particletracer->yOffset) + particletracer->dt * v_n;
particletracer->particlePool[i].y = new_y;
@ -216,91 +217,109 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
x2 = ((double)iCoord - 0.5) * dx;
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) +
(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)
);
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));
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("\t U N : %.2f, V N : %.2f\n\n", u_n, v_n);
// 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)
{
buff[i][particleBufIndex[i]].x = new_x;
buff[i][particleBufIndex[i]].y = new_y;
buff[i][particleBufIndex[i]].z = new_z;
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;
buff[i][particleBufIndex[i]].flag = true;
++particleBufIndex[i];
}
}
particletracer->particlePool[i].flag = false;
int i_new = new_x/dx, j_new = new_y/dy, k_new = new_z/dz;
int i_new = new_x / dx, j_new = new_y / dy, k_new = new_z / dz;
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)
{
particletracer->particlePool[i].flag = false;
}
jOffset = particletracer->yOffset / dy,
kOffset = particletracer->zOffset / dz;
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)
{
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);
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);
}
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,45 +395,43 @@ 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;
fprintf(fp, "%f %f %f\n", x, y, z);
}
fprintf(fp, "CELLS %d %d\n", overallTotalParticles, 2 * overallTotalParticles);
fprintf(fp, "CELLS %d %d\n", overallTotalParticles, 2 * overallTotalParticles);
for (int i = 0; i < overallTotalParticles; ++i) {
fprintf(fp, "1 %d\n", i);
}
for (int i = 0; i < overallTotalParticles; ++i)
{
fprintf(fp, "1 %d\n", i);
}
fprintf(fp, "CELL_TYPES %d\n", overallTotalParticles);
fprintf(fp, "CELL_TYPES %d\n", overallTotalParticles);
for (int i = 0; i < overallTotalParticles; ++i)
{
fprintf(fp, "1\n");
}
for (int i = 0; i < overallTotalParticles; ++i) {
fprintf(fp, "1\n");
}
fclose(fp);
}
@ -412,7 +439,7 @@ void writeParticles(ParticleTracer* particletracer)
++ts;
}
void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solver* solver)
void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solver* solver)
{
/* initializing local properties from params */
@ -421,122 +448,168 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solv
particletracer->injectTimePeriod = params->injectTimePeriod;
particletracer->writeTimePeriod = params->writeTimePeriod;
particletracer->dt = params->dt;
particletracer->dx = params->xlength / params->imax;
particletracer->dy = params->ylength / params->jmax;
particletracer->dz = params->zlength / params->kmax;
particletracer->dt = params->dt;
particletracer->dx = params->xlength / params->imax;
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;
particletracer->x2 = params->x2;
particletracer->y2 = params->y2;
particletracer->z2 = params->z2;
particletracer->xlength = params->xlength;
particletracer->ylength = params->ylength;
particletracer->zlength = params->zlength;
particletracer->lastInjectTime = params->startTime;
particletracer->lastUpdateTime = params->startTime;
particletracer->lastWriteTime = params->startTime;
particletracer->x1 = params->x1;
particletracer->y1 = params->y1;
particletracer->z1 = params->z1;
particletracer->x2 = params->x2;
particletracer->y2 = params->y2;
particletracer->z2 = params->z2;
particletracer->pointer = 0;
particletracer->totalParticles = 0;
particletracer->lastInjectTime = params->startTime;
particletracer->lastUpdateTime = params->startTime;
particletracer->lastWriteTime = params->startTime;
particletracer->imax = params->imax;
particletracer->jmax = params->jmax;
particletracer->kmax = params->kmax;
particletracer->pointer = 0;
particletracer->totalParticles = 0;
particletracer->imaxLocal = solver->comm.imaxLocal;
particletracer->jmaxLocal = solver->comm.jmaxLocal;
particletracer->kmaxLocal = solver->comm.kmaxLocal;
particletracer->imax = params->imax;
particletracer->jmax = params->jmax;
particletracer->kmax = params->kmax;
particletracer->estimatedNumParticles = (particletracer->imaxLocal * particletracer->jmaxLocal * particletracer->kmaxLocal);
particletracer->imaxLocal = solver->comm.imaxLocal;
particletracer->jmaxLocal = solver->comm.jmaxLocal;
particletracer->kmaxLocal = solver->comm.kmaxLocal;
particletracer->particlePool = malloc(sizeof(Particle) * particletracer->estimatedNumParticles);
particletracer->estimatedNumParticles = (particletracer->imaxLocal *
particletracer->jmaxLocal *
particletracer->kmaxLocal);
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 = malloc(
sizeof(Particle) * particletracer->estimatedNumParticles);
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);
particletracer->rank = solver->comm.rank;
particletracer->size = solver->comm.size;
particletracer->offset = (double *)malloc(sizeof(double) * 4 * particletracer->size);
particletracer->rank = solver->comm.rank;
particletracer->size = solver->comm.size;
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;
particletracer->yOffset = solver->yOffset;
particletracer->zOffset = solver->zOffset;
particletracer->xOffsetEnd = solver->xOffsetEnd;
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);
particletracer->xOffset = solver->xOffset;
particletracer->yOffset = solver->yOffset;
particletracer->zOffset = solver->zOffset;
particletracer->xOffsetEnd = solver->xOffsetEnd;
particletracer->yOffsetEnd = solver->yOffsetEnd;
particletracer->zOffsetEnd = solver->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);
// 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);
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;
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;
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].flag = true;
}
// Create the mpi_particle datatype
MPI_Datatype mpi_particle;
int lengths[4] = { 1, 1, 1, 1 };
MPI_Aint displacements[4];
Particle dummy_particle;
MPI_Aint base_address;
@ -545,48 +618,80 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params, Solv
MPI_Get_address(&dummy_particle.y, &displacements[1]);
MPI_Get_address(&dummy_particle.z, &displacements[2]);
MPI_Get_address(&dummy_particle.flag, &displacements[3]);
displacements[0] = MPI_Aint_diff(displacements[0], base_address);
displacements[1] = MPI_Aint_diff(displacements[1], base_address);
displacements[2] = MPI_Aint_diff(displacements[2], base_address);
displacements[3] = MPI_Aint_diff(displacements[3], base_address);
displacements[0] = MPI_Aint_diff(displacements[0], base_address);
displacements[1] = MPI_Aint_diff(displacements[1], base_address);
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)
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)
{
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;
}
advanceParticles(particletracer, u, v, w, seg, time);
compress(particletracer);
particletracer->lastUpdateTime = time;
particletracer->lastUpdateTime = time;
}
}
@ -595,19 +700,16 @@ void compress(ParticleTracer* particletracer)
Particle* memPool = particletracer->particlePool;
Particle tempPool[particletracer->totalParticles];
for(int i = 0; i < particletracer->totalParticles; ++i)
{
tempPool[i].x = 0.0;
tempPool[i].y = 0.0;
tempPool[i].z = 0.0;
for (int i = 0; i < particletracer->totalParticles; ++i) {
tempPool[i].x = 0.0;
tempPool[i].y = 0.0;
tempPool[i].z = 0.0;
tempPool[i].flag = false;
}
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,53 +9,54 @@
#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;
double dx, dy,dz, dt;
double dx, dy, dz, dt;
Particle* linSpaceLine;
Particle* particlePool;
int pointer;
double imax, jmax, kmax, xlength, ylength, zlength, imaxLocal, jmaxLocal, kmaxLocal;
double x1, y1, z1, x2, y2, z2;
MPI_Comm comm;
MPI_Datatype mpi_particle;
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;
} ParticleTracer;
void initParticleTracer(ParticleTracer*, Parameter*, Solver* );
void initParticleTracer(ParticleTracer*, Parameter*, Solver*);
void injectParticles(ParticleTracer*, int*);
void advanceParticles(ParticleTracer*, double* , double* , double* ,int*, double);
void advanceParticles(ParticleTracer*, double*, double*, double*, int*, double);
void freeParticles(ParticleTracer*);
void writeParticles(ParticleTracer*);
void printParticleTracerParameters(ParticleTracer*);
void printParticles(ParticleTracer*);
void trace(ParticleTracer*, double* , double* , double* , int*, double );
void compress(ParticleTracer* );
void trace(ParticleTracer*, double*, double*, double*, int*, double);
void compress(ParticleTracer*);
#endif

File diff suppressed because it is too large Load Diff

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

@ -9,7 +9,7 @@
#include <string.h>
#include "vtkWriter.h"
#define G(v, i, j, k) v[(k)*imax * jmax + (j)*imax + (i)]
#define G(v, i, j, k) v[(k) * imax * jmax + (j) * imax + (i)]
static double floatSwap(double f)
{

View File

@ -12,20 +12,20 @@
#include "vtkWriter.h"
#define U(i, j, k) u[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define V(i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define W(i, j, k) w[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define S(i, j, k) seg[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define U(i, j, k) u[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define V(i, j, k) v[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define W(i, j, k) w[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
#define S(i, j, k) seg[(k) * (imax + 2) * (jmax + 2) + (j) * (imax + 2) + (i)]
static int ts = 0;
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,
particletracer->particlePool[i].y,
particletracer->particlePool[i].flag);
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, int* seg)
@ -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)
{
// 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;
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->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,20 +103,18 @@ 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) +
(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;
double new_x = x + particletracer->dt * u_n;
particletracer->particlePool[i].x = new_x;
iCoord = (int)((x + 0.5 * dx) / dx) + 1;
@ -124,20 +128,19 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
x2 = ((double)iCoord - 0.5) * dx;
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) +
(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)
);
double new_y = y + particletracer->dt * v_n;
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));
double new_y = y + particletracer->dt * v_n;
particletracer->particlePool[i].y = new_y;
iCoord = (int)((x + 0.5 * dx) / dx) + 1;
@ -151,37 +154,41 @@ void advanceParticles(ParticleTracer* particletracer, double* restrict u, double
x2 = ((double)iCoord - 0.5) * dx;
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) +
(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)
);
double new_z = z + particletracer->dt * w_n;
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));
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;
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;
}
}
@ -213,85 +220,105 @@ void initParticleTracer(ParticleTracer* particletracer, Parameter* params)
particletracer->injectTimePeriod = params->injectTimePeriod;
particletracer->writeTimePeriod = params->writeTimePeriod;
particletracer->dt = params->dt;
particletracer->dx = params->xlength / params->imax;
particletracer->dy = params->ylength / params->jmax;
particletracer->dz = params->zlength / params->kmax;
particletracer->dt = params->dt;
particletracer->dx = params->xlength / params->imax;
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->xlength = params->xlength;
particletracer->ylength = params->ylength;
particletracer->zlength = params->zlength;
particletracer->x1 = params->x1;
particletracer->y1 = params->y1;
particletracer->z1 = params->z1;
particletracer->x2 = params->x2;
particletracer->y2 = params->y2;
particletracer->z2 = params->z2;
particletracer->x1 = params->x1;
particletracer->y1 = params->y1;
particletracer->z1 = params->z1;
particletracer->x2 = params->x2;
particletracer->y2 = params->y2;
particletracer->z2 = params->z2;
particletracer->lastInjectTime = params->startTime;
particletracer->lastUpdateTime = params->startTime;
particletracer->lastWriteTime = params->startTime;
particletracer->lastInjectTime = params->startTime;
particletracer->lastUpdateTime = params->startTime;
particletracer->lastWriteTime = params->startTime;
particletracer->pointer = 0;
particletracer->totalParticles = 0;
particletracer->pointer = 0;
particletracer->totalParticles = 0;
particletracer->imax = params->imax;
particletracer->jmax = params->jmax;
particletracer->kmax = params->kmax;
particletracer->imax = params->imax;
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].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].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)
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->startTime) {
// printParticles(particletracer);
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);
particletracer->lastUpdateTime = time;
particletracer->lastUpdateTime = time;
}
}
@ -301,13 +328,11 @@ void compress(ParticleTracer* particletracer)
Particle tempPool[particletracer->totalParticles];
int totalParticles = 0;
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;
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;
tempPool[totalParticles].flag = memPool[i].flag;
++totalParticles;
}
@ -316,5 +341,5 @@ void compress(ParticleTracer* particletracer)
particletracer->totalParticles = totalParticles;
particletracer->pointer = totalParticles + 1;
memcpy(particletracer->particlePool, tempPool, totalParticles*sizeof(Particle));
memcpy(particletracer->particlePool, tempPool, totalParticles * sizeof(Particle));
}

View File

@ -38,7 +38,7 @@ typedef struct {
extern void initParticleTracer(ParticleTracer*, Parameter*);
extern void injectParticles(ParticleTracer*, int* seg);
extern void advanceParticles(ParticleTracer*, double*, double*, double*, int*,double);
extern void advanceParticles(ParticleTracer*, double*, double*, double*, int*, double);
extern void freeParticles(ParticleTracer*);
extern void writeParticles(ParticleTracer*);
extern void printParticleTracerParameters(ParticleTracer*);

View File

@ -438,17 +438,16 @@ void computeRHS(Solver* s)
double* f = s->f;
double* g = s->g;
double* h = s->h;
int* seg = s->seg;
int* seg = s->seg;
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)
{
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) *
idt;
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) *
idt;
}
}
}
@ -475,7 +474,7 @@ void solve(Solver* s)
double epssq = eps * eps;
int it = 0;
double res = 1.0;
int* seg = s->seg;
int* seg = s->seg;
while ((res >= epssq) && (it < itermax)) {
res = 0.0;
@ -483,19 +482,18 @@ 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 +
(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)) *
idz2);
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)) *
idz2);
P(i, j, k) -= (factor * r);
res += (r * r);
}
P(i, j, k) -= (factor * r);
res += (r * r);
}
}
}
}
@ -561,7 +559,7 @@ void solveRB(Solver* s)
res = 0.0;
ksw = 1;
for (int j = 1; j < jmax + 1; j++) {
for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) {
P(i, j, 0) = P(i, j, 1);
P(i, j, kmax + 1) = P(i, j, kmax);
@ -591,19 +589,19 @@ 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)
{
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)) *
idz2);
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)) *
idz2);
P(i, j, k) -= (factor * r);
res += (r * r);
}
P(i, j, k) -= (factor * r);
res += (r * r);
}
}
isw = 3 - isw;
}
@ -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,19 +657,19 @@ 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)
{
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)) *
idz2);
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)) *
idz2);
P(i, j, k) -= (omega * factor * r);
res += (r * r);
}
P(i, j, k) -= (omega * factor * r);
res += (r * r);
}
}
isw = 3 - isw;
}
@ -1005,10 +1001,10 @@ void setSpecialBoundaryCondition(Solver* s)
}
} else if (strcmp(s->problem, "backstep") == 0) {
int* seg = s->seg;
int* seg = s->seg;
for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) {
if(S(0,j,k) == NONE) U(0, j, k) = 1.0;
if (S(0, j, k) == NONE) U(0, j, k) = 1.0;
}
}
}
@ -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,243 +1044,244 @@ 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)
{
du2dx = inverseDx * 0.25 *
((U(i, j, k) + U(i + 1, j, k)) *
(U(i, j, k) + U(i + 1, j, k)) -
(U(i, j, k) + U(i - 1, j, k)) *
(U(i, j, k) + U(i - 1, j, k))) +
gamma * inverseDx * 0.25 *
(fabs(U(i, j, k) + U(i + 1, j, k)) *
(U(i, j, k) - U(i + 1, j, k)) +
fabs(U(i, j, k) + U(i - 1, j, k)) *
(U(i, j, k) - U(i - 1, j, k)));
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)) -
(U(i, j, k) + U(i - 1, j, k)) *
(U(i, j, k) + U(i - 1, j, k))) +
gamma * inverseDx * 0.25 *
(fabs(U(i, j, k) + U(i + 1, j, k)) *
(U(i, j, k) - U(i + 1, j, k)) +
fabs(U(i, j, k) + U(i - 1, j, k)) *
(U(i, j, k) - U(i - 1, j, k)));
duvdy = inverseDy * 0.25 *
((V(i, j, k) + V(i + 1, j, k)) *
(U(i, j, k) + U(i, j + 1, k)) -
(V(i, j - 1, k) + V(i + 1, j - 1, k)) *
(U(i, j, k) + U(i, j - 1, k))) +
gamma * inverseDy * 0.25 *
(fabs(V(i, j, k) + V(i + 1, j, k)) *
(U(i, j, k) - U(i, j + 1, k)) +
fabs(V(i, j - 1, k) + V(i + 1, j - 1, k)) *
(U(i, j, k) - U(i, j - 1, k)));
duvdy = inverseDy * 0.25 *
((V(i, j, k) + V(i + 1, j, k)) *
(U(i, j, k) + U(i, j + 1, k)) -
(V(i, j - 1, k) + V(i + 1, j - 1, k)) *
(U(i, j, k) + U(i, j - 1, k))) +
gamma * inverseDy * 0.25 *
(fabs(V(i, j, k) + V(i + 1, j, k)) *
(U(i, j, k) - U(i, j + 1, k)) +
fabs(V(i, j - 1, k) + V(i + 1, j - 1, k)) *
(U(i, j, k) - U(i, j - 1, k)));
duwdz = inverseDz * 0.25 *
((W(i, j, k) + W(i + 1, j, k)) *
(U(i, j, k) + U(i, j, k + 1)) -
(W(i, j, k - 1) + W(i + 1, j, k - 1)) *
(U(i, j, k) + U(i, j, k - 1))) +
gamma * inverseDz * 0.25 *
(fabs(W(i, j, k) + W(i + 1, j, k)) *
(U(i, j, k) - U(i, j, k + 1)) +
fabs(W(i, j, k - 1) + W(i + 1, j, k - 1)) *
(U(i, j, k) - U(i, j, k - 1)));
duwdz = inverseDz * 0.25 *
((W(i, j, k) + W(i + 1, j, k)) *
(U(i, j, k) + U(i, j, k + 1)) -
(W(i, j, k - 1) + W(i + 1, j, k - 1)) *
(U(i, j, k) + U(i, j, k - 1))) +
gamma * inverseDz * 0.25 *
(fabs(W(i, j, k) + W(i + 1, j, k)) *
(U(i, j, k) - U(i, j, k + 1)) +
fabs(W(i, j, k - 1) + W(i + 1, j, k - 1)) *
(U(i, j, k) - U(i, j, k - 1)));
du2dx2 = inverseDx * inverseDx *
(U(i + 1, j, k) - 2.0 * U(i, j, k) + U(i - 1, j, k));
du2dy2 = inverseDy * inverseDy *
(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);
du2dx2 = inverseDx * inverseDx *
(U(i + 1, j, k) - 2.0 * U(i, j, k) + U(i - 1, j, k));
du2dy2 = inverseDy * inverseDy *
(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);
duvdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j + 1, k)) *
(V(i, j, k) + V(i + 1, j, k)) -
(U(i - 1, j, k) + U(i - 1, j + 1, k)) *
(V(i, j, k) + V(i - 1, j, k))) +
gamma * inverseDx * 0.25 *
(fabs(U(i, j, k) + U(i, j + 1, k)) *
(V(i, j, k) - V(i + 1, j, k)) +
fabs(U(i - 1, j, k) + U(i - 1, j + 1, k)) *
(V(i, j, k) - V(i - 1, j, k)));
duvdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j + 1, k)) *
(V(i, j, k) + V(i + 1, j, k)) -
(U(i - 1, j, k) + U(i - 1, j + 1, k)) *
(V(i, j, k) + V(i - 1, j, k))) +
gamma * inverseDx * 0.25 *
(fabs(U(i, j, k) + U(i, j + 1, k)) *
(V(i, j, k) - V(i + 1, j, k)) +
fabs(U(i - 1, j, k) + U(i - 1, j + 1, k)) *
(V(i, j, k) - V(i - 1, j, k)));
dv2dy = inverseDy * 0.25 *
((V(i, j, k) + V(i, j + 1, k)) *
(V(i, j, k) + V(i, j + 1, k)) -
(V(i, j, k) + V(i, j - 1, k)) *
(V(i, j, k) + V(i, j - 1, k))) +
gamma * inverseDy * 0.25 *
(fabs(V(i, j, k) + V(i, j + 1, k)) *
(V(i, j, k) - V(i, j + 1, k)) +
fabs(V(i, j, k) + V(i, j - 1, k)) *
(V(i, j, k) - V(i, j - 1, k)));
dv2dy = inverseDy * 0.25 *
((V(i, j, k) + V(i, j + 1, k)) *
(V(i, j, k) + V(i, j + 1, k)) -
(V(i, j, k) + V(i, j - 1, k)) *
(V(i, j, k) + V(i, j - 1, k))) +
gamma * inverseDy * 0.25 *
(fabs(V(i, j, k) + V(i, j + 1, k)) *
(V(i, j, k) - V(i, j + 1, k)) +
fabs(V(i, j, k) + V(i, j - 1, k)) *
(V(i, j, k) - V(i, j - 1, k)));
dvwdz = inverseDz * 0.25 *
((W(i, j, k) + W(i, j + 1, k)) *
(V(i, j, k) + V(i, j, k + 1)) -
(W(i, j, k - 1) + W(i, j + 1, k - 1)) *
(V(i, j, k) + V(i, j, k + 1))) +
gamma * inverseDz * 0.25 *
(fabs(W(i, j, k) + W(i, j + 1, k)) *
(V(i, j, k) - V(i, j, k + 1)) +
fabs(W(i, j, k - 1) + W(i, j + 1, k - 1)) *
(V(i, j, k) - V(i, j, k + 1)));
dvwdz = inverseDz * 0.25 *
((W(i, j, k) + W(i, j + 1, k)) *
(V(i, j, k) + V(i, j, k + 1)) -
(W(i, j, k - 1) + W(i, j + 1, k - 1)) *
(V(i, j, k) + V(i, j, k + 1))) +
gamma * inverseDz * 0.25 *
(fabs(W(i, j, k) + W(i, j + 1, k)) *
(V(i, j, k) - V(i, j, k + 1)) +
fabs(W(i, j, k - 1) + W(i, j + 1, k - 1)) *
(V(i, j, k) - V(i, j, k + 1)));
dv2dx2 = inverseDx * inverseDx *
(V(i + 1, j, k) - 2.0 * V(i, j, k) + V(i - 1, j, k));
dv2dy2 = inverseDy * inverseDy *
(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);
dv2dx2 = inverseDx * inverseDx *
(V(i + 1, j, k) - 2.0 * V(i, j, k) + V(i - 1, j, k));
dv2dy2 = inverseDy * inverseDy *
(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);
duwdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j, k + 1)) *
(W(i, j, k) + W(i + 1, j, k)) -
(U(i - 1, j, k) + U(i - 1, j, k + 1)) *
(W(i, j, k) + W(i - 1, j, k))) +
gamma * inverseDx * 0.25 *
(fabs(U(i, j, k) + U(i, j, k + 1)) *
(W(i, j, k) - W(i + 1, j, k)) +
fabs(U(i - 1, j, k) + U(i - 1, j, k + 1)) *
(W(i, j, k) - W(i - 1, j, k)));
duwdx = inverseDx * 0.25 *
((U(i, j, k) + U(i, j, k + 1)) *
(W(i, j, k) + W(i + 1, j, k)) -
(U(i - 1, j, k) + U(i - 1, j, k + 1)) *
(W(i, j, k) + W(i - 1, j, k))) +
gamma * inverseDx * 0.25 *
(fabs(U(i, j, k) + U(i, j, k + 1)) *
(W(i, j, k) - W(i + 1, j, k)) +
fabs(U(i - 1, j, k) + U(i - 1, j, k + 1)) *
(W(i, j, k) - W(i - 1, j, k)));
dvwdy = inverseDy * 0.25 *
((V(i, j, k) + V(i, j, k + 1)) *
(W(i, j, k) + W(i, j + 1, k)) -
(V(i, j - 1, k + 1) + V(i, j - 1, k)) *
(W(i, j, k) + W(i, j - 1, k))) +
gamma * inverseDy * 0.25 *
(fabs(V(i, j, k) + V(i, j, k + 1)) *
(W(i, j, k) - W(i, j + 1, k)) +
fabs(V(i, j - 1, k + 1) + V(i, j - 1, k)) *
(W(i, j, k) - W(i, j - 1, k)));
dvwdy = inverseDy * 0.25 *
((V(i, j, k) + V(i, j, k + 1)) *
(W(i, j, k) + W(i, j + 1, k)) -
(V(i, j - 1, k + 1) + V(i, j - 1, k)) *
(W(i, j, k) + W(i, j - 1, k))) +
gamma * inverseDy * 0.25 *
(fabs(V(i, j, k) + V(i, j, k + 1)) *
(W(i, j, k) - W(i, j + 1, k)) +
fabs(V(i, j - 1, k + 1) + V(i, j - 1, k)) *
(W(i, j, k) - W(i, j - 1, k)));
dw2dz = inverseDz * 0.25 *
((W(i, j, k) + W(i, j, k + 1)) *
(W(i, j, k) + W(i, j, k + 1)) -
(W(i, j, k) + W(i, j, k - 1)) *
(W(i, j, k) + W(i, j, k - 1))) +
gamma * inverseDz * 0.25 *
(fabs(W(i, j, k) + W(i, j, k + 1)) *
(W(i, j, k) - W(i, j, k + 1)) +
fabs(W(i, j, k) + W(i, j, k - 1)) *
(W(i, j, k) - W(i, j, k - 1)));
dw2dz = inverseDz * 0.25 *
((W(i, j, k) + W(i, j, k + 1)) *
(W(i, j, k) + W(i, j, k + 1)) -
(W(i, j, k) + W(i, j, k - 1)) *
(W(i, j, k) + W(i, j, k - 1))) +
gamma * inverseDz * 0.25 *
(fabs(W(i, j, k) + W(i, j, k + 1)) *
(W(i, j, k) - W(i, j, k + 1)) +
fabs(W(i, j, k) + W(i, j, k - 1)) *
(W(i, j, k) - W(i, j, k - 1)));
dw2dx2 = inverseDx * inverseDx *
(W(i + 1, j, k) - 2.0 * W(i, j, k) + W(i - 1, j, k));
dw2dy2 = inverseDy * inverseDy *
(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{
dw2dx2 = inverseDx * inverseDx *
(W(i + 1, j, k) - 2.0 * W(i, j, k) + W(i - 1, j, k));
dw2dy2 = inverseDy * inverseDy *
(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 {
switch (S(i, j, k)) {
case TOPFACE:
G(i, j, k) = V(i, j, k);
break;
case BOTTOMFACE:
G(i, j, k) = V(i, j, k);
break;
case LEFTFACE:
F(i, j, k) = U(i, j, k);
break;
case RIGHTFACE:
F(i, j, k) = U(i, j, k);
break;
case FRONTFACE:
H(i, j, k) = W(i, j, k);
break;
case BACKFACE:
H(i, j, k) = W(i, j, k);
break;
case FRONTLEFTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTRIGHTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTTOPLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTBOTTOMLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case MIDTOPLEFTLINE:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
break;
case MIDTOPRIGHTLINE:
F(i, j, k) = U(i, j, k);
G(i, j, k) = V(i, j, k);
break;
case MIDBOTTOMLEFTLINE:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
break;
case MIDBOTTOMRIGHTLINE:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
break;
case BACKLEFTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKRIGHTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKTOPLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKBOTTOMLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTTOPLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTTOPRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTBOTTOMLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTBOTTOMRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKTOPLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKTOPRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKBOTTOMLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKBOTTOMRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
}
case TOPFACE:
G(i, j, k) = V(i, j, k);
break;
case BOTTOMFACE:
G(i, j, k) = V(i, j, k);
break;
case LEFTFACE:
F(i, j, k) = U(i, j, k);
break;
case RIGHTFACE:
F(i, j, k) = U(i, j, k);
break;
case FRONTFACE:
H(i, j, k) = W(i, j, k);
break;
case BACKFACE:
H(i, j, k) = W(i, j, k);
break;
case FRONTLEFTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTRIGHTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTTOPLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTBOTTOMLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case MIDTOPLEFTLINE:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
break;
case MIDTOPRIGHTLINE:
F(i, j, k) = U(i, j, k);
G(i, j, k) = V(i, j, k);
break;
case MIDBOTTOMLEFTLINE:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
break;
case MIDBOTTOMRIGHTLINE:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
break;
case BACKLEFTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKRIGHTLINE:
F(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKTOPLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKBOTTOMLINE:
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTTOPLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTTOPRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTBOTTOMLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case FRONTBOTTOMRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKTOPLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKTOPRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKBOTTOMLEFTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
case BACKBOTTOMRIGHTCORNER:
F(i, j, k) = 0.0;
G(i, j, k) = 0.0;
H(i, j, k) = 0.0;
break;
}
}
}
}
@ -1362,136 +1358,137 @@ void setObjectBoundaryCondition(Solver* s)
for (int i = 1; i < imax + 1; i++) {
switch (S(i, j, k)) {
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);;
U(i, j, k) = -U(i, j + 1, k);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j + 1, k);
;
break;
case BOTTOMFACE:
U(i, j, k) = -U(i, j-1, k);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j - 1, k);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j - 1, k);
break;
case LEFTFACE:
U(i, j, k) = 0.0;
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = -W(i-1, j, k);
U(i, j, k) = 0.0;
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = -W(i - 1, j, k);
break;
case RIGHTFACE:
U(i, j, k) = 0.0;
V(i, j, k) = -V(i+1, j, k);
W(i, j, k) = -W(i+1, j, k);
U(i, j, k) = 0.0;
V(i, j, k) = -V(i + 1, j, k);
W(i, j, k) = -W(i + 1, j, k);
break;
case FRONTFACE:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = -V(i, j, k-1);
W(i, j, k) = 0.0;
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = -V(i, j, k - 1);
W(i, j, k) = 0.0;
break;
case BACKFACE:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = -V(i, j, k+1);
W(i, j, k) = 0.0;
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = -V(i, j, k + 1);
W(i, j, k) = 0.0;
break;
case FRONTLEFTLINE:
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k-1);
W(i, j, k) = -W(i-1, j, k);
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k - 1);
W(i, j, k) = -W(i - 1, j, k);
break;
case FRONTRIGHTLINE:
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k-1);
W(i, j, k) = -W(i+1, j, k);
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k - 1);
W(i, j, k) = -W(i + 1, j, k);
break;
case FRONTTOPLINE:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j+1, k);
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j + 1, k);
break;
case FRONTBOTTOMLINE:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j - 1, k);
break;
case MIDTOPLEFTLINE:
U(i, j, k) = -U(i, j+1, k);
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = 0.0;
U(i, j, k) = -U(i, j + 1, k);
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = 0.0;
break;
case MIDTOPRIGHTLINE:
U(i, j, k) = 0.0;
V(i, j, k) = 0.0;
U(i-1, j, k) = -U(i-1, j+1, k);
V(i, j-1, k) = -V(i+1, j-1, k);
U(i - 1, j, k) = -U(i - 1, j + 1, k);
V(i, j - 1, k) = -V(i + 1, j - 1, k);
W(i, j, k) = 0.0;
break;
case MIDBOTTOMLEFTLINE:
U(i, j, k) = -U(i, j-1, k);
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = 0.0;
U(i, j, k) = -U(i, j - 1, k);
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = 0.0;
break;
case MIDBOTTOMRIGHTLINE:
U(i, j, k) = -U(i, j-1, k);
V(i, j, k) = -V(i+1, j, k);
W(i, j, k) = 0.0;
U(i, j, k) = -U(i, j - 1, k);
V(i, j, k) = -V(i + 1, j, k);
W(i, j, k) = 0.0;
break;
case BACKLEFTLINE:
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k+1);
W(i, j, k) = -W(i-1, j, k);
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k + 1);
W(i, j, k) = -W(i - 1, j, k);
break;
case BACKRIGHTLINE:
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k+1);
W(i, j, k) = -W(i+1, j, k);
U(i, j, k) = 0.0;
V(i, j, k) = -V(i, j, k + 1);
W(i, j, k) = -W(i + 1, j, k);
break;
case BACKTOPLINE:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j+1, k);
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j + 1, k);
break;
case BACKBOTTOMLINE:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = 0.0;
W(i, j, k) = -W(i, j - 1, k);
break;
case FRONTTOPLEFTCORNER:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = -W(i, j+1, k);
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = -W(i, j + 1, k);
break;
case FRONTTOPRIGHTCORNER:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = -V(i+1, j, k);
W(i, j, k) = -W(i, j+1, k);
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = -V(i + 1, j, k);
W(i, j, k) = -W(i, j + 1, k);
break;
case FRONTBOTTOMLEFTCORNER:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = -W(i, j - 1, k);
break;
case FRONTBOTTOMRIGHTCORNER:
U(i, j, k) = -U(i, j, k-1);
V(i, j, k) = -V(i+1, j, k);
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j, k - 1);
V(i, j, k) = -V(i + 1, j, k);
W(i, j, k) = -W(i, j - 1, k);
break;
case BACKTOPLEFTCORNER:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = -W(i, j+1, k);
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = -W(i, j + 1, k);
break;
case BACKTOPRIGHTCORNER:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = -V(i+1, j, k);
W(i, j, k) = -W(i, j+1, k);
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = -V(i + 1, j, k);
W(i, j, k) = -W(i, j + 1, k);
break;
case BACKBOTTOMLEFTCORNER:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = -V(i-1, j, k);
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = -V(i - 1, j, k);
W(i, j, k) = -W(i, j - 1, k);
break;
case BACKBOTTOMRIGHTCORNER:
U(i, j, k) = -U(i, j, k+1);
V(i, j, k) = -V(i+1, j, k);
W(i, j, k) = -W(i, j-1, k);
U(i, j, k) = -U(i, j, k + 1);
V(i, j, k) = -V(i + 1, j, k);
W(i, j, k) = -W(i, j - 1, k);
break;
}
}
@ -1511,82 +1508,82 @@ void setObjectPBoundaryCondition(Solver* s)
for (int i = 1; i < imax + 1; i++) {
switch (S(i, j, k)) {
case TOPFACE:
P(i,j,k) = P(i,j+1,k);
P(i, j, k) = P(i, j + 1, k);
break;
case BOTTOMFACE:
P(i,j,k) = P(i,j-1,k);
P(i, j, k) = P(i, j - 1, k);
break;
case LEFTFACE:
P(i,j,k) = P(i-1,j,k);
P(i, j, k) = P(i - 1, j, k);
break;
case RIGHTFACE:
P(i,j,k) = P(i+1,j,k);
P(i, j, k) = P(i + 1, j, k);
break;
case FRONTFACE:
P(i,j,k) = P(i,j,k-1);
P(i, j, k) = P(i, j, k - 1);
break;
case BACKFACE:
P(i,j,k) = P(i,j,k+1);
P(i, j, k) = P(i, j, k + 1);
break;
case FRONTLEFTLINE:
P(i,j,k) = (P(i,j,k-1) + P(i-1,j,k)) / 2;
P(i, j, k) = (P(i, j, k - 1) + P(i - 1, j, k)) / 2;
break;
case FRONTRIGHTLINE:
P(i,j,k) = (P(i,j,k-1) + P(i+1,j,k)) / 2;
P(i, j, k) = (P(i, j, k - 1) + P(i + 1, j, k)) / 2;
break;
case FRONTTOPLINE:
P(i,j,k) = (P(i,j,k-1) + P(i,j+1,k)) / 2;
P(i, j, k) = (P(i, j, k - 1) + P(i, j + 1, k)) / 2;
break;
case FRONTBOTTOMLINE:
P(i,j,k) = (P(i,j,k-1) + P(i,j-1,k)) / 2;
P(i, j, k) = (P(i, j, k - 1) + P(i, j - 1, k)) / 2;
break;
case MIDTOPLEFTLINE:
P(i,j,k) = (P(i-1,j,k) + P(i,j+1,k)) / 2;
P(i, j, k) = (P(i - 1, j, k) + P(i, j + 1, k)) / 2;
break;
case MIDTOPRIGHTLINE:
P(i,j,k) = (P(i+1,j,k) + P(i,j+1,k)) / 2;
P(i, j, k) = (P(i + 1, j, k) + P(i, j + 1, k)) / 2;
break;
case MIDBOTTOMLEFTLINE:
P(i,j,k) = (P(i-1,j,k) + P(i,j-1,k)) / 2;
P(i, j, k) = (P(i - 1, j, k) + P(i, j - 1, k)) / 2;
break;
case MIDBOTTOMRIGHTLINE:
P(i,j,k) = (P(i+1,j,k) + P(i,j-1,k)) / 2;
P(i, j, k) = (P(i + 1, j, k) + P(i, j - 1, k)) / 2;
break;
case BACKLEFTLINE:
P(i,j,k) = (P(i,j,k+1) + P(i-1,j,k)) / 2;
P(i, j, k) = (P(i, j, k + 1) + P(i - 1, j, k)) / 2;
break;
case BACKRIGHTLINE:
P(i,j,k) = (P(i,j,k+1) + P(i+1,j,k)) / 2;
P(i, j, k) = (P(i, j, k + 1) + P(i + 1, j, k)) / 2;
break;
case BACKTOPLINE:
P(i,j,k) = (P(i,j,k+1) + P(i,j+1,k)) / 2;
P(i, j, k) = (P(i, j, k + 1) + P(i, j + 1, k)) / 2;
break;
case BACKBOTTOMLINE:
P(i,j,k) = (P(i,j,k+1) + P(i,j-1,k)) / 2;
P(i, j, k) = (P(i, j, k + 1) + P(i, j - 1, k)) / 2;
break;
case FRONTTOPLEFTCORNER:
P(i,j,k) = (P(i,j,k-1) + P(i-1,j,k) + P(i,j+1,k)) / 3;
P(i, j, k) = (P(i, j, k - 1) + P(i - 1, j, k) + P(i, j + 1, k)) / 3;
break;
case FRONTTOPRIGHTCORNER:
P(i,j,k) = (P(i,j,k-1) + P(i+1,j,k) + P(i,j+1,k)) / 3;
P(i, j, k) = (P(i, j, k - 1) + P(i + 1, j, k) + P(i, j + 1, k)) / 3;
break;
case FRONTBOTTOMLEFTCORNER:
P(i,j,k) = (P(i,j,k-1) + P(i-1,j,k) + P(i,j-1,k)) / 3;
P(i, j, k) = (P(i, j, k - 1) + P(i - 1, j, k) + P(i, j - 1, k)) / 3;
break;
case FRONTBOTTOMRIGHTCORNER:
P(i,j,k) = (P(i,j,k-1) + P(i+1,j,k) + P(i,j-1,k)) / 3;
P(i, j, k) = (P(i, j, k - 1) + P(i + 1, j, k) + P(i, j - 1, k)) / 3;
break;
case BACKTOPLEFTCORNER:
P(i,j,k) = (P(i,j,k+1) + P(i-1,j,k) + P(i,j+1,k)) / 3;
P(i, j, k) = (P(i, j, k + 1) + P(i - 1, j, k) + P(i, j + 1, k)) / 3;
break;
case BACKTOPRIGHTCORNER:
P(i,j,k) = (P(i,j,k+1) + P(i+1,j,k) + P(i,j+1,k)) / 3;
P(i, j, k) = (P(i, j, k + 1) + P(i + 1, j, k) + P(i, j + 1, k)) / 3;
break;
case BACKBOTTOMLEFTCORNER:
P(i,j,k) = (P(i,j,k+1) + P(i-1,j,k) + P(i,j-1,k)) / 3;
P(i, j, k) = (P(i, j, k + 1) + P(i - 1, j, k) + P(i, j - 1, k)) / 3;
break;
case BACKBOTTOMRIGHTCORNER:
P(i,j,k) = (P(i,j,k+1) + P(i+1,j,k) + P(i,j-1,k)) / 3;
P(i, j, k) = (P(i, j, k + 1) + P(i + 1, j, k) + P(i, j - 1, k)) / 3;
break;
}
}

View File

@ -9,7 +9,7 @@
#include <string.h>
#include "vtkWriter.h"
#define G(v, i, j, k) v[(k)*imax * jmax + (j)*imax + (i)]
#define G(v, i, j, k) v[(k) * imax * jmax + (j) * imax + (i)]
static float floatSwap(float f)
{
@ -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)
{
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);
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");
}
}