// pde22js_la Galerkin FEM // solve ccxx*uxx+cxy*uxy+ccyy*uyy+ccx*ux+ccy*uy+cc*u=F(x,y) // given f(x,y) = // Analytic solution u(x,y) = boundary and check // inside nx by ny grid, Gauss Legendre integration class pde22js_la { laphi L = new laphi(); pde22js_la() { double start, now; boolean debug = false; double ccxx = 1.0; // PDE definition double ccxy = 2.0; double ccyy = 3.0; double ccx = 4.0; double ccy = 5.0; double cc = 6.0; final int nx = 5; final int ny = 6; int nxy = nx*ny; double x, y, hx, hy, tmp; int npx = 10; // Gauss Legendre integration order int npy = 11; double xmin = 0.0; // problem parameters double xmax = 1.0; double ymin = 0.1; double ymax = 1.1; double val, err, avgerr, maxerr; double xg[] = new double[nx]; double yg[] = new double[ny]; double xx[] = new double[npx+1]; // for Gauss-Legendre double wx[] = new double[npx+1]; double yy[] = new double[npy+1]; double wy[] = new double[npy+1]; double kg[][] = new double[nxy][nxy]; double fg[] = new double[nxy]; double ug[] = new double[nxy]; double Ua[] = new double[nxy]; System.out.print("pde22js_la.java running \n"); System.out.print("solve ccxx*uxx+cxy*uxy+ccyy*uyy+ccx*ux+ccy*uy+cc*u=F(x,y)\n"); System.out.print("given F(x,y) \n"); System.out.print(" xmin<=x<=xmax ymin<=y<=ymax Boundaries \n"); System.out.print(" boundary and possibly check uana(x,y) \n"); System.out.print("ccxx="+ccxx+", ccxy="+ccxy+", ccyy="+ccyy+" \n"); System.out.print("ccx="+ccx+", ccy="+ccy+", cc="+cc+" \n"); System.out.print("xmin="+xmin+", xmax="+xmax+", nx="+nx+" \n"); System.out.print("ymin="+ymin+", ymax="+ymax+", ny="+ny+" \n"); System.out.print("npx="+npx+", npy="+npy+" \n"); start = System.currentTimeMillis()/1000.0; hx = (xmax-xmin)/(nx-1); for(int i=0; imaxerr) maxerr = err; avgerr = avgerr + err; System.out.print("ug["+i+","+ii+"]="+ug[S(i,ii,ny)]+", Ua="+ Ua[S(i,ii,ny)]+", err="+ (ug[S(i,ii,ny)]-Ua[S(i,ii,ny)])+"\n"); } } System.out.print(" maxerr="+maxerr+", avgerr="+ (avgerr/(nx*ny))+"\n"); now = System.currentTimeMillis()/1000.0; System.out.println("total time "+(now-start)+" seconds"); System.out.print("pde22js_la.java finished\n"); } // end pde22js_la int S(int i, int j, int ny) // zero based index includes boundary { // this is row of k[][] return i*ny+j; // index into us and ut, RHS } // end S // from uana22_fem.js problem definition double F(double x, double y) // RHS { return 6.0*x*x*x+6.0*y*y*y+12.0*x*x+15.0*y*y+6.0*x*y+11.0*x+22.0*y+8.0; } // end f // Analytic solution double uana(double x, double y) { return x*x*x + y*y*y + x*y + 1.0; } // end u // needs laphi.java available // for finite element method (not needed if coefficients available) double galk(double x, double y, int i, int ii, int j, int jj, double ccxx, double ccxy, double ccyy, double ccx, double ccy, double cc, int nx, int ny, double xg[], double yg[]) { // Galerkin k stiffness function for this problem return (ccxx * L.phipp(x,j,nx-1,xg)* L.phi(y,jj,ny-1,yg) + ccxy * L.phip(x,j,nx-1,xg)* L.phip(y,jj,ny-1,yg) + ccyy * L.phi(x,j,nx-1,xg)*L.phipp(y,jj,ny-1,yg) + ccx * L.phip(x,j,nx-1,xg)* L.phi(y,jj,ny-1,yg) + ccy * L.phi(x,j,nx-1,xg)* L.phip(y,jj,ny-1,yg) + cc * L.phi(x,j,nx-1,xg)* L.phi(y,jj,ny-1,yg) )* L.phi(x,i,nx-1,xg)* L.phi(y,ii,ny-1,yg); } // end galk used by integration double galf(double x, double y, int i, int ii, int nx, int ny, double xg[], double yg[]) { // Galerkin f function for this problem return F(x,y)*L.phi(x,i,nx-1,xg)*L.phi(y,ii,ny-1,yg); } // end galf used by integration public static void main (String[] args) // "main" required { new pde22js_la(); // construct and execute } // end main } // end class pde22js_la