// pdenu22_eq.java 2D non uniform grid boundary value PDE non iterative // known solution to test method // u(x,y) = x^3+2y^3+3x^2y+4xy^2+5x^2+6y^2+7x+8 // // differential equation to solve // d^2u/dx^2 + 2*d^2u/dy^2 + 3*d^2u/dxdy + 4*du/dx + 5*du/dy +6*u = c(x,y) // c(x,y) = 6x^3+12y^3+18x^2y+24xy^2+57x^2+82y^2+64xy+122x+114y+110 // 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 // uses nuderiv.java // uses simeq.java import java.text.*; class pdenu22_eq { int nx = 11; // includes boundary int ny = 10; // includes boundary double xg[] = {-1.0, -0.9, -0.8, -0.6, -0.3, 0.0, 0.35, 0.65, 0.85, 1.0, 1.2}; double yg[] = {-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 double cxx[] = new double[nx]; // nuderiv coefficients double cyy[] = new double[ny]; double cxy[][] = new double[nx][ny]; double cx[] = new double[nx]; double cy[] = new double[ny]; double coefdxx, coefdyy, coefdxdy, coefdx, coefdy, coefu; int nxy = (nx-2)*(ny-2); // inside boundaries double us[] = new double[nxy]; // solution being computed 9*8 double ut[][] = new double[nxy][nxy+1]; // temporary equations double error; // sum of absolute exact-computed double avgerror; // average error double maxerror; // maximum cell error DecimalFormat fe = new DecimalFormat("0.00E00"); DecimalFormat f6 = new DecimalFormat("0.00000"); pdenu22_eq() { System.out.println("pdenu22_eq.java running"); System.out.println("differential equation to solve"); System.out.println("d^2u/dx^2 + 2*d^2u/dy^2 + 3*d^2u/dxdy + 4*du/dx + 5*du/dy +6*u = c(x,y)"); System.out.println("c(x,y) = 6x^3+12y^3+18x^2y+24xy^2+57x^2+82y^2+64xy+122x+114y+110"); System.out.println("non uniform grid on rectangle -1.0,-1.1 to 1.2,1.3"); System.out.println("known solution, U(x,y), to test method"); System.out.println("u(x,y) = x^3+2y^3+3x^2y+4xy^2+5x^2+6y^2+7x+8"); System.out.println("xmin="+f6.format(xg[0])+ ", xmax="+f6.format(xg[nx-1])+ ", nx="+nx); System.out.println("ymin="+f6.format(yg[0])+ ", ymax="+f6.format(yg[ny-1])+ ", ny="+ny); System.out.println("u(xg[0],yg[0])="+f6.format(u(xg[0],yg[0]))); System.out.println("c(xg[0],yg[0])="+f6.format(c(xg[0],yg[0]))); init_matrix(); System.out.println("matrix initialized"); System.out.println("initial matrix, left side, upper "); for(int i=0; i<8; i++) { for(int j=0; j<8; j++) { System.out.print(" "+f6.format(ut[i][j])); } System.out.println(" "); } System.out.println("initial matrix, right side, upper "); for(int i=0; i<8; i++) { for(int j=65; j<73; j++) { System.out.print(" "+f6.format(ut[i][j])); } System.out.println(" "); } System.out.println("initial matrix, left side, lower "); for(int i=64; i<72; i++) { for(int j=0; j<8; j++) { System.out.print(" "+f6.format(ut[i][j])); } System.out.println(" "); } System.out.println("initial matrix, right side, lower "); for(int i=64; i<72; i++) { for(int j=65; j<73; j++) { System.out.print(" "+f6.format(ut[i][j])); } System.out.println(" "); } System.out.println(" "); new simeq(nxy, ut, us); printexact(); check(); avgerror = error/(double)(nxy); System.out.println("total error="+fe.format(error)+ ", average error="+fe.format(avgerror)+ ", max error="+fe.format(maxerror)); } // end pdenu22_eq double u(double x, double y) // for boundary and optional check { return x*x*x + 2.0*y*y*y + 3.0*x*x*y + 4.0*x*y*y + 5.0*x*x + 6.0*y*y + 7.0*x + 8.0; } double c(double x, double y) // RHS of differential equation to solve { return 6.0*x*x*x + 12.0*y*y*y + 18.0*x*x*y + 24.0*x*y*y + 57.0*x*x + 82.0*y*y + 64.0*x*y + 122.0*x + 114.0*y + 110.0; } void check() // typically not known, instrumentation { double uexact, err; error = 0.0; maxerror = 0.0; for(int i=1; imaxerror) maxerror=err; } } } // end check void printexact() // typically not known { System.out.println("exact solution u, computed us, error"); for(int i=1; i