forked from moebiusband/NuSiF-Solver
		
	Cleanup
This commit is contained in:
		| @@ -20,6 +20,7 @@ int main(int argc, char** argv) | ||||
|     Parameter p; | ||||
|     Discretization d; | ||||
|     Solver s; | ||||
|      | ||||
|     initParameter(&p); | ||||
|  | ||||
|     if (argc != 2) { | ||||
| @@ -31,6 +32,7 @@ int main(int argc, char** argv) | ||||
|     printParameter(&p); | ||||
|     initDiscretization(&d, &p); | ||||
|     initSolver(&s, &d, &p); | ||||
|      | ||||
| #ifndef VERBOSE | ||||
|     initProgress(d.te); | ||||
| #endif | ||||
|   | ||||
| @@ -9,15 +9,14 @@ | ||||
| #include <string.h> | ||||
|  | ||||
| #include "parameter.h" | ||||
| #include "util.h" | ||||
| #define MAXLINE 4096 | ||||
|  | ||||
| void initParameter(Parameter* param) | ||||
| { | ||||
|     param->xlength = 1.0; | ||||
|     param->ylength = 1.0; | ||||
|     param->imax    = 100; | ||||
|     param->jmax    = 100; | ||||
|     param->imax    = 128; | ||||
|     param->jmax    = 128; | ||||
|     param->itermax = 1000; | ||||
|     param->eps     = 0.0001; | ||||
|     param->omg     = 1.7; | ||||
|   | ||||
| @@ -12,7 +12,7 @@ | ||||
| #include "util.h" | ||||
|  | ||||
| #define FINEST_LEVEL   0 | ||||
| #define COARSEST_LEVEL (solver->levels - 1) | ||||
| #define COARSEST_LEVEL (s->levels - 1) | ||||
| #define S(i, j)        s[(j) * (imax + 2) + (i)] | ||||
| #define E(i, j)        e[(j) * (imax + 2) + (i)] | ||||
| #define R(i, j)        r[(j) * (imax + 2) + (i)] | ||||
| @@ -106,47 +106,41 @@ static double smooth(Solver* s, double* p, double* rhs, int level, int imax, int | ||||
|     return res; | ||||
| } | ||||
|  | ||||
| static double multiGrid( | ||||
|     Solver* solver, double* p, double* rhs, int level, int imax, int jmax) | ||||
| static double multiGrid(Solver* s, double* p, double* rhs, int level, int imax, int jmax) | ||||
| { | ||||
|     double res = 0.0; | ||||
|  | ||||
|     // coarsest level TODO: Use direct solver? | ||||
|     if (level == (solver->levels - 1)) { | ||||
|     if (level == COARSEST_LEVEL) { | ||||
|         for (int i = 0; i < 5; i++) { | ||||
|             smooth(solver, p, rhs, level, imax, jmax); | ||||
|             smooth(s, p, rhs, level, imax, jmax); | ||||
|         } | ||||
|         return res; | ||||
|     } | ||||
|  | ||||
|     // pre-smoothing TODO: Make smoothing steps configurable? | ||||
|     for (int i = 0; i < 5; i++) { | ||||
|         smooth(solver, p, rhs, level, imax, jmax); | ||||
|         smooth(s, p, rhs, level, imax, jmax); | ||||
|         if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax); | ||||
|     } | ||||
|  | ||||
|     // restrict | ||||
|     restrictMG(solver, level, imax, jmax); | ||||
|     restrictMG(s, level, imax, jmax); | ||||
|  | ||||
|     // MGSolver on residual and error. | ||||
|     // TODO: What if there is a rest? | ||||
|     multiGrid(solver, | ||||
|         solver->e[level + 1], | ||||
|         solver->r[level + 1], | ||||
|         level + 1, | ||||
|         imax / 2, | ||||
|         jmax / 2); | ||||
|     multiGrid(s, s->e[level + 1], s->r[level + 1], level + 1, imax / 2, jmax / 2); | ||||
|  | ||||
|     // prolongate | ||||
|     prolongate(solver, level, imax, jmax); | ||||
|     prolongate(s, level, imax, jmax); | ||||
|  | ||||
|     // correct p on finer level using residual | ||||
|     correct(solver, p, level, imax, jmax); | ||||
|     correct(s, p, level, imax, jmax); | ||||
|     if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax); | ||||
|  | ||||
|     // post-smoothing | ||||
|     for (int i = 0; i < 5; i++) { | ||||
|         res = smooth(solver, p, rhs, level, imax, jmax); | ||||
|         res = smooth(s, p, rhs, level, imax, jmax); | ||||
|         if (level == FINEST_LEVEL) setBoundaryCondition(p, imax, jmax); | ||||
|     } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user