/* ion scatter QED2D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2004.04.25 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class ionScatterQED2D extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice cvw; Button bt_reset, bt_start, bt_stop; Scrollbar spx,spy; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 30; int dispMode = 1; int started = 1; double px0 = 4.0; double py0 = 0.0; int dgX, dgY, dgXb,dgYb; double viewTheta = -15.0*3.14/180.0; double viewFai = -72.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; double cosTh = Math.cos(viewTheta); double sinTh = Math.sin(viewTheta); double cosFi = Math.cos(viewFai); double sinFi = Math.sin(viewFai); double t = 0.0; double dx = 1.0/32.0; double dy = 1.0/32.0; double dt = 8.0*dx*dx; int NNx = 512+1; int NNy = 512+1; int NN = NNx+1; /* max(NNx,NNy)+1 */ double phRe[][] = new double[NNx][NNy]; double phIm[][] = new double[NNx][NNy]; double vv[][] = new double[NNx][NNy]; double aaRe[] = new double[NN]; double aaIm[] = new double[NN]; double bbRe[] = new double[NN]; double bbIm[] = new double[NN]; double bRe[] = new double[NN]; double bIm[] = new double[NN]; double uRe[] = new double[NN]; double uIm[] = new double[NN]; int xpts[] = new int[NN]; int ypts[] = new int[NN]; double icol[] = new double[NN]; /* ----------------------------- applet control ------ */ public void init() { resize(630,320); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); cvw = new Choice(); cvw.addItem("density"); cvw.addItem("grid"); cvw.addItemListener(this); cvw.select("grid"); bt_reset= new Button("reset"); bt_reset.addActionListener(this); bt_start= new Button("start"); bt_start.addActionListener(this); bt_stop = new Button("stop"); bt_stop.addActionListener(this); spx= new Scrollbar(Scrollbar.HORIZONTAL,80,10,0,210); spx.addAdjustmentListener(this); spy= new Scrollbar(Scrollbar.HORIZONTAL,0,10,0,210); spy.addAdjustmentListener(this); addMouseListener(this); addMouseMotionListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,6,5,0)); pnl.add(bt_reset); pnl.add(bt_start); pnl.add(bt_stop); pnl.add(cvw); pnl.add(spx); pnl.add(spy); add(pnl,"North"); setInitialCondition(); } public void start() { if (th == null) { th = new Thread(this); th.start(); } } public void stop() { if (th != null) { th.stop(); th = null; } } public void itemStateChanged(ItemEvent ev){ if (ev.getSource() == cvw){ dispMode = cvw.getSelectedIndex(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ t = 0.0; setInitialCondition(); started = 0; } else if(ev.getSource() == bt_start){ started = 1; } else if(ev.getSource() == bt_stop){ started = 0; } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == spx) { px0 = 0.1*(double)(spx.getValue()); } else if (ev.getSource() == spy) { py0 = 0.1*(double)(spy.getValue()); } } public void mousePressed(MouseEvent ev){ } public void mouseReleased(MouseEvent ev){ dgXb = 0; dgYb = 0; dgX = 0; dgY = 0; } public void mouseClicked(MouseEvent ev){ } public void mouseEntered(MouseEvent ev){ } public void mouseExited (MouseEvent ev){ } public void mouseMoved (MouseEvent ev){ } public void mouseDragged(MouseEvent ev){ dgXb = dgX; dgYb = dgY; dgX=ev.getX(); dgY=ev.getY(); if (dgXb==0 && dgYb==0) { dgXb = dgX; dgYb = dgY; } viewTheta += 0.5*3.14/180.0*(dgX-dgXb); viewFai += 0.5*3.14/180.0*(dgY-dgYb); cosTh = Math.cos(viewTheta); sinTh = Math.sin(viewTheta); cosFi = Math.cos(viewFai); sinFi = Math.sin(viewFai); } public void run() { while (th != null) { try { timeEvolution(); offPaint(); repaint(); Thread.sleep(sleepTime); } catch (InterruptedException e) { } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(imgOff,0,0,this); } /* ----------------------------- offPaint -------------------- */ void offPaint() { int i,j,gbx,gby,mag; int cx,cy,cz; double z,px,py,pz,sc; double v1,v2,ph2; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); if (dispMode==0) { gbx = 30; gby = 60; mag = 2; gOff.setColor(Color.black); gOff.fillRect(gbx-1,gby-1,(NNx+1)/mag,(NNy+1)/mag); for (i=1; i0.9) { ph2 = 0.9; } if (ph2>=0.01) { gOff.setColor(Color.getHSBColor( (float)(0.15+0.0004*vv[i][j]), 0.95f, (float)(ph2+0.1))); gOff.fillRect(gbx+i/mag,gby+j/mag, 1, 1); } } } } else if (dispMode==1) { cx = NNx/2; cy = NNy/2; cz = 0; sc = 1.0; gbx = -200+(int)(cx/sc); gby = -300+(int)(cy/sc); for(j=0; j0.02) { icol[i] = 0.15; } else if (vv[i][j]>0.0) { icol[i] = 0.33+0.001*vv[i][j]; } else { icol[i] = 0.66; } } for (i=0; i0.02) { icol[j] = 0.15; } else if (vv[i][j]>0.0) { icol[j] = 0.33; } else { icol[j] = 0.66; } } for (j=0; j50.0) { v = 50.0; } vv[i][j] = v; } } } /* ----------------------------- set wave packet -------------- */ void setWave(double xPos, double yPos, double waveWidth, double kx, double ky) { int i,j; double a,x,y,phAb,phPh; for (i=1;i=1; i--) { phRe[i][j] -= phRe[i+1][j]*uRe[i] - phIm[i+1][j]*uIm[i]; phIm[i][j] -= phRe[i+1][j]*uIm[i] + phIm[i+1][j]*uRe[i]; } } } void kyStep() { int i,j; double aaAb,auAb; for (i=1; i=1; j--) { phRe[i][j] -= phRe[i][j+1]*uRe[j] - phIm[i][j+1]*uIm[j]; phIm[i][j] -= phRe[i][j+1]*uIm[j] + phIm[i][j+1]*uRe[j]; } } } void phaseStep() { int i,j; double th,cs,sn,phr,phi; for (i=1; i