/* Kronig-Penney Model */ /* periodic steepest descent method 1D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2004.10.25 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class KronigPenney extends Applet implements ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice cpt,cvw; 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 vWidth = 20.0; double vHight = 1.0; double energy = 0.5; int potentialMode = 1; int dispMode = 0; double t = 0.0; double dt = 1.0/256.0; double dx = 1.0/8.0; int NNx = 256; double ph[] = new double[NNx]; double vv[] = new double[NNx]; double sdEnergy[] = new double[20]; double sdState[][] = new double[20][NNx]; double wrk[] = new double[NNx]; /* ----------------------------- applet control ------ */ public void init() { resize(630,320); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); cpt = new Choice(); cpt.addItem("well"); cpt.addItem("parabolic"); cpt.addItem("triangle"); cpt.addItemListener(this); cvw = new Choice(); cvw.addItem("wave func"); cvw.addItem("density"); cvw.addItem("both"); cvw.addItemListener(this); 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,20,10,0,42); sc_ww.addAdjustmentListener(this); sc_wh= new Scrollbar(Scrollbar.HORIZONTAL,100,10,0,210); sc_wh.addAdjustmentListener(this); spx= new Scrollbar(Scrollbar.HORIZONTAL,500,10,0,2010); spx.addAdjustmentListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,6,5,0)); pnl.add(new Label(" ")); pnl.add(sc_ww); pnl.add(sc_wh); pnl.add(new Label(" ")); pnl.add(new Label(" ")); pnl.add(new Label(" ")); add(pnl,"North"); initSD(20); 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() == cpt){ potentialMode = 1+cpt.getSelectedIndex(); setInitialCondition(); } else if (ev.getSource() == cvw){ dispMode = cvw.getSelectedIndex(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ started = -1; } 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) { energy = 0.001*(double)(spx.getValue())-1.0; } else if (ev.getSource() == sc_ww) { vWidth = (double)(sc_ww.getValue()); setInitialCondition(); } else if (ev.getSource() == sc_wh) { vHight = 0.01*(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,istate,gbx,gby,gby2; double v1,v2,ph2,y,z,p1,p2; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); gbx = 30; gby = 280; gOff.setColor(Color.green); for (i=1; i integral ----------*/ double intersection(double f[], double g[]) { int i; double s; s = 0.0; for (i=0; i=vw) { vv[i*32+j] = vHight; } else { vv[i*32+j] = 0.0; } } } } /* ----------------------------- timeEvolution -------------- */ void timeEvolution() { int i; if (started==1) { SD(20, vv, 100, 0.01); sortState(20); } else if (started==-1) { t = 0.0; setInitialCondition(); started = 0; } } void sortState(int maxState) { int ist,i; double w; for (ist=0; istsdEnergy[ist+1]+0.001) { for (i=0;i