/* oscillators time dependent Khon-Sham 1D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2004.11.18 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class oscillatorsTDKS1D extends Applet implements ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Button bt_reset, bt_start, bt_stop, bt_loss; Scrollbar sc_x0, sc_x1; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 30; int started = 1; int lossSW = 0; int setkFlag = 0; double xPos0 = 8.0; double xPos1 = 3.0; double xPos2 = 5.5; double xPos3 =10.0; double xPos4 =12.0; double t = 0.0; double dx = 1.0/16.0; double dt = 0.5*dx*dx; double lylz = 4.0*4.0; int NNx = 256+1; int NNe = 5; double energy[] = new double[NNe]; double psi[][][] = new double[NNe][NNx][2]; double vv[] = new double[NNx]; double wrk[][] = new double[NNx][2]; double vvext[] = new double[NNx]; double vvh[] = new double[NNx]; double vvx[] = new double[NNx]; double vvc[] = new double[NNx]; double rho[] = 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[NNx+1]; int ypts[] = new int[NNx+1]; /* ----------------------------- applet control ------ */ public void init() { resize(630,320); 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); bt_loss = new Button("loss"); bt_loss.addActionListener(this); sc_x0= new Scrollbar(Scrollbar.HORIZONTAL,80,10,30,140); sc_x0.addAdjustmentListener(this); sc_x1= new Scrollbar(Scrollbar.HORIZONTAL,30,10,30,140); sc_x1.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(new Label(" ")); pnl.add(new Label(" ")); pnl.add(bt_loss); 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){ started = -1; lossSW = 0; } else if(ev.getSource() == bt_start){ started = 1; } else if(ev.getSource() == bt_stop){ started = 0; } else if(ev.getSource() == bt_loss){ if (lossSW==0) { lossSW = 1; } else { lossSW = 0; } } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == sc_x0) { xPos0 = 0.1*(double)(sc_x0.getValue()); setInitialCondition(); } else if (ev.getSource() == sc_x1) { xPos1 = 0.1*(double)(sc_x1.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,ie,gb,gbx,gby,gby2; double v1,v2,ph2,y,z; double ek0,ev0,ek1,ev1; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); gbx = 20; gby = 220; gOff.setColor(Color.getHSBColor(0.10f,0.5f,0.9f)); for (i=1; i=1.0) { gOff.drawLine(gbx+i,gby2-(int)(ph2), gbx+i, gby2); } } for (ie=0; ie|="+(float)(innerNorm(psi[ie],psi[0]))+" ",gb,100+15*ie); } for (ie=0; ie=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 ); } /* ----------------------------- time step -------------- */ void kxStep(double ph[][],double deltat) { int i; double a,aaAb,auAb; a = 4.0*dx*dx/deltat; for (i=1; i=1; i--) { ph[i][0] -= ph[i+1][0]*uRe[i] - ph[i+1][1]*uIm[i]; ph[i][1] -= ph[i+1][0]*uIm[i] + ph[i+1][1]*uRe[i]; } } void phaseStep(double ph[][],double deltat) { int i; double th,cs,sn,phr,phi; for (i=1; i