/** applet No. 0080 * * time reverse - molecular dynamics 2D * - Lennard-Jones potential - Ar * * Created by Ikeuchi Mitsuru on September 09 2002. * Copyright (c) 2002 Ikeuchi Mitsuru. All rights reserved. * * ver 0.0.1 2002.09.09 created * ver 0.0.2 2006.11.23 bug fixed * */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class timeReverse extends Applet implements ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Choice ch_tempCont, ch_view; Button bt_reset, bt_start, bt_stop, bt_reverse; Scrollbar sc_temp; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int dispWidth = 630; int dispHeight = 320; int sleepTime = 30; double sgm = 3.40e-10; // sigma of L-J potential for Ar (m) double eps = 0.0104*1.602e-19;// epsilon of L-J potential for Ar (J) double mas = 39.948*1.661e-27;// mass of L-J potential for Ar (kg) double xMax = 6.0e-9; double yMax = 6.0e-9; int Nmt = 18; double t = 0.0; double dt = 5.0*1.0e-15; int resetSW = 0; int started = 1; int dispMode = 0; int tempMode = 0; // 0-adiabatic 1-scaling 2-wall cont double contTemp = 200.0; // control temperature double boxDispWidth = 250.0; double dispScale = (boxDispWidth/xMax); double viewScale = 1.0; int NN = Nmt; double xx[] = new double[NN]; double yy[] = new double[NN]; double vx[] = new double[NN]; double vy[] = new double[NN]; double ffx[] = new double[NN]; double ffy[] = new double[NN]; int MM = 200; int mmp = 0; int mtt[] = new int[MM]; double mxx[][] = new double[NN][MM]; double myy[][] = new double[NN][MM]; /* ---------------------------------- applet control -------- */ public void init() { resize(dispWidth,dispHeight); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); ch_tempCont = new Choice(); ch_tempCont.addItem("adiabatic"); ch_tempCont.addItem("T scaling"); ch_tempCont.addItem("wall cont."); ch_tempCont.addItemListener(this); ch_tempCont.select("wall cont."); ch_view = new Choice(); ch_view.addItem("ball"); ch_view.addItem("velocity"); ch_view.addItem("trace"); ch_view.addItemListener(this); ch_view.select("ball"); 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); bt_reverse= new Button("reverse"); bt_reverse.addActionListener(this); sc_temp = new Scrollbar(Scrollbar.HORIZONTAL,300,10,10,610); sc_temp.addAdjustmentListener(this); setLayout(new BorderLayout()); Panel pnl = new Panel(); pnl.setLayout(new GridLayout(1,6,5,0)); /* pnl.add(new Label(" ")); */ pnl.add(bt_reset); pnl.add(bt_start); pnl.add(bt_stop); pnl.add(bt_reverse); pnl.add(new Label(" ")); 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; } public void itemStateChanged(ItemEvent ev){ if (ev.getSource() == ch_tempCont) { tempMode = ch_tempCont.getSelectedIndex(); } else if (ev.getSource() == ch_view) { dispMode = ch_view.getSelectedIndex(); } } public void actionPerformed(ActionEvent ev){ if(ev.getSource() == bt_reset){ resetSW = 1; if (dt<0) dt = -dt; } else if (ev.getSource() == bt_start){ if (started==0) { started = 1; if (dt<0) dt = -dt; } } else if (ev.getSource() == bt_stop){ started = 0; } else if (ev.getSource() == bt_reverse){ if (started==0) { started = -1; if (dt>0) dt = -dt; } } } public void adjustmentValueChanged(AdjustmentEvent ev){ if(ev.getSource() == sc_temp) { contTemp = 1.0*(double)(sc_temp.getValue()); } } 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 sc; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); gbx = 30; gby = 60; sc = viewScale*dispScale; if (dispMode==0) { ballPlot(gbx,gby,sc); } else if (dispMode==1) { velocityPlot(gbx,gby,sc, 0.05); } else if (dispMode==2) { tracePlot(gbx,gby,sc); } else if (dispMode==3) { ; } gOff.setColor(Color.black); gOff.drawString("t="+(int)(t*1.0e14+0.5)/100.0+" ps",10,40); if (started==0) { gOff.drawString("stop",dispWidth/6*1+10,40); } else if (started==1) { gOff.drawString("start",dispWidth/6*1+10,40); } else if (started==-1) { gOff.drawString("reverse",dispWidth/6*1+10,40); } gOff.drawString("T="+(int)(temperature()*10+0.5)/10.0+" K",dispWidth/6*4+10,40); gOff.drawString("view",dispWidth/6*5+10,40); gOff.drawString("Box="+(int)(xMax*1.0e10+0.5)/10.0+" x "+(int)(yMax*1.0e10+0.5)/10.0+" nm",500,80); } /*------------------------------------ plot method ----------*/ void ballPlot(int gbx, int gby, double sc) { int i, ix, iy, ballSize; ballSize = (int)(sgm*sc); drawBox(gbx, gby, sc, ballSize); gOff.setColor(Color.blue); for (i=0; i1; j--) { k = (mmp-j+MM)%MM; ix = (int)(sc*mxx[i][k])+gbx; iy = (int)(sc*myy[i][k])+gby; k = (mmp-j-1+MM)%MM; ix2 = (int)(sc*mxx[i][k])+gbx; iy2 = (int)(sc*myy[i][k])+gby; if (mtt[k]==1) { gOff.setColor(Color.getHSBColor(0.66f,0.8f,0.6f )); } else if (mtt[k]==-1) { gOff.setColor(Color.getHSBColor(0.05f,0.8f,0.6f )); } else { gOff.setColor(Color.getHSBColor(0.66f,0.01f,0.9f )); } gOff.drawLine(ix,iy,ix2,iy2); } } } void drawBox(int gbx, int gby, double sc, int ballSize) { int ix, iy, gball; double tmp; gball = ballSize/2; tmp = temperature(); gOff.setColor(Color.gray); if (tempMode==2) { 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