// corner0.java 2D uniform grid boundary value PDE // known solution to test method // alpha = Pi/omega // r = sqrt(x^2+y^2) // theta = atan2(y,x) 0..2Pi // u(x,y) = r^alpha * sin(alpha*theta) // // differential equation to solve // d^2u/dx^2 + d^2u/dy^2 = 0 // // uniform grid on rectangle -1 to 1, -1 to 1 // set up and solve system of (nx-2)*(ny-2) linear equations // // uses nuderiv.java // uses simeq.java import java.text.*; import java.io.*; class corner0 { int nx = 11; // includes boundary int ny = 11; // includes boundary double xg[] = new double[nx]; double yg[] = new double[ny]; double cxx[] = new double[nx]; // nuderiv coefficients double cyy[] = 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 = -1.0; double xmax = 1.0; double ymin = -1.0; double ymax = 1.0; 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"); corner0() { System.out.println("corner0.java running"); System.out.println("differential equation to solve"); System.out.println("d^2u/dx^2 + d^2u/dy^2 = 0"); System.out.println("uniform grid on rectangle -1,1 to -1,1"); System.out.println("known Solution, for testing method"); System.out.println("omega = 2Pi"); System.out.println("alpha = Pi/omega"); System.out.println("theta = atan2(y,x) 0..2Pi"); System.out.println("u(x,y) = r^alpha * sin(alpha*theta)"); 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; 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); } // ii y } // i x System.out.println("check soln against PDE max error="+smaxerr); } // end Check_Soln // write_soln2 for gnuplot void write_soln2(double Ux[]) { try { FileWriter fout = new FileWriter("corner0_java.dat"); BufferedWriter fileout = new BufferedWriter(fout); System.out.println("writing corner0_java.dat"); for(int i=0; i