Minkowski test code.
[voro++.git] / trunk / examples / no_release / r_pts_interface.cc
bloba14481bb540d8ced5dc2a51e348703f2f9fc0f03
1 // Voronoi calculation example code
2 //
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 #include "voro++.hh"
8 using namespace voro;
10 // Set up constants for the container geometry
11 const double x_min=-1,x_max=1;
12 const double y_min=-1,y_max=1;
13 const double z_min=-1,z_max=1;
14 const double cvol=(x_max-x_min)*(y_max-y_min)*(z_max-z_min);
16 // Set up the number of blocks that the container is divided into
17 const int n_x=6,n_y=6,n_z=6;
19 // Set the number of particles that are going to be randomly introduced
20 const int particles=20;
22 // This function returns a random double between 0 and 1
23 double rnd() {return double(rand())/RAND_MAX;}
25 int main() {
26 int i;
27 double x,y,z;
29 // Create a container with the geometry given above, and make it
30 // non-periodic in each of the three coordinates. Allocate space for
31 // eight particles within each computational block
32 container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
33 false,false,false,8);
35 // Randomly add particles into the container
36 for(i=0;i<particles;i++) {
37 x=x_min+rnd()*(x_max-x_min);
38 y=y_min+rnd()*(y_max-y_min);
39 z=z_min+rnd()*(z_max-z_min);
40 con.put(i,x,y,z);
43 // Use the C++ interface to do custom computations
44 double cx,cy,cz,vvol=0;
45 voronoicell c;
46 c_loop_all cl(con);
47 if(cl.start()) do if(con.compute_cell(c,cl)) {
49 // Get particle position and ID
50 cl.pos(x,y,z);i=cl.pid();
52 // Calculate centroid
53 c.centroid(cx,cy,cz);
54 printf("Particle %2d at (% .3f,% .3f,% .3f), centroid at (% .3f,% .3f,% .3f)\n",
55 i,x,y,z,x+cx,y+cy,z+cz);
57 // Calculate volume and sum it
58 vvol+=c.volume();
60 // Do other calculations and store the information
61 // ...
62 // ...
63 // ...
65 } while(cl.inc());
67 // Print the volume check
68 printf("\nContainer volume : %g\n"
69 "Voronoi volume : %g\n"
70 "Difference : %g\n",cvol,vvol,vvol-cvol);
72 // Output the particle positions in gnuplot format
73 con.draw_particles("random_points_p.gnu");
75 // Output the Voronoi cells in gnuplot format
76 con.draw_cells_gnuplot("random_points_v.gnu");