EnhancedSolver completed
This commit is contained in:
		@@ -38,9 +38,9 @@ $(BUILD_DIR)/%.s:  %.c
 | 
			
		||||
	$(info ===>  GENERATE ASM  $@)
 | 
			
		||||
	$(CC) -S $(CPPFLAGS) $(CFLAGS) $< -o $@
 | 
			
		||||
 | 
			
		||||
.PHONY: clean distclean tags info asm format
 | 
			
		||||
.PHONY: clean distclean vis vis_clean tags info asm format
 | 
			
		||||
 | 
			
		||||
clean:
 | 
			
		||||
clean: vis_clean
 | 
			
		||||
	$(info ===>  CLEAN)
 | 
			
		||||
	@rm -rf $(BUILD_DIR)
 | 
			
		||||
	@rm -f tags
 | 
			
		||||
@@ -74,6 +74,7 @@ vis:
 | 
			
		||||
	$(info ===>  GENERATE VISUALIZATION)
 | 
			
		||||
	@gnuplot -e "filename='pressure.dat'" ./surface.plot
 | 
			
		||||
	@gnuplot -e "filename='velocity.dat'" ./vector.plot
 | 
			
		||||
	@gnuplot -e "filename='residual.dat'" ./residual.plot
 | 
			
		||||
 | 
			
		||||
vis_clean:
 | 
			
		||||
	$(info ===>  CLEAN VISUALIZATION)
 | 
			
		||||
 
 | 
			
		||||
@@ -15,7 +15,7 @@ bcRight    3			#
 | 
			
		||||
gx    0.0      # Body forces (e.g. gravity)
 | 
			
		||||
gy    0.0      #
 | 
			
		||||
 | 
			
		||||
re    20000.0	   # Reynolds number
 | 
			
		||||
re    36000.0	   # Reynolds number
 | 
			
		||||
 | 
			
		||||
u_init    1.0      # initial value for velocity in x-direction
 | 
			
		||||
v_init    0.0      # initial value for velocity in y-direction
 | 
			
		||||
@@ -56,7 +56,7 @@ postsmooth    5         # Post-smoothning iterations
 | 
			
		||||
# -----------------------
 | 
			
		||||
 | 
			
		||||
numberOfParticles   200
 | 
			
		||||
startTime           10
 | 
			
		||||
startTime           0
 | 
			
		||||
injectTimePeriod    1.0
 | 
			
		||||
writeTimePeriod     0.5
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -25,14 +25,14 @@ p_init    1.0      # initial value for pressure
 | 
			
		||||
# -------------
 | 
			
		||||
 | 
			
		||||
xlength    30.0     # domain size in x-direction
 | 
			
		||||
ylength    4.0	   # domain size in y-direction
 | 
			
		||||
imax       256      # number of interior cells in x-direction
 | 
			
		||||
jmax       64	   # number of interior cells in y-direction
 | 
			
		||||
ylength    4.0	    # domain size in y-direction
 | 
			
		||||
imax       200      # number of interior cells in x-direction
 | 
			
		||||
jmax       40	    # number of interior cells in y-direction
 | 
			
		||||
 | 
			
		||||
# Time Data:
 | 
			
		||||
# ---------
 | 
			
		||||
 | 
			
		||||
te      80.0   # final time
 | 
			
		||||
te      60.0   # final time
 | 
			
		||||
dt      0.02    # time stepsize
 | 
			
		||||
tau     0.5     # safety factor for time stepsize control (<0 constant delt)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -49,7 +49,7 @@ gamma    0.9		# upwind differencing factor gamma
 | 
			
		||||
# ---------
 | 
			
		||||
 | 
			
		||||
levels        3         # Multigrid levels
 | 
			
		||||
presmooth     10        # Pre-smoothning iterations
 | 
			
		||||
presmooth     20        # Pre-smoothning iterations
 | 
			
		||||
postsmooth    5         # Post-smoothning iterations
 | 
			
		||||
 | 
			
		||||
# Particle Tracing Data:
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								EnhancedSolver/2D-seq/residual.plot
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								EnhancedSolver/2D-seq/residual.plot
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
set terminal png size 1800,768 enhanced font ,12
 | 
			
		||||
set output 'residual.png'
 | 
			
		||||
set datafile separator whitespace
 | 
			
		||||
set xlabel "Timestep"
 | 
			
		||||
set ylabel "Residual"
 | 
			
		||||
 | 
			
		||||
set logscale y 2
 | 
			
		||||
 | 
			
		||||
plot 'residual.dat' using 1:2 title "Residual"
 | 
			
		||||
@@ -24,6 +24,8 @@ int main(int argc, char** argv)
 | 
			
		||||
    ParticleTracer particletracer;
 | 
			
		||||
 | 
			
		||||
    initParameter(&p);
 | 
			
		||||
    FILE* fp;
 | 
			
		||||
    fp = initResidualWriter();
 | 
			
		||||
 | 
			
		||||
    if (argc != 2) {
 | 
			
		||||
        printf("Usage: %s <configFile>\n", argv[0]);
 | 
			
		||||
@@ -45,8 +47,9 @@ int main(int argc, char** argv)
 | 
			
		||||
    double te  = d.te;
 | 
			
		||||
    double t   = 0.0;
 | 
			
		||||
    int nt     = 0;
 | 
			
		||||
    double res = 0.0;
 | 
			
		||||
 | 
			
		||||
    timeStart = getTimeStamp();
 | 
			
		||||
    timeStart  = getTimeStamp();
 | 
			
		||||
 | 
			
		||||
    while (t <= te) {
 | 
			
		||||
        if (tau > 0.0) computeTimestep(&d);
 | 
			
		||||
@@ -57,10 +60,12 @@ int main(int argc, char** argv)
 | 
			
		||||
        computeFG(&d);
 | 
			
		||||
        computeRHS(&d);
 | 
			
		||||
        if (nt % 100 == 0) normalizePressure(&d);
 | 
			
		||||
        solve(&s, d.p, d.rhs);
 | 
			
		||||
        res = solve(&s, d.p, d.rhs);
 | 
			
		||||
        adaptUV(&d);
 | 
			
		||||
        trace(&particletracer, d.u, d.v, d.dt, t);
 | 
			
		||||
 | 
			
		||||
        writeResidual(fp, t, res);
 | 
			
		||||
 | 
			
		||||
        t += d.dt;
 | 
			
		||||
        nt++;
 | 
			
		||||
 | 
			
		||||
@@ -73,6 +78,7 @@ int main(int argc, char** argv)
 | 
			
		||||
 | 
			
		||||
    timeStop = getTimeStamp();
 | 
			
		||||
 | 
			
		||||
    fclose(fp);
 | 
			
		||||
    stopProgress();
 | 
			
		||||
    freeParticles(&particletracer);
 | 
			
		||||
    printf("Solution took %.2fs\n", timeStop - timeStart);
 | 
			
		||||
 
 | 
			
		||||
@@ -14,18 +14,20 @@
 | 
			
		||||
 | 
			
		||||
void initParameter(Parameter* param)
 | 
			
		||||
{
 | 
			
		||||
    param->xlength = 1.0;
 | 
			
		||||
    param->ylength = 1.0;
 | 
			
		||||
    param->imax    = 100;
 | 
			
		||||
    param->jmax    = 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->rho     = 0.99;
 | 
			
		||||
    param->levels  = 5;
 | 
			
		||||
    param->xlength    = 1.0;
 | 
			
		||||
    param->ylength    = 1.0;
 | 
			
		||||
    param->imax       = 100;
 | 
			
		||||
    param->jmax       = 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->rho        = 0.99;
 | 
			
		||||
    param->levels     = 5;
 | 
			
		||||
    param->presmooth  = 5;
 | 
			
		||||
    param->postsmooth = 5;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void readParameter(Parameter* param, const char* filename)
 | 
			
		||||
@@ -64,6 +66,8 @@ void readParameter(Parameter* param, const char* filename)
 | 
			
		||||
            PARSE_INT(jmax);
 | 
			
		||||
            PARSE_INT(itermax);
 | 
			
		||||
            PARSE_INT(levels);
 | 
			
		||||
            PARSE_INT(presmooth);
 | 
			
		||||
            PARSE_INT(postsmooth);
 | 
			
		||||
            PARSE_REAL(eps);
 | 
			
		||||
            PARSE_REAL(omg);
 | 
			
		||||
            PARSE_REAL(re);
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
typedef struct {
 | 
			
		||||
    double xlength, ylength;
 | 
			
		||||
    int imax, jmax;
 | 
			
		||||
    int itermax, levels;
 | 
			
		||||
    int itermax, levels, presmooth, postsmooth;
 | 
			
		||||
    double eps, omg, rho;
 | 
			
		||||
    double re, tau, gamma;
 | 
			
		||||
    double te, dt;
 | 
			
		||||
 
 | 
			
		||||
@@ -110,7 +110,7 @@ static void compress(ParticleTracer* p)
 | 
			
		||||
    Particle tempPool[p->totalParticles];
 | 
			
		||||
    int totalParticles = 0;
 | 
			
		||||
 | 
			
		||||
    printf("Performing compression ...");
 | 
			
		||||
    // printf("Performing compression ...");
 | 
			
		||||
 | 
			
		||||
    for (int i = 0; i < p->totalParticles; i++) {
 | 
			
		||||
        if (memPool[i].flag == 1) {
 | 
			
		||||
@@ -121,7 +121,7 @@ static void compress(ParticleTracer* p)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    printf(" remove %d particles\n", p->totalParticles - totalParticles);
 | 
			
		||||
    // printf(" remove %d particles\n", p->totalParticles - totalParticles);
 | 
			
		||||
    p->totalParticles   = totalParticles;
 | 
			
		||||
    p->removedParticles = 0;
 | 
			
		||||
    p->pointer          = totalParticles + 1;
 | 
			
		||||
@@ -130,7 +130,9 @@ static void compress(ParticleTracer* p)
 | 
			
		||||
 | 
			
		||||
void writeParticles(ParticleTracer* p)
 | 
			
		||||
{
 | 
			
		||||
    static int ts   = 0;
 | 
			
		||||
    static int ts = 0;
 | 
			
		||||
    compress(p);
 | 
			
		||||
    
 | 
			
		||||
    VtkOptions opts = { .particletracer = p };
 | 
			
		||||
 | 
			
		||||
    char filename[50];
 | 
			
		||||
 
 | 
			
		||||
@@ -49,3 +49,21 @@ void stopProgress()
 | 
			
		||||
    printf("\n");
 | 
			
		||||
    fflush(stdout);
 | 
			
		||||
}
 | 
			
		||||
FILE* initResidualWriter()
 | 
			
		||||
{
 | 
			
		||||
    FILE* fp;
 | 
			
		||||
    fp = fopen("residual.dat", "w");
 | 
			
		||||
 | 
			
		||||
    if (fp == NULL) {
 | 
			
		||||
        printf("Error!\n");
 | 
			
		||||
        exit(EXIT_FAILURE);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return fp;
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void writeResidual(FILE* fp, double ts, double res)
 | 
			
		||||
{
 | 
			
		||||
    fprintf(fp, "%f, %f\n", ts, res);
 | 
			
		||||
}
 | 
			
		||||
@@ -10,5 +10,6 @@
 | 
			
		||||
extern void initProgress(double);
 | 
			
		||||
extern void printProgress(double);
 | 
			
		||||
extern void stopProgress(void);
 | 
			
		||||
 | 
			
		||||
extern FILE* initResidualWriter(void);
 | 
			
		||||
extern void writeResidual(FILE*, double, double);
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,38 @@ static void setBoundaryCondition(double* p, int imax, int jmax)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static double smooth(Solver* s, double* p, double* rhs, int level, int imax, int jmax)
 | 
			
		||||
static void smooth(Solver* s, double* p, double* rhs, int level, int imax, int jmax)
 | 
			
		||||
{
 | 
			
		||||
    double dx2    = s->grid->dx * s->grid->dx;
 | 
			
		||||
    double dy2    = s->grid->dy * s->grid->dy;
 | 
			
		||||
    double idx2   = 1.0 / dx2;
 | 
			
		||||
    double idy2   = 1.0 / dy2;
 | 
			
		||||
    double factor = s->omega * 0.5 * (dx2 * dy2) / (dx2 + dy2);
 | 
			
		||||
    double* r     = s->r[level];
 | 
			
		||||
    double res    = 1.0;
 | 
			
		||||
    int pass, jsw, isw;
 | 
			
		||||
 | 
			
		||||
    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) {
 | 
			
		||||
 | 
			
		||||
                P(i, j) -= factor * (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));
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            isw = 3 - isw;
 | 
			
		||||
        }
 | 
			
		||||
        jsw = 3 - jsw;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static double calculateResidual(Solver* s, double* p, double* rhs, int level, int imax, int jmax)
 | 
			
		||||
{
 | 
			
		||||
    double dx2    = s->grid->dx * s->grid->dx;
 | 
			
		||||
    double dy2    = s->grid->dy * s->grid->dy;
 | 
			
		||||
@@ -94,7 +125,6 @@ static double smooth(Solver* s, double* p, double* rhs, int level, int imax, int
 | 
			
		||||
                          ((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(i, j));
 | 
			
		||||
                res += (R(i, j) * R(i, j));
 | 
			
		||||
            }
 | 
			
		||||
            isw = 3 - isw;
 | 
			
		||||
@@ -110,7 +140,7 @@ static double multiGrid(Solver* s, double* p, double* rhs, int level, int imax,
 | 
			
		||||
{
 | 
			
		||||
    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);
 | 
			
		||||
@@ -118,17 +148,18 @@ static double multiGrid(Solver* s, double* p, double* rhs, int level, int imax,
 | 
			
		||||
        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);
 | 
			
		||||
        if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    res = calculateResidual(s, p, rhs, level, imax, jmax);
 | 
			
		||||
 | 
			
		||||
    // restrict
 | 
			
		||||
    restrictMG(s, level, imax, jmax);
 | 
			
		||||
 | 
			
		||||
    // MGSolver on residual and error.
 | 
			
		||||
    // TODO: What if there is a rest?
 | 
			
		||||
    multiGrid(s, s->e[level + 1], s->r[level + 1], level + 1, imax / 2, jmax / 2);
 | 
			
		||||
 | 
			
		||||
    // prolongate
 | 
			
		||||
@@ -139,8 +170,8 @@ static double multiGrid(Solver* s, double* p, double* rhs, int level, int imax,
 | 
			
		||||
    if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax);
 | 
			
		||||
 | 
			
		||||
    // post-smoothing
 | 
			
		||||
    for (int i = 0; i < 5; i++) {
 | 
			
		||||
        res = smooth(s, p, rhs, level, imax, jmax);
 | 
			
		||||
    for (int i = 0; i < s->postsmooth; i++) {
 | 
			
		||||
        smooth(s, p, rhs, level, imax, jmax);
 | 
			
		||||
        if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -154,6 +185,8 @@ void initSolver(Solver* s, Discretization* d, Parameter* p)
 | 
			
		||||
    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;
 | 
			
		||||
@@ -176,11 +209,13 @@ void initSolver(Solver* s, Discretization* d, Parameter* p)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
double solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
{
 | 
			
		||||
    double res = multiGrid(s, p, rhs, 0, s->grid->imax, s->grid->jmax);
 | 
			
		||||
 | 
			
		||||
#ifdef VERBOSE
 | 
			
		||||
    printf("Residuum: %.6f\n", res);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
return res;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,18 +18,9 @@ void initSolver(Solver* s, Discretization* d, Parameter* p)
 | 
			
		||||
    Grid* g  = s->grid;
 | 
			
		||||
    int imax = s->grid->imax;
 | 
			
		||||
    int jmax = s->grid->jmax;
 | 
			
		||||
 | 
			
		||||
    s->totalFluidCells = 0;
 | 
			
		||||
    for (int j = 0; j < jmax + 2; j++) {
 | 
			
		||||
        for (int i = 0; i < imax + 2; i++) {
 | 
			
		||||
            if (gridIsFluid(g, i, j)) {
 | 
			
		||||
                s->totalFluidCells++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
double solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
{
 | 
			
		||||
    int imax      = s->grid->imax;
 | 
			
		||||
    int jmax      = s->grid->jmax;
 | 
			
		||||
@@ -55,15 +46,13 @@ void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
 | 
			
		||||
            for (int j = 1; j < jmax + 1; j++) {
 | 
			
		||||
                for (int i = isw; i < imax + 1; i += 2) {
 | 
			
		||||
                    if (gridIsFluid(g, i, j)) {
 | 
			
		||||
                        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);
 | 
			
		||||
                    }
 | 
			
		||||
                    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);
 | 
			
		||||
                }
 | 
			
		||||
                isw = 3 - isw;
 | 
			
		||||
            }
 | 
			
		||||
@@ -80,7 +69,7 @@ void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
            P(imax + 1, j) = P(imax, j);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        res = res / (double)(s->totalFluidCells);
 | 
			
		||||
        res = res / (double)(imax * jmax);
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
        printf("%d Residuum: %e\n", it, res);
 | 
			
		||||
#endif
 | 
			
		||||
@@ -90,4 +79,6 @@ void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
#ifdef VERBOSE
 | 
			
		||||
    printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -18,18 +18,9 @@ void initSolver(Solver* s, Discretization* d, Parameter* p)
 | 
			
		||||
    Grid* g  = s->grid;
 | 
			
		||||
    int imax = s->grid->imax;
 | 
			
		||||
    int jmax = s->grid->jmax;
 | 
			
		||||
 | 
			
		||||
    s->totalFluidCells = 0;
 | 
			
		||||
    for (int j = 0; j < jmax + 2; j++) {
 | 
			
		||||
        for (int i = 0; i < imax + 2; i++) {
 | 
			
		||||
            if (gridIsFluid(g, i, j)) {
 | 
			
		||||
                s->totalFluidCells++;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
double solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
{
 | 
			
		||||
    int imax      = s->grid->imax;
 | 
			
		||||
    int jmax      = s->grid->jmax;
 | 
			
		||||
@@ -50,14 +41,12 @@ void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
 | 
			
		||||
        for (int j = 1; j < jmax + 1; j++) {
 | 
			
		||||
            for (int i = 1; i < imax + 1; i++) {
 | 
			
		||||
                if (gridIsFluid(g, i, j)) {
 | 
			
		||||
                    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);
 | 
			
		||||
                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);
 | 
			
		||||
                }
 | 
			
		||||
                P(i, j) -= (factor * r);
 | 
			
		||||
                res += (r * r);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@@ -71,7 +60,7 @@ void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
            P(imax + 1, j) = P(imax, j);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        res = res / (double)(s->totalFluidCells);
 | 
			
		||||
        res = res / (double)(imax * jmax);
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
        printf("%d Residuum: %e\n", it, res);
 | 
			
		||||
#endif
 | 
			
		||||
@@ -81,4 +70,6 @@ void solve(Solver* s, double* p, double* rhs)
 | 
			
		||||
#ifdef VERBOSE
 | 
			
		||||
    printf("Solver took %d iterations to reach %f\n", it, sqrt(res));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    return res;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -16,12 +16,12 @@ typedef struct {
 | 
			
		||||
    /* parameters */
 | 
			
		||||
    double eps, omega, rho;
 | 
			
		||||
    int itermax;
 | 
			
		||||
    int levels;
 | 
			
		||||
    int levels, presmooth, postsmooth;
 | 
			
		||||
    int totalFluidCells;
 | 
			
		||||
    double **r, **e;
 | 
			
		||||
} Solver;
 | 
			
		||||
 | 
			
		||||
extern void initSolver(Solver*, Discretization*, Parameter*);
 | 
			
		||||
extern void solve(Solver*, double*, double*);
 | 
			
		||||
extern double solve(Solver*, double*, double*);
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user