1 // Voronoi calculation example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : July 1st 2008
11 // Set up constants for the container geometry
12 const double x_min
=-1,x_max
=1;
13 const double y_min
=-1,y_max
=1;
14 const double z_min
=-1,z_max
=1;
16 // Set up the number of blocks that the container is divided into. If the
17 // preprocessor variable NNN hasn't been passed to the code, then initialize it
18 // to a good value. Otherwise, use the value that has been passed.
22 const int n_x
=NNN
,n_y
=NNN
,n_z
=NNN
;
24 // Set the number of particles that are going to be randomly introduced
25 const int particles
=100000;
27 // This function returns a random double between 0 and 1
28 double rnd() {return double(rand())/RAND_MAX
;}
34 // Create a container with the geometry given above, and make it
35 // periodic in each of the three coordinates. Allocate space for eight
36 // particles within each computational block.
37 container
con(x_min
,x_max
,y_min
,y_max
,z_min
,z_max
,n_x
,n_y
,n_z
,
40 //Randomly add particles into the container
41 for(i
=0;i
<particles
;i
++) {
42 x
=x_min
+rnd()*(x_max
-x_min
);
43 y
=y_min
+rnd()*(y_max
-y_min
);
44 z
=z_min
+rnd()*(z_max
-z_min
);
48 // Store the initial clock time
51 // Carry out a dummy computation of all cells in the entire container
52 con
.compute_all_cells();
54 // Calculate the elapsed time and print it
56 double runtime
=double(end
-start
)/CLOCKS_PER_SEC
;
57 cout
<< runtime
<< endl
;