3 /**************************************************************************
5 * Java Grande Forum Benchmark Suite - Version 2.0 *
9 * Java Grande Benchmarking Project *
13 * Edinburgh Parallel Computing Centre *
15 * email: epcc-javagrande@epcc.ed.ac.uk *
17 * Original version of this code by *
19 * converted to Java by *
20 * Lorna Smith (l.smith@epcc.ed.ac.uk) *
21 * (see copyright notice below) *
23 * This version copyright (c) The University of Edinburgh, 2001. *
24 * All rights reserved. *
26 **************************************************************************/
44 float hsq, hsq2, den, h, vaver,vaverh;
50 public Particle[] one;
51 public float[][] sh_force;
52 //public float[] epot;
62 public void MD(int d, int g) {
65 this.mdsize = this.mm * this.mm * this.mm * 4;
66 this.one = new Particle [this.mdsize];
67 this.sh_force = new float[3][this.mdsize];
70 this.den = (float)0.83134;
71 this.h = (float)0.064;
72 this.side = Math.powf((float)(this.mdsize/this.den),(float)0.3333333);
73 this.hsq = this.h * this.h;
74 this.hsq2 = this.hsq * (float)0.5;
75 this.vaver = (float)1.13 * Math.sqrtf((float)this.tref / (float)24.0);
76 this.vaverh = this.vaver * this.h;
79 //this.epot = (float)0.0;
80 //this.vir = (float)0.0;
81 this.tref = (float)0.722;
82 this.tscale = (float)16.0 / ((float)1.0 * (float)this.mdsize - (float)1.0);
86 this.epot = (float)0.0;//new float[this.group + 1];
87 this.vir = (float)0.0;//new float[this.group + 1];
88 this.ek = (float)0.0;//new float[this.group + 1];
92 /*for(int i = 0; i < this.group + 1; i++) {
93 this.epot[i] = (float)0.0;
94 this.vir[i] = (float)0.0;
96 this.epot = (float)0.0;
97 this.vir = (float)0.0;
98 for(int j = 0; j < 3; j++) {
99 for (int i = 0; i < this.mdsize; i++) {
100 this.sh_force[j][i] = (float)0.0;
106 public void initialise() {
108 /* Particle Generation */
109 float xvelocity, yvelocity, zvelocity;
110 int ijk, lg, i, j, k;
111 float a = this.side/this.mm;
112 xvelocity = (float)0.0;
113 yvelocity = (float)0.0;
114 zvelocity = (float)0.0;
115 //System.printString("here 1\n");
116 //System.printI(0xa0);
118 for (lg=0; lg<=1; lg++) {
119 for (i=0; i<mm; i++) {
120 for (j=0; j<mm; j++) {
121 for (k=0; k<mm; k++) {
122 one[ijk] = new Particle((float)(i*a+lg*a*(float)0.5),(float)(j*a+lg*a*(float)0.5),(k*a),
123 xvelocity,yvelocity,zvelocity,this);
129 for (lg=1; lg<=2; lg++) {
130 for (i=0; i<mm; i++) {
131 for (j=0; j<mm; j++) {
132 for (k=0; k<mm; k++) {
133 one[ijk] = new Particle((float)(i*a+(2-lg)*a*(float)0.5),(float)(j*a+(lg-1)*a*(float)0.5),
134 (float)(k*a+a*(float)0.5),xvelocity,yvelocity,zvelocity,this);
140 //System.printString("here 2\n");
141 //System.printI(0xa1);
142 /* Initialise velocities */
149 MyRandom random = new MyRandom(iseed,v1,v2);
150 //System.printString("here 3\n");
151 //System.printI(0xa2);
152 for (i=0; i<this.mdsize; i+=2) {
154 one[i].xvelocity = r*random.v1;
155 one[i+1].xvelocity = r*random.v2;
157 //System.printString("here 4\n");
158 //System.printI(0xa3);
159 for (i=0; i<this.mdsize; i+=2) {
161 one[i].yvelocity = r*random.v1;
162 one[i+1].yvelocity = r*random.v2;
164 //System.printString("here 5\n");
165 //System.printI(0xa4);
166 for (i=0; i<this.mdsize; i+=2) {
168 one[i].zvelocity = r*random.v1;
169 one[i+1].zvelocity = r*random.v2;
172 /*for(i = 0; i < this.mdsize; i++) {
173 System.printString("xvel: " + (int)(one[i].xvelocity*100000) + "; yvel: " + (int)(one[i].yvelocity*100000) + "; zvel: " + (int)(one[i].zvelocity*100000) + "\n");
176 //System.printString("here 6\n");
177 //System.printI(0xa5);
178 /* velocity scaling */
182 //System.printString("here 7\n");
183 //System.printI(0xa6);
184 for(i=0;i<this.mdsize;i++) {
185 sp = sp + one[i].xvelocity;
187 sp = sp / this.mdsize;
188 //System.printString("here 8\n");
189 //System.printI(0xa7);
190 for(i=0;i<this.mdsize;i++) {
191 one[i].xvelocity = one[i].xvelocity - sp;
192 ekin = ekin + one[i].xvelocity*one[i].xvelocity;
194 //System.printString("here 9\n");
195 //System.printI(0xa8);
197 for(i=0;i<this.mdsize;i++) {
198 sp = sp + one[i].yvelocity;
200 sp = sp / this.mdsize;
201 //System.printString("here 10\n");
202 //System.printI(0xa9);
203 for(i=0;i<this.mdsize;i++) {
204 one[i].yvelocity = one[i].yvelocity - sp;
205 ekin = ekin + one[i].yvelocity*one[i].yvelocity;
207 //System.printString("here 11\n");
208 //System.printI(0xa10);
210 for(i=0;i<this.mdsize;i++) {
211 sp = sp + one[i].zvelocity;
213 sp = sp / this.mdsize;
214 //System.printString("here 12\n");
215 //System.printI(0xa11);
216 for(i=0;i<this.mdsize;i++) {
217 one[i].zvelocity = one[i].zvelocity - sp;
218 ekin = ekin + one[i].zvelocity*one[i].zvelocity;
220 //System.printString("here 13\n");
221 //System.printI(0xa12);
222 ts = this.tscale * ekin;
223 sc = h * Math.sqrtf(this.tref/ts);
225 for(i=0;i<this.mdsize;i++) {
226 one[i].xvelocity = one[i].xvelocity * sc;
227 one[i].yvelocity = one[i].yvelocity * sc;
228 one[i].zvelocity = one[i].zvelocity * sc;
230 //System.printString("here 14\n");
231 //System.printI(0xa13);
235 public void domove(){
236 for (int i=0;i<this.mdsize;i++) {
237 one[i].domove(this.side,i);
240 /*for(int j=0;j<3;j++) {
241 for (int i=0;i<mdsize;i++) {
242 sh_force[j][i] = (float)0.0;
249 public boolean finish() {
250 if(this.move == this.movemx) {
256 public void update(MDRunner runner) {
257 float sum, vel,velt, count, sc;
258 float etot,temp,pres,rp;
260 /* update force arrays */
261 for(int k=0;k<3;k++) {
262 for(int i=0;i<this.mdsize;i++) {
263 sh_force[k][i] += runner.sh_force2[k][i];
269 //this.epot[runner.id + 1] = runner.epot;
270 //this.vir[runner.id + 1] = runner.vir;
271 this.epot += runner.epot;
272 this.vir += runner.vir;
276 float sum = (float)0.0;
278 for (int j=0;j<3;j++) {
279 for (int i=0;i<this.mdsize;i++) {
280 sh_force[j][i] = sh_force[j][i] * hsq2;
285 for (int i=0;i<this.mdsize;i++) {
286 sum = sum + this.one[i].mkekin(hsq2,i);
288 ekin = (float)(sum/hsq);
291 public void scale() {
292 float sum, vel,velt, count, sc;
293 float etot,temp,pres,rp;
295 //runner.epot = this.epot[0];
296 //runner.vir = this.vir[0];
301 /* average velocity */
302 for (int i=0;i<this.mdsize;i++) {
303 velt = this.one[i].velavg(vaverh,h);
305 count = count + (float)1.0;
309 vel = (float)(vel / h);
311 /* temperature scale if required */
312 if((this.move < this.istop) && (((this.move+1) % this.irep) == 0)) {
313 sc = Math.sqrtf(this.tref / (this.tscale*ekin));
314 for (int i=0;i<mdsize;i++) {
317 ekin = (float)(this.tref / this.tscale);
320 /* sum to get full potential energy and virial */
321 if(((this.move+1) % this.iprint) == 0) {
322 /*this.ek[runner.id+1] = (float)24.0*ekin;
323 this.epot[runner.id+1] = (float)4.0*this.epot[runner.id+1];
324 etot = this.ek[runner.id+1] + this.epot[runner.id+1];
325 temp = this.tscale * ekin;
326 pres = den * (float)16.0 * (ekin - this.vir[runner.id+1]) / mdsize;
327 vel = vel / this.mdsize;
328 rp = (count / this.mdsize) * (float)100.0;
330 if(this.counter == this.group) {*/
331 this.ek = (float)24.0*ekin;
332 //this.epot[0] = (float)4.0*this.epot[0];
333 //etot = this.ek[0] + this.epot[0];
334 //temp = this.tscale * ekin;
335 //pres = den * (float)16.0 * (ekin - this.vir[0]) / mdsize;
336 //vel = vel / this.mdsize;
337 //rp = (count / this.mdsize) * (float)100.0;
338 //System.printString("ek: " + (int)(this.ek*1000000) + " (" + this.move + ")\n");
343 public void validate() {
344 float refval = (float)1731.4306625334357;
345 float dev = Math.abs(this.ek - refval);
347 //System.printString("Validation failed\n");
348 //System.printString("Kinetic Energy = " + (int)(this.ek*1000000) + "; " + (int)(refval*1000000) + "\n");
349 //System.printI(0xdddf);
350 //System.printI((int)(this.ek[0]*1000000));
351 //System.printI((int)(refval*1000000));
352 //System.printI((int)(ek*10000));
353 //System.printI((int)(refval*10000));