Bugfix in search_for_outside_edge routine.
[voro++.git] / trunk / examples / no_release / minkowski.cc
blobbd71fd7c46b2f18ff238c518bd6f5f72157e05ba
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;
15 // Set up the number of blocks that the container is divided into
16 const int n_x=6,n_y=6,n_z=6;
18 // Set the number of particles that are going to be randomly introduced
19 const int particles=20;
21 // This function returns a random double between 0 and 1
22 double rnd() {return double(rand())/RAND_MAX;}
24 int main() {
25 int i;
26 double x,y,z;
28 // Create a container with the geometry given above, and make it
29 // non-periodic in each of the three coordinates. Allocate space for
30 // eight particles within each computational block
31 container con(x_min,x_max,y_min,y_max,z_min,z_max,n_x,n_y,n_z,
32 false,false,false,8);
34 // Randomly add particles into the container
35 for(i=0;i<particles;i++) {
36 x=x_min+rnd()*(x_max-x_min);
37 y=y_min+rnd()*(y_max-y_min);
38 z=z_min+rnd()*(z_max-z_min);
39 con.put(i,x,y,z);
42 double vo[400],ar[400],tvo,tar;
43 for(i=0;i<400;i++) vo[i]=0;
44 for(i=0;i<400;i++) ar[i]=0;
46 voronoicell c;
47 c_loop_all cl(con);
48 if(cl.start()) do if(con.compute_cell(c,cl)) {
49 for(i=0;i<400;i++) {
50 c.minkowski(i*0.005,tvo,tar);
51 vo[i]+=tvo;ar[i]+=tar;
53 } while(cl.inc());
56 for(i=0;i<400;i++) printf("%g %g %g\n",i*0.005,vo[i],ar[i]);