File: frustum.cc

package info (click to toggle)
voro%2B%2B 0.4.6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,372 kB
  • sloc: cpp: 6,384; perl: 232; makefile: 164
file content (49 lines) | stat: -rw-r--r-- 1,498 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Frustum example code
//
// Author   : Chris H. Rycroft (LBL / UC Berkeley)
// Email    : chr@alum.mit.edu
// Date     : August 30th 2011

#include "voro++.hh"
using namespace voro;

const double pi=3.1415926535897932384626433832795;

int main() {
	int i=0;
	double x,y,z,evol,vvol;

	// Create a container with the geometry given above, and make it
	// non-periodic in each of the three coordinates. Allocate space for
	// eight particles within each computational block.
	container con(-1.2,1.2,-1.2,1.2,0,1,14,14,7,
			false,false,false,8);

	// Add a cylindrical wall to the container
	wall_cone cone(0,0,2,0,0,-1,atan(0.5));
	con.add_wall(cone);

	// Place particles in a regular grid within the frustum, for points
	// which are within the wall boundaries
	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) {
		if (con.point_inside(x,y,z)) {
			con.put(i,x,y,z);i++;
		}
	}

	// Output the particle positions and Voronoi cells in Gnuplot format
	con.draw_particles("frustum_p.gnu");
	con.draw_cells_gnuplot("frustum_v.gnu");

	// Output the particle positions and Voronoi cells in POV-Ray format
	con.draw_particles_pov("frustum_p.pov");
	con.draw_cells_pov("frustum_v.pov");

	// Compute the volume of the Voronoi cells and compare it to the
	// exact frustum volume
	evol=pi*1*(0.5*0.5+0.5*1+1*1)/3;
	vvol=con.sum_cell_volumes();
	printf("Exact frustum volume : %g\n"
	       "Voronoi cell volume  : %g\n"
	       "Difference           : %g\n",evol,vvol,vvol-evol);
}