/** applet No. 015 * * template - Lennard-Jones potential - molecular dynamics 2D * * Created by Ikeuchi Mitsuru on July 17 2002. * Copyright (c) 2002-2007 Ikeuchi Mitsuru. All rights reserved. * * ver 0.0.1 2002.07.17 created * ver 0.0.2 2002.09.07 eps(i,j) = sqrt(eps(i)*eps(j)) * ver 0.0.3 2003.07.29 off screen * ver 0.0.4 2003.11.18 improved display code * ver 0.0.5 2004.02.04 improved pannel layout * ver 0.0.6 2007.05.12 added setBoundary() * ver 0.0.7 2007.05.18 improved code * ver 0.0.8 2007.06.26 improved code * */ import java.awt.*; import java.awt.event.*; import java.applet.*; public class LennardJonesGas2D extends Applet implements ItemListener, ActionListener, AdjustmentListener, Runnable { // ------------------------------------ preset field ----------- Thread th = null; // for run()-paint() thread // for event Choice ch_mat1, ch_mat2, ch_tempCont, ch_view; Button bt_reset, bt_startStop; Scrollbar sc_temp; // for off-paint buffer Dimension dim; Image imgOff; Graphics gOff; // MD2D double t = 0.0; // time (s) double dt = 10.0*1.0e-15; // time division (s) double xMax = 6.0e-9; // x-Box size (m) double yMax = 6.0e-9; // y-Box size (m) int tempMode = 2; // 0-adiabatic 1-scaling 2-wall cont double contTemp = 300.0; // control temperature (K) int resetSW = 0; // 1-reset int startSW = 1; // 0-stop 1-start double AU = 1.661e-27; double EE = 1.602e-19; double AA = 1.0e-10; double KB = 1.38e-23; double FS = 1.0e-15; double Molec[][] = { // mass charge E(in kB) sigma(A) dt(s) color { 4.003*AU, 0.0*EE, 10.2*KB, 2.576*AA, 5.0*FS, 0.65 }, // 0 He { 20.183*AU, 0.0*EE, 36.2*KB, 2.976*AA, 10.0*FS, 0.60 }, // 1 Ne { 39.948*AU, 0.0*EE, 124.0*KB, 3.418*AA, 10.0*FS, 0.55 }, // 2 Ar { 83.50 *AU, 0.0*EE, 190.0*KB, 3.610*AA, 10.0*FS, 0.50 }, // 3 Kr { 131.30 *AU, 0.0*EE, 229.0*KB, 4.055*AA, 10.0*FS, 0.45 }, // 4 Xe { 200.59 *AU, 0.0*EE, 851.0*KB, 2.898*AA, 10.0*FS, 0.40 }, // 5 Hg { 2.016*AU, 0.0*EE, 33.3*KB, 2.968*AA, 5.0*FS, 0.01}, // 6 H2 { 28.013*AU, 0.0*EE, 91.5*KB, 3.681*AA, 10.0*FS, 0.10 }, // 7 N2 { 31.999*AU, 0.0*EE, 113.0*KB, 3.433*AA, 10.0*FS, 0.15 }, // 8 O2 { 18.015*AU, 0.0*EE, 809.1*KB, 2.641*AA, 10.0*FS, 0.20 }, // 9 H2O { 16.043*AU, 0.0*EE, 137.0*KB, 3.822*AA, 10.0*FS, 0.70 }, //10 CH4 { 44.010*AU, 0.0*EE, 190.0*KB, 3.996*AA, 10.0*FS, 0.25 }, //11 CO2 { 28.011*AU, 0.0*EE, 110.0*KB, 3.590*AA, 10.0*FS, 0.30 }, //12 CO { 30.000*AU, 0.0*EE, 230.0*KB, 4.418*AA, 10.0*FS, 0.74 }, //13 C2H6 { 44.000*AU, 0.0*EE, 254.0*KB, 5.061*AA, 10.0*FS, 0.78 }, //14 C3H8 { 78.000*AU, 0.0*EE, 440.0*KB, 5.270*AA, 10.0*FS, 0.82 }, //15 C6H6 { 32.000*AU, 0.0*EE, 507.0*KB, 3.585*AA, 10.0*FS, 0.86 }, //16 CH3OH { 46.000*AU, 0.0*EE, 415.0*KB, 4.370*AA, 10.0*FS, 0.90 } //17 C2H5OH }; String material[] = { "He" ,"Ne","Ar","Kr","Xe","Hg","H2","N2","O2","H2O", "CH4","CO2","CO","C2H6" ,"C3H8","C6H6","CH3OH","C2H5OH" }; int kindMax = 18; int MAT1 = 2; // Ar int MAT2 = 9; // H2O int Nmt = 36; // number of molecules int NN = Nmt; int kind[] = new int[NN]; // i-th particle kind double xx[] = new double[NN]; // i-th x-position double yy[] = new double[NN]; // i-th y-position double vx[] = new double[NN]; // i-th x-velocity double vy[] = new double[NN]; // i-th y-velocity double ffx[] = new double[NN]; // i-th x-force double ffy[] = new double[NN]; // i-th y-force // display int sleepTime = 30; // sleep time (ms) int dispWidth = 630; int dispHeight = 460; int dispMode = 0; double boxDispWidth = 320.0; double dispScale = (boxDispWidth/xMax); double viewScale = 1.0; // ------------------------------ applet main thread ----------- public void init() { resize(dispWidth,dispHeight); setBackground(Color.white); dim = getSize(); imgOff = createImage(dim.width,dim.height); gOff = imgOff.getGraphics(); ch_mat1 = new Choice(); for (int i=0; i1.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]; } } } // --------------------------------------- utilities ----------- private double temperature() { int i; double s; s = 0.0; for (i=0; i