1 // Voro++, a 2D and 3D cell-based Voronoi library
3 // Author : Chris H. Rycroft (LBL / UC Berkeley)
4 // Email : chr@alum.mit.edu
5 // Date : August 30th 2011
8 * \brief Function implementations for the base 2D Voronoi container class. */
11 #include "v_base_2d.hh"
16 /** This function is called during container construction. The routine scans
17 * all of the worklists in the wl[] array. For a given worklist of blocks
18 * labeled \f$w_1\f$ to \f$w_n\f$, it computes a sequence \f$r_0\f$ to
19 * \f$r_n\f$ so that $r_i$ is the minimum distance to all the blocks
20 * \f$w_{j}\f$ where \f$j>i\f$ and all blocks outside the worklist. The values
21 * of \f$r_n\f$ is calculated first, as the minimum distance to any block in
22 * the shell surrounding the worklist. The \f$r_i\f$ are then computed in
23 * reverse order by considering the distance to \f$w_{i+1}\f$. */
24 voro_base_2d::voro_base_2d(int nx_
,int ny_
,double boxx_
,double boxy_
) :
25 nx(nx_
), ny(ny_
), nxy(nx_
*ny_
), boxx(boxx_
), boxy(boxy_
),
26 xsp(1/boxx_
), ysp(1/boxy_
), mrad(new double[wl_hgridsq_2d
*wl_seq_length_2d
]) {
27 const unsigned int b1
=1<<21,b2
=1<<22,b3
=1<<24,b4
=1<<25;
28 const double xstep
=boxx
/wl_fgrid_2d
,ystep
=boxy
/wl_fgrid_2d
;
30 unsigned int f
,*e
=const_cast<unsigned int*> (wl
);
31 double xlo
,ylo
,xhi
,yhi
,minr
,*radp
=mrad
;
32 for(ylo
=0,yhi
=ystep
,ly
=0;ly
<wl_hgrid_2d
;ylo
=yhi
,yhi
+=ystep
,ly
++) {
33 for(xlo
=0,xhi
=xstep
,lx
=0;lx
<wl_hgrid_2d
;xlo
=xhi
,xhi
+=xstep
,lx
++) {
35 for(q
=e
[0]+1;q
<wl_seq_length_2d
;q
++) {
40 compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
-1,j
);
41 if((f
&b1
)==0) compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
+1,j
);
42 } else if((f
&b1
)==b1
) compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
+1,j
);
44 compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
,j
-1);
45 if((f
&b3
)==0) compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
,j
+1);
46 } else if((f
&b3
)==b3
) compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
,j
+1);
54 compute_minimum(minr
,xlo
,xhi
,ylo
,yhi
,i
,j
);
59 radp
+=wl_seq_length_2d
;
64 /** Computes the minimum distance from a subregion to a given block. If this distance
65 * is smaller than the value of minr, then it passes
66 * \param[in,out] minr a pointer to the current minimum distance. If the distance
67 * computed in this function is smaller, then this distance is
69 * \param[out] (xlo,ylo) the lower coordinates of the subregion being
71 * \param[out] (xhi,yhi) the upper coordinates of the subregion being
73 * \param[in] (ti,tj) the coordinates of the block. */
74 void voro_base_2d::compute_minimum(double &minr
,double &xlo
,double &xhi
,double &ylo
,double &yhi
,int ti
,int tj
) {
76 if(ti
>0) {temp
=boxx
*ti
-xhi
;radsq
=temp
*temp
;}
77 else if(ti
<0) {temp
=xlo
-boxx
*(1+ti
);radsq
=temp
*temp
;}
80 if(tj
>0) {temp
=boxy
*tj
-yhi
;radsq
+=temp
*temp
;}
81 else if(tj
<0) {temp
=ylo
-boxy
*(1+tj
);radsq
+=temp
*temp
;}
83 if(radsq
<minr
) minr
=radsq
;
86 /** Checks to see whether "%n" appears in a format sequence to determine
87 * whether neighbor information is required or not.
88 * \param[in] format the format string to check.
89 * \return True if a "%n" is found, false otherwise. */
90 bool voro_base_2d::contains_neighbor(const char *format
) {
91 char *fmp
=(const_cast<char*>(format
));
93 // Check to see if "%n" appears in the format sequence
97 if(*fmp
=='n') return true;
98 else if(*fmp
==0) return false;
106 /*bool voro_base_2d::contains_neighbor_global(const char *format) {
107 char *fmp=(const_cast<char*>(format));
109 // Check to see if "%N" appears in the format sequence
113 if(*fmp=='N') return true;
114 else if(*fmp==0) return false;
121 void voro_base_2d::add_globne_info(int pid, int *nel, int length){
122 for(int i=0;i<length;i++){
124 globne[((totpar*pid)+nel[i])/32] |= (unsigned int)(1 << (((totpar*pid)+nel[i])%32));
129 void voro_base_2d::print_globne(FILE *fp){
131 fprintf(fp, "Global neighbor info: Format \n [Particle-ID] \t [Neighbors] \n [Particle-ID] \t [Neighbors]");
132 for(int i=0; i<totpar; i++){
133 fprintf(fp,"\n %d \t",i);
134 for(j=0;j<totpar;j++){
135 if((globne[(((i*totpar)+j)/32)] & (unsigned int)(1 << (((i*totpar)+j)%32))) != 0){
136 fprintf(fp,"%d \t",j);
142 #include "v_base_wl_2d.cc"