proj home

Files   Classes   Functions   Hierarchy  

cell.h

Go to the documentation of this file.
00001 #ifndef CELL_H
00002 #define CELL_H
00003 
00004 #include <cassert>
00005 #include <vector>
00006 #include <cmath>
00007 #include <iostream>
00008 using namespace std;
00009 
00010 #include <typedefs.h>
00011 
00012 
00013 //#define DEBUG_CELL
00014 
00015 //
00016 //  F Interface
00017 //
00018 //  uint F::W;
00019 //
00020 //  int const F::index( P const & ) const;
00021 //
00022 //  void getsurroundingcells
00023 //  (
00024 //    uint * & _nb,
00025 //    uint & sz,
00026 //    uintc k
00027 //  );
00028 //
00029 
00030 
00036 class cell
00037 {
00038 public:
00039 
00041   uint * count;  // 
00043   uint * index;  
00044   uint * vi;
00046   uint * fi;    
00047 
00049   uint W;
00051   uint WW;
00053   uint N;
00054 public:
00055 
00057   cell();
00059   cell(uintc N_);
00061   ~cell();
00062 
00064   void reset(uintc N_);
00065 
00067   template <typename F>
00068   void eval(F & f);
00069 
00070   template <typename F>
00071   void getsurroundingparticles
00072   (
00073     uint * const nb,
00074     uint & sz,
00075     F & f,
00076     uintc pti
00077   );
00078 
00079 };
00080 
00081 
00082 //----------------------------------------------------------
00083 // Implementation
00084 
00085 template< typename T >
00086 void print(T const * v, T const * vend)
00087 {
00088   for (;v!=vend; ++v)
00089     cout << *v << " "; 
00090 
00091   cout << endl;
00092 }
00093 
00094 template <typename F>
00095 void cell::eval(F & f)
00096 {
00097   f.W = W;
00098 assert(WW==W*W);
00099 
00100   for (uint i=0; i<WW; ++i)
00101     assert(count[i]==0);
00102 
00103   for (uint i=0; i<N; ++i)
00104   {
00105     fi[i] = f.index(i);
00106     ++count[fi[i]];
00107   }
00108 
00109   index[0] = 0;
00110   for (uint i=1; i<WW; ++i)
00111     index[i] = index[i-1]+count[i-1];
00112 
00113 
00114 #ifdef DEBUG_CELL 
00115 cout << "fi     ";
00116 print(fi,fi+N);
00117 
00118 cout << "count  ";
00119 print(count,count+WW);
00120 
00121 cout << "index  ";
00122 print(index,index+WW);
00123 #endif
00124 
00125   uint k;
00126   for (uint i=0; i<N; ++i)
00127   {
00128     k = fi[i];
00129     assert(k<WW);
00130     vi[index[k] + count[k] - 1] = i;
00131     --count[k];
00132   }
00133 
00134   // count[] should be all zero.
00135   for (uint i=0; i<WW; ++i)
00136     assert(count[i]==0);
00137 
00138 #ifdef DEBUG_CELL
00139 cout << "vi      ";
00140 print(vi,vi+N);
00141 
00142 cout << "count  ";
00143 print(count,count+WW);
00144 #endif
00145 
00146 }
00147 
00148 template <typename F>
00149 void cell::getsurroundingparticles
00150 (
00151   uint * const nb,
00152   uint & sz,
00153   F & f,
00154   uintc pti
00155 )
00156 {
00157   uint * ci;
00158   uint n(0);
00159   uint c;
00160   uint c0;
00161   uint z(0);
00162   f.getsurroundingcells(ci,n,f.index(pti));
00163   for (uint i=0; i<n; ++i)
00164   {
00165     // Determine how many particles in cell k
00166     c0 = index[ci[i]];
00167     c = index[ci[i]+1]-c0;
00168 
00169     for (uint k=0; k<c; ++k)
00170       nb[z++] = vi[c0+k];
00171   }
00172   sz = z;
00173 }
00174 
00175 
00176 
00177 
00178 
00179 #endif
00180 
00181 

Generated on Fri Mar 4 00:49:29 2011 for Chelton Evans Source by  doxygen 1.5.8