// pde_cylinderical_eq.java cylinderical coordinates // solve del^2 U(radius,theta,z) + U(radius,theta,z) = f(r,t,z) // given Dirchlet boundary values Ub(r,t,z), and f(r,t,z) // Much checking in this code, analytic solution is // U(r,t,z) = r^3 + t^3/216 + z^3 // // f(r,t,z) := 12*r + 1/36*t/(r^2) + 6*z // r^3 + 1/216*t^3 + z^3 // // x = r cos theta 0 <= theta < 2 Pi // y = r sin theta r < 0 restriction for derivative // z = z z double // r = sqrt(x^2+y^2+z^2) // theta = arctan(y,x) if theta<0 theta = 2 Pi + arctan(y,x) // z = z // // use existing partial derivative computation in Cartesian coordinates to // compute partial derivatives in cylinderical coordinates // // compute del U(radius,theta,z) r=radius, t=theta angle, z=height // del U = (d/dr U, 1/r d/dt U, d/dz U) // // compute del^2 U(radius,theta,z) r=radius, t=theta angle, z=height // del^2 U = d/dr(r d/dr U) + 1/r^2 d^2/dt^2 U + d^2/dz^2 U // = 2/r d/dr U + d^2/dr^2 U + 1/r^2 d^2/dt^2 U + d^2/dz^2 U // needs nuderiv.java // needs simeq.java public class pde_cylinderical_eq { final int Nr = 5; // number radius final int Nt = 7; // number theta angle final int Nz = 5; // number Z coordinates final int Nrtz = (Nr-2)*(Nt-2)*(Nz-2); // matrix, equations double A[][] = new double[Nrtz][Nrtz+1]; // no bound, has RHS double X[] = new double[Nrtz]; // computed solution to U double Rg[] = new double[Nr]; // r grid values double Tg[] = new double[Nt]; // theta grid values double Zg[] = new double[Nz]; // z grid values double Ua[] = new double[Nr*Nt*Nz]; // analytic solution for checking double Cr[] = new double[Nr]; // first deriv wrt r double Crr[] = new double[Nr]; // second deriv wrt r double Ctt[] = new double[Nt]; // second deriv wrt t double Czz[] = new double[Nz]; // second deriv wrt z pde_cylinderical_eq() { double Pi = 3.1415926535897932384626433832795028841971; double Rmin = 0.2; double Rmax = 1.0; double Hr = (Rmax-Rmin)/(double)(Nr-1); double Tmin = 0.1; double Tmax = 300.0*Pi/180.0; // Ht not applicable double Zmin = -1.0; double Zmax = 1.0; double Hz = (Zmax-Zmin)/(double)(Nz-1); double R, T, Z, Ana, Cmp, Err; double Urv, Urrv, Uttv, Uzzv; // computed derivatives double Maxerrur=0.0, Maxerrurr=0.0, Maxerrutt=0.0; double Maxerruzz=0.0, Maxerr=0.0; double Xt, Yt, Tmp; double time_wall_start, time_wall_end; System.out.println("pde_cylinderical_eq.java starting"); time_wall_start = System.currentTimeMillis()/1000.0; System.out.println("r gird values, not necessarily equally spaced"); for(int i=0; i0.0001) System.out.println("Theta error"); } // k } // j } // i for(int i=0; i 0.001) { System.out.println("["+i+"]["+j+"]["+k+"] Ud2ck="+Ud2ck+ ", Err="+Err); } } // k if(2==2) // debug print { Err1 = 0.0; Err2 = 0.0; Err3 = 0.0; for(int ii=1; ii