/* Brownian motion */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2002.07.28 */ /* ver 0.0.2 2003.08.09 flicker noise reduced */ /* ver 0.0.3 2004.07.18 improved control pannel */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class BrownianMotion extends Applet implements ActionListener, AdjustmentListener, Runnable { /*-------------------------------------- define gloval -----*/ Button bt_disp; Scrollbar scr; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 50; int atomSizeX = 20; int atomSizeY = 20; int dispR = 10; /* display molecular radious */ int paintSizeX = atomSizeX*dispR; int paintSizeY = atomSizeY*dispR; int wakuX = paintSizeX + dispR; int wakuY = paintSizeY + dispR; int Nmt = 36+1; /* number of molecules */ int NN = Nmt + 1; double t = 0.0; /* time (s) */ double dt = 25.0*1.0e-15; /* time division (s) */ double sgm = 3.40e-10; /* L-J sigma for Ar (m) */ double eps = 1.67e-21; /* L-J epsilon for Ar (J) */ double mas = 39.95*1.67e-27; /* mass of Ar (kg) */ int dispSW = 0; double contTemp = 300.0; double xMax = atomSizeX*sgm; /* x-Box size in (m) */ double yMax = atomSizeY*sgm; /* y-Box size in (m) */ double zMax = 0.0; /* z-Box size in (m) */ double AU = 1.661e-27; double EE = 1.602e-19; double KB = 1.38e-23; double AA = 1.0e-10; double FS = 1.0e-15; double Molec[][] = { /* mass charge E(in kB) sigma(A) dt(s) */ /* 0 He*/ { 4.003*AU, 0.0*EE, 10.2*KB, 2.576*AA, 5.0*FS }, /* 1 Ne*/ { 20.183*AU, 0.0*EE, 36.2*KB, 2.976*AA, 10.0*FS }, /* 2 Ar*/ { 39.948*AU, 0.0*EE, 124.0*KB, 3.418*AA, 25.0*FS }, /* 3 Kr*/ { 83.50 *AU, 0.0*EE, 190.0*KB, 3.610*AA, 25.0*FS }, /* 4 Xe*/ { 131.30 *AU, 0.0*EE, 229.0*KB, 4.055*AA, 25.0*FS }, /* 5 Hg*/ { 200.59 *AU, 0.0*EE, 851.0*KB, 2.898*AA, 25.0*FS }, /* 6 H2*/ { 2.016*AU, 0.0*EE, 33.3*KB, 2.968*AA, 5.0*FS }, /* 7 N2*/ { 28.013*AU, 0.0*EE, 91.5*KB, 3.681*AA, 20.0*FS }, /* 8 O2*/ { 31.999*AU, 0.0*EE, 113.0*KB, 3.433*AA, 20.0*FS }, /* 9 Ball*/{200.00 *AU, 0.0*EE, 124.0*KB,10.0 *AA, 25.0*FS } }; int Nkind = 10; int GAS1 = 2; double mass[] = new double[Nkind]; /* k-th kind mass */ double epsi[] = new double[Nkind]; /* k-th kind epsilon */ double sigm[] = new double[Nkind]; /* k-th kind sigma */ int kind[] = new int[NN]; /* i-th molec kind */ double xx[] = new double[NN]; /* i-th x-position */ double yy[] = new double[NN]; /* i-th y-position */ double vx[] = new double[NN]; /* i-th x-velocity */ double vy[] = new double[NN]; /* i-th y-velocity */ double ffx[] = new double[NN]; /* i-th x-force */ double ffy[] = new double[NN]; /* i-th y-force */ /*----------------------------- applet control functions -----*/ public void init() { resize(500,250); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); bt_disp = new Button("disp ON/OFF"); bt_disp.addActionListener(this); scr= new Scrollbar(Scrollbar.HORIZONTAL,300,100,10,700); scr.addAdjustmentListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,4,5,0)); pnl.add(new Label(" ")); pnl.add(bt_disp); pnl.add(new Label(" ")); pnl.add(scr); add(pnl,"North"); setInitialPosition(); } 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_disp) { if(dispSW==1) { dispSW=0; } else if (dispSW==0) { dispSW=1; } } } public void adjustmentValueChanged(AdjustmentEvent ev){ if(ev.getSource() == scr) { contTemp = (double)(scr.getValue()); } } public void run() { while (th != null) { try { calcposition(); 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,ix,iy,ir; double tmp; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); tmp = temperature(); gOff.setColor(Color.black); if (tmp1.2){ rr=1.2; }; for (i=0; i xMax) { xx[i] = xMax; vx[i] = -rr*vx[i]; vy[i] = rr*vy[i]; }; if (yy[i] < 0.0) { yy[i] = 0.0; vx[i] = rr*vx[i]; vy[i] = -rr*vy[i]; }; if (yy[i] > yMax) { yy[i] = yMax; vx[i] = rr*vx[i]; vy[i] = -rr*vy[i]; }; } } void forceCalc() { int i,j; double rij,f,fxij,fyij; for(i=0;i