/* pdenu23_eq.c 3D non uniform grid boundary value PDE */ /* known solution to test method */ /* u(x,y,z) = x^3+2y^3+3z^3+4x^2y+5zy^2+6zx^2+7xy+8z+9 */ /* */ /* differential equation to solve */ /* d^2u/dx^2 + 2*d^2u/dy^2 + 3*d^2u/dz^2 + 4*d^2u/dxdy + 5*d^u/dxdz +*/ /* 6*d^2u/dydz + 7*du/dx + 8*du/dy + 9*du/dz + 10*u = */ /* 10x^3+20y^3+30z^3+40x^2y+50y^2z+60z^2x+53x^2+93y^2+123z^2+126xy+ */ /* 80yz+108zx+130x+141y+214z+190 */ /* non uniform grid on cude (-1.0,-1.1,-1.2) to (1.2,1.3,1.4) */ /* */ /* set up and solve system of linear equations */ /* */ /* create two dimensional array with */ /* (nx-2)*(ny-2)*(nz-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 int nz = 9; /* 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}; static double zg[10] = {-1.2, -1.0, -0.9, -0.5, 0.0, 0.5, 0.9, 1.2, 1.4}; /* nx-2 by ny-2 by nz-2 internal, non boundary cells */ static double cxx[11]; /* nuderiv coefficients */ static double cyy[10]; static double czz[9]; static double cxy[11][10]; static double cxz[11][9]; static double cyz[10][9]; static double cx[11]; static double cy[10]; static double cz[9]; static double coefdxx, coefdyy, coefdzz, coefdxdy, coefdxdz, coefdydz, coefdx, coefdy, coefdz, coefu; static double us[504]; /* solution being computed 9*8*7 */ static double ut[504][505]; /* 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, double z) /* for boundary and optional check */ { return x*x*x + 2.0*y*y*y + 3.0*z*z*z + 4.0*x*x*y + 5.0*y*y*z + 6.0*z*z*x + 7.0*x*y + 8.0*z + 9.0; } static double c(double x, double y, double z) /* RHS of differential equation to solve */ { return 10.0*x*x*x + 20.0*y*y*y + 30.0*z*z*z + 40.0*x*x*y + 50.0*y*y*z + 60.0*z*z*x + 53.0*x*x + 93.0*y*y + 123.0*z*z + 126.0*x*y + 108.0*x*z + 80.0*y*z + 130.0*x + 141.0*y + 214.0*z + 190.0; } static void check() /* typically not known, instrumentation */ { int i, j, k; double uexact, err; error = 0.0; maxerror = 0.0; for(i=1; imaxerror) maxerror=err; } } } } /* end check */ static void printus() { int i, j, k; 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