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