import java.io.*; import java.awt.*; import java.lang.*; import java.applet.*; import java.util.*; public class Lines extends Applet { MuControls controls; public void init() { setLayout(new BorderLayout()); GridCanvas c = new GridCanvas(); add("Center", c); add("South", controls = new MuControls(c)); } public void start() { controls.enable(); } public void stop() { controls.disable(); } public boolean handleEvent(Event e) { if (e.id == Event.WINDOW_DESTROY) { System.exit(0); } return false; } public static void main(String args[]) { Frame f = new Frame("Lines"); Lines aTest = new Lines(); aTest.init(); aTest.start(); f.add("Center", aTest); f.resize(300, 300); f.show(); } } class GridCanvas extends Canvas { static double k1=1.0,k2=2.0; static double a1; static double a2; static double z1; static double z2; static double[][] rho_save = null; static double[][] z_save = null; double mu1 = 1; double mu2 = 2; Font font = new Font ("TimesRoman", Font.BOLD, 18); // some functions final static double pow2(double x) { return x*x; } final static double dist(double x1,double y1,double x2,double y2) { return Math.sqrt(pow2(x1-x2)+pow2(y1-y2)); } final static double acosh(double x) { return Math.log( x+(1.0+x)*Math.sqrt((x-1.0)/(x+1.0)) ); } final static double asinh(double x) { if(x == 0.0) return 0.0; return (x > 0.0 ? 1.0 : -1.0)*acosh(Math.sqrt(1.0+pow2(x))); } final static double sinh(double x) { return 0.5*(Math.exp(x)-Math.exp(-x)); } final static double cosh(double x) { return 0.5*(Math.exp(x)+Math.exp(-x)); } // the radial coordinate final static double r(double rho,double z) { double r1 = dist(0,z1,rho,z)-a1; double r2 = dist(0,-z2,rho,z)-a2; double r3a = dist(0,z1-a1,rho,z); double r3b = dist(0,-z2+a2,rho,z); double r3 = 0.5*(r3a+r3b-z1-z2+a1+a2); // Class I coordinate return ((2*k1+1)*r1*r2*r3)/(k1*r1*r3+r1*r2+k1*r2*r3); // Cadez-like coordinate // if(!classI.getState()) // return 2.*r1*r2/(r1+r2)*(1-0.3*Math.exp(-rho*rho-2.0*z*z)); } // coordinate derivs final static double r_rho(double rho,double z) { double drho = .001; return (2./3.*(r(rho+drho,z)-r(rho-drho,z)) -1./12.*(r(rho+2.*drho,z)-r(rho-2.*drho,z)))/drho; } final static double r_z(double rho,double z) { double dz = .001; return (2./3.*(r(rho,z+dz)-r(rho,z-dz)) -1./12.*(r(rho,z+2.*dz)-r(rho,z-2.*dz)))/dz; } // eta coord, and it's derivatives... final static double eta(double rho,double z) { return asinh(r(rho,z)/k2); } final static double eta_rho(double rho,double z) { return ( r_rho(rho,z)/k2)/Math.sqrt( 1.0+pow2(r(rho,z)/k2) ); } final static double eta_z(double rho,double z) { return ( r_z(rho,z)/k2)/Math.sqrt( 1.0+pow2(r(rho,z)/k2) ); } // the other way, derivatives of rho and z... final static double z_eta(double rho,double z) { if(eta_z(rho,z)==0 && eta_rho(rho,z)==0) return 0; return eta_z(rho,z)/( pow2(eta_z(rho,z))+pow2(eta_rho(rho,z)) ); } final static double rho_eta(double rho,double z) { if(eta_z(rho,z)==0 && eta_rho(rho,z)==0) return 0; return eta_rho(rho,z)/( pow2(eta_z(rho,z))+pow2(eta_rho(rho,z)) ); } // the eta and theta coord static double eta(int i) { return deta*(i+.5); } static double theta(int j) { return dtheta*(j-.5); } static int eta_zones=150; static int theta_zones=60; static double eta_max = 5.5; static double deta = eta_max/(eta_zones-1); static double dtheta=Math.PI/(theta_zones-1); double rho_grid1; double rho_grid2; double z_grid1; double z_grid2; boolean use_old_data=false; public void paint(Graphics g) { Rectangle r = bounds(); int hlines = r.height / 10; int vlines = r.width / 10; double ymin; double ymax; double xmin; double xmax; g.setColor(Color.gray); g.fillRect(r.x, r.y, r.width, r.height); g.setColor(Color.black); g.fillRect(r.x+5, r.y+5, r.width-10, r.height-10); g.setColor(Color.darkGray); int xc,yc,xw,yh; xw = r.width/10; yh = r.height/5; xc = r.width/2; yc = r.height/2; a1 = 1/sinh(mu1); a2 = 1/sinh(mu2); z1 = cosh(mu1)*a1; z2 = cosh(mu2)*a2; ymin = -0.5*a2; ymin = -z2-2*a2; ymax = z1+2*a1; xmax = 3*(a1+a2); xmin = -xmax; double rmax1 = Math.sqrt(pow2(xmax)+pow2(ymax)); double rmax2 = Math.sqrt(pow2(xmax)+pow2(ymin)); double rmax = rmax1 > rmax2 ? rmax1 : rmax2; int imin=0; for(int ii=1;ii= 1;i--) { rho_old = rho_grid1; z_old = z_grid1; // second order Runge-Kutta integration if(!use_old_data) { rho_new = rho_old-0.5*deta*rho_eta(rho_old,z_old); z_new = z_old-0.5*deta*z_eta(rho_old,z_old); rho_new = rho_old-deta*rho_eta(rho_new,z_new); z_new = z_old-deta*z_eta(rho_new,z_new); rho_grid2 = rho_new; z_grid2 = z_new; rho_save[i-1][j] = rho_grid2; z_save [i-1][j] = z_grid2; } else { rho_grid1 = rho_save[i-1][j]; z_grid1 = z_save[i-1][j]; rho_grid2 = rho_save[i][j]; z_grid2 = z_save[i][j]; } zg1 = (int)(my*(ymax - z_grid1)); zg2 = (int)(my*(ymax - z_grid2)); rhog1 = (int)(mx*(rho_grid1 - xmin)); rhog2 = (int)(mx*(rho_grid2 - xmin)); if(i=0;i--) { zg1 = (int)(my*(ymax - z_save[i][j ])); zg2 = (int)(my*(ymax - z_save[i][j+1])); rhog1 = (int)(mx*(rho_save[i][j ] - xmin)); rhog2 = (int)(mx*(rho_save[i][j+1] - xmin)); g.drawLine(rhog1, zg1, rhog2, zg2); rhog1 = (int)(mx*(-rho_save[i][j ] - xmin)); rhog2 = (int)(mx*(-rho_save[i][j+1] - xmin)); g.drawLine(rhog1, zg1, rhog2, zg2); } } int sx = 10; int sy = r.height - 28; g.setColor(Color.white); g.drawString("Mu1 = " + mu1 , sx, sy); g.drawString("Mu2 = " + mu2 , sx, sy + 14); use_old_data = true; } Hashtable rho_hash = new Hashtable(); Hashtable z_hash = new Hashtable(); public void get_rho_z(double v1,double v2) { String index = null; // Store previous calculation index = ""+mu1+"_"+mu2; if(use_old_data && rho_save != null) { rho_hash.put(index,rho_save); z_hash.put(index,z_save); rho_save = null; z_save = null; } // See if we can retrieve new data index = ""+v1+"_"+v2; double[][] rho_a = (double[][])rho_hash.get(index); double[][] z_a = (double[][])z_hash.get(index); if(rho_a != null) { use_old_data = true; rho_save = rho_a; z_save = z_a; } // try one more time... if(rho_save == null) { index = ""+v2+"_"+v1; rho_a = (double[][])rho_hash.get(index); z_a = (double[][])z_hash.get(index); if(rho_a != null) { use_old_data = true; rho_save = rho_a; z_save = new double[eta_zones][theta_zones]; for(int j=0;j