WIP: Pull Request for a complete Solver package #1

Closed
AdityaUjeniya wants to merge 51 commits from (deleted):main into main
9 changed files with 341216 additions and 21082 deletions
Showing only changes of commit 175ec58667 - Show all commits

View File

@ -65,8 +65,8 @@ y2 1.5
shape 1 shape 1
xCenter 0.0 xCenter 0.0
yCenter 0.0 yCenter 0.0
xRectLength 2.0 xRectLength 1.0
yRectLength 1.0 yRectLength 2.0
circleRadius 1.0 circleRadius 1.0
#=============================================================================== #===============================================================================

View File

@ -18,9 +18,9 @@ gx 0.0 # Body forces (e.g. gravity)
gy 0.0 # gy 0.0 #
gz 0.0 # gz 0.0 #
re 36000.0 # Reynolds number re 5000.0 # Reynolds number
u_init 0.0 # initial value for velocity in x-direction u_init 1.0 # initial value for velocity in x-direction
v_init 0.0 # initial value for velocity in y-direction v_init 0.0 # initial value for velocity in y-direction
w_init 0.0 # initial value for velocity in z-direction w_init 0.0 # initial value for velocity in z-direction
p_init 1.0 # initial value for pressure p_init 1.0 # initial value for pressure
@ -55,7 +55,7 @@ gamma 0.9 # upwind differencing factor gamma
# ----------------------- # -----------------------
numberOfParticles 200 numberOfParticles 200
startTime 100 startTime 0
injectTimePeriod 2.0 injectTimePeriod 2.0
writeTimePeriod 0.2 writeTimePeriod 0.2

File diff suppressed because it is too large Load Diff

View File

@ -7,18 +7,22 @@
name karman # name of flow setup name karman # name of flow setup
bcTop 1 # flags for boundary conditions bcLeft 3 # flags for boundary conditions
bcBottom 1 # 1 = no-slip 3 = outflow bcRight 3 # 1 = no-slip 3 = outflow
bcLeft 3 # 2 = free-slip 4 = periodic bcBottom 1 # 2 = free-slip 4 = periodic
bcRight 3 # bcTop 1 #
bcFront 1 #
bcBack 1 #
gx 0.0 # Body forces (e.g. gravity) gx 0.0 # Body forces (e.g. gravity)
gy 0.0 # gy 0.0 #
gz 0.0 #
re 5050.0 # Reynolds number re 100.0 # Reynolds number
u_init 1.0 # initial value for velocity in x-direction u_init 0.0 # initial value for velocity in x-direction
v_init 0.0 # initial value for velocity in y-direction v_init 0.0 # initial value for velocity in y-direction
w_init 0.0 # initial value for velocity in z-direction
p_init 0.0 # initial value for pressure p_init 0.0 # initial value for pressure
# Geometry Data: # Geometry Data:
@ -26,37 +30,41 @@ p_init 0.0 # initial value for pressure
xlength 30.0 # domain size in x-direction xlength 30.0 # domain size in x-direction
ylength 8.0 # domain size in y-direction ylength 8.0 # domain size in y-direction
imax 400 # number of interior cells in x-direction zlength 8.0 # domain size in z-direction
jmax 200 # number of interior cells in y-direction imax 100 # number of interior cells in x-direction
jmax 40 # number of interior cells in y-direction
kmax 40 # number of interior cells in z-direction
# Time Data: # Time Data:
# --------- # ---------
te 150.0 # final time te 100.0 # final time
dt 0.02 # time stepsize dt 0.02 # time stepsize
tau 0.5 # safety factor for time stepsize control (<0 constant delt) tau 0.5 # safety factor for time stepsize control (<0 constant delt)
# Pressure Iteration Data: # Pressure Iteration Data:
# ----------------------- # -----------------------
itermax 200 # maximal number of pressure iteration in one time step itermax 500 # maximal number of pressure iteration in one time step
eps 0.001 # stopping tolerance for pressure iteration eps 0.0001 # stopping tolerance for pressure iteration
rho 0.52 omg 0.52
omg 1.75 # relaxation parameter for SOR iteration omg 1.7 # relaxation parameter for SOR iteration
gamma 0.9 # upwind differencing factor gamma gamma 0.9 # upwind differencing factor gamma
# Particle Tracing Data: # Particle Tracing Data:
# ----------------------- # -----------------------
numberOfParticles 200 numberOfParticles 200
startTime 50 startTime 0
injectTimePeriod 1.0 injectTimePeriod 2.0
writeTimePeriod 0.5 writeTimePeriod 1.0
x1 0.0 x1 1.0
y1 3.8 y1 0.0
x2 0.0 z1 1.0
y2 4.1 x2 1.0
y2 4.0
z2 1.0
# Obstacle Geometry Data: # Obstacle Geometry Data:
# ----------------------- # -----------------------
@ -65,18 +73,7 @@ y2 4.1
shape 2 shape 2
xCenter 5.0 xCenter 5.0
yCenter 4.0 yCenter 4.0
xRectLength 2.0 zCenter 4.0
yRectLength 1.0
circleRadius 1.0
# Obstacle Geometry Data:
# -----------------------
# Shape 0 disable, 1 Rectangle/Square, 2 Circle
shape 1
xCenter 10.0
yCenter 2.0
zCenter 2.0
xRectLength 8.0 xRectLength 8.0
yRectLength 2.0 yRectLength 2.0
zRectLength 2.0 zRectLength 2.0

320011
BasicSolver/3D-seq/karman.vtk Normal file

File diff suppressed because it is too large Load Diff

View File

@ -28,8 +28,12 @@ void printParticles(ParticleTracer* particletracer)
particletracer->particlePool[i].flag); particletracer->particlePool[i].flag);
} }
} }
void injectParticles(ParticleTracer* particletracer) void injectParticles(ParticleTracer* particletracer, int* seg)
{ {
int imax = particletracer->imax;
int jmax = particletracer->jmax;
int kmax = particletracer->kmax;
for(int i = 0; i < particletracer->numberOfParticles; ++i) for(int i = 0; i < particletracer->numberOfParticles; ++i)
{ {
@ -41,11 +45,17 @@ void injectParticles(ParticleTracer* particletracer)
particletracer->particlePool[particletracer->pointer].y = (double) rand() / RAND_MAX * particletracer->ylength; 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].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;
if(S(i,j,k) == NONE)
{
particletracer->particlePool[particletracer->pointer].flag = true; particletracer->particlePool[particletracer->pointer].flag = true;
++(particletracer->pointer); ++(particletracer->pointer);
++(particletracer->totalParticles); ++(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)
@ -269,7 +279,7 @@ void trace(ParticleTracer* particletracer, double* u, double* v, double* w, int*
//printParticles(particletracer); //printParticles(particletracer);
if( (time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod) if( (time - particletracer->lastInjectTime) >= particletracer->injectTimePeriod)
{ {
injectParticles(particletracer); injectParticles(particletracer, seg);
particletracer->lastInjectTime = time; particletracer->lastInjectTime = time;
} }
if( (time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod) if( (time - particletracer->lastWriteTime) >= particletracer->writeTimePeriod)

View File

@ -37,7 +37,7 @@ typedef struct {
} ParticleTracer; } ParticleTracer;
extern void initParticleTracer(ParticleTracer*, Parameter*); extern void initParticleTracer(ParticleTracer*, Parameter*);
extern void injectParticles(ParticleTracer*); 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 freeParticles(ParticleTracer*);
extern void writeParticles(ParticleTracer*); extern void writeParticles(ParticleTracer*);

View File

@ -438,10 +438,13 @@ void computeRHS(Solver* s)
double* f = s->f; double* f = s->f;
double* g = s->g; double* g = s->g;
double* h = s->h; double* h = s->h;
int* seg = s->seg;
for (int k = 1; k < kmax + 1; k++) { for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) { for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) { 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 + RHS(i, j, k) = ((F(i, j, k) - F(i - 1, j, k)) * idx +
(G(i, j, k) - G(i, j - 1, k)) * idy + (G(i, j, k) - G(i, j - 1, k)) * idy +
(H(i, j, k) - H(i, j, k - 1)) * idz) * (H(i, j, k) - H(i, j, k - 1)) * idz) *
@ -449,6 +452,7 @@ void computeRHS(Solver* s)
} }
} }
} }
}
} }
void solve(Solver* s) void solve(Solver* s)
@ -471,6 +475,7 @@ void solve(Solver* s)
double epssq = eps * eps; double epssq = eps * eps;
int it = 0; int it = 0;
double res = 1.0; double res = 1.0;
int* seg = s->seg;
while ((res >= epssq) && (it < itermax)) { while ((res >= epssq) && (it < itermax)) {
res = 0.0; res = 0.0;
@ -478,7 +483,8 @@ void solve(Solver* s)
for (int k = 1; k < kmax + 1; k++) { for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) { for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) { for (int i = 1; i < imax + 1; i++) {
if(S(i,j,k) == NONE)
{
double r = RHS(i, j, k) - double r = RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * ((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) *
idx2 + idx2 +
@ -492,6 +498,7 @@ void solve(Solver* s)
} }
} }
} }
}
for (int j = 1; j < jmax + 1; j++) { for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) { for (int i = 1; i < imax + 1; i++) {
@ -513,6 +520,7 @@ void solve(Solver* s)
P(imax + 1, j, k) = P(imax, j, k); P(imax + 1, j, k) = P(imax, j, k);
} }
} }
setObjectPBoundaryCondition(s);
res = res / (double)(imax * jmax * kmax); res = res / (double)(imax * jmax * kmax);
#ifdef DEBUG #ifdef DEBUG
@ -547,37 +555,12 @@ void solveRB(Solver* s)
int it = 0; int it = 0;
double res = 1.0; double res = 1.0;
int pass, ksw, jsw, isw; int pass, ksw, jsw, isw;
int* seg = s->seg;
while ((res >= epssq) && (it < itermax)) { while ((res >= epssq) && (it < itermax)) {
res = 0.0; res = 0.0;
ksw = 1; ksw = 1;
for (pass = 0; pass < 2; pass++) {
jsw = ksw;
for (int k = 1; k < kmax + 1; k++) {
isw = jsw;
for (int j = 1; j < jmax + 1; j++) {
for (int i = isw; i < imax + 1; i += 2) {
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);
}
isw = 3 - isw;
}
jsw = 3 - jsw;
}
ksw = 3 - ksw;
}
for (int j = 1; j < jmax + 1; j++) { for (int j = 1; j < jmax + 1; j++) {
for (int i = 1; i < imax + 1; i++) { for (int i = 1; i < imax + 1; i++) {
P(i, j, 0) = P(i, j, 1); P(i, j, 0) = P(i, j, 1);
@ -599,6 +582,37 @@ void solveRB(Solver* s)
} }
} }
setObjectPBoundaryCondition(s);
for (pass = 0; pass < 2; pass++) {
jsw = ksw;
for (int k = 1; k < kmax + 1; k++) {
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);
P(i, j, k) -= (factor * r);
res += (r * r);
}
}
isw = 3 - isw;
}
jsw = 3 - jsw;
}
ksw = 3 - ksw;
}
res = res / (double)(imax * jmax * kmax); res = res / (double)(imax * jmax * kmax);
#ifdef DEBUG #ifdef DEBUG
printf("%d Residuum: %e\n", it, res); printf("%d Residuum: %e\n", it, res);
@ -633,6 +647,8 @@ void solveRBA(Solver* s)
int it = 0; int it = 0;
double res = 1.0; double res = 1.0;
int pass, ksw, jsw, isw; int pass, ksw, jsw, isw;
int* seg = s->seg;
while ((res >= epssq) && (it < itermax)) { while ((res >= epssq) && (it < itermax)) {
res = 0.0; res = 0.0;
@ -645,7 +661,8 @@ void solveRBA(Solver* s)
isw = jsw; isw = jsw;
for (int j = 1; j < jmax + 1; j++) { for (int j = 1; j < jmax + 1; j++) {
for (int i = isw; i < imax + 1; i += 2) { for (int i = isw; i < imax + 1; i += 2) {
if(S(i,j,k) == NONE)
{
double r = double r =
RHS(i, j, k) - RHS(i, j, k) -
((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 + ((P(i + 1, j, k) - 2.0 * P(i, j, k) + P(i - 1, j, k)) * idx2 +
@ -656,6 +673,7 @@ void solveRBA(Solver* s)
P(i, j, k) -= (omega * factor * r); P(i, j, k) -= (omega * factor * r);
res += (r * r); res += (r * r);
}
} }
isw = 3 - isw; isw = 3 - isw;
} }
@ -686,6 +704,7 @@ void solveRBA(Solver* s)
P(imax + 1, j, k) = P(imax, j, k); P(imax + 1, j, k) = P(imax, j, k);
} }
} }
setObjectPBoundaryCondition(s);
res = res / (double)(imax * jmax * kmax); res = res / (double)(imax * jmax * kmax);
#ifdef DEBUG #ifdef DEBUG
@ -985,10 +1004,11 @@ void setSpecialBoundaryCondition(Solver* s)
} }
} }
} else if (strcmp(s->problem, "backstep") == 0) { } else if (strcmp(s->problem, "backstep") == 0) {
int* seg = s->seg;
for (int k = 1; k < kmax + 1; k++) { for (int k = 1; k < kmax + 1; k++) {
for (int j = 1; j < jmax + 1; j++) { for (int j = 1; j < jmax + 1; j++) {
if(S(0,j,k) == NONE) U(0, j, k) = 1.0;
U(0, j, k) = 1.0;
} }
} }
} }
@ -1478,3 +1498,98 @@ void setObjectBoundaryCondition(Solver* s)
} }
} }
} }
void setObjectPBoundaryCondition(Solver* s)
{
int imax = s->grid.imax;
int jmax = s->grid.jmax;
int kmax = s->grid.kmax;
double* p = s->p;
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++) {
switch (S(i, j, k)) {
case TOPFACE:
P(i,j,k) = P(i,j+1,k);
break;
case BOTTOMFACE:
P(i,j,k) = P(i,j-1,k);
break;
case LEFTFACE:
P(i,j,k) = P(i-1,j,k);
break;
case RIGHTFACE:
P(i,j,k) = P(i+1,j,k);
break;
case FRONTFACE:
P(i,j,k) = P(i,j,k-1);
break;
case BACKFACE:
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;
break;
case FRONTRIGHTLINE:
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;
break;
case FRONTBOTTOMLINE:
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;
break;
case MIDTOPRIGHTLINE:
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;
break;
case MIDBOTTOMRIGHTLINE:
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;
break;
case BACKRIGHTLINE:
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;
break;
case BACKBOTTOMLINE:
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;
break;
case FRONTTOPRIGHTCORNER:
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;
break;
case FRONTBOTTOMRIGHTCORNER:
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;
break;
case BACKTOPRIGHTCORNER:
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;
break;
case BACKBOTTOMRIGHTCORNER:
P(i,j,k) = (P(i,j,k+1) + P(i+1,j,k) + P(i,j-1,k)) / 3;
break;
}
}
}
}
}

View File

@ -80,6 +80,7 @@ extern void normalizePressure(Solver*);
extern void computeTimestep(Solver*); extern void computeTimestep(Solver*);
extern void setBoundaryConditions(Solver*); extern void setBoundaryConditions(Solver*);
extern void setObjectBoundaryCondition(Solver*); extern void setObjectBoundaryCondition(Solver*);
extern void setObjectPBoundaryCondition(Solver*);
extern void setSpecialBoundaryCondition(Solver*); extern void setSpecialBoundaryCondition(Solver*);
extern void computeFG(Solver*); extern void computeFG(Solver*);
extern void adaptUV(Solver*); extern void adaptUV(Solver*);