/* template - periodic direct simulation Monte Carlo method 2D */ /* coded by Ikeuchi Mitsuru */ /* ver 0.0.1 2005.11.12 */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class templatePDSMC2D extends Applet implements MouseListener, MouseMotionListener, ItemListener, ActionListener, AdjustmentListener, Runnable { /* -------------------------------------- set global ------ */ Button bt_reset, bt_startStop; Choice ch_kind, ch_kind2, ch_col, ch_view; Scrollbar sc_ratio,sc_temp, sc_adsorption, sc_scale; Thread th = null; Dimension dim; Image imgOff; Graphics gOff; int sleepTime = 50; double t = 0.0; double dt = 1.0e-7;/* s */ double dx = 1.0e-3;/* m */ double dy = 1.0e-3;/* m */ double vvc = dx*dy; int Nsx = 40; int Nsy = 40; double xMax = Nsx*dx; double yMax = Nsy*dy; double ffn = 5.0e4; double sigmaMax = 2.0*4.19e-10; double vvmax2 = 2000.0; int dispMode = 3; int resetSW = 0; int started = 1; int incRate = 1; double dispScale = (250.0/yMax); double viewScale = 1.0; double adsorptionEnergy = 0.1; /* eV */ int collisionMode = 1; int kindOfGas = 18; /* Xe */ int kindOfGas2 = 2; /* He */ int kind1Ratio = 50; double setTemp = 300.0; int dispWidth = 630; int dispHeight = 400; int dragSW = 1; int dgX, dgY, dgXb, dgYb; double xShift = 0.0; double yShift = 0.0; double viewTheta = -15.0*3.14/180.0; double viewFai = -72.0*3.14/180.0; double dtheta = 0.0*3.14/180.0; double pai = 3.1415926536; double cosTh = Math.cos(viewTheta); double sinTh = Math.sin(viewTheta); double cosFi = Math.cos(viewFai); double sinFi = Math.sin(viewFai); int NNp = 40*40*30; int kind[] = new int [NNp]; double xx[] = new double [NNp]; double yy[] = new double [NNp]; double vx[] = new double [NNp]; double vy[] = new double [NNp]; int collisionMark[] = new int [NNp]; double gasData[][] = { /* mass(x1.66e-27 kg), d(x1.0e-10 m), HSBcolor */ { 29.0 , 4.19, 0.00 }, /* 0 dummy */ { 2.02, 2.29, 0.01 }, /* 1 H2 */ { 4.0 , 2.33, 0.05 }, /* 2 He */ { 16.05, 4.83, 0.95 }, /* 3 CH4 */ { 17.04, 5.94, 0.90 }, /* 4 NH3 */ { 20.18, 2.77, 0.10 }, /* 5 Ne */ { 28.01, 4.19, 0.85 }, /* 6 CO */ { 28.02, 4.17, 0.30 }, /* 7 N2 */ { 30.01, 4.20, 0.80 }, /* 8 NO */ { 29.0 , 4.19, 0.33 }, /* 9 air */ { 32.0 , 4.07, 0.40 }, /* 10 O2 */ { 36.46, 5.76, 0.75 }, /* 11 HCl */ { 39.95, 4.17, 0.15 }, /* 12 Ar */ { 44.01, 5.62, 0.70 }, /* 13 CO2 */ { 44.02, 5.71, 0.65 }, /* 14 N2O */ { 64.06, 7.16, 0.60 }, /* 15 SO2 */ { 70.9 , 6.98, 0.55 }, /* 16 Cl2 */ { 83.8 , 4.76, 0.20 }, /* 17 Kr */ {131.3 , 5.74, 0.25 } /* 18 Xe */ }; String gasStr[] = { " ","H2","He","CH4","NH3","Ne","CO", "N2","NO","air","O2","HCl","Ar", "CO2","N2O","SO2","Cl2","Kr","Xe" }; int section[][][] = new int [Nsx][Nsy][200]; int cellAttribute[][] = new int [Nsx][Nsy]; double density[][] = new double [Nsx][Nsy]; double temperature[][] = new double [Nsx][Nsy]; double pressure[][] = new double [Nsx][Nsy]; int vDistribution[][] = new int [200][3]; int vSpace[][] = new int [250][250]; int xpts[] = new int[100]; int ypts[] = new int[100]; /* ----------------------------- applet control ------ */ public void init() { resize(dispWidth,dispHeight); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); bt_reset= new Button("reset"); bt_reset.addActionListener(this); bt_startStop= new Button("start/stop"); bt_startStop.addActionListener(this); ch_kind = new Choice(); ch_kind.addItem("H2"); ch_kind.addItem("He"); ch_kind.addItem("CH4"); ch_kind.addItem("NH3"); ch_kind.addItem("Ne"); ch_kind.addItem("CO"); ch_kind.addItem("N2"); ch_kind.addItem("NO"); ch_kind.addItem("air"); ch_kind.addItem("O2"); ch_kind.addItem("HCl"); ch_kind.addItem("Ar"); ch_kind.addItem("CO2"); ch_kind.addItem("N2O"); ch_kind.addItem("SO2"); ch_kind.addItem("Cl2"); ch_kind.addItem("Kr"); ch_kind.addItem("Xe"); ch_kind.addItemListener(this); ch_kind.select("Xe"); ch_kind2 = new Choice(); ch_kind2.addItem("H2"); ch_kind2.addItem("He"); ch_kind2.addItem("CH4"); ch_kind2.addItem("NH3"); ch_kind2.addItem("Ne"); ch_kind2.addItem("CO"); ch_kind2.addItem("N2"); ch_kind2.addItem("NO"); ch_kind2.addItem("air"); ch_kind2.addItem("O2"); ch_kind2.addItem("HCl"); ch_kind2.addItem("Ar"); ch_kind2.addItem("CO2"); ch_kind2.addItem("N2O"); ch_kind2.addItem("SO2"); ch_kind2.addItem("Cl2"); ch_kind2.addItem("Kr"); ch_kind2.addItem("Xe"); ch_kind2.addItemListener(this); ch_kind2.select("He"); ch_col = new Choice(); ch_col.addItem("null"); ch_col.addItem("rigid sphere"); ch_col.addItemListener(this); ch_col.select("rigid sphere"); ch_view = new Choice(); ch_view.addItem("particle"); ch_view.addItem("collision"); ch_view.addItem("velocity"); ch_view.addItem("sample 1000"); ch_view.addItem("veloc. 1000"); ch_view.addItem("mass flow"); ch_view.addItem("v space"); ch_view.addItem("n density"); ch_view.addItem("Temperature"); ch_view.addItem("Pressure"); ch_view.addItem("grid n"); ch_view.addItem("grid T"); ch_view.addItem("grid P"); ch_view.addItemListener(this); ch_view.select("sample 1000"); sc_ratio= new Scrollbar(Scrollbar.HORIZONTAL,50,10,0,110); sc_ratio.addAdjustmentListener(this); sc_temp= new Scrollbar(Scrollbar.HORIZONTAL,300,10,100,610); sc_temp.addAdjustmentListener(this); sc_adsorption= new Scrollbar(Scrollbar.HORIZONTAL,100,10,0,160); sc_adsorption.addAdjustmentListener(this); sc_scale= new Scrollbar(Scrollbar.HORIZONTAL,100,10,50,1010); 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_kind); pnl.add(ch_kind2); pnl.add(sc_ratio); 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_kind) { kindOfGas = 1 + ch_kind.getSelectedIndex(); resetSW = 1; } else if (ev.getSource() == ch_kind2) { kindOfGas2 = 1 + ch_kind2.getSelectedIndex(); resetSW = 1; } else if (ev.getSource() == ch_view) { dispMode = ch_view.getSelectedIndex(); dragSW = 1; if (dispMode==10 || dispMode==11 || dispMode==12) { dragSW = 2; } } else if (ev.getSource() == ch_col) { collisionMode = ch_col.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; } } } public void adjustmentValueChanged(AdjustmentEvent ev){ if (ev.getSource() == sc_ratio) { kind1Ratio = sc_ratio.getValue(); resetSW = 1; } else if (ev.getSource() == sc_temp) { setTemp = 1.0*sc_temp.getValue(); setTemperature(setTemp,kindOfGas); setTemperature(setTemp,kindOfGas2); } else if (ev.getSource() == sc_adsorption) { adsorptionEnergy = 0.001*sc_adsorption.getValue(); } else if (ev.getSource() == sc_scale) { viewScale = 0.01*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; } if (dragSW==1) { xShift += (1.0/viewScale/dispScale)*(dgX-dgXb); yShift += (1.0/viewScale/dispScale)*(dgY-dgYb); } else if (dragSW==2) { viewTheta += 0.5*3.14/180.0*(dgX-dgXb); viewFai += 0.5*3.14/180.0*(dgY-dgYb); cosTh = Math.cos(viewTheta); sinTh = Math.sin(viewTheta); cosFi = Math.cos(viewFai); sinFi = Math.sin(viewFai); } } 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 gx, gbx, gby; double sc; gOff.setColor(Color.white); gOff.fillRect(0,0,dim.width,dim.height); sc = viewScale*dispScale; gbx = 30+(int)(sc*xShift); gby = 60+(int)(sc*yShift); if (dispMode==0) { ovalPlot(gbx,gby,sc,NNp); } else if (dispMode==1) { collisionPlot(gbx,gby,sc); } else if (dispMode==2) { velosityPlot(gbx,gby,sc,NNp,20.0); } else if (dispMode==3) { ovalPlot(gbx,gby,sc,1000); } else if (dispMode==4) { velosityPlot(gbx,gby,sc,1000,20.0); } else if (dispMode==5) { massflowPlot(gbx,gby,sc,5.0); } else if (dispMode==6) { vSpacePlot(gbx,gby,0.1); } else if (dispMode==7) { fieldPlot(density,gbx,gby,sc,2.0/1.0e13,1); } else if (dispMode==8) { fieldPlot(temperature,gbx,gby,sc,0.001,1); } else if (dispMode==9) { fieldPlot(pressure,gbx,gby,sc,5.0e7,1); } else if (dispMode==10) { gridPlot(density,50*2.0/1.0e13,2); } else if (dispMode==11) { gridPlot(temperature,0.02,2); } else if (dispMode==12) { gridPlot(pressure,20.0*5.0e7,2); } velocityDistributionPlot(410,200,0.1,kindOfGas,kindOfGas2); gOff.setColor(Color.black); gOff.drawString("t="+(int)(t*1.0e6*1000.0+0.5)/1000.0+" us",630/6*0+10,40); gOff.drawString(gasStr[kindOfGas]+"("+kind1Ratio+") : "+gasStr[kindOfGas2]+"("+(100-kind1Ratio)+")",630/6*2+5,40); gOff.drawString("setT="+(int)(setTemp*10.0+0.5)/10.0+" K",630/6*3+10,40); gOff.drawString("scale="+(int)(viewScale*100.0)/100.0+" ",630/6*4+10,40); gOff.drawString("view",630/6*5+10,40); gOff.setColor(Color.black); gx = 430; gOff.drawString("Lx="+(float)(xMax*1000.0)+"(mm), Ly="+(float)(yMax*1000.0)+"(mm)",gx,60); gOff.drawString("max Nc="+maxSection()+"",gx,80); gOff.drawString("N="+NNp+", FN="+(float)ffn+"",gx,100); gOff.drawString("sigmaMax="+(float)(sigmaMax)+"(m^2)",gx,120); gOff.drawString("vmax="+(float)(vvmax2/2.0)+"(m/s)",gx,140); gOff.drawString("Etot="+(float)totalKineticEnergy()+"(J)",gx,160); /* gOff.setColor(Color.black); gOff.drawString("alive =",gx,180); gOff.setColor(Color.getHSBColor((float)(gasData[kindOfGas][2]),0.9f,0.9f)); gOff.drawString(" "+numberOfPartickes(kindOfGas)+",",gx+60,180); gOff.setColor(Color.getHSBColor((float)(gasData[kindOfGas2][2]),0.9f,0.9f)); gOff.drawString(" "+numberOfPartickes(kindOfGas2)+" ",gx+120,180); */ } /*------------------------- plot methods -------------------*/ void ovalPlot(int gx, int gy, double sc,int Nsample) { int i,ir; drawWaku(gx,gy,sc); drawBlock(gx,gy,sc); ir = 2; for (i=0; i0) { gOff.setColor(Color.getHSBColor((float)(gasData[kind[i]][2]),0.9f,0.9f)); gOff.drawOval(gx+(int)(xx[i]*sc+0.5)-ir/2,gy+(int)(yy[i]*sc+0.5)-ir/2, ir, ir); } else if (kind[i]<0) { gOff.setColor(Color.getHSBColor((float)(gasData[kind[i]][2]),0.9f,0.4f)); gOff.drawOval(gx+(int)(xx[i]*sc+0.5)-ir/2,gy+(int)(yy[i]*sc+0.5)-ir/2, ir, ir); } } } void collisionPlot(int gx, int gy, double sc) { int i,ir; drawWaku(gx,gy,sc); drawBlock(gx,gy,sc); ir = 2; for (i=0; i0) { ix = gx+(int)(xx[i]*sc+0.5); iy = gy+(int)(yy[i]*sc+0.5); ix2 = ix+(int)(vx[i]*dt*sc*mag+0.5); iy2 = iy+(int)(vy[i]*dt*sc*mag+0.5); gOff.setColor(Color.getHSBColor((float)(gasData[kind[i]][2]),0.9f,0.7f)); gOff.drawLine(ix,iy,ix2,iy2); } } } void massflowPlot(int gx, int gy, double sc,double mag) { int ix,iy,ip,iss,ii,igx,igy,igx2,igy2; double ss,m,mvx,mvy; drawWaku(gx,gy,sc); drawBlock(gx,gy,sc); ss = sc*xMax/(double)Nsx; iss = (int)(ss+0.999); for (ix=0; ix0.0) { gOff.setColor(Color.getHSBColor(0.66f,0.8f,0.8f)); } else { gOff.setColor(Color.getHSBColor(0.01f,0.8f,0.8f)); } igx2 = igx+(int)(mvx*dt*sc*mag+0.5); igy2 = igy+(int)(mvy*dt*sc*mag+0.5); gOff.drawLine(igx,igy,igx2,igy2); } } } void fieldPlot(double fld[][], int gx, int gy, double sc, double mag, int meanWidth) { int ix,iy,iss; double ss,f; setField(); ss = sc*xMax/(double)Nsx; iss = (int)(ss+0.999); for (ix=0; ix0.999) f = 0.999; gOff.setColor(Color.getHSBColor((float)(0.66-0.66*f),0.9f,0.9f)); gOff.fillRect(gx+(int)(ss*ix+0.5),gy+(int)(ss*iy+0.5), iss, iss); } } drawBlock(gx,gy,sc); } void setField() { int i,j,k,ip,n; double ke,vmx,vmy; for(i=0;i10) { vmx = 0.0; vmy = 0.0; for(ip=1;ip<=section[i][j][0];ip++) { k = section[i][j][ip]; vmx += vx[k]; vmy += vy[k]; } vmx = vmx/n; vmy = vmy/n; ke = 0.0; for(ip=1;ip<=section[i][j][0];ip++) { k = section[i][j][ip]; ke += 0.5*(gasData[kind[k]][0]*1.66e-27)*((vx[k]-vmx)*(vx[k]-vmx)+(vy[k]-vmy)*(vy[k]-vmy)); } temperature[i][j] = ke/n/(1.0*1.38e-23); } pressure[i][j] = density[i][j]*1.38e-23*temperature[i][j]; } } } void drawBlock(int gx, int gy, double sc) { int ix,iy,iss,ca; double ss; ss = sc*xMax/(double)Nsx; iss = (int)(ss+0.999); for (ix=0; ix0) { if (ca==1) { gOff.setColor(Color.getHSBColor(0.85f,0.9f,0.9f)); } else if (ca==2) { gOff.setColor(Color.getHSBColor(0.85f,0.9f,0.2f)); } else if (ca==3) { gOff.setColor(Color.getHSBColor(0.85f,0.9f,0.5f)); } gOff.fillRect(gx+(int)(ss*ix+0.5),gy+(int)(ss*iy+0.5), iss, iss); } } } } void drawWaku(int gx, int gy, double sc) { gOff.setColor(Color.gray); gOff.drawRect(gx,gy,(int)(sc*xMax+0.5),(int)(sc*yMax+0.5)); } /* ---- grid plot ---- */ void gridPlot(double fld[][],double weight, int meanWidth) { gridPlot11(fld,0.0,1); gridPlot11(fld,weight,meanWidth); } void gridPlot11(double fld[][],double weight, int meanWidth) { int i,j,k,gbx,gby; int cx,cy,cz; double z,f,px,py,pz,sc,col; col = 0.85; if (weight>0.0) { setField(); col = 0.66; } cx = Nsx/2; cy = Nsy/2; cz = 0; sc = 6.0; gbx = 40+(int)(cx/sc); gby = 120+(int)(cy/sc); for(j=0; j0.999) f = 0.999; if (f>0.0) { gOff.setColor(Color.getHSBColor((float)(0.66-0.66*f),0.9f,0.9f)); gOff.fillRect(gx+i,gy+j,1,1); } } } gOff.setColor(Color.yellow); gOff.drawLine(gx,gy+125,gx+250,gy+125); gOff.drawLine(gx+125,gy,gx+125,gy+250); } void setVSpace() { int i,j,ip; double v; for(i=0;i<250;i++) { for(j=0;j<250;j++) { vSpace[i][j] = 0; } } for(ip=0;ip0) { i = (int)((vx[ip]+1250.0)/10.0+0.5); if (i<0) { i = 0; } else if (i>249) { i = 249; } j = (int)((vy[ip]+1250.0)/10.0+0.5); if (j<0) { j = 0; } else if (j>249) { j = 249; } vSpace[i][j] += 1; } } } /* ---- velocity distribution plot ---- */ void velocityDistributionPlot(int gx, int gy, double yMag,int kind1, int kind2) { int i,n1,n2; int hoganWidth,hoganHight,xDiv,yDiv; double c1,c2,cm; setVelocityDistribution(kind1, kind2); hoganWidth = 200; hoganHight = 160; xDiv = 50; yDiv = 80; for (i=0; i<200; i++) { n1 = (int)(yMag*vDistribution[i][0]); if (n1>0) { gOff.setColor(Color.lightGray); gOff.drawLine(gx+i,gy+hoganHight,gx+i,gy+hoganHight-n1); } } for (i=0; i<200; i++) { n1 = (int)(yMag*vDistribution[i][1]); n2 = (int)(yMag*vDistribution[i][2]); c1 = gasData[kindOfGas][2]; c2 = gasData[kindOfGas2][2]; cm = 0.5*(c1+c2); if (n1>=n2 && n1>0) { gOff.setColor(Color.getHSBColor((float)cm,0.9f,0.6f)); gOff.drawLine(gx+i,gy+hoganHight,gx+i,gy+hoganHight-n2); gOff.setColor(Color.getHSBColor((float)c1,0.9f,0.9f)); gOff.drawLine(gx+i,gy+hoganHight-n2-1,gx+i,gy+hoganHight-n1); } else if (n10) { gOff.setColor(Color.getHSBColor((float)cm,0.9f,0.6f)); gOff.drawLine(gx+i,gy+hoganHight,gx+i,gy+hoganHight-n1); gOff.setColor(Color.getHSBColor((float)c2,0.9f,0.9f)); gOff.drawLine(gx+i,gy+hoganHight-n1-1,gx+i,gy+hoganHight-n2); } } drawHogan(gx,gy,hoganWidth,hoganHight,xDiv,yDiv); gOff.setColor(Color.black); gOff.drawString("0",gx-5,gy+hoganHight+15); gOff.drawString("2000",gx+hoganWidth-20,gy+hoganHight+15); gOff.drawString("velocity distribution (m/s)",gx+20,gy+hoganHight+30); } void setVelocityDistribution(int kind1, int kind2) { int i,iv; double v; for(i=0;i<200;i++) { vDistribution[i][0] = 0; vDistribution[i][1] = 0; vDistribution[i][2] = 0; } for(i=0;i0) { v = Math.sqrt(vx[i]*vx[i]+vy[i]*vy[i]); iv = (int)(v/10.0); if (iv<200) { vDistribution[iv][0] += 1; if (kind[i]==kind1) { vDistribution[iv][1] += 1; } else if (kind[i]==kind2) { vDistribution[iv][2] += 1; } } } } } void drawHogan(int gx, int gy, int hoganWidth, int hoganHight, int xDiv, int yDiv) { int i; gOff.setColor(Color.gray); for (i=0; i0) { tke += 0.5*(gasData[kind[i]][0]*1.66e-27)*(vx[i]*vx[i]+vy[i]*vy[i]); } } return( ffn*tke ); } int numberOfPartickes(int knd) { int i,n; n = 0; for(i=0;iNsy/2+2)) { cellAttribute[i][j] = 1; } */ } } for (i=0; i0) { s = gasData[kind[i]][1]*1.0e-10; if (s>sMax) sMax = s; } } sigmaMax = 2.0*sMax; } void setTemperature(double temp0, int knd) { int i,n; double m,tke,tmp,r; m = gasData[knd][0]*1.66e-27; n = 0; tke = 0.0; for(i=0;i0) { for(i=0;i0) { xx[i] += vx[i]*dt; yy[i] += vy[i]*dt; ca = cellAttributeAt(xx[i],yy[i]); if (ca>0) { if (ca==1) { wallCell(i); } else if (ca==2) { absorbCell(i); } else if (ca==3) { adsorbCell(i); } } } else if (kind[i]<0) { if (Math.random()<1.0*Math.exp(-adsorptionEnergy/0.025)) { kind[i] = -kind[i]; vx[i] = -vx[i]; vy[i] = -vy[i]; } } } for (i=0; i0) { if (xx[i] < 0.0) { xx[i] = xx[i] + xMax; } if (xx[i] > xMax) { xx[i] = xx[i] - xMax; } if (yy[i] < 0.0) { yy[i] = yy[i] + yMax; } if (yy[i] > yMax) { yy[i] = yy[i] - yMax; } } } } int cellAttributeAt(double x, double y) { int ix,iy; ix = (int)(Nsx*x/xMax); if (ix>=Nsx) ix = Nsx-1; iy = (int)(Nsy*y/yMax); if (iy>=Nsy) iy = Nsy-1; return( cellAttribute[ix][iy] ); } void wallCell(int i) { int at10, at01; xx[i] -= vx[i]*dt; yy[i] -= vy[i]*dt; at10 = cellAttributeAt(xx[i]+vx[i]*dt, yy[i]); at01 = cellAttributeAt(xx[i], yy[i]+vy[i]*dt); if (at10==1) vx[i] = -vx[i]; if (at01==1) vy[i] = -vy[i]; if (at10==0 && at01==0) { vx[i] = -vx[i]; vy[i] = -vy[i]; } } void absorbCell(int i) { kind[i] = 0; } void adsorbCell(int i) { kind[i] = -kind[i]; xx[i] -= vx[i]*dt; yy[i] -= vy[i]*dt; } /*------------------------------- dividing section -------------*/ void dividingSection() { int i,j,ip,iq; for(i=0;i0) { i = (int)(Nsx*xx[ip]/xMax); if (i>=Nsx) i = Nsx-1; j = (int)(Nsy*yy[ip]/yMax); if (j>=Nsy) j = Nsy-1; iq = section[i][j][0]+1; section[i][j][0] = iq; section[i][j][iq] = ip; } } } int maxSection() { int i,j,m; m = 0; for(i=0;im) m = section[i][j][0]; } } return ( m ); } /*------------------------------- interaction -------------*/ void interaction() { int ic,jc,ii,ir,i,j,nn,immc,pi,pj; double vmax,mmc; vvmax2 = 2.0*maxSpeed(); for(ic=0;ic1) { mmc = 0.5*nn*nn*ffn*sigmaMax*vvmax2*dt/vvc; immc = (int)mmc; for(ii=0;ii0) { v2 = vx[i]*vx[i]+vy[i]*vy[i]; if (v2>vm2) vm2 = v2; } } return( Math.sqrt(vm2) ); } void collisionInTheCell(int ic, int jc) { int i,j,pi,pj,nnc; nnc = section[ic][jc][0]; do { i = (int)(nnc*Math.random()); if (i>=nnc) i = nnc-1; j = (int)(nnc*Math.random()); if (j>=nnc) j = nnc-1; } while (i==j); pi = section[ic][jc][i+1]; pj = section[ic][jc][j+1]; collision(pi,pj); } void collision(int i, int j) { double vrel,a,b,vcmx,vcmy,th,costh,sinth; vrel = Math.sqrt((vx[i]-vx[j])*(vx[i]-vx[j])+(vy[i]-vy[j])*(vy[i]-vy[j])); if ( (vrel/vvmax2)> Math.random() && ((gasData[kind[i]][1]+gasData[kind[j]][1])/sigmaMax) > Math.random() ) { a = gasData[kind[i]][0]/(gasData[kind[i]][0]+gasData[kind[j]][0]); b = 1.0 - a; vcmx = a*vx[i] + b*vx[j]; vcmy = a*vy[i] + b*vy[j]; th = 2.0*3.14159265*Math.random(); costh = Math.cos(th); sinth = Math.sin(th); vx[i] = vcmx + vrel*costh*b; vx[j] = vcmx - vrel*costh*a; vy[i] = vcmy + vrel*sinth*b; vy[j] = vcmy - vrel*sinth*a; collisionMark[i] = 1; collisionMark[j] = 1; } } /* ----------------------------- end of applet -------------- */ } /** direct simulation Monte Carlo method (DSMC) * * cell size; Lc = 0.001 (m) * mean free path; lambda ~ 0.002 (m) * No. of representative particle in the cell; Nc ~ 30 (particles) * maximum relative speed; Vmax ~ 2000 (m/s) * time interval; dt = 0.2*Lc/Vmax = 1.0e-7 (s) * maximum cross section of the collision; sgmMax = 2D = 2*4.2e-10 (m) * number density; n = Nc*FN/Lc^2, lambda = 1/(n*sgmMax) * n = 1/(lambda*sgmMax) = 1/(0.002*8.4e-10) = 6.0e11 (particles/m^2) * represent numbers of the real molecule; FN * FN = n*Lc^2/Nc = 6e11*1e-6/30 = 2e4 (particles) --> 5.0e4 (sgm