Structural changes in 2D versions
This commit is contained in:
		@@ -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  | 
		Reference in New Issue
	
	Block a user