Structural changes in 2D versions

This commit is contained in:
2023-06-27 16:24:55 +02:00
parent acc831e0b0
commit ca99356d45
62 changed files with 100926 additions and 56 deletions

View File

@@ -41,6 +41,7 @@ tau 0.5 # safety factor for time stepsize control (<0 constant delt)
itermax 500 # maximal number of pressure iteration in one time step
eps 0.00001 # stopping tolerance for pressure iteration
rho 0.9999
omg 1.8 # relaxation parameter for SOR iteration
gamma 0.9 # upwind differencing factor gamma
#===============================================================================

View File

@@ -1,5 +1,5 @@
# Supported: GCC, CLANG, ICC
TAG ?= CLANG
TAG ?= ICC
ENABLE_OPENMP ?= false
#Feature options

View File

@@ -41,6 +41,7 @@ tau 0.5 # safety factor for time stepsize control (<0 constant delt)
itermax 1000 # maximal number of pressure iteration in one time step
eps 0.001 # stopping tolerance for pressure iteration
rho 0.9999
omg 1.7 # relaxation parameter for SOR iteration
gamma 0.9 # upwind differencing factor gamma
#===============================================================================

File diff suppressed because it is too large Load Diff

View File

@@ -15,19 +15,29 @@
#include "solver.h"
#include "timing.h"
int main(int argc, char** argv)
enum VARIANT { SOR = 1, RB, RBA };
int main (int argc, char** argv)
{
int rank;
int variant = SOR;
double S, E;
Parameter params;
Solver solver;
initParameter(&params);
if (argc != 2) {
if (argc < 2) {
printf("Usage: %s <configFile>\n", argv[0]);
exit(EXIT_SUCCESS);
}
readParameter(&params, argv[1]);
if (argc == 3)
{
variant = atoi(argv[2]);
}
printParameter(&params);
initSolver(&solver, &params);
#ifndef VERBOSE
@@ -40,24 +50,77 @@ int main(int argc, char** argv)
int nt = 0;
S = getTimeStamp();
while (t <= te) {
if (tau > 0.0) computeTimestep(&solver);
setBoundaryConditions(&solver);
setSpecialBoundaryCondition(&solver);
computeFG(&solver);
computeRHS(&solver);
if (nt % 100 == 0) normalizePressure(&solver);
solveRB(&solver);
adaptUV(&solver);
t += solver.dt;
nt++;
#ifdef VERBOSE
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
#else
printProgress(t);
#endif
switch (variant) {
case SOR:
printf("Plain SOR\n");
while (t <= te)
{
if (tau > 0.0) computeTimestep(&solver);
setBoundaryConditions(&solver);
setSpecialBoundaryCondition(&solver);
computeFG(&solver);
computeRHS(&solver);
if (nt % 100 == 0) normalizePressure(&solver);
solve(&solver);
adaptUV(&solver);
t += solver.dt;
nt++;
#ifdef VERBOSE
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
#else
printProgress(t);
#endif
}
break;
case RB:
printf("Red-black SOR\n");
while (t <= te)
{
if (tau > 0.0) computeTimestep(&solver);
setBoundaryConditions(&solver);
setSpecialBoundaryCondition(&solver);
computeFG(&solver);
computeRHS(&solver);
if (nt % 100 == 0) normalizePressure(&solver);
solveRB(&solver);
adaptUV(&solver);
t += solver.dt;
nt++;
#ifdef VERBOSE
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
#else
printProgress(t);
#endif
}
break;
case RBA:
printf("Red-black SOR with acceleration\n");
while (t <= te)
{
if (tau > 0.0) computeTimestep(&solver);
setBoundaryConditions(&solver);
setSpecialBoundaryCondition(&solver);
computeFG(&solver);
computeRHS(&solver);
if (nt % 100 == 0) normalizePressure(&solver);
solveRBA(&solver);
adaptUV(&solver);
t += solver.dt;
nt++;
#ifdef VERBOSE
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
#else
printProgress(t);
#endif
}
break;
}
E = getTimeStamp();
stopProgress();
printf("Solution took %.2fs\n", E - S);

View File

@@ -24,6 +24,7 @@ void initParameter(Parameter* param)
param->re = 100.0;
param->gamma = 0.9;
param->tau = 0.5;
param->rho = 0.99;
}
void readParameter(Parameter* param, const char* filename)
@@ -78,6 +79,8 @@ void readParameter(Parameter* param, const char* filename)
PARSE_REAL(u_init);
PARSE_REAL(v_init);
PARSE_REAL(p_init);
PARSE_REAL(rho);
}
}
@@ -108,4 +111,6 @@ void printParameter(Parameter* param)
printf("\tepsilon (stopping tolerance) : %f\n", param->eps);
printf("\tgamma (stopping tolerance) : %f\n", param->gamma);
printf("\tomega (SOR relaxation): %f\n", param->omg);
printf("\trho (SOR relaxation): %f\n", param->rho);
}

View File

@@ -11,7 +11,7 @@ typedef struct {
double xlength, ylength;
int imax, jmax;
int itermax;
double eps, omg;
double eps, omg, rho;
double re, tau, gamma;
double te, dt;
double gx, gy;

View File

@@ -83,6 +83,8 @@ void initSolver(Solver* solver, Parameter* params)
solver->te = params->te;
solver->tau = params->tau;
solver->gamma = params->gamma;
solver->rho = params->rho;
int imax = solver->imax;
int jmax = solver->jmax;
@@ -247,6 +249,72 @@ void solveRB(Solver* solver)
#endif
}
void solveRBA(Solver* solver)
{
int imax = solver->imax;
int jmax = solver->jmax;
double eps = solver->eps;
int itermax = solver->itermax;
double dx2 = solver->dx * solver->dx;
double dy2 = solver->dy * solver->dy;
double idx2 = 1.0 / dx2;
double idy2 = 1.0 / dy2;
double factor = solver->omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
double* p = solver->p;
double* rhs = solver->rhs;
double epssq = eps * eps;
double rho = solver->rho;
int it = 0;
double res = 1.0;
int pass, jsw, isw;
double omega = 1.0;
while ((res >= epssq) && (it < itermax)) {
res = 0.0;
jsw = 1;
for (pass = 0; pass < 2; pass++) {
isw = jsw;
for (int j = 1; j < jmax + 1; j++) {
for (int i = isw; i < imax + 1; i += 2) {
double r = RHS(i, j) -
((P(i + 1, j) - 2.0 * P(i, j) + P(i - 1, j)) * idx2 +
(P(i, j + 1) - 2.0 * P(i, j) + P(i, j - 1)) * idy2);
P(i, j) -= (omega * factor * r);
res += (r * r);
}
isw = 3 - isw;
}
jsw = 3 - jsw;
omega = (it == 0 && pass == 0 ? 1.0 / (1.0 - 0.5 * rho * rho)
: 1.0 / (1.0 - 0.25 * rho * rho * omega));
}
for (int i = 1; i < imax + 1; i++) {
P(i, 0) = P(i, 1);
P(i, jmax + 1) = P(i, jmax);
}
for (int j = 1; j < jmax + 1; j++) {
P(0, j) = P(1, j);
P(imax + 1, j) = P(imax, j);
}
res = res / (double)(imax * jmax);
#ifdef DEBUG
printf("%d Residuum: %e\n", it, res);
#endif
it++;
}
#ifdef VERBOSE
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
#endif
}
static double maxElement(Solver* solver, double* m)
{
int size = (solver->imax + 2) * (solver->jmax + 2);

View File

@@ -20,7 +20,7 @@ typedef struct {
double *f, *g;
double *u, *v;
/* parameters */
double eps, omega;
double eps, omega, rho;
double re, tau, gamma;
double gx, gy;
/* time stepping */

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB