1 // Irregular packing 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 x_min
=-15,x_max
=15;
15 const double y_min
=-7,y_max
=7;
16 const double z_min
=-15,z_max
=15;
18 // Golden ratio constants
19 const double Phi
=0.5*(1+sqrt(5.0));
20 const double phi
=0.5*(1-sqrt(5.0));
22 // Set up the number of blocks that the container is divided
24 const int n_x
=8,n_y
=8,n_z
=8;
26 // ID for dodecahedron faces
29 // Create a wall class that, whenever called, will replace the Voronoi cell
30 // with a prescribed shape, in this case a dodecahedron
31 class wall_initial_shape
: public wall
{
33 wall_initial_shape() {
35 // Create a dodecahedron with neighbor information all
37 v
.init(-2,2,-2,2,-2,2);
38 v
.nplane(0,Phi
,1,wid
);v
.nplane(0,-Phi
,1,wid
);v
.nplane(0,Phi
,-1,wid
);
39 v
.nplane(0,-Phi
,-1,wid
);v
.nplane(1,0,Phi
,wid
);v
.nplane(-1,0,Phi
,wid
);
40 v
.nplane(1,0,-Phi
,wid
);v
.nplane(-1,0,-Phi
,wid
);v
.nplane(Phi
,1,0,wid
);
41 v
.nplane(-Phi
,1,0,wid
);v
.nplane(Phi
,-1,0,wid
);v
.nplane(-Phi
,-1,0,wid
);
43 bool point_inside(double x
,double y
,double z
) {return true;}
44 bool cut_cell(voronoicell
&c
,double x
,double y
,double z
) {
46 // Just ignore this case
49 bool cut_cell(voronoicell_neighbor
&c
,double x
,double y
,double z
) {
51 // Set the cell to be equal to the dodecahedron
56 voronoicell_neighbor v
;
59 // Determines whether any of the sides in the neighbor information are from the
60 // initial dodecahedron
61 bool has_dodec_sides(vector
<int> &vi
) {
62 for(unsigned int i
=0;i
<vi
.size();i
++) if(vi
[i
]==wid
) return true;
68 // Create a container with the geometry given above. This is bigger
69 // than the particle packing itself.
70 container
con(x_min
,x_max
,y_min
,y_max
,z_min
,z_max
,n_x
,n_y
,n_z
,
73 // Create the "initial shape" wall class and add it to the container
74 wall_initial_shape(wis
);
77 // Import the irregular particle packing
78 con
.import("pack_semicircle");
80 // Open files to save the "inside" and "outside" particles
81 FILE *finside
=safe_fopen("finite_sys_in.pov","w"),
82 *foutside
=safe_fopen("finite_sys_out.pov","w");
84 // Loop over all particles
87 voronoicell_neighbor c
;
91 // Get particle position
94 // Remove half of the particles to see a cross-section
97 if(con
.compute_cell(c
,cl
)) {
99 // Get the neighboring IDs of all the faces
102 // Depending on whether any of the faces are
103 // from the original dodecahedron, print to
104 // the "inside" or "outside" file
105 fprintf(has_dodec_sides(vi
)?foutside
:finside
,
106 "sphere{<%g,%g,%g>,s}\n",x
,y
,z
);
110 // Close the output files