/* 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; i