/* jellium - periodic DFT LDA 1D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2004.10.04 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class jelliumPeriodicDFT1D extends Applet implements ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice cpt,cne,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 = 8.0; double vHight = -1.0; double energy = 0.5; int potentialMode = 1; int dispMode = 0; int numberOfElectrons = 4; double t = 0.0; double dt = 1.0/256.0; double dx = 1.0/16.0; double lylz = 4.0*4.0; int NNx = 256; double ph[] = new double[NNx]; double vv[] = new double[NNx]; double vvext[] = new double[NNx]; double vvh[] = new double[NNx]; double vvx[] = new double[NNx]; double vvc[] = new double[NNx]; double vvhe[] = new double[NNx]; double vvhp[] = new double[NNx]; double rho[] = new double[NNx]; double rhop[] = 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); cne = new Choice(); cne.addItem("2"); cne.addItem("4"); cne.addItem("6"); cne.addItem("8"); cne.addItemListener(this); cne.select("4"); 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,800,10,50,1210); 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(cpt); pnl.add(sc_ww); pnl.add(sc_wh); pnl.add(cne); pnl.add(new Label(" ")); pnl.add(cvw); add(pnl,"North"); setInitialCondition(); initSD(10); } 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() == cne){ numberOfElectrons = 2*(cne.getSelectedIndex()+1); } 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 = 0.01*(double)(sc_ww.getValue()); setVext(potentialMode, vWidth, vHight); } else if (ev.getSource() == sc_wh) { vHight = -0.01*(double)(sc_wh.getValue()); setVext(potentialMode, vWidth, vHight); } } 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,gb; double emag, dmag; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); gbx = 30; gby = 160; emag = 100.0; dmag = 50.0; gOff.setColor(Color.getHSBColor( 0.85f, 0.4f, 0.9f )); fillGraph(rho, gbx, gby-10, lylz*dmag); for (istate=0;istate<5; istate++) { gby2 = gby-(int)(emag*sdEnergy[istate]); if (istate="+(float)intersection(istate,i)+" ",400,180+(istate*3+i)*15); } } } void drawDensity(int istate, int gx, int gy, double mag) { int i; double ph2; for (i=1; i=1.0) { gOff.drawLine(gx+i,gy-(int)(ph2), gx+i, gy); } } } void drawGraph(double fn[],int gx, int gy, double mag) { int i; double f1,f2; for (i=1; i=1.0) { gOff.drawLine(gx+i,gy-(int)(f), gx+i, gy); } } } /*------------------------- integral ----------*/ double intersection(int st1,int st2) { int i; double s; s = 0.0; for (i=0; ix0-0.5*vw && x<(x0+0.5*vw)) { vvext[i] = vh; } else { vvext[i] = 0.0; } } } else if (mode==2) { a = -vh*4.0/(vw*vw); for (i=1;ix0-0.5*vw && x<(x0+0.5*vw)) { vvext[i] = a*(x-x0)*(x-x0)+vh; } else { vvext[i] = 0.0; } } } else if (mode==3) { for (i=1;ix0-0.5*vw && x<=x0) { vvext[i] = 2.0*((0.5*vw-(x0-x))/vw)*vh; } else if (x>x0 && x<=x0+0.5*vw) { vvext[i] = 2.0*((0.5*vw-(x-x0))/vw)*vh; } else { vvext[i] = 0.0; } } } } /* ----------------------------- time evolution -------------- */ void timeEvolution() { int i,istate,nstate; if (started==1) { setVeff(); SD(5, vv, 100, 0.003); } else if (started==-1) { t = 0.0; setInitialCondition(); started = 0; } } /* ----------------- effective potential <-- electron density ------- */ void setVeff() { int i; setRho(numberOfElectrons/2); poisson(); setVcx(); for (i=0;i=NNx) ip = 0; im = i-1; if (im<0) im = NNx-1; vvh[i] = vvh[i]+0.66*(vvh[ip]+vvh[im]-2.0*vvh[i]+dx*dx*(rho[i]+rhp)); } } } void setVcx() { int i; double drho; drho = 0.01; for (i=1; i=1.0) { ec = -0.1423/(1.0+1.0529*Math.sqrt(r)+0.3334*r); } else { ec = -0.0480-0.0116*r+(0.0311+0.0020*r)*Math.log(r); } return ( ec ); } /* ----------------- Gram-Schmidt --------- */ void GramSchmidt(int stateMax) { int i,ist,istate; double s; normalize(sdState[0]); for (istate=1; istate