// Voronoi calculation example code // // Author : Chris H. Rycroft (LBL / UC Berkeley) // Email : chr@alum.mit.edu // Date : August 30th 2011 #include "voro++.hh" using namespace voro; #include using namespace std; // Set up constants for the container geometry const double boxl=1; // Set up the number of blocks that the container is divided into const int bl=10; // Set the number of particles that are going to be randomly introduced const int particles=4000; // Set the number of Voronoi faces to bin const int nface=40; // This function returns a random double between 0 and 1 double rnd() {return double(rand())/RAND_MAX;} int main() { int i,l; double x,y,z,r,dx,dy,dz; int faces[nface],*fp; double p[3*particles]; // 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(-boxl,boxl,-boxl,boxl,-boxl,boxl,bl,bl,bl,false,false,false,8); // Randomly add particles into the container for(i=0;i=nface) i=nface-1; faces[i]++; } while (vl.inc()); con.clear(); for(i=0;i vi; voronoicell_neighbor c; c_loop_all vl(con); if(vl.start()) do if(con.compute_cell(c,vl)) { i=vl.pid(); c.neighbors(vi); for(l=0;l<(signed int) vi.size();l++) if(vi[l]>i) fprintf(ff,"%g %g %g\n%g %g %g\n\n\n", p[3*i],p[3*i+1],p[3*i+2], p[3*vi[l]],p[3*vi[l]+1],p[3*vi[l]+2]); } while (vl.inc()); fclose(ff); }