1 // Voro++, a 3D cell-based Voronoi library
2 //
3 // Author   : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email    : chr@alum.mit.edu
5 // Date     : August 30th 2011
6 
7 /** \file v_base.hh
8  * \brief Header file for the base Voronoi container class. */
9 
10 #ifndef VOROPP_V_BASE_HH
11 #define VOROPP_V_BASE_HH
12 
13 #include "worklist.hh"
14 
15 namespace voro {
16 
17 /** \brief Class containing data structures common across all particle container classes.
18  *
19  * This class contains constants and data structures that are common across all
20  * particle container classes. It contains constants setting the size of the
21  * underlying subgrid of blocks that forms the basis of the Voronoi cell
22  * computations. It also constructs bound tables that are used in the Voronoi
23  * cell computation, and contains a number of routines that are common across
24  * all container classes. */
25 class voro_base {
26 	public:
27 		/** The number of blocks in the x direction. */
28 		const int nx;
29 		/** The number of blocks in the y direction. */
30 		const int ny;
31 		/** The number of blocks in the z direction. */
32 		const int nz;
33 		/** A constant, set to the value of nx multiplied by ny, which
34 		 * is used in the routines that step through blocks in
35 		 * sequence. */
36 		const int nxy;
37 		/** A constant, set to the value of nx*ny*nz, which is used in
38 		 * the routines that step through blocks in sequence. */
39 		const int nxyz;
40 		/** The size of a computational block in the x direction. */
41 		const double boxx;
42 		/** The size of a computational block in the y direction. */
43 		const double boxy;
44 		/** The size of a computational block in the z direction. */
45 		const double boxz;
46 		/** The inverse box length in the x direction. */
47 		const double xsp;
48 		/** The inverse box length in the y direction. */
49 		const double ysp;
50 		/** The inverse box length in the z direction. */
51 		const double zsp;
52 		/** An array to hold the minimum distances associated with the
53 		 * worklists. This array is initialized during container
54 		 * construction, by the initialize_radii() routine. */
55 		double *mrad;
56 		/** The pre-computed block worklists. */
57 		static const unsigned int wl[wl_seq_length*wl_hgridcu];
58 		bool contains_neighbor(const char* format);
59 		voro_base(int nx_,int ny_,int nz_,double boxx_,double boxy_,double boxz_);
~voro_base()60 		~voro_base() {delete [] mrad;}
61 	protected:
62 		/** A custom int function that returns consistent stepping
63 		 * for negative numbers, so that (-1.5, -0.5, 0.5, 1.5) maps
64 		 * to (-2,-1,0,1).
65 		 * \param[in] a the number to consider.
66 		 * \return The value of the custom int operation. */
step_int(double a)67 		inline int step_int(double a) {return a<0?int(a)-1:int(a);}
68 		/** A custom modulo function that returns consistent stepping
69 		 * for negative numbers. For example, (-2,-1,0,1,2) step_mod 2
70 		 * is (0,1,0,1,0).
71 		 * \param[in] (a,b) the input integers.
72 		 * \return The value of a modulo b, consistent for negative
73 		 * numbers. */
step_mod(int a,int b)74 		inline int step_mod(int a,int b) {return a>=0?a%b:b-1-(b-1-a)%b;}
75 		/** A custom integer division function that returns consistent
76 		 * stepping for negative numbers. For example, (-2,-1,0,1,2)
77 		 * step_div 2 is (-1,-1,0,0,1).
78 		 * \param[in] (a,b) the input integers.
79 		 * \return The value of a div b, consistent for negative
80 		 * numbers. */
step_div(int a,int b)81 		inline int step_div(int a,int b) {return a>=0?a/b:-1+(a+1)/b;}
82 	private:
83 		void compute_minimum(double &minr,double &xlo,double &xhi,double &ylo,double &yhi,double &zlo,double &zhi,int ti,int tj,int tk);
84 };
85 
86 }
87 
88 #endif
89