// pde_nl22c.java solve non linear second order, second degree nonlinear // solve uxx*uxx + 2*uxx*uxy + uyy*uyy = f(x,y) // f(x,y) = 4*sin(x-y)^2 // with boundary ub(x,y) = sin(x-y) 0 < x < 1.0 < y < 1.0 // set up system of equations, use specialized Jacobian, simeq_newton3 // solution u(x,y) = sin(x-y) // x at i, y at ii rderiv or nuderiv cxx, cyy with nx=5, ny=5 // xg is X grid coordinates, yg is Y grid coordinates // subscripts 0 and 4 are known on boundary, thus there are 9 unknowns // u(xg[1],yg[1]), u(xg[2],yg[1]), u(xg[3],yg[1]), // u(xg[1],yg[2]), u(xg[2],yg[2]), u(xg[3],yg[2]), // u(xg[1],yg[3]), u(xg[2],yg[3]), u(xg[3],yg[3]) // thus 1 <= i <= 3, 1 <= ii <= 3 for inside boundary, boundary at 0 and 4 // // discrete uxx(xg[i],yg[ii) = cxx[0]*ub(xg[0],yg[ii]) + // cxx[1]* u(xg[1],yg[ii]) + cxx[2]* u(xg[2],yg[ii]) + // cxx[3]* u(xg[3],yg[ii]) + cxx[4]*ub(xg[4],yg[ii]); // // ub(xg[0]) and ub(xg[4]) are known boundary conditions, at xg 1,2,3 u unknown // similarly uyy(xg[i],yg[ii) = cyy[0]*ub(xg[i],yg[0]) + // cyy[1]* u(xg[i],yg[1]) + cyy[2]* u(xg[i],yg[2]) + // cyy[3]* u(xg[i],yg[3]) + cyy[4]*ub(xg[i],yg[4]); // // the product uxx(xg[i],yg[ii])*uyy(xg[i],yg[ii]) has 25 terms // 4 terms constant cxx[0]*ub(xg[0],yg[ii]) * cyy[0]*ub(xg[i],yg[0]) // cxx[4]*ub(xg[4],yg[ii]) * cyy[0]*ub(xg[i],yg[0]) // cxx[0]*ub(xg[0],yg[ii]) * cyy[4]*ub(xg[i],yg[4]) // cxx[4]*ub(xg[4],yg[ii]) * cyy[4]*ub(xg[i],yg[4]) // 12 terms one unknown // cxx[0]*ub(xg[0],yg[ii]) * cyy[1]* u(xg[i],yg[1]) // ... // cxx[4]*ub(xg[4],yg[ii]) * cyy[3]* u(xg[i],yg[3]) // 9 terms product of two unknonws // cxx[1]* u(xg[1],yg[ii]) * cyy[1]* u(xg[i],yg[1]) // ... // cxx[3]* u(xg[3],yg[ii]) * cyy[3]* u(xg[i],yg[3]) // // similarly for uxx*uxx and uyy*uxx public class pde_nl22c { int nx = 7; // problem parameters int ny = 6; // number of equations and number of linear unknowns int neqn = (nx-2)*(ny-2); // number of nonlinear terms, all pairs of unknowns int nlin = neqn*neqn; // total number of terms needed for nonlinear solution int ntot = neqn+nlin; double A[][] = new double[neqn][ntot]; // nonlinear system of equations double F[] = new double[neqn]; // RHS of nonlinear equations double xg[] = new double[nx]; // xgrid double yg[] = new double[ny]; // ygrid double U[] = new double[neqn+nlin]; // solution being computed, big double Ua[] = new double[neqn]; // solution known, single variable double cxx[][] = new double[nx][nx]; // numerical second derivative i,j double cyy[][] = new double[ny][ny]; // numerical second derivative ii,jj int var1[] = new int[ntot]; // unknown variable index in U int var2[] = new int[ntot]; // unknown variable index in U second power int var3[] = new int[ntot]; // unknown variable index in U third power double var[] = new double[neqn]; // for initial guess, middle of range double xmin = 0.0; double xmax = 0.6; double ymin = 0.0; double ymax = 0.4; double hx, hy; boolean check = true; // set true for debugging double f(double x, double y) // RHS, forcing function { return 4.0*Math.sin(x-y)*Math.sin(x-y); } // end f // boundary values, in this case, exact solution for checking double ub(double x, double y) { return Math.sin(x-y); } // end ub int S(int i, int ii) // 0 <= i <= nx, 0 <= ii <= ny { return (i-1)*(ny-2) + (ii-1); // unknown zero based inside boundary } // end S index into neqn int SS(int unk, int nlk) // unknown S(i,ii),S(j,jj) nonlinear term { return neqn+unk*neqn+nlk; // zero based } // end SS index into ntot void nlterms() // build var1, var2, var3 for simeq_newton3 { int unk, nlk; // linear, then nonlinear terms neqn, nlin System.out.println(neqn+" linear terms, then "+nlin+" nonlinear terms"); System.out.println("unk = S(i,ii)"); for(int i=1; i