1 // File import example code
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
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;
20 // Manually import the file
21 int i
,j
,id
,max_id
=0,n
;
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
;
32 if(j
!=EOF
) voro_fatal_error("File import error",VOROPP_FILE_ERROR
);
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];
49 id
=vid
[j
];x
=vx
[j
];y
=vy
[j
];z
=vz
[j
];
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
;
64 if(cl
.start()) do if(con
.compute_cell(c
,cl
)) {
66 // Get particle position, ID, and neighbor vector
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) {
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
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
);
104 // Delete dynamically allocated arrays