void DiagonalizationPoisson1Dfst(Vector u, const Vector lambda) { Vector btilde = createVector(u->len); Vector buf = createVector(4*(u->len+1)); int i; int N=u->len+1; int NN=4*N; copyVector(btilde, u); fst(btilde->data, &N, buf->data, &NN); for (i=0;i<btilde->len;++i) btilde->data[i] /= (lambda->data[i]+alpha); fstinv(btilde->data, &N, buf->data, &NN); copyVector(u, btilde); freeVector(btilde); freeVector(buf); }
int main(int argc, char** argv) { int rank, size; init_app(argc, argv, &rank, &size); if (argc < 2) { printf("usage: %s <N> [L]\n",argv[0]); close_app(); return 1; } /* the total number of grid points in each spatial direction is (N+1) */ /* the total number of degrees-of-freedom in each spatial direction is (N-1) */ int N = atoi(argv[1]); int M = N-1; double L=1; if (argc > 2) L = atof(argv[2]); double h = L/N; Vector lambda = createEigenValues(M); Vector grid = createVector(M); for (int i=0;i<M;++i) grid->data[i] = (i+1)*h; Matrix u = createMatrix(M, M); Matrix ut = createMatrix(M, M); evalMesh(u->as_vec, grid, grid, poisson_source); scaleVector(u->as_vec, h*h); int NN = 4*N; Vector z = createVector(NN); double time = WallTime(); for (int j=0; j < M; j++) fst(u->data[j], &N, z->data, &NN); transposeMatrix(ut, u); for (int i=0; i < M; i++) fstinv(ut->data[i], &N, z->data, &NN); for (int j=0; j < M; j++) for (int i=0; i < M; i++) ut->data[j][i] /= lambda->data[i]+lambda->data[j]; for (int i=0; i < M; i++) fst(ut->data[i], &N, z->data, &NN); transposeMatrix(u, ut); for (int j=0; j < M; j++) fstinv(u->data[j], &N, z->data, &NN); evalMesh2(u->as_vec, grid, grid, exact_solution, -1.0); double max = maxNorm(u->as_vec); if (rank == 0) { printf("elapsed: %f\n", WallTime()-time); printf("max: %f\n", max); } freeMatrix(u); freeMatrix(ut); freeVector(grid); freeVector(z); freeVector(lambda); close_app(); return 0; }