//This source code was created by Kostas Theocharis (kostastheoSam@gmail.com) and Tasos Papadopoulos (tasospap1995@gmail.com) for the pusrposes of the module "Computational Techniques and Solution Algorithms" of the "Computational Mechanics" Postgraduate Program //Ιn case you have questions or corrections regarding the code, contact one of the authors at the emails found above #include #include #include using namespace std; void msip5(double** A, double psi, int N, int jmax); void msip9(double** LU, double** A,double psi, int N, int jmax); void rhs_constructor(double* rhs, double** A, double* b, double* u, int N, int jmax, int stencil); int main() { //-----------Variable declaration and user inputs---------- int solver,imax,jmax,N,maxiter,stencil,i,j,k,write,iter,selection,extra_iter; double psi,tol,omega,dx,dy,res_init,res,err,err_init; cout<<"This program solves the Poisson Equation u_xx+u_yy=4 , 0<=x<=1 , 0<=y<=1, with Dirichlet boundary conditions on all boundaries, using the ILU decomposition algorithms MSIP-5,MSIP-9."<>imax; cout<<"Enter the number of intervals in the y-direction: "; cin>>jmax; cout<<"Select the solver:"<>solver; cout<<"Enter the damping coefficient (0<=psi<1): "; cin>>psi; if (psi<0) psi=0; if (psi>=1) psi = 0.9; cout<<"Enter the relaxation factor: "; cin>>omega; if (omega<=0) omega = 1; if (omega>2) omega = 1; cout<<"Enter the desired relative residual tolerance in exponential form: "; cin>>tol; cout<<"Enter the maximum number of iterations: "; cin>>maxiter; cout<<"Do you want to write the matrices on a .txt file?"<>write; imax++; //number of nodes in the x-direction = number of intervals in the x-direction +1 jmax++; //number of nodes in the y-direction = number of intervals in the y-direction +1 N = imax*jmax; //total number of nodes dx = (double)1/(imax-1); //length of the interval in the x-direction dy = (double)1/(jmax-1); //length of the interval in the y-direction if (solver==1) stencil = 5; else stencil = 9; //----------Dynamic memory allocation---------- double **A; double **LU; double *b; double *du; double *u_exact; double *u; double *w; double *rhs; b = new double [N]; du = new double [N]; u_exact = new double [N]; u = new double [N]; w = new double [N]; rhs = new double [N]; A = new double* [N]; for (i=0;i>selection; if (selection == 1) { cout<<"Select the number of extra iterations: "; cin>>extra_iter; maxiter += extra_iter; } else break; } //count the next iteration iter ++; //solution of the forward system L*w=rhs k=0; w[k] = rhs[k]/LU[k][2]; for (k=1;k=N-jmax-2;k--) du[k] = w[k] - LU[k][3]*du[k+1]; for (k=N-jmax-1;k>=0;k--) du[k] = w[k] - LU[k][3]*du[k+1] - LU[k][4]*du[k+jmax]; //new u for (k=1;k>selection; if (selection == 1) { cout<<"Select the number of extra iterations: "; cin>>extra_iter; maxiter += extra_iter; } else break; } //count the next iteration iter ++; //solution of the forward system L*w=rhs k=0; w[k] = rhs[k]/LU[k][4]; for (k=1;k=N-jmax+1;k--) du[k] = w[k] - LU[k][5]*du[k+1]; k = N-jmax; du[k] = w[k] - LU[k][5]*du[k+1] - LU[k][6]*du[k+jmax-1]; k=N-jmax-1; du[k] = w[k] - LU[k][5]*du[k+1] - LU[k][6]*du[k+jmax-1] - LU[k][7]*du[k+jmax]; for (k=N-jmax-2;k>=0;k--) du[k] = w[k] - LU[k][5]*du[k+1] - LU[k][6]*du[k+jmax-1] - LU[k][7]*du[k+jmax] - LU[k][8]*du[k+jmax+1]; //new u for (k=1;k=0;j--) { for (i=0;i=0;j--) { for (i=0;i