L-shape calculation added.
[voro++.git] / trunk / examples / timing / timing_test.cc
blobf3dedd714215915f36c4445d0f6c4f6bedc00d78
1 // Timing test example code
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 #include <ctime>
8 using namespace std;
10 #include "voro++.cc"
11 using namespace voro;
13 // Set up constants for the container geometry
14 const double x_min=-1,x_max=1;
15 const double y_min=-1,y_max=1;
16 const double z_min=-1,z_max=1;
18 // Set up the number of blocks that the container is divided into. If the
19 // preprocessor variable NNN hasn't been passed to the code, then initialize it
20 // to a good value. Otherwise, use the value that has been passed.
21 #ifndef NNN
22 #define NNN 26
23 #endif
24 const int n_x=NNN,n_y=NNN,n_z=NNN;
26 // Set the number of particles that are going to be randomly introduced
27 const int particles=100000;
29 // This function returns a random double between 0 and 1
30 double rnd() {return double(rand())/RAND_MAX;}
32 int main() {
33 clock_t start,end;
34 int i;double x,y,z;
36 // Create a container with the geometry given above, and make it
37 // periodic in each of the three coordinates. Allocate space for eight
38 // particles within each computational block.
39 container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
40 true,true,true,8);
42 //Randomly add particles into the container
43 for(i=0;i<particles;i++) {
44 x=x_min+rnd()*(x_max-x_min);
45 y=y_min+rnd()*(y_max-y_min);
46 z=z_min+rnd()*(z_max-z_min);
47 con.put(i,x,y,z);
50 // Store the initial clock time
51 start=clock();
53 // Carry out a dummy computation of all cells in the entire container
54 con.compute_all_cells();
56 // Calculate the elapsed time and print it
57 end=clock();
58 double runtime=double(end-start)/CLOCKS_PER_SEC;
59 printf("%g\n",runtime);