Strip extra spaces from code.
[voro++.git] / trunk / examples / extra / l_shape.cc
blobcf6a65fa9843ecf4dd9a5cdd35a20419aa791ff0
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=20;
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 will initialize the Voronoi cell to fill the
17 // L-shaped domain
18 class wall_l_shape : public wall {
19 public:
20 wall_l_shape() {
21 v.init_l_shape();
22 v.draw_gnuplot(0,0,0,"l_shape_init.gnu");
24 bool point_inside(double x,double y,double z) {return true;}
25 bool cut_cell(voronoicell &c,double x,double y,double z) {
27 // Set the cell to be equal to the L-shape
28 c=v;
29 c.translate(-x,-y,-z);
31 // Set the tolerance to 100, to make the code search
32 // for cases where non-convex cells are cut in multiple
33 // places
34 c.big_tol=100;
35 return true;
37 bool cut_cell(voronoicell_neighbor &c,double x,double y,double z) {
39 // Set the cell to be equal to the L-shape
40 c=v;
41 c.translate(-x,-y,-z);
43 // Set the tolerance to 100, to make the code search
44 // for cases where non-convex cells are cut in multiple
45 // places
46 c.big_tol=100;
47 return true;
49 private:
50 voronoicell v;
53 int main() {
54 int i=0;
55 double x,y,z;
57 // Create a container
58 container con(-1,1,-1,1,-1,1,5,5,5,false,false,false,8);
60 // Create the L-shape wall class and add it to the container
61 wall_l_shape(wls);
62 con.add_wall(wls);
64 // Add particles, making sure not to place any outside of the L-shape
65 while(i<particles) {
66 x=2*rnd()-1;
67 y=2*rnd()-1;
68 if(x<0&&y>0) continue;
69 z=2*rnd()-1;
70 con.put(i,x,y,z);
71 i++;
74 // Check the Voronoi cell volume; it should be 6
75 printf("Voronoi cell volume: %.8g\n",con.sum_cell_volumes());
77 // Save the particles and Voronoi cells in gnuplot format
78 con.draw_particles("l_shape_p.gnu");
79 con.draw_cells_gnuplot("l_shape_v.gnu");