Minkowski test code.
[voro++.git] / trunk / examples / no_release / rad_test.cc
blob94986cf14a7d45922c9a31dface607296e96f8af
1 // Voronoi calculation 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 // 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=3,n_y=3,n_z=3;
19 // Set the number of particles that are going to be randomly introduced
20 const int particles=1000;
22 // This function returns a random double between 0 and 1
23 double rnd() {return double(rand())/RAND_MAX;}
25 int main() {
26 int i;
27 double pos[particles*4],*posp=pos;
29 for(i=0;i<particles;i++) {
30 *(posp++)=x_min+rnd()*(x_max-x_min);
31 *(posp++)=y_min+rnd()*(y_max-y_min);
32 *(posp++)=z_min+rnd()*(z_max-z_min);
33 *(posp++)=rnd();
36 char buf[128];
37 for(i=0;i<=200;i++) {
38 int j;double x,y,z,r,mul=i*0.01,vol=0;
40 container_poly con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
41 false,false,false,8);
43 posp=pos;
44 for(int j=0;j<particles;j++) {
45 x=*(posp++);y=*(posp++);z=*(posp++);r=*(posp++)*mul;
46 con.put(j,x,y,z,r);
49 sprintf(buf,"rad_test_out/fr%d.pov",i);
50 // FILE *pf=safe_fopen(buf,"w");
51 j=0;
52 c_loop_all cl(con);
53 voronoicell c;
54 cl.start();
55 do {
56 if(con.compute_cell(c,cl)) {
57 vol+=c.volume();
58 cl.pos(x,y,z);
59 // c.draw_pov(x,y,z,pf);
60 j++;
62 } while(cl.inc());
64 printf("%g %d %g %g\n",mul,j,vol,vol-8);
65 // fclose(pf);