/* phase of wave function QED1D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2004.04.25 */ /* ver 0.0.2 2005.11.23 bug in energy() fixed */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class phaseQED1D extends Applet implements ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Button bt_reset, bt_start, bt_stop; Scrollbar sc_ww, sc_wh, spx; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 30; int started = 1; double px0 = 12.0; double wallPos = 7.0; double wallWidth = 0.3; double wallHight = 85.0; double t = 0.0; double dx = 16.0/512.0; double dt = 0.25*dx*dx; int NNx = 512+1; double phRe[] = new double[NNx]; double phIm[] = new double[NNx]; double vv[] = new double[NNx]; int NN = NNx+1; 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]; /* ----------------------------- applet control ------ */ public void init() { resize(630,300); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); 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); sc_ww= new Scrollbar(Scrollbar.HORIZONTAL,30,10,0,110); sc_ww.addAdjustmentListener(this); sc_wh= new Scrollbar(Scrollbar.HORIZONTAL,85,10,0,160); sc_wh.addAdjustmentListener(this); spx= new Scrollbar(Scrollbar.HORIZONTAL,120,10,0,210); spx.addAdjustmentListener(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(sc_ww); pnl.add(sc_wh); pnl.add(spx); 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 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()); setInitialCondition(); } else if (ev.getSource() == sc_ww) { wallWidth = 0.01*(double)(sc_ww.getValue()); setInitialCondition(); } else if (ev.getSource() == sc_wh) { wallHight = 1.0*(double)(sc_wh.getValue()); setInitialCondition(); } } 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,gbx,gby; double v1,v2,ph2,y,z; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); gbx = 30; gby = 220; gOff.setColor(Color.green); for (i=1; i=1.0) { gOff.drawLine(gbx+i,gby-(int)(100.0*ph2), gbx+i, gby); } } for (i=0; iwallPos+wallWidth) { p += (phRe[i]*phRe[i]+phIm[i]*phIm[i])*dx; } } return ( p ); } double energy() { int i; double s,hphRe,hphIm; s = 0.0; for (i=1; ivPos && x<(vPos+vWidth)) { vv[i] = vHight; } else { vv[i] = 0.0; } } } /* ----------------------------- set wave packet -------------- */ void setWave(double wavePos, double waveWidth, double momentum) { int i; double a,x,phAb,phPh; a = Math.pow(2.0*Math.PI*waveWidth*waveWidth,-0.25); for (i=1;i=1; i--) { phRe[i] -= phRe[i+1]*uRe[i] - phIm[i+1]*uIm[i]; phIm[i] -= phRe[i+1]*uIm[i] + phIm[i+1]*uRe[i]; } } void phaseStep() { int i; double th,cs,sn,phr,phi; for (i=1; i