Strip extra spaces from code.
[voro++.git] / branches / exact / examples / walls / frustum.cc
blob925ded31fd42c730aacd917cbe2684ffed46b7b3
1 // Frustum 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 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(-1.2,1.2,-1.2,1.2,0,1,14,14,7,
20 false,false,false,8);
22 // Add a cylindrical wall to the container
23 wall_cone cone(0,0,2,0,0,-1,atan(0.5));
24 con.add_wall(cone);
26 // Place particles in a regular grid within the frustum, for points
27 // which are within the wall boundaries
28 for(z=0.1;z<1;z+=0.2) for(y=-0.85;y<1;y+=0.2) for(x=-0.95;x<1;x+=0.2) {
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("frustum_p.gnu");
36 con.draw_cells_gnuplot("frustum_v.gnu");
38 // Output the particle positions and Voronoi cells in POV-Ray format
39 con.draw_particles_pov("frustum_p.pov");
40 con.draw_cells_pov("frustum_v.pov");
42 // Compute the volume of the Voronoi cells and compare it to the
43 // exact frustum volume
44 evol=pi*1*(0.5*0.5+0.5*1+1*1)/3;
45 vvol=con.sum_cell_volumes();
46 printf("Exact frustum volume : %g\n"
47 "Voronoi cell volume : %g\n"
48 "Difference : %g\n",evol,vvol,vvol-evol);