Structural changes in 2D versions
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Supported: GCC, CLANG, ICC
|
||||
TAG ?= CLANG
|
||||
TAG ?= ICC
|
||||
ENABLE_OPENMP ?= false
|
||||
|
||||
#Feature options
|
||||
|
10100
BasicSolver/2D-mpi-v1/pressure.dat
Normal file
10100
BasicSolver/2D-mpi-v1/pressure.dat
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,9 +17,12 @@
|
||||
#include "timing.h"
|
||||
#include <mpi.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;
|
||||
@@ -28,12 +31,16 @@ int main(int argc, char** argv)
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
initParameter(¶ms);
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
if (argc == 3)
|
||||
{
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
if (rank == 0) {
|
||||
printParameter(¶ms);
|
||||
}
|
||||
@@ -45,7 +52,10 @@ int main(int argc, char** argv)
|
||||
double t = 0.0;
|
||||
|
||||
S = getTimeStamp();
|
||||
while (t <= te) {
|
||||
switch (variant) {
|
||||
case SOR:
|
||||
printf("Plain SOR\n");
|
||||
while (t <= te) {
|
||||
if (tau > 0.0) {
|
||||
computeTimestep(&solver);
|
||||
}
|
||||
@@ -56,7 +66,6 @@ int main(int argc, char** argv)
|
||||
computeRHS(&solver);
|
||||
solve(&solver);
|
||||
adaptUV(&solver);
|
||||
/* exit(EXIT_SUCCESS); */
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
@@ -67,6 +76,57 @@ int main(int argc, char** argv)
|
||||
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);
|
||||
solveRB(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
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);
|
||||
solveRBA(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
|
||||
}
|
||||
#else
|
||||
printProgress(t);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
E = getTimeStamp();
|
||||
stopProgress();
|
||||
if (rank == 0) {
|
||||
|
@@ -24,6 +24,8 @@ 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 +80,8 @@ void readParameter(Parameter* param, const char* filename)
|
||||
PARSE_REAL(u_init);
|
||||
PARSE_REAL(v_init);
|
||||
PARSE_REAL(p_init);
|
||||
PARSE_REAL(rho);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -231,6 +231,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 jmaxLocal = solver->jmaxLocal;
|
||||
@@ -349,6 +351,142 @@ void solve(Solver* solver)
|
||||
#endif
|
||||
}
|
||||
|
||||
void solveRB(Solver* solver)
|
||||
{
|
||||
int imax = solver->imax;
|
||||
int jmax = solver->jmax;
|
||||
int jmaxLocal = solver->jmaxLocal;
|
||||
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;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
exchange(solver, p);
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->rank == 0) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->rank == (solver->size - 1)) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
P(imax + 1, j) = P(imax, j);
|
||||
}
|
||||
|
||||
MPI_Allreduce(MPI_IN_PLACE, &res, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (solver->rank == 0) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (solver->rank == 0) {
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void solveRBA(Solver* solver)
|
||||
{
|
||||
int imax = solver->imax;
|
||||
int jmax = solver->jmax;
|
||||
int jmaxLocal = solver->jmaxLocal;
|
||||
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;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
exchange(solver, p);
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->rank == 0) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->rank == (solver->size - 1)) {
|
||||
for (int i = 1; i < imax + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
P(imax + 1, j) = P(imax, j);
|
||||
}
|
||||
|
||||
MPI_Allreduce(MPI_IN_PLACE, &res, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (solver->rank == 0) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (solver->rank == 0) {
|
||||
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->jmaxLocal + 2);
|
||||
|
@@ -21,7 +21,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 */
|
||||
@@ -38,6 +38,8 @@ typedef struct {
|
||||
void initSolver(Solver*, Parameter*);
|
||||
void computeRHS(Solver*);
|
||||
void solve(Solver*);
|
||||
void solveRB(Solver*);
|
||||
void solveRBA(Solver*);
|
||||
void normalizePressure(Solver*);
|
||||
void computeTimestep(Solver*);
|
||||
void setBoundaryConditions(Solver*);
|
||||
|
10000
BasicSolver/2D-mpi-v1/velocity.dat
Normal file
10000
BasicSolver/2D-mpi-v1/velocity.dat
Normal file
File diff suppressed because it is too large
Load Diff
BIN
BasicSolver/2D-mpi-v1/velocity.png
Normal file
BIN
BasicSolver/2D-mpi-v1/velocity.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 206 KiB |
@@ -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
|
||||
#===============================================================================
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Supported: GCC, CLANG, ICC
|
||||
TAG ?= CLANG
|
||||
TAG ?= ICC
|
||||
ENABLE_OPENMP ?= false
|
||||
|
||||
#Feature options
|
||||
|
@@ -42,5 +42,6 @@ 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
|
||||
omg 1.7 # relaxation parameter for SOR iteration
|
||||
rho 0.9999 #
|
||||
gamma 0.9 # upwind differencing factor gamma
|
||||
#===============================================================================
|
||||
|
9900
BasicSolver/2D-mpi-v2/pressure.dat
Normal file
9900
BasicSolver/2D-mpi-v2/pressure.dat
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,9 +16,12 @@
|
||||
#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;
|
||||
@@ -27,12 +30,16 @@ int main(int argc, char** argv)
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
initParameter(¶ms);
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
if (argc == 3)
|
||||
{
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
if (rank == 0) {
|
||||
printParameter(¶ms);
|
||||
}
|
||||
@@ -47,7 +54,10 @@ int main(int argc, char** argv)
|
||||
double t = 0.0;
|
||||
|
||||
S = getTimeStamp();
|
||||
while (t <= te) {
|
||||
switch (variant) {
|
||||
case SOR:
|
||||
printf("Plain SOR\n");
|
||||
while (t <= te) {
|
||||
if (tau > 0.0) {
|
||||
computeTimestep(&solver);
|
||||
}
|
||||
@@ -67,6 +77,56 @@ int main(int argc, char** argv)
|
||||
#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);
|
||||
solveRB(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
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);
|
||||
solveRBA(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
|
||||
}
|
||||
#else
|
||||
printProgress(t);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
E = getTimeStamp();
|
||||
stopProgress();
|
||||
|
@@ -21,6 +21,8 @@ void initParameter(Parameter* param)
|
||||
param->itermax = 1000;
|
||||
param->eps = 0.0001;
|
||||
param->omg = 1.8;
|
||||
param->rho = 0.99;
|
||||
|
||||
}
|
||||
|
||||
void readParameter(Parameter* param, const char* filename)
|
||||
@@ -75,6 +77,8 @@ void readParameter(Parameter* param, const char* filename)
|
||||
PARSE_REAL(u_init);
|
||||
PARSE_REAL(v_init);
|
||||
PARSE_REAL(p_init);
|
||||
PARSE_REAL(rho);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -401,6 +401,8 @@ void initSolver(Solver* solver, Parameter* params)
|
||||
solver->te = params->te;
|
||||
solver->tau = params->tau;
|
||||
solver->gamma = params->gamma;
|
||||
solver->rho = params->rho;
|
||||
|
||||
|
||||
/* setup communication */
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &(solver->rank));
|
||||
@@ -565,6 +567,168 @@ int solve(Solver* solver)
|
||||
}
|
||||
}
|
||||
|
||||
int solveRB(Solver* solver)
|
||||
{
|
||||
int imax = solver->imax;
|
||||
int jmax = solver->jmax;
|
||||
int imaxLocal = solver->imaxLocal;
|
||||
int jmaxLocal = solver->jmaxLocal;
|
||||
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;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
exchange(solver, p);
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == 0) { // set bottom bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == (solver->dims[JDIM] - 1)) { // set top bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == 0) { // set left bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == (solver->dims[IDIM] - 1)) { // set right bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(imaxLocal + 1, j) = P(imaxLocal, j);
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Allreduce(MPI_IN_PLACE, &res, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (solver->rank == 0) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (solver->rank == 0) {
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
}
|
||||
#endif
|
||||
if (res < eps) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int solveRBA(Solver* solver)
|
||||
{
|
||||
int imax = solver->imax;
|
||||
int jmax = solver->jmax;
|
||||
int imaxLocal = solver->imaxLocal;
|
||||
int jmaxLocal = solver->jmaxLocal;
|
||||
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;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
exchange(solver, p);
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == 0) { // set bottom bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == (solver->dims[JDIM] - 1)) { // set top bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == 0) { // set left bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == (solver->dims[IDIM] - 1)) { // set right bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(imaxLocal + 1, j) = P(imaxLocal, j);
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Allreduce(MPI_IN_PLACE, &res, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (solver->rank == 0) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (solver->rank == 0) {
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
}
|
||||
#endif
|
||||
if (res < eps) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static double maxElement(Solver* solver, double* m)
|
||||
{
|
||||
int size = (solver->imaxLocal + 2) * (solver->jmaxLocal + 2);
|
||||
|
@@ -21,7 +21,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 */
|
||||
@@ -43,6 +43,8 @@ typedef struct {
|
||||
void initSolver(Solver*, Parameter*);
|
||||
void computeRHS(Solver*);
|
||||
int solve(Solver*);
|
||||
int solveRB(Solver*);
|
||||
int solveRBA(Solver*);
|
||||
void computeTimestep(Solver*);
|
||||
void setBoundaryConditions(Solver*);
|
||||
void setSpecialBoundaryCondition(Solver*);
|
||||
|
9801
BasicSolver/2D-mpi-v2/velocity.dat
Normal file
9801
BasicSolver/2D-mpi-v2/velocity.dat
Normal file
File diff suppressed because it is too large
Load Diff
BIN
BasicSolver/2D-mpi-v2/velocity.png
Normal file
BIN
BasicSolver/2D-mpi-v2/velocity.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 184 KiB |
@@ -7,10 +7,10 @@
|
||||
|
||||
name canal # name of flow setup
|
||||
|
||||
bcN 1 # flags for boundary conditions
|
||||
bcE 3 # 1 = no-slip 3 = outflow
|
||||
bcS 1 # 2 = free-slip 4 = periodic
|
||||
bcW 3 #
|
||||
bcTop 1 # flags for boundary conditions
|
||||
bcBottom 1 # 1 = no-slip 3 = outflow
|
||||
bcLeft 3 # 2 = free-slip 4 = periodic
|
||||
bcRight 3 #
|
||||
|
||||
gx 0.0 # Body forces (e.g. gravity)
|
||||
gy 0.0 #
|
||||
@@ -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
|
||||
#===============================================================================
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Supported: GCC, CLANG, ICC
|
||||
TAG ?= CLANG
|
||||
TAG ?= ICC
|
||||
ENABLE_OPENMP ?= false
|
||||
|
||||
#Feature options
|
||||
|
@@ -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
|
||||
#===============================================================================
|
||||
|
9900
BasicSolver/2D-mpi-v3/pressure.dat
Normal file
9900
BasicSolver/2D-mpi-v3/pressure.dat
Normal file
File diff suppressed because it is too large
Load Diff
@@ -16,9 +16,14 @@
|
||||
#include "timing.h"
|
||||
#include <mpi.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;
|
||||
@@ -27,12 +32,16 @@ int main(int argc, char** argv)
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
initParameter(¶ms);
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
if (argc == 3)
|
||||
{
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
if (rank == 0) {
|
||||
printParameter(¶ms);
|
||||
}
|
||||
@@ -44,7 +53,10 @@ int main(int argc, char** argv)
|
||||
double t = 0.0;
|
||||
|
||||
S = getTimeStamp();
|
||||
while (t <= te) {
|
||||
switch (variant) {
|
||||
case SOR:
|
||||
printf("Plain SOR\n");
|
||||
while (t <= te) {
|
||||
if (tau > 0.0) {
|
||||
computeTimestep(&solver);
|
||||
}
|
||||
@@ -65,6 +77,57 @@ int main(int argc, char** argv)
|
||||
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);
|
||||
solveRB(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
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);
|
||||
solveRBA(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
|
||||
}
|
||||
#else
|
||||
printProgress(t);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
E = getTimeStamp();
|
||||
stopProgress();
|
||||
if (rank == 0) {
|
||||
|
@@ -24,6 +24,8 @@ 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 +80,8 @@ void readParameter(Parameter* param, const char* filename)
|
||||
PARSE_REAL(u_init);
|
||||
PARSE_REAL(v_init);
|
||||
PARSE_REAL(p_init);
|
||||
PARSE_REAL(rho);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -313,6 +313,8 @@ void initSolver(Solver* solver, Parameter* params)
|
||||
solver->te = params->te;
|
||||
solver->tau = params->tau;
|
||||
solver->gamma = params->gamma;
|
||||
solver->rho = params->rho;
|
||||
|
||||
|
||||
/* setup communication */
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &(solver->rank));
|
||||
@@ -498,6 +500,170 @@ int solve(Solver* solver)
|
||||
}
|
||||
}
|
||||
|
||||
int solveRB(Solver* solver)
|
||||
{
|
||||
int imax = solver->imax;
|
||||
int jmax = solver->jmax;
|
||||
int imaxLocal = solver->imaxLocal;
|
||||
int jmaxLocal = solver->jmaxLocal;
|
||||
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;
|
||||
// identical to 1/((2/dx2)+(2/dy2))
|
||||
double factor = solver->omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||
double* p = solver->p;
|
||||
double* rhs = solver->rhs;
|
||||
double epssq = eps * eps;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
exchange(solver, p);
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == 0) { // set bottom bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == (solver->dims[JDIM] - 1)) { // set top bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == 0) { // set left bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == (solver->dims[IDIM] - 1)) { // set right bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(imaxLocal + 1, j) = P(imaxLocal, j);
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Allreduce(MPI_IN_PLACE, &res, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (solver->rank == 0) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (solver->rank == 0) {
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
}
|
||||
#endif
|
||||
if (res < eps) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int solveRBA(Solver* solver)
|
||||
{
|
||||
int imax = solver->imax;
|
||||
int jmax = solver->jmax;
|
||||
int imaxLocal = solver->imaxLocal;
|
||||
int jmaxLocal = solver->jmaxLocal;
|
||||
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;
|
||||
// identical to 1/((2/dx2)+(2/dy2))
|
||||
double factor = solver->omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||
double* p = solver->p;
|
||||
double* rhs = solver->rhs;
|
||||
double epssq = eps * eps;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
exchange(solver, p);
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == 0) { // set bottom bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[JDIM] == (solver->dims[JDIM] - 1)) { // set top bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == 0) { // set left bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (solver->coords[IDIM] == (solver->dims[IDIM] - 1)) { // set right bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(imaxLocal + 1, j) = P(imaxLocal, j);
|
||||
}
|
||||
}
|
||||
|
||||
MPI_Allreduce(MPI_IN_PLACE, &res, 1, MPI_DOUBLE, MPI_SUM, MPI_COMM_WORLD);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (solver->rank == 0) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (solver->rank == 0) {
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
}
|
||||
#endif
|
||||
if (res < eps) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
static double maxElement(Solver* solver, double* m)
|
||||
{
|
||||
int size = (solver->imaxLocal + 2) * (solver->jmaxLocal + 2);
|
||||
|
@@ -23,7 +23,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 */
|
||||
@@ -46,6 +46,8 @@ typedef struct {
|
||||
void initSolver(Solver*, Parameter*);
|
||||
void computeRHS(Solver*);
|
||||
int solve(Solver*);
|
||||
int solveRB(Solver*);
|
||||
int solveRBA(Solver*);
|
||||
void computeTimestep(Solver*);
|
||||
void setBoundaryConditions(Solver*);
|
||||
void setSpecialBoundaryCondition(Solver*);
|
||||
|
9801
BasicSolver/2D-mpi-v3/velocity.dat
Normal file
9801
BasicSolver/2D-mpi-v3/velocity.dat
Normal file
File diff suppressed because it is too large
Load Diff
BIN
BasicSolver/2D-mpi-v3/velocity.png
Normal file
BIN
BasicSolver/2D-mpi-v3/velocity.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 169 KiB |
@@ -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
|
||||
#===============================================================================
|
||||
|
@@ -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
|
||||
#===============================================================================
|
||||
|
9900
BasicSolver/2D-mpi/pressure.dat
Normal file
9900
BasicSolver/2D-mpi/pressure.dat
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,9 +17,14 @@
|
||||
#include "timing.h"
|
||||
#include <mpi.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;
|
||||
@@ -28,12 +33,16 @@ int main(int argc, char** argv)
|
||||
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
|
||||
initParameter(¶ms);
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
if (argc == 3)
|
||||
{
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
if (rank == 0) {
|
||||
printParameter(¶ms);
|
||||
}
|
||||
@@ -47,7 +56,11 @@ int main(int argc, char** argv)
|
||||
double t = 0.0;
|
||||
|
||||
S = getTimeStamp();
|
||||
while (t <= te) {
|
||||
|
||||
switch (variant) {
|
||||
case SOR:
|
||||
printf("Plain SOR\n");
|
||||
while (t <= te) {
|
||||
if (tau > 0.0) {
|
||||
computeTimestep(&solver);
|
||||
}
|
||||
@@ -68,6 +81,58 @@ int main(int argc, char** argv)
|
||||
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);
|
||||
solveRB(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
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);
|
||||
solveRBA(&solver);
|
||||
adaptUV(&solver);
|
||||
t += solver.dt;
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (rank == 0) {
|
||||
printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
|
||||
}
|
||||
#else
|
||||
printProgress(t);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
E = getTimeStamp();
|
||||
stopProgress();
|
||||
if (rank == 0) {
|
||||
|
@@ -21,6 +21,7 @@ void initParameter(Parameter* param)
|
||||
param->itermax = 1000;
|
||||
param->eps = 0.0001;
|
||||
param->omg = 1.8;
|
||||
param->rho = 0.99;
|
||||
}
|
||||
|
||||
void readParameter(Parameter* param, const char* filename)
|
||||
@@ -75,6 +76,8 @@ void readParameter(Parameter* param, const char* filename)
|
||||
PARSE_REAL(u_init);
|
||||
PARSE_REAL(v_init);
|
||||
PARSE_REAL(p_init);
|
||||
PARSE_REAL(rho);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -243,6 +243,156 @@ void computeTimestep(Solver* s)
|
||||
s->dt = dt * s->tau;
|
||||
}
|
||||
|
||||
int solveRB(Solver* s)
|
||||
{
|
||||
int imax = s->imax;
|
||||
int jmax = s->jmax;
|
||||
int imaxLocal = s->comm.imaxLocal;
|
||||
int jmaxLocal = s->comm.jmaxLocal;
|
||||
double eps = s->eps;
|
||||
int itermax = s->itermax;
|
||||
double dx2 = s->dx * s->dx;
|
||||
double dy2 = s->dy * s->dy;
|
||||
double idx2 = 1.0 / dx2;
|
||||
double idy2 = 1.0 / dy2;
|
||||
double factor = s->omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||
double* p = s->p;
|
||||
double* rhs = s->rhs;
|
||||
double epssq = eps * eps;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
commExchange(&s->comm, p);
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, BOTTOM)) { // set bottom bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, TOP)) { // set top bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, LEFT)) { // set left bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, RIGHT)) { // set right bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(imaxLocal + 1, j) = P(imaxLocal, j);
|
||||
}
|
||||
}
|
||||
|
||||
commReduction(&res, SUM);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (commIsMaster(&s->comm)) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
}
|
||||
int solveRBA(Solver* s)
|
||||
{
|
||||
int imax = s->imax;
|
||||
int jmax = s->jmax;
|
||||
int imaxLocal = s->comm.imaxLocal;
|
||||
int jmaxLocal = s->comm.jmaxLocal;
|
||||
double eps = s->eps;
|
||||
int itermax = s->itermax;
|
||||
double dx2 = s->dx * s->dx;
|
||||
double dy2 = s->dy * s->dy;
|
||||
double idx2 = 1.0 / dx2;
|
||||
double idy2 = 1.0 / dy2;
|
||||
double factor = s->omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
|
||||
double* p = s->p;
|
||||
double* rhs = s->rhs;
|
||||
double epssq = eps * eps;
|
||||
int it = 0;
|
||||
double res = 1.0;
|
||||
commExchange(&s->comm, p);
|
||||
|
||||
while ((res >= epssq) && (it < itermax)) {
|
||||
res = 0.0;
|
||||
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
|
||||
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) -= (factor * r);
|
||||
res += (r * r);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, BOTTOM)) { // set bottom bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, 0) = P(i, 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, TOP)) { // set top bc
|
||||
for (int i = 1; i < imaxLocal + 1; i++) {
|
||||
P(i, jmaxLocal + 1) = P(i, jmaxLocal);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, LEFT)) { // set left bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(0, j) = P(1, j);
|
||||
}
|
||||
}
|
||||
|
||||
if (commIsBoundary(&s->comm, RIGHT)) { // set right bc
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
P(imaxLocal + 1, j) = P(imaxLocal, j);
|
||||
}
|
||||
}
|
||||
|
||||
commReduction(&res, SUM);
|
||||
res = res / (double)(imax * jmax);
|
||||
#ifdef DEBUG
|
||||
if (commIsMaster(&s->comm)) {
|
||||
printf("%d Residuum: %e\n", it, res);
|
||||
}
|
||||
#endif
|
||||
it++;
|
||||
}
|
||||
|
||||
#ifdef VERBOSE
|
||||
if (commIsMaster(&s->comm)) {
|
||||
printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
|
||||
}
|
||||
#endif
|
||||
if (res < eps) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void setBoundaryConditions(Solver* s)
|
||||
{
|
||||
int imaxLocal = s->comm.imaxLocal;
|
||||
@@ -448,6 +598,7 @@ void computeFG(Solver* s)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ----------------------------- boundary of F --------------------------- */
|
||||
if (commIsBoundary(&s->comm, LEFT)) {
|
||||
for (int j = 1; j < jmaxLocal + 1; j++) {
|
||||
|
@@ -21,7 +21,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 */
|
||||
@@ -37,6 +37,8 @@ typedef struct {
|
||||
void initSolver(Solver*, Parameter*);
|
||||
void computeRHS(Solver*);
|
||||
int solve(Solver*);
|
||||
int solveRB(Solver*);
|
||||
int solveRBA(Solver*);
|
||||
void normalizePressure(Solver*);
|
||||
void computeTimestep(Solver*);
|
||||
void setBoundaryConditions(Solver*);
|
||||
|
9801
BasicSolver/2D-mpi/velocity.dat
Normal file
9801
BasicSolver/2D-mpi/velocity.dat
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 11 KiB |
@@ -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
|
||||
#===============================================================================
|
||||
|
@@ -1,5 +1,5 @@
|
||||
# Supported: GCC, CLANG, ICC
|
||||
TAG ?= CLANG
|
||||
TAG ?= ICC
|
||||
ENABLE_OPENMP ?= false
|
||||
|
||||
#Feature options
|
||||
|
@@ -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
|
||||
#===============================================================================
|
||||
|
10050
BasicSolver/2D-seq/pressure.dat
Normal file
10050
BasicSolver/2D-seq/pressure.dat
Normal file
File diff suppressed because it is too large
Load Diff
@@ -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(¶ms);
|
||||
|
||||
if (argc != 2) {
|
||||
if (argc < 2) {
|
||||
printf("Usage: %s <configFile>\n", argv[0]);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
readParameter(¶ms, argv[1]);
|
||||
if (argc == 3)
|
||||
{
|
||||
variant = atoi(argv[2]);
|
||||
}
|
||||
|
||||
printParameter(¶ms);
|
||||
initSolver(&solver, ¶ms);
|
||||
#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);
|
||||
|
@@ -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);
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
|
@@ -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 */
|
||||
|
10000
BasicSolver/2D-seq/velocity.dat
Normal file
10000
BasicSolver/2D-seq/velocity.dat
Normal file
File diff suppressed because it is too large
Load Diff
BIN
BasicSolver/2D-seq/velocity.png
Normal file
BIN
BasicSolver/2D-seq/velocity.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
Reference in New Issue
Block a user