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  | 
		Reference in New Issue
	
	Block a user