/* pdenu_eq.c 2D non uniform grid boundary value PDE non iterative */ /* known solution to test method */ /* u(x,y) = exp(x*y)*sin(x+y) */ /* */ /* differential equation to solve */ /* d^2u/dx^2 + 2*d^2u/dy^2 - 3*d^2u/dxdy + y*du/dx - x*du/dy = c(x,y) */ /* exp(x*y)*sin(x+y)*(x*x + 2*y*y -3*x*y -3) */ /* non uniform grid on rectangle -1.0,-1.1 to 1.2,1.3 */ /* */ /* set up and solve system of linear equations */ /* */ /* create two dimensional array with */ /* (nx-2)*(ny-2) rows, one for each equation */ #include "nuderiv.h" #include #include #include #undef abs #define abs(a) ((a)<0.0?(-(a)):(a)) #undef min #define min(a,b) ((a)<(b)?(a):(b)) #undef max #define max(a,b) ((a)>(b)?(a):(b)) static int nx = 11; /* includes boundary */ static int ny = 10; /* includes boundary */ static double xg[11] = {-1.0, -0.9, -0.8, -0.6, -0.3, 0.0, 0.35, 0.65, 0.85, 1.0, 1.2}; static double yg[10] = {-1.1, -1.0, -0.9, -0.6, -0.2, 0.3, 0.8, 1.0, 1.2, 1.3}; /* nx-2 by ny-2 internal, non boundary cells */ static double cxx[11]; /* nuderiv coefficients */ static double cyy[10]; static double cxy[11][10]; static double cx[11]; static double cy[10]; static double coefdxx, coefdyy, coefdxdy, coefdx, coefdy, coefu; static double us[72]; /* solution being computed 9*8 */ static double ut[72][73]; /* temporary equations */ static double error; /* sum of absolute exact-computed */ static double avgerror; /* average error */ static double maxerror; /* maximum cell error */ static double u(double x, double y) /* for boundary and optional check */ { return exp(x*y)*sin(x+y); } static double c(double x, double y) /* RHS of differential equation to solve */ { return exp(x*y)*sin(x+y)*(x*x + 2.0*y*y -3.0*x*y -3.0); } static void check() /* typically not known, instrumentation */ { int i, j; double uexact, err; error = 0.0; maxerror = 0.0; for(i=1; imaxerror) maxerror=err; } } } /* end check */ static void printus() { int i, j; printf("computed solution\n"); for(i=1; i abs_pivot) { i_pivot = i; pivot = B[row[i]][k]; abs_pivot = abs ( pivot ); } } /* have pivot, interchange row pointers */ hold = row[k]; row[k] = row[i_pivot]; row[i_pivot] = hold; /* check for near singular */ if( abs_pivot < 1.0E-10 ) { for(j=k+1; j