/* * gd2.java - revised 15 Apr 05 - width 257, height 257 * @author jackord@kw.igs.net * solution of Laplace's equation for concentric square prisms sides L and 2L * relaxation calculation with 5120 passes * the field is plotted after 20 passes, and whenever the number * of passes doubles thereafter * the capacitance is calculated using Gauss's law and is expressed as a * multiple of that of a cylindrical capacitor with diameters L and 2L */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class gd2 extends Applet implements ActionListener { int kk=0; // Declarations String bs="Plot"; Button b = new Button(bs); TextField tx1=new TextField(16); TextField tx2=new TextField(16); Color col[]={ Color.blue, Color.cyan, Color.red, Color.yellow, Color.magenta, Color.green }; public void init() { // Layout add(b); add(tx1); add(tx2); b.addActionListener(this); setBackground(new Color(211, 211, 211)); tx1.setBackground(getBackground()); tx2.setBackground(getBackground()); } public void paint(Graphics g) { // Main Program b.setBounds(108, 118, 40, 20); // Revise layout tx1.setBounds(78, 86, 100, 20); tx1.setText("Pass /5120"); tx2.setBounds(78, 150, 100, 20); tx2.setText("Csqr/Ccir "); int n=64; double s, e; double [][] v=new double[130][65]; g.setColor(Color.blue); g.drawRect(0, 0, 256, 256); g.setColor(col[(int)(100/7)%6]); g.drawRect(64, 64, 128, 128); if (kk==1) { for (int i=n; i<=2*n; i=i+1) { // Define V on boundary v[i][n]=100; // .. default is 0 } for (int j=1; j<=n-1; j=j+1) { // Initial linear distn for (int i=j; i<=2*n; i=i+1) { v[i][j]=100.*j/n; } } int k=1; for (int ii=0; ii<=5121; ii=ii+1) { // Main loop for (int j=1; j<=n-1; j=j+1) { // Project across bdry v[j][j+1]=v[j+1][j]; v[2*n+1][j]=v[2*n-1][j]; } if ((ii==0)||(ii==10*k)) { tx1.setText("Pass "+ii+"/5120"); for (int j=1; j<=n-1; j=j+1) { // Plot potential.. for (int i=j; i<=2*n; i=i+1) { g.setColor(col[(int)(v[i][j]/7)%6]); g.drawLine(i, j, i, j); // ..in g.drawLine(4*n-i, j, 4*n-i, j); // ..all g.drawLine(j, i, j, i); // ..eight g.drawLine(j, 4*n-i, j, 4*n-i); // ..symmetry g.drawLine(4*n-j, i, 4*n-j, i); // ..related g.drawLine(4*n-j, 4*n-i, 4*n-j, 4*n-i); g.drawLine(i, 4*n-j, i, 4*n-j); g.drawLine(4*n-i, 4*n-j, 4*n-i, 4*n-j); // ..regions } } int j=n/2; s=0; e=0; // Calculate C for (int i=j; i<=2*n; i=i+1) { // Gauss's Law e=v[i][j]-v[i][j-1]; s=s+e; } s=s-e/2; s=s*8/100/4/Math.PI; s=s*2*Math.log(2); s=(int)(1000*s)/1000.; tx2.setText("Csqr/Ccir "+s); // Display C ratio k=2*k; // Double plot interval } for (int j=1; j<=n-1; j=j+1) { // The calculation! for (int i=j; i<=2*n; i=i+1) { v[i][j]=(v[i][j-1]+v[i][j+1]+v[i-1][j]+v[i+1][j])/4; } } } tx1.setText(" Finished"); kk=0; } } public void actionPerformed(ActionEvent e) { // Button String tst; tst=e.getActionCommand(); if (bs.equals(tst)) { kk=1; } repaint(); } }