Minkowski test code.
[voro++.git] / trunk / examples / no_release / sphere.cc
blob5461a78465596f3d28a4119b760cf97898e4c189
1 // Sphere example code
2 //
3 // Author : Chris H. Rycroft (Harvard SEAS)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
7 #include "voro++.hh"
8 using namespace voro;
10 const double pi=3.1415926535897932384626433832795;
12 int main() {
13 int i=0;
14 double x,y,z,evol,vvol;
16 // Create a container with the geometry given above, and make it
17 // non-periodic in each of the three coordinates. Allocate space for
18 // eight particles within each computational block.
19 container con(-5,5,-5,5,-5,5,6,6,6,
20 false,false,false,8);
22 // Add a cylindrical wall to the container
23 wall_sphere sph(0,0,0,4);
24 con.add_wall(sph);
26 // Place particles in a regular grid within the frustum, for points
27 // which are within the wall boundaries
28 for(z=-4.5;z<5;z+=1) for(y=-4.5;y<5;y+=1) for(x=-4.5;x<5;x+=1) {
29 if (con.point_inside(x,y,z)) {
30 con.put(i,x,y,z);i++;
34 // Output the particle positions and Voronoi cells in Gnuplot format
35 con.draw_particles("sphere_p.gnu");
36 con.draw_cells_gnuplot("sphere_v.gnu");
38 // Compute the volume of the Voronoi cells and compare it to the
39 // exact frustum volume
40 evol=4/3.0*pi*4*4*4;
41 vvol=con.sum_cell_volumes();
42 printf("Exact sphere volume : %g\n"
43 "Voronoi cell volume : %g\n"
44 "Difference : %g\n",evol,vvol,vvol-evol);