Diploma Thesis Percolation Simulation C++ Sourcecode Documentation |
00001 // cluster.h 00002 // storage containers for clusters 00003 // (c) 2000 Andreas Krueger 00004 // Version 1.0 00005 // last change: 28.6.2000 00006 00007 class cluson { 00008 private: 00009 LONGBITS spanning_dirs; 00010 public: 00011 NUMLIST sphlist; 00012 public: 00013 cluson(); 00014 void add_spanning(int direction); 00015 void set_spanning_dirs(LONGBITS direction); 00016 00017 bool spanning(); 00018 bool spanning(int direction); 00019 bool sp_lr(); 00020 bool sp_tb(); 00021 bool sp_alldirs(int dim); 00022 }; 00023 00024 cluson::cluson(){ spanning_dirs=(LONGBITS)0; } 00025 00026 void cluson::add_spanning(int direction){ 00027 spanning_dirs|=(LONGBITS)pow(2,direction-1); 00028 } 00029 void cluson::set_spanning_dirs(LONGBITS sp_dirs){ 00030 spanning_dirs=sp_dirs; 00031 } 00032 00033 bool cluson::spanning(){ return (spanning_dirs!=(LONGBITS)0 ); } 00034 00035 bool cluson::spanning(int direction){ 00036 return ( spanning_dirs&(LONGBITS)pow(2,direction-1) )!=0 ; 00037 } 00038 bool cluson::sp_lr(){ return spanning(1); } 00039 bool cluson::sp_tb(){ return spanning(2); } 00040 00041 bool cluson::sp_alldirs(int dim){ 00042 return spanning_dirs==(LONGBITS)pow(2,dim)-1 ; 00043 } 00044 00045 void add_spanning_dir_to_clusters(cluson* clusters, NUMLIST clnos, int direction){ 00046 NUMLIST::iterator clno; 00047 for (clno=clnos.begin();clno!=clnos.end();clno++){ 00048 clusters[*clno].add_spanning(direction); 00049 } 00050 } 00051 00052 void swapcluson (cluson &c1, cluson &c2) { 00053 cluson temp=c1; 00054 c1=c2; c2=temp; 00055 } 00056 00057 void reset_clusters(cluson* array, NUMBER N) { 00058 for (NUMBER i=0;i<=N;i++){ 00059 array[i].sphlist.clear(); 00060 array[i].set_spanning_dirs((LONGBITS)0); 00061 } 00062 } 00063 00064 void nonspanning_clusters(cluson* array, NUMBER N) { 00065 for (NUMBER i=0;i<=N;i++){ 00066 array[i].set_spanning_dirs((LONGBITS)0); 00067 } 00068 } 00069 00070 void make_clusterlist_array ( sphere* spheres, 00071 NUMLIST &sphlist, 00072 cluson* clst){ 00073 NUMLIST::iterator iter; 00074 NUMBER clusno, sphno; 00075 for (iter=sphlist.begin(); iter!=sphlist.end();iter++){ 00076 sphno=*iter; 00077 clusno=spheres[sphno].clno; 00078 clst[clusno].sphlist.push_back(sphno); 00079 } 00080 } 00081 00082 struct clusterneighbours { 00083 NUMLIST clusno; 00084 public: 00085 clusterneighbours(){}; 00086 }; 00087 00088 void set_clusternumber(sphere *array, NUMLIST &sphlist, NUMBER clno) { 00089 NUMLIST::iterator iter; 00090 00091 // first run for error detection 00092 // for (iter = sphlist.begin(); iter != sphlist.end(); ++iter){ 00093 // array[*iter].clno=0; 00094 // }//error detection end 00095 00096 for (iter = sphlist.begin(); iter != sphlist.end(); ++iter){ 00097 // this is error detection 00098 // if (array[*iter].clno != 0) { 00099 // errorout ("sphere twice mentioned in cluster"); 00100 // cout <<" clno="<<clno<<" sphere #"<<*iter<<" sphlist.size()="<<sphlist.size()<<endl; 00101 // exit(1); 00102 // }// error detection end 00103 array[*iter].clno=clno; 00104 } 00105 } 00106 00107 void set_clustersize(sphere *array, 00108 NUMLIST &sphlist, 00109 NUMBER clsz) { // one clustersize for all spheres 00110 NUMLIST::iterator iter; 00111 for (iter = sphlist.begin(); iter != sphlist.end(); ++iter){ 00112 array[*iter].clsz=clsz; 00113 } 00114 } 00115 00116 void set_clustersizes(sphere *array, 00117 NUMLIST &sphlist, 00118 cluson *cluster) { // get the size of cluster[clno] 00119 // and assign to each sphere in that cluster 00120 NUMLIST::iterator iter; 00121 for (iter = sphlist.begin(); iter != sphlist.end(); ++iter){ 00122 array[*iter].clsz=cluster[array[*iter].clno].sphlist.size(); 00123 } 00124 } 00125 00126 00127 00128 void copy_array(sphere *array1,sphere *array2, NUMBER first, NUMBER last) { 00129 for (NUMBER i=first;i<=last;i++) { 00130 array2[i]=array1[i]; 00131 } 00132 } 00133 00134 void compare_clustersizes(sphere *array1, sphere *array2, NUMBER first, NUMBER last) { 00135 for (NUMBER i=first;i<=last;i++) { 00136 if (array1[i].clsz != array2[i].clsz){ 00137 cout<<"\n"<<array1[i].c; 00138 cout<<" clsz1="<<array1[i].clsz; 00139 cout<<" clsz2="<<array2[i].clsz; 00140 } 00141 } 00142 cout<<endl; 00143 } 00144 00145 00146 00147 void throw_spheres(sphere *array, NUMBER start, NUMBER end) { 00148 for ( NUMBER i=start; i<=end; i++) { 00149 array[i].c.randomvect(GRIDSIZE); // random coordinate 00150 } 00151 } 00152 00153 void throw_spheres(sphere *array, NUMLIST L_sph) { 00154 NUMLIST::iterator sph; 00155 for (sph=L_sph.begin();sph!=L_sph.end(); sph++) { 00156 array[*sph].c.randomvect(GRIDSIZE); // random coordinate 00157 } 00158 } 00159 00160 void set_dim(sphere *array, NUMBER first, NUMBER last, int setdim){ 00161 for (NUMBER i=first;i<=last;i++) { 00162 array[i].c.set_dim(setdim); 00163 } 00164 } 00165 00166 void set_clusternumber(sphere *array, NUMBER first, NUMBER last, NUMBER clno) { 00167 for (NUMBER i=first;i<=last;i++) { 00168 array[i].clno=clno; 00169 } 00170 } 00171 void set_radius(sphere *array, NUMBER first, NUMBER last, REAL radius ) { 00172 for (NUMBER i=first;i<=last;i++) { 00173 array[i].r=radius; 00174 } 00175 } 00176 void set_clustersize(sphere *array, NUMBER first, NUMBER last, NUMBER clsz) { 00177 for (NUMBER i=first;i<=last;i++) { 00178 array[i].clsz=clsz; 00179 } 00180 } 00181 00182 00183 bool same_array (sphere *array1, sphere *array2, NUMBER first, NUMBER last) { 00184 for (NUMBER i=first;i<=last;i++){ 00185 if (array1[i]!=array2[i]) return 0; 00186 } 00187 return 1; 00188 } 00189 00190 00191 00192 void set_clusternumber_l(sphere *array, NUMLIST &sphlist, NUMBER clno) { 00193 NUMLIST::iterator iter; 00194 for (iter = sphlist.begin(); iter != sphlist.end(); ++iter){ 00195 array[*iter].clno=clno; 00196 } 00197 } 00198 00199 00200 00201 void increasing_integers (NUMLIST &sphlist, NUMBER N){ 00202 for (NUMBER i=1;i<=N;i++){ 00203 sphlist.insert(sphlist.end(), i); 00204 } 00205 } 00206 00207 void increasing_integers (std::vector<NUMBER> &sphnumbers, NUMBER N){ 00208 for (NUMBER i=0;i<=N;i++){ 00209 sphnumbers[i]=i; 00210 } 00211 } 00212 00213 00214 REAL set_clustersize_to_each_sphere (NUMBER *tableofclusters, 00215 sphere *spherearray, 00216 NUMBER first, NUMBER last){ 00217 NUMBER size; 00218 REAL sum=0; 00219 00220 for (NUMBER i=first;i<=last;i++){ 00221 size=tableofclusters[spherearray[i].clno]; 00222 spherearray[i].clsz=size; 00223 sum+=size; 00224 } 00225 return sum/(last-first+1); //returns the average clustersize 00226 } 00227 00228 00229 REAL set_clustersize_to_each_sphere_l (NUMBER *tableofclusters, 00230 sphere *spherearray, 00231 NUMLIST &sphlist){ 00232 NUMBER size; 00233 REAL sum=0; 00234 00235 NUMLIST::iterator k; 00236 for (k = sphlist.begin(); k != sphlist.end(); k++){ 00237 00238 size=tableofclusters[spherearray[*k].clno]; 00239 spherearray[*k].clsz=size; 00240 sum+=size; 00241 } 00242 return sum/(sphlist.size()); //returns the average clustersize 00243 }
Diploma Thesis Sourcecode
Documentation check out the text and the executable binaries |