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 rad_option.hh
8  * \brief Header file for the classes encapsulating functionality for the
9  * regular and radical Voronoi tessellations. */
10 
11 #ifndef VOROPP_RAD_OPTION_HH
12 #define VOROPP_RAD_OPTION_HH
13 
14 namespace voro {
15 
16 /** \brief Class containing all of the routines that are specific to computing
17  * the regular Voronoi tessellation.
18  *
19  * The container and container_periodic classes are derived from this class,
20  * and during the Voronoi cell computation, these routines are used to create
21  * the regular Voronoi tessellation. */
22 class radius_mono {
23 	protected:
24 		/** This is called prior to computing a Voronoi cell for a
25 		 * given particle to initialize any required constants.
26 		 * \param[in] ijk the block that the particle is within.
27 		 * \param[in] s the index of the particle within the block. */
r_init(int ijk,int s)28 		inline void r_init(int ijk,int s) {}
29 		/** Sets a required constant to be used when carrying out a
30 		 * plane bounds check. */
r_prime(double rv)31 		inline void r_prime(double rv) {}
32 		/** Carries out a radius bounds check.
33 		 * \param[in] crs the radius squared to be tested.
34 		 * \param[in] mrs the current maximum distance to a Voronoi
35 		 *                vertex multiplied by two.
36 		 * \return True if particles at this radius could not possibly
37 		 * cut the cell, false otherwise. */
r_ctest(double crs,double mrs)38 		inline bool r_ctest(double crs,double mrs) {return crs>mrs;}
39 		/** Scales a plane displacement during a plane bounds check.
40 		 * \param[in] lrs the plane displacement.
41 		 * \return The scaled value. */
r_cutoff(double lrs)42 		inline double r_cutoff(double lrs) {return lrs;}
43 		/** Adds the maximum radius squared to a given value.
44 		 * \param[in] rs the value to consider.
45 		 * \return The value with the radius squared added. */
r_max_add(double rs)46 		inline double r_max_add(double rs) {return rs;}
47 		/** Subtracts the radius squared of a particle from a given
48 		 * value.
49 		 * \param[in] rs the value to consider.
50 		 * \param[in] ijk the block that the particle is within.
51 		 * \param[in] q the index of the particle within the block.
52 		 * \return The value with the radius squared subtracted. */
r_current_sub(double rs,int ijk,int q)53 		inline double r_current_sub(double rs,int ijk,int q) {return rs;}
54 		/** Scales a plane displacement prior to use in the plane cutting
55 		 * algorithm.
56 		 * \param[in] rs the initial plane displacement.
57 		 * \param[in] ijk the block that the particle is within.
58 		 * \param[in] q the index of the particle within the block.
59 		 * \return The scaled plane displacement. */
r_scale(double rs,int ijk,int q)60 		inline double r_scale(double rs,int ijk,int q) {return rs;}
61 		/** Scales a plane displacement prior to use in the plane
62 		 * cutting algorithm, and also checks if it could possibly cut
63 		 * the cell.
64 		 * \param[in,out] rs the plane displacement to be scaled.
65 		 * \param[in] mrs the current maximum distance to a Voronoi
66 		 *                vertex multiplied by two.
67 		 * \param[in] ijk the block that the particle is within.
68 		 * \param[in] q the index of the particle within the block.
69 		 * \return True if the cell could possibly cut the cell, false
70 		 * otherwise. */
r_scale_check(double & rs,double mrs,int ijk,int q)71 		inline bool r_scale_check(double &rs,double mrs,int ijk,int q) {return rs<mrs;}
72 };
73 
74 /**  \brief Class containing all of the routines that are specific to computing
75  * the radical Voronoi tessellation.
76  *
77  * The container_poly and container_periodic_poly classes are derived from this
78  * class, and during the Voronoi cell computation, these routines are used to
79  * create the radical Voronoi tessellation. */
80 class radius_poly {
81 	public:
82 		/** A two-dimensional array holding particle positions and radii. */
83 		double **ppr;
84 		/** The current maximum radius of any particle, used to
85 		 * determine when to cut off the radical Voronoi computation.
86 		 * */
87 		double max_radius;
88 		/** The class constructor sets the maximum particle radius to
89 		 * be zero. */
radius_poly()90 		radius_poly() : max_radius(0) {}
91 	protected:
92 		/** This is called prior to computing a Voronoi cell for a
93 		 * given particle to initialize any required constants.
94 		 * \param[in] ijk the block that the particle is within.
95 		 * \param[in] s the index of the particle within the block. */
r_init(int ijk,int s)96 		inline void r_init(int ijk,int s) {
97 			r_rad=ppr[ijk][4*s+3]*ppr[ijk][4*s+3];
98 			r_mul=r_rad-max_radius*max_radius;
99 		}
100 		/** Sets a required constant to be used when carrying out a
101 		 * plane bounds check. */
r_prime(double rv)102 		inline void r_prime(double rv) {r_val=1+r_mul/rv;}
103 		/** Carries out a radius bounds check.
104 		 * \param[in] crs the radius squared to be tested.
105 		 * \param[in] mrs the current maximum distance to a Voronoi
106 		 *                vertex multiplied by two.
107 		 * \return True if particles at this radius could not possibly
108 		 * cut the cell, false otherwise. */
r_ctest(double crs,double mrs)109 		inline bool r_ctest(double crs,double mrs) {return crs+r_mul>sqrt(mrs*crs);}
110 		/** Scales a plane displacement during a plane bounds check.
111 		 * \param[in] lrs the plane displacement.
112 		 * \return The scaled value. */
r_cutoff(double lrs)113 		inline double r_cutoff(double lrs) {return lrs*r_val;}
114 		/** Adds the maximum radius squared to a given value.
115 		 * \param[in] rs the value to consider.
116 		 * \return The value with the radius squared added. */
r_max_add(double rs)117 		inline double r_max_add(double rs) {return rs+max_radius*max_radius;}
118 		/** Subtracts the radius squared of a particle from a given
119 		 * value.
120 		 * \param[in] rs the value to consider.
121 		 * \param[in] ijk the block that the particle is within.
122 		 * \param[in] q the index of the particle within the block.
123 		 * \return The value with the radius squared subtracted. */
r_current_sub(double rs,int ijk,int q)124 		inline double r_current_sub(double rs,int ijk,int q) {
125 			return rs-ppr[ijk][4*q+3]*ppr[ijk][4*q+3];
126 		}
127 		/** Scales a plane displacement prior to use in the plane cutting
128 		 * algorithm.
129 		 * \param[in] rs the initial plane displacement.
130 		 * \param[in] ijk the block that the particle is within.
131 		 * \param[in] q the index of the particle within the block.
132 		 * \return The scaled plane displacement. */
r_scale(double rs,int ijk,int q)133 		inline double r_scale(double rs,int ijk,int q) {
134 			return rs+r_rad-ppr[ijk][4*q+3]*ppr[ijk][4*q+3];
135 		}
136 		/** Scales a plane displacement prior to use in the plane
137 		 * cutting algorithm, and also checks if it could possibly cut
138 		 * the cell.
139 		 * \param[in,out] rs the plane displacement to be scaled.
140 		 * \param[in] mrs the current maximum distance to a Voronoi
141 		 *                vertex multiplied by two.
142 		 * \param[in] ijk the block that the particle is within.
143 		 * \param[in] q the index of the particle within the block.
144 		 * \return True if the cell could possibly cut the cell, false
145 		 * otherwise. */
r_scale_check(double & rs,double mrs,int ijk,int q)146 		inline bool r_scale_check(double &rs,double mrs,int ijk,int q) {
147 			double trs=rs;
148 			rs+=r_rad-ppr[ijk][4*q+3]*ppr[ijk][4*q+3];
149 			return rs<sqrt(mrs*trs);
150 		}
151 	private:
152 		double r_rad,r_mul,r_val;
153 };
154 
155 }
156 #endif
157