Completed 3D-seq and mpi refactoring in BasicSolver
This commit is contained in:
		@@ -42,6 +42,13 @@ te       100.0   # final time
 | 
			
		||||
dt       0.02    # time stepsize
 | 
			
		||||
tau      0.5     # safety factor for time stepsize control (<0 constant delt)
 | 
			
		||||
 | 
			
		||||
# Multigrid data:
 | 
			
		||||
# ---------
 | 
			
		||||
 | 
			
		||||
levels        3         # Multigrid levels
 | 
			
		||||
presmooth     5         # Pre-smoothning iterations
 | 
			
		||||
postsmooth    5         # Post-smoothning iterations
 | 
			
		||||
 | 
			
		||||
# Pressure Iteration Data:
 | 
			
		||||
# -----------------------
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,12 @@
 | 
			
		||||
# Supported: GCC, CLANG, ICC
 | 
			
		||||
TAG ?= CLANG
 | 
			
		||||
TAG ?= ICC
 | 
			
		||||
ENABLE_OPENMP ?= false
 | 
			
		||||
# Supported: sor, mg
 | 
			
		||||
# Supported: rb, mg
 | 
			
		||||
SOLVER ?= mg
 | 
			
		||||
# Run in debug settings
 | 
			
		||||
DEBUG ?= false
 | 
			
		||||
 | 
			
		||||
#Feature options
 | 
			
		||||
OPTIONS +=  -DARRAY_ALIGNMENT=64
 | 
			
		||||
#OPTIONS +=  -DVERBOSE
 | 
			
		||||
OPTIONS +=  -DVERBOSE
 | 
			
		||||
#OPTIONS +=  -DDEBUG
 | 
			
		||||
 
 | 
			
		||||
@@ -38,10 +38,17 @@ kmax       128		# number of interior cells in z-direction
 | 
			
		||||
# Time Data:
 | 
			
		||||
# ---------
 | 
			
		||||
 | 
			
		||||
te      2.0		# final time
 | 
			
		||||
te       2.0		# final time
 | 
			
		||||
dt       0.02	    # time stepsize
 | 
			
		||||
tau      0.5		# safety factor for time stepsize control (<0 constant delt)
 | 
			
		||||
 | 
			
		||||
# Multigrid data:
 | 
			
		||||
# ---------
 | 
			
		||||
 | 
			
		||||
levels        3         # Multigrid levels
 | 
			
		||||
presmooth     10         # Pre-smoothning iterations
 | 
			
		||||
postsmooth    5         # Post-smoothning iterations
 | 
			
		||||
 | 
			
		||||
# Pressure Iteration Data:
 | 
			
		||||
# -----------------------
 | 
			
		||||
 | 
			
		||||
@@ -50,5 +57,4 @@ eps      0.001		# stopping tolerance for pressure iteration
 | 
			
		||||
rho      0.5
 | 
			
		||||
omg      1.7		# relaxation parameter for SOR iteration
 | 
			
		||||
gamma    0.9		# upwind differencing factor gamma
 | 
			
		||||
levels   5         # Multigrid levels
 | 
			
		||||
#===============================================================================
 | 
			
		||||
 
 | 
			
		||||
@@ -106,7 +106,7 @@ void initDiscretization(Discretization* d, Parameter* p)
 | 
			
		||||
    d->dtBound       = 0.5 * d->re * 1.0 / invSqrSum;
 | 
			
		||||
 | 
			
		||||
#ifdef VERBOSE
 | 
			
		||||
    printConfig(s);
 | 
			
		||||
    printConfig(d);
 | 
			
		||||
#endif /* VERBOSE */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -105,7 +105,7 @@ int main(int argc, char** argv)
 | 
			
		||||
        nt++;
 | 
			
		||||
 | 
			
		||||
#ifdef VERBOSE
 | 
			
		||||
        printf("TIME %f , TIMESTEP %f\n", t, solver.dt);
 | 
			
		||||
        printf("TIME %f , TIMESTEP %f\n", t, d.dt);
 | 
			
		||||
#else
 | 
			
		||||
        printProgress(t);
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -14,19 +14,21 @@
 | 
			
		||||
 | 
			
		||||
void initParameter(Parameter* param)
 | 
			
		||||
{
 | 
			
		||||
    param->xlength = 1.0;
 | 
			
		||||
    param->ylength = 1.0;
 | 
			
		||||
    param->zlength = 1.0;
 | 
			
		||||
    param->imax    = 100;
 | 
			
		||||
    param->jmax    = 100;
 | 
			
		||||
    param->kmax    = 100;
 | 
			
		||||
    param->itermax = 1000;
 | 
			
		||||
    param->eps     = 0.0001;
 | 
			
		||||
    param->omg     = 1.7;
 | 
			
		||||
    param->re      = 100.0;
 | 
			
		||||
    param->gamma   = 0.9;
 | 
			
		||||
    param->tau     = 0.5;
 | 
			
		||||
    param->levels  = 5;
 | 
			
		||||
    param->xlength    = 1.0;
 | 
			
		||||
    param->ylength    = 1.0;
 | 
			
		||||
    param->zlength    = 1.0;
 | 
			
		||||
    param->imax       = 100;
 | 
			
		||||
    param->jmax       = 100;
 | 
			
		||||
    param->kmax       = 100;
 | 
			
		||||
    param->itermax    = 1000;
 | 
			
		||||
    param->eps        = 0.0001;
 | 
			
		||||
    param->omg        = 1.7;
 | 
			
		||||
    param->re         = 100.0;
 | 
			
		||||
    param->gamma      = 0.9;
 | 
			
		||||
    param->tau        = 0.5;
 | 
			
		||||
    param->levels     = 5;
 | 
			
		||||
    param->presmooth  = 5;
 | 
			
		||||
    param->postsmooth = 5;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void readParameter(Parameter* param, const char* filename)
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ typedef struct {
 | 
			
		||||
    char* name;
 | 
			
		||||
    int bcLeft, bcRight, bcBottom, bcTop, bcFront, bcBack;
 | 
			
		||||
    double u_init, v_init, w_init, p_init;
 | 
			
		||||
    int presmooth, postsmooth;
 | 
			
		||||
} Parameter;
 | 
			
		||||
 | 
			
		||||
void initParameter(Parameter*);
 | 
			
		||||
 
 | 
			
		||||
@@ -141,13 +141,62 @@ static double smooth(
 | 
			
		||||
            for (int j = 1; j < jmax + 1; j++) {
 | 
			
		||||
                for (int i = isw; i < imax + 1; i += 2) {
 | 
			
		||||
 | 
			
		||||
                    R(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, 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 *
 | 
			
		||||
                        (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));
 | 
			
		||||
                }
 | 
			
		||||
                isw = 3 - isw;
 | 
			
		||||
            }
 | 
			
		||||
            jsw = 3 - jsw;
 | 
			
		||||
        }
 | 
			
		||||
        ksw = 3 - ksw;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static double calculateResidual(
 | 
			
		||||
    Solver* s, double* p, double* rhs, int level, int imax, int jmax, int kmax)
 | 
			
		||||
{
 | 
			
		||||
    double eps    = s->eps;
 | 
			
		||||
    int itermax   = s->itermax;
 | 
			
		||||
    double dx2    = s->grid->dx * s->grid->dx;
 | 
			
		||||
    double dy2    = s->grid->dy * s->grid->dy;
 | 
			
		||||
    double dz2    = s->grid->dz * s->grid->dz;
 | 
			
		||||
    double idx2   = 1.0 / dx2;
 | 
			
		||||
    double idy2   = 1.0 / dy2;
 | 
			
		||||
    double idz2   = 1.0 / dz2;
 | 
			
		||||
    double factor = s->omega * 0.5 * (dx2 * dy2 * dz2) /
 | 
			
		||||
                    (dy2 * dz2 + dx2 * dz2 + dx2 * dy2);
 | 
			
		||||
    double* r    = s->r[level];
 | 
			
		||||
    double epssq = eps * eps;
 | 
			
		||||
    int it       = 0;
 | 
			
		||||
    int pass, ksw, jsw, isw;
 | 
			
		||||
    double res = 1.0;
 | 
			
		||||
 | 
			
		||||
    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) {
 | 
			
		||||
 | 
			
		||||
                    R(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, 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(i, j, k));
 | 
			
		||||
                    res += (R(i, j, k) * R(i, j, k));
 | 
			
		||||
                }
 | 
			
		||||
                isw = 3 - isw;
 | 
			
		||||
@@ -167,7 +216,7 @@ static double multiGrid(
 | 
			
		||||
{
 | 
			
		||||
    double res = 0.0;
 | 
			
		||||
 | 
			
		||||
    // coarsest level TODO: Use direct solver?
 | 
			
		||||
    // coarsest level
 | 
			
		||||
    if (level == COARSEST_LEVEL) {
 | 
			
		||||
        for (int i = 0; i < 5; i++) {
 | 
			
		||||
            smooth(s, p, rhs, level, imax, jmax, kmax);
 | 
			
		||||
@@ -175,17 +224,18 @@ static double multiGrid(
 | 
			
		||||
        return res;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // pre-smoothing TODO: Make smoothing steps configurable?
 | 
			
		||||
    for (int i = 0; i < 5; i++) {
 | 
			
		||||
    // pre-smoothing
 | 
			
		||||
    for (int i = 0; i < s->presmooth; i++) {
 | 
			
		||||
        smooth(s, p, rhs, level, imax, jmax, kmax);
 | 
			
		||||
        if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax, kmax);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    res = calculateResidual(s, p, rhs, level, imax, jmax, kmax);
 | 
			
		||||
 | 
			
		||||
    // restrict
 | 
			
		||||
    restrictMG(s, level, imax, jmax, kmax);
 | 
			
		||||
 | 
			
		||||
    // MGSolver on residual and error.
 | 
			
		||||
    // TODO: What if there is a rest?
 | 
			
		||||
    multiGrid(s,
 | 
			
		||||
        s->e[level + 1],
 | 
			
		||||
        s->r[level + 1],
 | 
			
		||||
@@ -202,8 +252,8 @@ static double multiGrid(
 | 
			
		||||
    if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax, kmax);
 | 
			
		||||
 | 
			
		||||
    // post-smoothing
 | 
			
		||||
    for (int i = 0; i < 5; i++) {
 | 
			
		||||
        res = smooth(s, p, rhs, level, imax, jmax, kmax);
 | 
			
		||||
    for (int i = 0; i < s->postsmooth; i++) {
 | 
			
		||||
        smooth(s, p, rhs, level, imax, jmax, kmax);
 | 
			
		||||
        if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax, kmax);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -212,11 +262,13 @@ static double multiGrid(
 | 
			
		||||
 | 
			
		||||
void initSolver(Solver* s, Discretization* d, Parameter* p)
 | 
			
		||||
{
 | 
			
		||||
    s->eps     = p->eps;
 | 
			
		||||
    s->omega   = p->omg;
 | 
			
		||||
    s->itermax = p->itermax;
 | 
			
		||||
    s->levels  = p->levels;
 | 
			
		||||
    s->grid    = &d->grid;
 | 
			
		||||
    s->eps        = p->eps;
 | 
			
		||||
    s->omega      = p->omg;
 | 
			
		||||
    s->itermax    = p->itermax;
 | 
			
		||||
    s->levels     = p->levels;
 | 
			
		||||
    s->grid       = &d->grid;
 | 
			
		||||
    s->presmooth  = p->presmooth;
 | 
			
		||||
    s->postsmooth = p->postsmooth;
 | 
			
		||||
 | 
			
		||||
    int imax   = s->grid->imax;
 | 
			
		||||
    int jmax   = s->grid->jmax;
 | 
			
		||||
 
 | 
			
		||||
@@ -18,6 +18,7 @@ typedef struct {
 | 
			
		||||
    int itermax;
 | 
			
		||||
    int levels;
 | 
			
		||||
    double **r, **e;
 | 
			
		||||
    int presmooth, postsmooth;
 | 
			
		||||
} Solver;
 | 
			
		||||
 | 
			
		||||
extern void initSolver(Solver*, Discretization*, Parameter*);
 | 
			
		||||
 
 | 
			
		||||
@@ -70,6 +70,7 @@ void vtkScalar(VtkOptions* o, char* name, double* s)
 | 
			
		||||
        exit(EXIT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
    fprintf(o->fh, "SCALARS %s float\n", name);
 | 
			
		||||
    fprintf(o->fh, "LOOKUP_TABLE default\n");
 | 
			
		||||
 | 
			
		||||
    for (int k = 0; k < kmax; k++) {
 | 
			
		||||
        for (int j = 0; j < jmax; j++) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user