// pde23_eqn2.java accuracy check pde23_eqn.java // // solve equation in pdedef232.java // class pdedef232(), ccxx(x,y,z) ... ub(x,x,z) f(x,y,z), coefs(coef) // // set up and solve system of (nx-2)*(ny-2)*(nz-2) linear equations // // uses nuderiv.java // uses invert.java // uses simeq.java // uses pdedef232.java to define problem import java.text.*; import java.io.*; class pde23_eqn2 { pdedef232 D = new pdedef232(); int nx = D.nx; int ny = D.ny; int nz = D.nz; int neqn = (nx-2)*(ny-2)*(nz-2); // dim-2 internal, non boundary cells int cs = neqn; // index of RHS double xg[] = new double[nx]; // data points double yg[] = new double[ny]; double zg[] = new double[nz]; double us[] = new double[neqn]; // solution being computed double U[] = new double[neqn]; // known solution double ut[][] = new double[neqn][neqn+1]; // equations incl RHS pde23_eqn2() { double error; // sum of absolute exact-computed double avgerror; // average error double maxerror; // maximum cell error double coef[] = new double[9]; double xmin, xmax, hx; double ymin, ymax, hy; double zmin, zmax, hz; System.out.print("pde23_eqn2.java running \n"); System.out.print("differential equation to solve, from pdedef232.java \n"); System.out.print("problem defined by pdedefs232.java \n"); System.out.print("provides D.ccxx(x,y,z), f(x,y,z), D.ub(x,y,x) coefs(coef)\n"); System.out.print("uniform grid on cube xmin,ymin,zmin to xmax,ymax,zmax\n"); System.out.print(" \n"); for(int i=0; i<9; i++) coef[i] = 0.0; System.out.print("coef initialized \n"); D.coefs(coef); System.out.print("have pde232_defs(defs) \n"); xmin = coef[0]; xmax = coef[1]; // nx = (int)coef[2]; ymin = coef[3]; ymax = coef[4]; // ny = (int)coef[5]; zmin = coef[6]; zmax = coef[7]; // nz = (int)coef[8]; System.out.print("xmin="+xmin+", xmax="+xmax+", nx="+nx+" \n"); System.out.print("ymin="+ymin+", ymax="+ymax+", ny="+ny+" \n"); System.out.print("zmin="+zmin+", zmax="+zmax+", nz="+nz+" \n"); System.out.println("build and solve "+neqn+" equations in "+neqn+ " unknowns \n"); hx = (xmax-xmin)/(nx-1); System.out.print("hx="+hx+" \n"); for(int i=0; imaxerror) maxerror=err; } //k } // j } // i System.out.print("check error="+error+", maxerror="+maxerror+" \n"); } // end check void check_rows() // only for(checking { // row is in ut solution coordinates int row, col; double sum, sum1; System.out.print("in check_rows \n"); for(int i=1; i0.001) { System.out.print("row i="+i+", j="+j+", k="+k+" is bad err="+sum+" \n"); System.out.print("ut[row][cs]="+ut[row][cs]+", sum1="+sum1+" \n"); } // end if } // k } // j } //i System.out.print("finished check_rows \n"); } // end check_rows void print() // typically not known { double error = 0.0; double max_error = 0.0; double avg_error = 0.0; System.out.print("exact solution u, computed us, error \n"); for(int i=1; imax_error) max_error = Math.abs(error); System.out.print("xg["+i+"]="+xg[i]+", yg["+j+"]="+yg[j]+ ", zg["+k+"]="+zg[k]+" \n"); System.out.print("u="+D.ub(xg[i],yg[j],zg[k])+", us="+us[S(i,j,k,ny,nz)]+ ", err="+error+" \n"); } // k } // j } // i System.out.print("max_error="+max_error+", avg_error="+avg_error/neqn+" \n"); System.out.print(" \n"); } // end print void printB() { System.out.print("matrix B includes RHS \n"); int cs = (nx-2)*(ny-2)*(nz-2); for(int i=1; i smaxerr) smaxerr = Math.abs(err); } // k z } // j y } // i x System.out.print(" \n"); System.out.print("check computed soln against PDE max error="+smaxerr+" \n"); System.out.print(" \n"); System.out.print("one point (nx-2,ny-2,nz-2) check \n"); System.out.print("x="+xg[nx-2]+", y="+yg[ny-2]+", z="+zg[nz-2]+" \n"); System.out.print("uxx="+uxx+", uyy="+uyy+", uzz="+uzz+" \n"); System.out.print("ux="+ux+", uy="+uy+", uz="+uz+" \n"); System.out.print("us="+us[S(nx-2,ny-2,nz-2,ny,nz)]+" \n"); System.out.print("D.f(x,y,z)="+D.f(xg[nx-2],yg[ny-2],zg[nz-2])+ ", D.ub(x,y,z)="+D.ub(xg[nx-2],yg[ny-2],zg[nz-2])+" \n"); System.out.print(" \n"); } // end Check_Soln void write_soln() { double x, y, z, u; try { FileWriter fout = new FileWriter("pde23_eqn2_java.dat"); BufferedWriter fileout = new BufferedWriter(fout); System.out.println("writing pde23_eqn2_java.dat"); fileout.write("3 "+nx+" "+ny+" "+nz+" \n"); for(int i=0; i