/** applet No. 354 * * bcc metal - AFS potential * * Created by Ikeuchi Mitsuru on September 16 2003. * Copyright (c) 2003-2007 Ikeuchi Mitsuru. All rights reserved. * * ver 0.0.1 2003.09.16 created * ver 0.0.2 2003.09.20 improved display code * ver 0.0.3 2003.11.23 Tr calc. code - bug fixed * ver 0.0.4 2004.02.11 improved pannel layout * ver 0.0.5 2004.03.10 bug fixed * ver 0.0.6 2007.05.19 improved code * */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class bccCrystalAFS extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { // ------------------------------------ preset field ----------- Thread th = null; // for run()-paint() thread // for event Choice ch_mat, ch_tempMode, ch_view; Button bt_reset, bt_startStop; Scrollbar sc_temp, sc_scale; // for off-paint buffer Dimension dim; Image imgOff; Graphics gOff; // MD3D double t = 0.0; double dt = 1.0*1.0e-15; double xMax = 3.4*1.0e-9; double yMax = 3.4*1.0e-9; double zMax = 3.4*1.0e-9; int resetSW = 0; // 1-reset int startSW = 1; // 0-stop 1-start int tempMode = 0; // 0-adiabatic 1-T scaling 2-wall control double contTemp = 300.0; int Ncube = 8; int Nmt = Ncube*Ncube*Ncube*2; // number of atoms int NN = Nmt + 1; int Nsx = 16; int Nsy = 16; int Nsz = 16; double FSmass = 183.85*1.661e-27; double FSd = 4.400224; double FSA = 1.896373; double FSb = 0.0; double FSc = 3.25; double FSc0 = 47.1346499; double FSc1 = -33.7665655; double FSc2 = 6.2541999; double FSbb = 90.3; double FSalpha = 1.2; double FSb0 = 2.7411; double AU = 1.661e-27; double FS[][] = { /* atom 0 mass 1 d 2 A(eV) 3 b 4 c 5 c0 6 c1 7 c2 8 a */ /* 0 W */ {183.85 *AU,4.400224,1.896373,0.0,3.25,47.1346499,-33.7665655, 6.2541999, 3.16, 1.00}, /* 1 Mo*/ { 95.94 *AU,4.114825,1.887117,0.0,3.25,43.4475218,-31.9332978, 6.0804249, 3.15, 1.00}, /* 2 Fe*/ { 55.847*AU,3.569745,1.828905,1.8,3.40, 1.2371147, -0.3592185,-0.0385607, 2.87, 1.00}, /* 3 Cr*/ { 51.996*AU,3.915720,1.453418,1.8,2.90,29.1429813,-23.3975027, 4.7578297, 2.88, 1.00}, /* 4 Ta*/ {180.948*AU,4.076980,2.591061,0.0,4.20, 1.2157373, 0.0271471,-0.1217350, 3.30, 1.00}, /* 5 Nb*/ { 92.906*AU,3.915354,3.013789,0.0,4.20,-1.5640104, 2.0055779,-0.4663764, 3.30, 0.99}, /* 6 V */ { 50.942*AU,3.692767,2.010637,0.0,3.80,-0.8816318, 1.4907756,-0.3976370, 3.03, 1.00} }; int MAT1 = 0; /* W */ double Ackland[][] = { /* atom 0 B(eV/A3) 1 alpha 2 b0(A) */ /* 0 W */ { 90.3, 1.2, 2.7411 }, /* 1 Mo*/ { 1223.0, 3.9, 2.7255 }, /* 2 Fe*/ { 0.0, 1.0, 0.0 }, /* 3 Cr*/ { 0.0, 1.0, 0.0 }, /* 4 Ta*/ { 91.0, 1.05, 2.8629 }, /* 5 Nb*/ { 48.0, 0.8, 2.8585 }, /* 6 V */ { 23.0, 0.5, 2.6320 } }; int kind[] = new int[NN]; double xx[] = new double[NN]; /* i-th position */ double yy[] = new double[NN]; double zz[] = new double[NN]; double vx[] = new double[NN]; /* i-th velocity */ double vy[] = new double[NN]; double vz[] = new double[NN]; double ffx[] = new double[NN]; /* i-th force */ double ffy[] = new double[NN]; double ffz[] = new double[NN]; double virx[] = new double[NN]; double viry[] = new double[NN]; double virz[] = new double[NN]; int reg[][] = new int[NN][50]; double rijReg[][] = new double[NN][50]; int regNr[][] = new int[NN][250]; int section[][][][] = new int[Nsx][Nsy][Nsz][100]; // 3D control (mouse control) 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 = 10.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; // 3D display int sleepTime = 50; int dispMode = 0; double dispWidth = 250.0; double dispScale = (dispWidth/xMax); double viewScale = 1.0; int srtz[][] = new int[2][NN]; int rdf[] = new int[260]; int vdf[] = new int[220]; double meanvdf[] = new double[220]; double ffvMaxwell[] = new double[220]; double virial[] = new double[256]; int virialp = 0; 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} }; // -------------------------------- applet main loop ----------- public void init() { resize(630,420); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); ch_mat = new Choice(); ch_mat.add("W"); ch_mat.add("Mo"); ch_mat.add("Fe"); ch_mat.add("Cr"); ch_mat.add("Ta"); ch_mat.add("Nb"); ch_mat.add("V"); ch_mat.addItemListener(this); ch_tempMode = new Choice(); ch_tempMode.add("adiabatic"); ch_tempMode.add("t scaling"); ch_tempMode.add("wall cont."); ch_tempMode.addItemListener(this); ch_tempMode.select("adiabatic"); ch_view = new Choice(); ch_view.add("ball"); ch_view.add("line"); ch_view.add("both"); ch_view.add("temp"); ch_view.add("real"); ch_view.add("velocity"); ch_view.add("v-space"); ch_view.add("rho@atom"); ch_view.add("dF/drho"); ch_view.addItemListener(this); ch_view.select("ball"); bt_reset= new Button("reset"); bt_reset.addActionListener(this); bt_startStop= new Button("start/stop"); bt_startStop.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,310); 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_startStop); pnl.add(ch_tempMode); 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 = null; } // ---------------------------------- event listener ----------- public void itemStateChanged(ItemEvent ev){ if (ev.getSource() == ch_mat){ MAT1 = ch_mat.getSelectedIndex(); resetSW = 1; } else if (ev.getSource() == ch_tempMode){ tempMode = ch_tempMode.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 (startSW==0) { startSW = 1; } else { startSW = 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); } // ========================= run() - paint() loop ============== public void run() { while (th != null) { timeEvolution(); offPaint(); repaint(); try { Thread.sleep(sleepTime); } catch (InterruptedException e) { } } } public void update(Graphics g) { paint(g); } public void paint(Graphics g) { g.drawImage(imgOff,0,0,this); } // --------------------------------------- off-paint ----------- private void offPaint() { int gbx,gby; double tmp; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); tmp = temperature(); gbx = 60; gby = 100; if (dispMode==0) { ballPlot(gbx,gby,0.6,0); rdfPlot(400,100,1.0); } else if (dispMode==1) { ballPlot(gbx,gby,0.0,2); rdfPlot(400,100,1.0); } else if (dispMode==2) { ballPlot(gbx,gby,0.5,2); rdfPlot(400,100,1.0); } else if (dispMode==3) { ballPlot(gbx,gby,0.6,1); rdfPlot(400,100,1.0); } else if (dispMode==4) { ballPlot(gbx,gby,1.0,0); rdfPlot(400,100,1.0); } else if (dispMode==5) { velocityPlot(gbx,gby, 50.0); } else if (dispMode==6) { vSpacePlot(gbx,gby); } else if (dispMode==7) { rhoPlot(gbx,gby); } else if (dispMode==8) { fpPlot(gbx,gby); } else if (dispMode==9) { ; } gOff.setColor(Color.black); gOff.drawString("atom",630/6*0+10,40); if (startSW==0) { gOff.drawString("stopped",630/6*1+10,40); } else { gOff.drawString("started",630/6*1+10,40); } gOff.drawString("temp control",630/6*2+10,40); gOff.drawString("T_cont="+(int)(contTemp+0.5)+" K",630/6*3+10,40); gOff.drawString("scale="+(int)(viewScale*100.0+0.499)+"%",630/6*4+10,40); gOff.drawString("view",630/6*5+10,40); gOff.setColor(Color.blue); gOff.drawString("a="+FS[MAT1][8]+"A",630/6*0+10,60); gOff.drawString("t="+Math.floor(t*1.0e15+0.5)+" fs",630/6*1+10,60); gOff.drawString("T="+(int)(tmp*10.0+0.5)/10.0+" K",630/6*3+10,60); gOff.drawString("
="+(int)(pressure()/1.0e6)+"MPa",630/6*4+10,60);
gOff.setColor(Color.black);
gOff.drawString("box="+(int)(xMax*1.0e10+0.5)/10.0+"x"+(int)(yMax*1.0e10+0.5)/10.0+"x"+(int)(zMax*1.0e10+0.5)/10.0+"nm",430,80);
}
// ------------------------------------ plot methods -----------
private void ballPlot(int gbx, int gby, double size,int mode) {
int i,j,k,jj,gx,gy,gz,g2x,g2y;
double sc,sz,bl;
setWaku();
rotate(theta,fai);
zSort();
drawWaku(gbx,gby,0);
sc = dispScale*viewScale;
sz = size*(1.732/2.0)*sc*FS[MAT1][8]*1.0e-10;
bl = 0.935*FS[MAT1][8]*1.0e-10;
for (i=0; i