1 // Voronoi calculation example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : October 19th 2007
9 // Set up constants for the container geometry
10 const double x_min
=-2,x_max
=2;
11 const double y_min
=-2,y_max
=2;
12 const double z_min
=-2,z_max
=2;
14 // Set up the number of blocks that the container is divided
16 const int n_x
=7,n_y
=7,n_z
=14;
18 // Set the number of particles that are going to be randomly
20 const int particles
=64;
22 // This function returns a random double between 0 and 1
23 double rnd() {return double(rand())/RAND_MAX
;}
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 // 8 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
,
35 // Add a cylindrical wall to the container
36 wall_plane
p1(1,1,1,1);con
.add_wall(p1
);
37 wall_plane
p2(-1,-1,1,1);con
.add_wall(p2
);
38 wall_plane
p3(1,-1,-1,1);con
.add_wall(p3
);
39 wall_plane
p4(-1,1,-1,1);con
.add_wall(p4
);
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
);
45 if (con
.point_inside(x
,y
,z
)) {
50 // Output the particle positions and the Voronoi cells in Gnuplot and
52 con
.draw_particles("tetrahedron_p.gnu");
53 con
.draw_cells_gnuplot("tetrahedron_v.gnu");
54 con
.draw_particles_pov("tetrahedron_p.pov");
55 con
.draw_cells_pov("tetrahedron_v.pov");