1 // Tetrahedron example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
10 // Set up constants for the container geometry
11 const double x_min
=-2,x_max
=2;
12 const double y_min
=-2,y_max
=2;
13 const double z_min
=-2,z_max
=2;
15 // Set up the number of blocks that the container is divided
17 const int n_x
=7,n_y
=7,n_z
=7;
19 // Set the number of particles that are going to be randomly
21 const int particles
=64;
23 // This function returns a random double between 0 and 1
24 double rnd() {return double(rand())/RAND_MAX
;}
30 // Create a container with the geometry given above, and make it
31 // non-periodic in each of the three coordinates. Allocate space for 8
32 // particles within each computational block.
33 container
con(x_min
,x_max
,y_min
,y_max
,z_min
,z_max
,n_x
,n_y
,n_z
,
36 // Add four plane walls to the container to make a tetrahedron
37 wall_plane
p1(1,1,1,1);con
.add_wall(p1
);
38 wall_plane
p2(-1,-1,1,1);con
.add_wall(p2
);
39 wall_plane
p3(1,-1,-1,1);con
.add_wall(p3
);
40 wall_plane
p4(-1,1,-1,1);con
.add_wall(p4
);
42 // Randomly insert particles into the container, checking that they lie
43 // inside the tetrahedron
45 x
=x_min
+rnd()*(x_max
-x_min
);
46 y
=y_min
+rnd()*(y_max
-y_min
);
47 z
=z_min
+rnd()*(z_max
-z_min
);
48 if (con
.point_inside(x
,y
,z
)) {
53 // Output the particle positions and the Voronoi cells in Gnuplot and
55 con
.draw_particles("tetrahedron_p.gnu");
56 con
.draw_cells_gnuplot("tetrahedron_v.gnu");
57 con
.draw_particles_pov("tetrahedron_p.pov");
58 con
.draw_cells_pov("tetrahedron_v.pov");