1 // Voronoi calculation example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : July 1st 2008
9 const double pi
=3.1415926535897932384626433832795;
13 fpoint x
,y
,z
,evol
,vvol
;
15 // Create a container with the geometry given above, and make it
16 // non-periodic in each of the three coordinates. Allocate space for
17 // eight particles within each computational block.
18 container
con(-1.2,1.2,-1.2,1.2,0,1,14,14,7,
21 // Add a cylindrical wall to the container
22 wall_cone
cone(0,0,2,0,0,-1,atan(0.5));
25 // Place particles in a regular grid within the frustum, for points
26 // which are within the wall boundaries
27 for(z
=0.1;z
<1;z
+=0.2) for(y
=-0.95;y
<1;y
+=0.2) for(x
=-0.95;x
<1;x
+=0.2) {
28 if (con
.point_inside(x
,y
,z
)) {
33 // Output the particle positions and Voronoi cells in Gnuplot format
34 con
.draw_particles("frustum_p.gnu");
35 con
.draw_cells_gnuplot("frustum_v.gnu");
37 // Output the particle positions and Voronoi cells in POV-Ray format
38 con
.draw_particles_pov("frustum_p.pov");
39 con
.draw_cells_pov("frustum_v.pov");
41 // Compute the volume of the Voronoi cells and compare it to the
42 // exact frustum volume
43 evol
=pi
*1*(0.5*0.5+0.5*1+1*1)/3;
44 vvol
=con
.sum_cell_volumes();
45 cout
<< "Exact frustum volume : " << evol
<< "\n";
46 cout
<< "Voronoi cell volume : " << vvol
<< "\n";
47 cout
<< "Difference : " << vvol
-evol
<< endl
;