L-shape calculation added.
[voro++.git] / trunk / examples / extra / l_shape.cc
blob69485a04590f4c7bd9b05b941de5deef165b5139
1 // Irregular packing 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 the number of particles that are going to be randomly introduced
11 const int particles=30;
13 // This function returns a random double between 0 and 1
14 double rnd() {return double(rand())/RAND_MAX;}
16 // Create a wall class that, whenever called, will replace the Voronoi cell
17 // with a prescribed shape, in this case a dodecahedron
18 class wall_l_shape : public wall {
19 public:
20 wall_l_shape() {
21 v.init_l_shape();
23 bool point_inside(double x,double y,double z) {return true;}
24 bool cut_cell(voronoicell &c,double x,double y,double z) {
26 // Set the cell to be equal to the dodecahedron
27 c=v;
28 c.translate(-x,-y,-z);
29 c.big_tol=100;
30 return true;
32 bool cut_cell(voronoicell_neighbor &c,double x,double y,double z) {
34 // Set the cell to be equal to the dodecahedron
35 c=v;
36 c.translate(-x,-y,-z);
37 c.big_tol=100;
38 return true;
40 private:
41 voronoicell v;
44 int main() {
45 int i=0;
46 double x,y,z;
48 // Create a container with the geometry given above. This is bigger
49 // than the particle packing itself.
50 container con(-1,1,-1,1,-1,1,5,5,5,false,false,false,8);
52 // Create the L-shape wall class and add it to the container
53 wall_l_shape(wls);
54 con.add_wall(wls);
56 // Import the irregular particle packing
57 while(i<particles) {
58 x=2*rnd()-1;
59 y=2*rnd()-1;
60 if(x<0&&y>0) continue;
61 z=2*rnd()-1;
62 con.put(i,x,y,z);
63 i++;
66 // Save the particles and Voronoi cells in POV-Ray format
67 con.draw_particles("l_shape_p.gnu");
68 con.draw_cells_gnuplot("l_shape_v.gnu");