Strip extra spaces from code.
[voro++.git] / trunk / examples / walls / tetrahedron.cc
blobeadfb8afecdd872525891ffefb67313f2ef7b6a1
1 // Tetrahedron 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=-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
16 // into
17 const int n_x=7,n_y=7,n_z=7;
19 // Set the number of particles that are going to be randomly
20 // introduced
21 const int particles=64;
23 // This function returns a random double between 0 and 1
24 double rnd() {return double(rand())/RAND_MAX;}
26 int main() {
27 int i=0;
28 double x,y,z;
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,
34 false,false,false,8);
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
44 while(i<particles) {
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)) {
49 con.put(i,x,y,z);i++;
53 // Output the particle positions and the Voronoi cells in Gnuplot and
54 // POV-Ray formats
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");