1 // Voronoi calculation 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
=-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
)*(x_max
-x_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
;}
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_periodic_poly
con(2,0.5,2,0,0,2,n_x
,n_y
,n_z
,8);
34 // Randomly add particles into the container
36 x
=x_min
+rnd()*(x_max
-x_min
);
37 y
=y_min
+rnd()*(y_max
-y_min
);
38 z
=z_min
+rnd()*(z_max
-z_min
);
42 // Output the particle positions in gnuplot format
43 con
.draw_particles("ghost_test_p.gnu");
45 // Output the Voronoi cells in gnuplot format
46 con
.draw_cells_gnuplot("ghost_test_v.gnu");
48 // Open file for test ghost cell
49 FILE *fp
=safe_fopen("ghost_test_c.gnu","w");
52 // Compute a range of ghost cells
53 // for(y=-3.5;y<3.5;y+=0.05) if(con.compute_ghost_cell(c,1,y,0,1))
54 // c.draw_gnuplot(1,y,0,fp);
56 // Compute a single ghost cell
57 if(con
.compute_ghost_cell(c
,1.56,0.67,0,1)) c
.draw_gnuplot(1.56,0.67,0,fp
);
59 // Close ghost cell file
63 con
.draw_domain_gnuplot("ghost_test_d.gnu");