// pde22a_eqp.java 2D uniform grid boundary value PDE using parts // known solution to test method using np=7 // solve uxx + 2*uxy + 3*uyy + 4*ux + 5*uy + 6*u = f(x,y) // f(x,y) = 6 x^2 + 18 xy + 12 y^2 + 47 x + 62 y + 97 // Analytic solution u(x,y)=x^2 + 2 y^2 + 3 xy + 4 x + 5 y + 6 // inside 0,1 by 0,1 grid // // using 9 parts, 3 each for nx, then inside 3 each for ny // row check in each of 9 parts // all changes in init_matrix, rest should be the same // // set up and solve system of (nx-2)*(ny-2) linear equations // // uses rderiv.java // uses simeq.java import java.text.*; import java.io.*; class pde22a_eqp { int np = 7; // number of points in derivative int nx = 20; // includes boundary int ny = 21; // includes boundary boolean debug = false; double xg[] = new double[nx]; double yg[] = new double[ny]; double cxx[] = new double[nx]; // rderiv coefficients double cyy[] = new double[ny]; double cx[] = new double[nx]; double cy[] = new double[ny]; // nx-2 by ny-2 internal, non boundary cells int neqn = (nx-2)*(ny-2); int cs = neqn; double us[] = new double[neqn]; // solution being computed double ut[][] = new double[neqn][neqn+1]; // equations incl RHS double xmin = 0.0; double xmax = 1.0; double ymin = 0.1; double ymax = 1.1; double hx, hy; double error; // sum of absolute exact-computed double avgerror; // average error double maxerror; // maximum cell error double time_start; double time_now; double time_last; DecimalFormat fe = new DecimalFormat("0.00E00"); DecimalFormat f6 = new DecimalFormat("0.00000"); pde22a_eqp() { System.out.println("pde22a_eqp.java running"); System.out.println("differential equation to solve"); System.out.println("uxx+2*uxy+3*uyy+4*ux+5*uy+6*u=f(x,y)"); System.out.println("f(x,y) = 6 x^2 + 18 xy + 12 y^2 + 47 x + 62 y + 97"); System.out.println("uniform grid on rectangle 0,1 to 0.1,1.1"); System.out.println("known Solution, for testing method"); System.out.println("u(x,y) = x^2 + 2 y^2 + 3 xy + 4 x + 5 y + 6"); System.out.println(" "); time_start = (double)System.currentTimeMillis()/1000.0; time_last = time_start; hx = (xmax-xmin)/(double)(nx-1); hy = (ymax-ymin)/(double)(ny-1); for(int i=0; imaxerror) maxerror=err; } } } // end check void check_rows() // only for(checking { // row is in ut solution coordinates int row, col; double sum, sum1; for(int i=1; i0.001) { System.out.println("row i="+i+", j="+j+", is bad err="+sum); } } // j } //i } // end check_rows void print() // typically not known { double error = 0.0; double max_error = 0.0; double avg_error = 0.0; System.out.println("exact solution u, computed us, error"); for(int i=1; imax_error) max_error = Math.abs(error); System.out.println("xg["+i+"]="+f6.format(xg[i])+ ", yg["+j+"]="+f6.format(yg[j])+ ", u="+f6.format(u(xg[i],yg[j]))+ ", us="+f6.format(us[S(i,j)])+ ", err="+fe.format(error)); } } System.out.println("max_error="+max_error+", avg_error="+ avg_error/(double)neqn); System.out.println(" "); } // end print void printB() { System.out.println("matrix B includes RHS"); for(int i=1; i smaxerr) smaxerr = Math.abs(err); } // j y } // i x System.out.println("check computed soln against PDE max error="+smaxerr); System.out.println("x="+xg[nx-2]+", y="+yg[ny-2]); System.out.println("uxx="+uxx+", uyy="+uyy+", ux="+ux+", uy="+uy); System.out.println("uxy="+uxy+", us="+us[S(nx-2,ny-2)]); System.out.println("f(x,y)="+f(xg[nx-2],yg[ny-2])); System.out.println(" "); } // end Check_Soln // write_soln2 for gnuplot void write_soln2(double Ux[]) { try { FileWriter fout = new FileWriter("pde22a_eqp_java.dat"); BufferedWriter fileout = new BufferedWriter(fout); System.out.println("writing pde22a_eqp_java.dat"); for(int i=0; i