/* explosion - molecular dynamics quasi-1D(3D) */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2005.11.05 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class explosionMDQ1D extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /*-------------------------------------- define gloval -----*/ Choice ch_mat,ch_tempControl,ch_view; Button bt_reset, bt_startStop, bt_gogogo; Scrollbar sc_temp,sc_scale; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 50; double t = 0.0; /* time (s) */ double dt = 5.0*1.0e-15; /* time division (s) */ int Nsx = 200; int Nsy = 5; int Nsz = 5; double xMax = Nsx*1.0e-9; /* x-Box size in (m) */ double yMax = Nsy*1.0e-9; /* y-Box size in (m) */ double zMax = Nsz*1.0e-9; /* z-Box size in (m) */ double zDepth = 100.0*1.0e-9; int Nmt = 200*5*5; /* number of molecules */ int NN = Nmt + 1; double dispWidth = 500.0; double dispScale = (dispWidth/xMax); double viewScale = 1.0; int resetSW = 0; int started = 1; int dispMode = 10; int tempMode = 0; double contTemp = 300.0; int dgX, dgY, dgXb,dgYb; double cx = 0.5*xMax; double cy = 0.5*yMax; double cz = 0.5*zMax; double theta = -20.0*3.14/180.0; double fai = -60.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; double rc = 1.0e-9; double rc2 = rc*rc; double AU = 1.661e-27; double EE = 1.602e-19; double AA = 1.0e-10; double Morse[][] = { /* 0:mass 1:charge 2:D(eV) 3:A(A^-1) 4:r0(A) 5:color */ /* 0 W */ {183.85 *AU, 0.0*EE, 0.9906*EE, 1.4116/AA, 3.032*AA, 0.30 }, /* 1 Mo*/ { 95.94 *AU, 0.0*EE, 0.8032*EE, 1.5079/AA, 2.976*AA, 0.33 }, /* 2 Cr*/ { 51.996*AU, 0.0*EE, 0.4414*EE, 1.5721/AA, 2.754*AA, 0.36 }, /* 3 Fe*/ { 55.847*AU, 0.0*EE, 0.4174*EE, 1.3885/AA, 2.845*AA, 0.39 }, /* 4 Ni*/ { 58.71 *AU, 0.0*EE, 0.4205*EE, 1.4199/AA, 2.780*AA, 0.42 }, /* 5 Al*/ { 26.98 *AU, 0.0*EE, 0.2703*EE, 1.1646/AA, 3.253*AA, 0.45 }, /* 6 Pb*/ {207.19 *AU, 0.0*EE, 0.2348*EE, 1.1836/AA, 3.733*AA, 0.48 }, /* 7 Cu*/ { 63.54 *AU, 0.0*EE, 0.3429*EE, 1.3588/AA, 2.866*AA, 0.20 }, /* 8 Ag*/ {107.87 *AU, 0.0*EE, 0.3323*EE, 1.3690/AA, 3.115*AA, 0.24 }, /* 9 Ca*/ { 40.08 *AU, 0.0*EE, 0.1623*EE, 0.8054/AA, 4.569*AA, 0.13 }, /*10 Sr*/ { 87.62 *AU, 0.0*EE, 0.1513*EE, 0.7878/AA, 4.988*AA, 0.16 }, /*11 Ba*/ {137.34 *AU, 0.0*EE, 0.1416*EE, 0.6570/AA, 5.373*AA, 0.19 }, /*12 Na*/ { 22.99 *AU, 0.0*EE, 0.0633*EE, 0.5900/AA, 5.336*AA, 0.01 }, /*13 K */ { 39.102*AU, 0.0*EE, 0.0542*EE, 0.4977/AA, 6.369*AA, 0.04 }, /*14 Rb*/ { 85.47 *AU, 0.0*EE, 0.0464*EE, 0.4298/AA, 7.207*AA, 0.07 }, /*15 Cs*/ {132.905*AU, 0.0*EE, 0.0449*EE, 0.4157/AA, 7.557*AA, 0.10 }, /*16 Ne*/ { 20.183*AU, 0.0*EE, 0.0031*EE, 1.6500/AA, 3.076*AA, 0.56 }, /*17 Ar*/ { 39.948*AU, 0.0*EE, 0.0104*EE, 1.3400/AA, 3.816*AA, 0.60 }, /*18 Kr*/ { 83.80 *AU, 0.0*EE, 0.0141*EE, 1.2500/AA, 4.097*AA, 0.64 }, /*19 Xe*/ {131.30 *AU, 0.0*EE, 0.0200*EE, 1.2400/AA, 4.467*AA, 0.68 }, /*20 Hg*/ {200.59 *AU, 0.0*EE, 0.0734*EE, 1.4900/AA, 3.255*AA, 0.72 } }; String material[] = { "W" ,"Mo","Cr","Fe","Ni","Al","Pb","Cu","Ag","Ca", "Sr","Ba","Na","K" ,"Rb","Cs","Ne","Ar","Kr","Xe","Hg" }; int NmatKind = 21; int MAT1 = 17; 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 zz[] = new double[NN]; /* i-th z-position */ double vx[] = new double[NN]; /* i-th x-velocity */ double vy[] = new double[NN]; /* i-th y-velocity */ double vz[] = new double[NN]; /* i-th z-velocity */ double ffx[] = new double[NN]; /* i-th x-force */ double ffy[] = new double[NN]; /* i-th y-force */ double ffz[] = new double[NN]; /* i-th z-force */ int reg[][] = new int[NN][250]; /* registration */ int section[][][][] = new int[Nsx][Nsy][Nsz][100]; int srtz[][] = new int[2][NN]; /* z-sort work space */ double forceTable[][][] = new double[NmatKind][NmatKind][1020]; double dispColor[] = new double[NmatKind]; double hh = 1.0e-12; double px[] = new double[NN]; double py[] = new double[NN]; double pz[] = new double[NN]; double wkx[] = new double[8]; double wky[] = new double[8]; double wkz[] = new double[8]; double pwkx[] = new double[8]; double pwky[] = new double[8]; double pwkz[] = new double[8]; int boxp[][] = { {0,1},{0,2},{0,4},{1,3},{1,5},{2,3},{2,6},{4,5},{4,6},{3,7},{5,7},{6,7} }; int rdf[] = new int[120]; int vdf[] = new int[220]; double virial[][] = new double[3][256]; double memTemp[] = new double[256]; int virialp = 0; int xpts[] = new int[200]; int ypts[] = new int[200]; double cpts[] = new double[200]; /*----------------------------- applet control functions -----*/ public void init() { resize(630,400); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); ch_mat = new Choice(); ch_mat.addItem("W"); ch_mat.addItem("Mo"); ch_mat.addItem("Cr"); ch_mat.addItem("Fe"); ch_mat.addItem("Ni"); ch_mat.addItem("Al"); ch_mat.addItem("Pb"); ch_mat.addItem("Cu"); ch_mat.addItem("Ag"); ch_mat.addItem("Ca"); ch_mat.addItem("Sr"); ch_mat.addItem("Ba"); ch_mat.addItem("Na"); ch_mat.addItem("K"); ch_mat.addItem("Rb"); ch_mat.addItem("Cs"); ch_mat.addItem("Ne"); ch_mat.addItem("Ar"); ch_mat.addItem("Kr"); ch_mat.addItem("Xe"); ch_mat.addItem("Hg"); ch_mat.addItemListener(this); ch_mat.select("Ar"); ch_tempControl = new Choice(); ch_tempControl.addItem("adiabatic"); ch_tempControl.addItem("t scaling"); ch_tempControl.addItem("wall cont."); ch_tempControl.addItemListener(this); ch_tempControl.select("adiabatic"); ch_view = new Choice(); ch_view.addItem("ball"); ch_view.addItem("bond"); ch_view.addItem("ball+bond"); ch_view.addItem("real size"); ch_view.addItem("temperature"); ch_view.addItem("velocity"); ch_view.addItem("momentum"); ch_view.addItem("bond+rdf"); ch_view.addItem("v+vdf"); ch_view.addItem("1d mean n"); ch_view.addItem("1d mean T"); ch_view.addItem("1d coarse n"); ch_view.addItem("1d coarse T"); ch_view.addItemListener(this); ch_view.select("1d mean T"); bt_reset= new Button("reset"); bt_reset.addActionListener(this); bt_startStop= new Button("start/stop"); bt_startStop.addActionListener(this); bt_gogogo= new Button("go"); bt_gogogo.addActionListener(this); sc_temp= new Scrollbar(Scrollbar.HORIZONTAL,30,10,1,210); sc_temp.addAdjustmentListener(this); sc_scale= new Scrollbar(Scrollbar.HORIZONTAL,100,10,50,510); sc_scale.addAdjustmentListener(this); addMouseListener(this); addMouseMotionListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,6,5,0)); /* pnl.add(new Label(" ")); */ pnl.add(ch_mat); pnl.add(bt_gogogo); pnl.add(ch_tempControl); pnl.add(sc_temp); pnl.add(sc_scale); pnl.add(ch_view); 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 itemStateChanged(ItemEvent ev){ if (ev.getSource() == ch_mat){ MAT1 = ch_mat.getSelectedIndex(); resetSW = 1; } else if (ev.getSource() == ch_tempControl) { tempMode = ch_tempControl.getSelectedIndex(); } else if (ev.getSource() == ch_view){ dispMode = ch_view.getSelectedIndex(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ resetSW = 1; } else if (ev.getSource() == bt_startStop){ if (started==0) { started = 1; } else { started = 0; } } else if (ev.getSource() == bt_gogogo){ gogogo(xMax/5.0, xMax/8.0, 3000.0); } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == sc_temp) { contTemp = 10.0*(double)(sc_temp.getValue()); vAjustment(); } else if(ev.getSource() == sc_scale) { viewScale = 0.01*(double)(sc_scale.getValue()); } } public void mousePressed(MouseEvent ev){ } public void mouseReleased(MouseEvent ev){ dgXb = 0; dgYb = 0; dgX = 0; dgY = 0; } public void mouseClicked(MouseEvent ev){ } public void mouseEntered(MouseEvent ev){ } public void mouseExited (MouseEvent ev){ } public void mouseMoved (MouseEvent ev){ } public void mouseDragged(MouseEvent ev){ dgXb = dgX; dgYb = dgY; dgX=ev.getX(); dgY=ev.getY(); if (dgXb==0 && dgYb==0) { dgXb = dgX; dgYb = dgY; } theta += 0.5*3.14/180.0*(dgX-dgXb); fai += 0.5*3.14/180.0*(dgY-dgYb); } 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 gbx,gby; double tmp; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); rotate(theta,fai); zSort(); tmp = temperature(); gbx = 20; gby = 100; if (dispMode==0) { ballPlot(gbx,gby, 0.6, 0); } else if (dispMode==1) { ballPlot(gbx,gby, 0.5, 1); } else if (dispMode==2) { ballPlot(gbx,gby, 0.5, 2); } else if (dispMode==3) { ballPlot(gbx,gby, 1.0, 0); } else if (dispMode==4) { ballPlot(gbx,gby, 0.6, 3); } else if (dispMode==5) { velocity3DPlot(gbx,gby, 10.0,0); } else if (dispMode==6) { velocity3DPlot(gbx,gby, 10.0,1); } else if (dispMode==7) { ballPlot(gbx,gby, 0.5, 1); rdfPlot(400,140, 0.2); } else if (dispMode==8) { velocity3DPlot(gbx,gby, 10.0,0); vdfPlot(400,140, 2.0,MAT1); } else if (dispMode==9) { ballPlot(gbx,gby, 0.6, 0); meanPlot1D(gbx,gby+220, 1, 1000*1.0e-28, 0); } else if (dispMode==10) { ballPlot(gbx,gby, 0.6, 3); meanPlot1D(gbx,gby+220, 1, 100/2000.0, 1); } else if (dispMode==11) { ballPlot(gbx,gby, 0.6, 0); meanPlot1D(gbx,gby+220, 4, 1000*1.0e-28, 0); } else if (dispMode==12) { ballPlot(gbx,gby, 0.6, 3); meanPlot1D(gbx,gby+220, 4, 100/2000.0, 1); } else if (dispMode==13) { ; } gbx = dim.width/6; gOff.setColor(Color.black); gOff.drawString("t="+(int)(t*1.0e13+0.5)/10.0+" ps",gbx*0+10,40); gOff.drawString("temp control",gbx*2+10,40); gOff.drawString("cont T="+contTemp+"K",gbx*3+10,40); gOff.drawString("scale="+(int)(viewScale*100.0+0.499)+"%",gbx*4+10,40); gOff.drawString("view",gbx*5+10,40); gOff.setColor(Color.blue); gOff.drawString("T="+(int)(tmp*10+0.5)/10.0+" K",gbx*3+10,60); gOff.drawString("L="+(int)(xMax*1.0e10+0.5)/10.0+" nm",gbx*4+10,60); gOff.drawString("P="+(int)(pressure()/1.0e4+0.5)/100.0+"MPa",gbx*5+0,60); gOff.drawString("

="+(int)(meanPressure()/1.0e4+0.5)/100.0+"MPa",gbx*5+0,80); gOff.drawString("nkT="+(int)((Nmt/(xMax*yMax*zMax)*1.38e-23*tmp)/1.0e4+0.5)/100.0+"MPa",gbx*4+0,80); gOff.setColor(Color.black); gOff.drawString("regMax="+regMax()+"",gbx*5+10,100); gOff.drawString("secMax="+secMax()+"",gbx*5+10,120); } /*------------------------------- plot methods ----------*/ void ballPlot(int gbx, int gby, double size, int imode) { int i,j,k,jj,gx,gy,g2x,g2y,gr; double sz,scl,tm; drawWaku(gbx,gby,0); scl = dispScale*viewScale; sz = size*viewScale/AA; for (i=0; i0.99) tm = 0.99; gOff.setColor(Color.getHSBColor( (float)Morse[kind[j]][5],0.8f,(float)(0.8*tm+0.2))); gOff.fillOval(gx-gr/2,gy-gr/2, gr, gr); } } drawWaku(gbx,gby,1); } double distance(int j, int jj) { double r2; r2 = (xx[j]-xx[jj])*(xx[j]-xx[jj])+(yy[j]-yy[jj])*(yy[j]-yy[jj])+(zz[j]-zz[jj])*(zz[j]-zz[jj]); return ( Math.sqrt(r2) ); } void velocity3DPlot(int gbx, int gby, double mag, int imode) { int i,j,gx,gy,g2x,g2y; double sc,m,p2x,p2y,p2z,rotp2x,rotp2y,rotp2z; double cosTh,sinTh,cosFi,sinFi; cosTh = Math.cos(theta); sinTh = Math.sin(theta); cosFi = Math.cos(fai); sinFi = Math.sin(fai); drawWaku(gbx,gby,0); sc = dispScale*viewScale; for (i=0; icontTemp) { gOff.setColor(Color.black); } else { gOff.setColor(Color.red); } } gOff.drawLine(gx,gy, g2x, g2y); } } } } int findMin() { int i,im; double m; im = 0; m = pwkz[im]; for (i=0; i<8; i++) { if (pwkz[i]srtz[1][j+1]) { w = srtz[0][j]; srtz[0][j]=srtz[0][j+1]; srtz[0][j+1]=w; w = srtz[1][j]; srtz[1][j]=srtz[1][j+1]; srtz[1][j+1]=w; } } } } void zSortInit() { int i,j,w; for (i=0; isrtz[1][j+1]) { w = srtz[0][j]; srtz[0][j]=srtz[0][j+1]; srtz[0][j+1]=w; w = srtz[1][j]; srtz[1][j]=srtz[1][j+1]; srtz[1][j+1]=w; } } } } /*------------------------------------- rotate ----------*/ void rotate(double th,double fi) { int i; double cosTh,sinTh,cosFi,sinFi; cosTh = Math.cos(theta); sinTh = Math.sin(theta); cosFi = Math.cos(fai); sinFi = Math.sin(fai); for (i=0; i0) { gOff.fillRect(gx+i*2,gy+hoganHight-iy,2,iy); } } drawHogan(gx, gy, hoganWidth, hoganHight, xDiv, yDiv); gOff.setColor(Color.black); gOff.drawString("0",gx-5,gy+hoganHight+20); gOff.drawString("1 (nm)",gx+hoganWidth-20,gy+hoganHight+20); gOff.drawString("radial distribution",gx+40,gy+hoganHight+40); } void drawHogan(int gx, int gy, int hoganWidth, int hoganHight, int xDiv, int yDiv) { int i; gOff.setColor(Color.gray); for (i=0; i0.5*yMax) { yj += yMax; }; if (yi-yj<-0.5*yMax) { yj -= yMax; }; if (zi-zj>0.5*zMax) { zj += zMax; }; if (zi-zj<-0.5*zMax) { zj -= zMax; }; r2 = (xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)+(zi-zj)*(zi-zj); rij = Math.sqrt(r2); if (rij<10.0e-10) { ir = (int)(rij*1.0e11+0.49999); rdf[ir] +=1; } } } } /*-------------------- verocity distribution set / plot ----------*/ void vdfPlot(int gx, int gy, double mag, int knd) { int hoganWidth,hoganHight,xDiv,yDiv; hoganWidth = 200; hoganHight = 200; xDiv = hoganWidth/4; yDiv = hoganHight/2; kindPlot(gx,gy+hoganHight, mag, -1); kindPlot(gx,gy+hoganHight, mag, knd); drawHogan(gx, gy, hoganWidth, hoganHight, xDiv, yDiv); gOff.setColor(Color.black); gOff.drawString("0",gx-5,gy+hoganHight+20); gOff.drawString("2000 m/s",gx+hoganWidth-30,gy+hoganHight+20); gOff.drawString("velocity distribution",gx+30,gy+hoganHight+40); } void kindPlot(int gx, int ghy, double mag, int knd) { int i,iy; setVelocityDistribution(knd); gOff.setColor(Color.lightGray); if (knd>=0) { gOff.setColor(Color.getHSBColor((float)Morse[knd][5],0.8f,0.8f)); } for (i=0; i<200; i++) { iy = (int)(mag*vdf[i]); if (iy>0) { gOff.drawLine(gx+i,ghy-iy,gx+i,ghy); } } } void setVelocityDistribution(int knd) { int i,iv; double v2,vv; for (i=0; i<220; i++) { vdf[i]=0; } for (i=0; im) { m = reg[i][0]; } } return(m); } int secMax() { int i,j,k,m; m = 0; for(i=0;im) { m = section[i][j][k][0]; } } } } return(m); } /* ----- pressure ----- */ void initVirial() { int i; for (i=0; i<256; i++) { virial[0][i] = 0.0; virial[1][i] = 0.0; virial[2][i] = 0.0; memTemp[i] = 0.0; } virialp = 0; } void setVirial() { int i; double xVir,yVir,zVir; xVir = 0.0; yVir = 0.0; zVir = 0.0; for (i=0; i=0.8*rc && r1.2){ rr=1.2; }; } for (i=0; i xMax) { xx[i] = xMax; vx[i] = -rr*vx[i]; vy[i] = rr*vy[i]; vz[i] = rr*vz[i]; } if (yy[i] < 0.0) { yy[i] += yMax; } if (yy[i] > yMax) { yy[i] -= yMax; } if (zz[i] < 0.0) { zz[i] += zMax; } if (zz[i] > zMax) { zz[i] -= zMax; } } } void forceCalc() { int i,j,k; double xi,xj,yi,yj,zi,zj; double r2,rij,f,fxij,fyij,fzij; for(i=0;i0.5*yMax) { yj += yMax; }; if (yi-yj<-0.5*yMax) { yj -= yMax; }; if (zi-zj>0.5*zMax) { zj += zMax; }; if (zi-zj<-0.5*zMax) { zj -= zMax; }; r2 = (xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)+(zi-zj)*(zi-zj); if (r2=Nsx) i1 = Nsx-1; j0 = (int)(Nsy*(yy[ip]-rreg)/yMax+(double)Nsy)-Nsy; j1 = (int)(Nsy*(yy[ip]+rreg)/yMax); k0 = (int)(Nsz*(zz[ip]-rreg)/zMax+(double)Nsz)-Nsz; k1 = (int)(Nsz*(zz[ip]+rreg)/zMax); for(i=i0;i<=i1;i++) { for(j=j0;j<=j1;j++) { jj = (j+Nsy)%Nsy; for(k=k0;k<=k1;k++) { kk = (k+Nsz)%Nsz; for(iq=1;iq<=section[i][jj][kk][0];iq++) { jp = section[i][jj][kk][iq]; if (jp>ip) { xi = xx[ip]; xj = xx[jp]; yi = yy[ip]; yj = yy[jp]; zi = zz[ip]; zj = zz[jp]; if (yi-yj>0.5*yMax) yj += yMax; if (yi-yj<-0.5*yMax) yj -= yMax; if (zi-zj>0.5*zMax) zj += zMax; if (zi-zj<-0.5*zMax) zj -= zMax; r2=(xi-xj)*(xi-xj)+(yi-yj)*(yi-yj)+(zi-zj)*(zi-zj); if (r2=Nsx) i = Nsx-1; j = (int)(Nsy*yy[ip]/yMax); if (j>=Nsy) j = Nsy-1; k = (int)(Nsz*zz[ip]/zMax); if (k>=Nsz) k = Nsz-1; iq = section[i][j][k][0]+1; section[i][j][k][0] = iq; section[i][j][k][iq] = ip; } } /*----- end of molecules motion -----*/ } /*----- end of applet -----*/