Summary
Heat equation, PDE: –?u(x,y) = 0 on ? ? R2 with ? = [xmin,xmax]x[ymin,ymax]
Boundary condition: u(x,y) given on ??
Discretization: – ui–1,j – ui,j–1 + 4ui,j – ui,j+1 – ui+1,j = 0 for i=0…m-1, j=0…n-1
4 Boundaries: i= –1, i=m, j= –1, j=m
New ordering: (i,j)i=0..m-1, j=0..n-1 ? I= 0..mn-1
Matrix equation: Au = b, A=sparse matrix, b=based on u on ??, u=solution on ?–??
Example with n=m=4, with solution & boundary u(x,y) := x
Linear Equation Solver (SLES) with PETSc
- MatSetValues(A, 1,&I, 1,&J, &v, INSERT_VALUES);
- VecSetValues(b,1,&I,&v,INSERT_VALUES);
- SLESSetOperators(sles,A,A,DIFFERENT_NONZERO_PATTERN);
- SLESSolve(sles,b,x,&its); ? x is the solution vector, ordered with I= 0..mn-1
- printing x in ordering (i,j)i=0..m-1, j=0..n-1 (transposed)
mpirun –np 3 ./heat_petsc –ksp_type cg –m 4 –n 4 –ksp_monitor –sles_view –view_sol –log_summary –options_table –options_left
Solution Grid (without boundary conditions):
0.199977 0.199891 0.199995 0.199985
0.400010 0.400072 0.400007 0.399864
0.600126 0.600078 0.599905 0.599989
0.800019 0.799936 0.799993 0.800014
Norm of error 0.000269002 iterations 7