/* fixed wall - diffusion Monte-Carlo method 1D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2005.06.11 */ import java.awt.*; import java.awt.event.*; import java.applet.*; import java.util.*; public class fixedWallDMC1D extends Applet implements ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Button bt_reset, bt_start, bt_stop; Scrollbar sc_xWidth, sc_deltaTau; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; Random rand = new Random(); int sleepTime = 50; int resetSW = 0; int started = 1; double xWidth = 4.0; double xnode = 0.0; double deltaTau = 0.01; double sqrtdt = Math.sqrt(deltaTau); double hbar = 1.0; double t = 0.0; double dt = deltaTau; int NNr = 2000; int repStatus[] = new int[NNr]; double replica[][] = new double[NNr][3]; double eeRef0 = 0.0; double eeRef1 = eeRef0; double eeRef = eeRef0; int NN0 = 1000; int NN1 = NN0; int NN00 = NN0; int NNb = 100; int box[] = new int[NNb]; double meanBox[] = new double[NNb]; double psi[] = new double[NNb]; double ffr[] = new double[NNb]; /* ----------------------------- 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); sc_xWidth= new Scrollbar(Scrollbar.HORIZONTAL,40,10,10,110); sc_xWidth.addAdjustmentListener(this); sc_deltaTau= new Scrollbar(Scrollbar.HORIZONTAL,10,10,1,110); sc_deltaTau.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(sc_xWidth); add(pnl,"North"); setInitialCondition(); repaint(); } 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){ resetSW = 1; 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() == sc_xWidth) { xWidth = 0.1*(double)(sc_xWidth.getValue()); } else if (ev.getSource() == sc_deltaTau) { deltaTau = 0.001*(double)(sc_deltaTau.getValue()); dt = deltaTau; } } 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 gx,gy,gb; gx = 30; gy = 60; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); plotReplica(gx,gy,10); plotMeanBox(gx,gy,2.0); drawPotential(gx,gy,10.0); plotPsi(gx,gy, 500.0); gOff.setColor(Color.black); gOff.drawString("t="+(int)(t*100+0.5)/100.0+" ",630/6*0+10,40); gOff.drawString("L="+(int)(xWidth*10.0+0.5)/10.0+"",630/6*5+10,40); gb = 460; gOff.drawString("Nmax="+NNr+"",gb,100); gOff.drawString("d tau="+(float)(deltaTau)+"",gb,120); gOff.drawString("ER="+(float)(eeRef0)+"",gb,200); gOff.drawString("="+(float)(eeRef)+"",gb,220); gOff.drawString("N="+NN0+"",gb,240); gOff.drawString("E0 = 0.3084au at L=4.0",gb,280); gOff.drawString("E0 = 0.0493au at L=10.0",gb,300); } /* ----------------------------- plot methods ----------------- */ void drawPotential(int gx, int gy, double mag) { int ix,ix1,ix2; double x,sc,p1,p2; gOff.setColor(Color.red); sc = 5.0/200.0; ix1 = (int)(-xWidth/2.0/sc+200); gOff.drawLine(gx+ix1,gy+200, gx+ix1, gy); ix2 = (int)(xWidth/2.0/sc+200); gOff.drawLine(gx+ix2,gy+200, gx+ix2, gy); for (ix=ix1; ix0) { gOff.fillRect(gx+i*a-a/2,gy+200-iy,a,iy); } } } void plotMeanBox(int gx, int gy, double mag) { int i,iy,a; a = 400/NNb; gOff.setColor(Color.green); for (i=0; i0.5) { gOff.fillRect(gx+i*a-a/2,gy+200-iy,a,iy); } } } void plotPsi(int gx, int gy, double mag) { int ix,a; double x,sc,p1,p2; a = 400/NNb; gOff.setColor(Color.orange); for (ix=0; ixNNb-1) ix=NNb-1; return( ix ); } void setPsi() { int i; double s,s2; s2 = 0; for (i=0; ixWidth/2 ) { repStatus[i] = 0; } else { replica[i][0] = xx; } } } for (i=0; i5) mn = 5; if (mn==0) { repStatus[i] = 0; } for(im=1; im=0) { repStatus[ip] = 2; replica[ip][0] = replica[i][0]; } } int seekSpace(int istart) { int i,ip; ip = -1; for (i=1; i