Minkowski test code.
[voro++.git] / trunk / examples / no_release / voro_lf.cc
blobc9a96d0ddba0432449bd961a88a2abfb62a4efec
1 // File import 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 #include <vector>
11 using namespace std;
13 // Set up constants for the container geometry
14 const double ax=-0.5,bx=25.5;
15 const double ay=-0.5,by=25.5;
16 const double az=-0.5,bz=25.5;
18 int main() {
20 // Manually import the file
21 int i,j,id,max_id=0,n;
22 double x,y,z;
23 vector<int> vid,neigh,f_order;
24 vector<double> vx,vy,vz,vd;
25 FILE *fp=safe_fopen("liq-900K.dat","r"),*fp2,*fp3;
26 while((j=fscanf(fp,"%d %lg %lg %lg",&id,&x,&y,&z))==4) {
27 vid.push_back(id);if(id>max_id) max_id=id;
28 vx.push_back(x);
29 vy.push_back(y);
30 vz.push_back(z);
32 if(j!=EOF) voro_fatal_error("File import error",VOROPP_FILE_ERROR);
33 n=vid.size();
34 fclose(fp);
36 // Compute optimal size for container, and then construct the container
37 double dx=bx-ax,dy=by-ay,dz=bz-az;
38 double l(pow(n/(5.6*dx*dy*dz),1/3.0));
39 int nx=int(dx*l+1),ny=int(dy*l+1),nz=int(dz*l+1);
40 container con(ax,bx,ay,by,az,bz,nx,ny,nz,false,false,false,8);
42 // Print status message
43 printf("Read %d particles, max ID is %d\n"
44 "Container grid is %d by %d by %d\n",n,max_id,nx,ny,nz);
46 // Import the particles, and create ID lookup tables
47 double *xi=new double[max_id+1],*yi=new double[max_id+1],*zi=new double[max_id+1];
48 for(j=0;j<n;j++) {
49 id=vid[j];x=vx[j];y=vy[j];z=vz[j];
50 con.put(id,x,y,z);
51 xi[id]=x;
52 yi[id]=y;
53 zi[id]=z;
56 // Open three output files for statistics and gnuplot cells
57 fp=safe_fopen("liq-900K.out","w");
58 fp2=safe_fopen("liq-900K.gnu","w");
59 fp3=safe_fopen("liq-900K-orig.gnu","w");
61 // Loop over all particles and compute their Voronoi cells
62 voronoicell_neighbor c,c2;
63 c_loop_all cl(con);
64 if(cl.start()) do if(con.compute_cell(c,cl)) {
66 // Get particle position, ID, and neighbor vector
67 cl.pos(x,y,z);
68 id=cl.pid();
69 c.neighbors(neigh);
71 // Get face areas et total surface of faces
72 c.face_areas(vd);c.surface_area();
73 c.draw_gnuplot(x,y,z,fp3);
75 // Initialize second cell
76 c2.init(ax-x,bx-x,ay-y,by-y,az-z,bz-z);
78 // Add condition on surface: >1% total surface. In addition,
79 // skip negative indices, since they correspond to faces
80 // against the container boundaries
81 for(i=0;i<(signed int) vd.size();i++)
82 if(vd[i]>0.01*c.surface_area()&&neigh[i]>=0) {
83 j=neigh[i];
84 c2.nplane(xi[j]-x,yi[j]-y,zi[j]-z,j);
87 // Get information of c2 cell
88 c2.face_areas(vd);c2.face_orders(f_order);
90 // Output information to file
91 i=vd.size();
92 fprintf(fp,"%d %d",id,i);
93 for(j=0;j<i;j++) fprintf(fp," %d",f_order[j]);
94 for(j=0;j<i;j++) fprintf(fp," %.3f",vd[j]);
95 fprintf(fp," %.3f %.3f %.3f\n",x,y,z);
97 c2.draw_gnuplot(x,y,z,fp2);
98 } while (cl.inc());
100 // Close files
101 fclose(fp);
102 fclose(fp2);
104 // Delete dynamically allocated arrays
105 delete [] xi;
106 delete [] yi;
107 delete [] zi;