Strip extra spaces from code.
[voro++.git] / branches / 2d / src / v_base_2d.cc
blobe2e7b3e40b4d550f2bfcbfbb1ba15d7a82377384
1 // Voro++, a 2D and 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
7 /** \file v_base_2d.cc
8 * \brief Function implementations for the base 2D Voronoi container class. */
9 //#include <stdio.h>
11 #include "v_base_2d.hh"
12 #include "config.hh"
14 namespace voro {
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;
29 int i,j,lx,ly,q;
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++) {
34 minr=large_number;
35 for(q=e[0]+1;q<wl_seq_length_2d;q++) {
36 f=e[q];
37 i=(f&127)-64;
38 j=(f>>7&127)-64;
39 if((f&b2)==b2) {
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);
43 if((f&b4)==b4) {
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);
48 q--;
49 while(q>0) {
50 radp[q]=minr;
51 f=e[q];
52 i=(f&127)-64;
53 j=(f>>7&127)-64;
54 compute_minimum(minr,xlo,xhi,ylo,yhi,i,j);
55 q--;
57 *radp=minr;
58 e+=wl_seq_length_2d;
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
68 * set to the new one.
69 * \param[out] (xlo,ylo) the lower coordinates of the subregion being
70 * considered.
71 * \param[out] (xhi,yhi) the upper coordinates of the subregion being
72 * considered.
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) {
75 double radsq,temp;
76 if(ti>0) {temp=boxx*ti-xhi;radsq=temp*temp;}
77 else if(ti<0) {temp=xlo-boxx*(1+ti);radsq=temp*temp;}
78 else radsq=0;
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
94 while(*fmp!=0) {
95 if(*fmp=='%') {
96 fmp++;
97 if(*fmp=='n') return true;
98 else if(*fmp==0) return false;
100 fmp++;
103 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
110 while(*fmp!=0) {
111 if(*fmp=='%') {
112 fmp++;
113 if(*fmp=='N') return true;
114 else if(*fmp==0) return false;
116 fmp++;
119 return false;
121 void voro_base_2d::add_globne_info(int pid, int *nel, int length){
122 for(int i=0;i<length;i++){
123 if(nel[i]>=0){
124 globne[((totpar*pid)+nel[i])/32] |= (unsigned int)(1 << (((totpar*pid)+nel[i])%32));
129 void voro_base_2d::print_globne(FILE *fp){
130 int j=0;
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"