Guest User

Untitled

a guest
Jun 14th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.26 KB | None | 0 0
  1.     //the only thing that changed since p2m is the delete vector. get the new one
  2.     _deleted->copy_all_data(*data->deleted);
  3.    
  4.     //to be sent to gpu
  5.     _alpha->clear_zero();
  6.  
  7.     for (int pi = 0; pi < _num_part; pi++)
  8.     {
  9.         if (_deleted->at(pi) == 1)
  10.             continue;
  11.  
  12.         //pos from array
  13.         float px = _px->at(pi);
  14.         float py = _py->at(pi);
  15.         float pz = _pz->at(pi);
  16.  
  17.         //mass to distribute
  18.         float p_mass = _alpha->at(pi);
  19.  
  20.         //index of cell particle belongs to
  21.         int i = (_px->at(pi)-_offset[0])/_h[0];
  22.         int j = (_py->at(pi)-_offset[1])/_h[1];
  23.         int k = (_pz->at(pi)-_offset[2])/_h[2];    
  24.  
  25.         //+1/-1 support
  26.         for (int ii = i-1; ii <= i+1; ii++)
  27.             for (int jj = j-1; jj <= j+1; jj++)
  28.                 for (int kk = k-1; kk <= k+1; kk++)
  29.                 {
  30.                     //target cell center
  31.                     float posii = ii * _h[0] + _offset[0] + 0.5f*_h[0];
  32.                     float posjj = jj * _h[1] + _offset[1] + 0.5f*_h[1];
  33.                     float poskk = kk * _h[2] + _offset[2] + 0.5f*_h[2];
  34.  
  35.                     //tent kernel interpol
  36.                     float m_mass = 1.f*tent(px-posii,_h[0])*tent(py-posjj,_h[1])*tent(pz-poskk,_h[2]);
  37.  
  38.                     //sum mass to target cell
  39.                     at(ii,jj,kk)._mass_sum += m_mass;
  40.                 }
  41.  
  42.     }
  43.  
  44.     for (int i = 0; i <_nx; i++) {
  45.         for (int j = 0; j <_ny; j++) {
  46.             for (int k = 0; k <_nz; k++) {             
  47.  
  48.                 //+1/-1 support
  49.                 for (int ii = i-1; ii <= i+1; ii++)
  50.                     for (int jj = j-1; jj <= j+1; jj++)
  51.                         for (int kk = k-1; kk <= k+1; kk++)
  52.                         {
  53.                             float mass_sum = at(ii,jj,kk)._mass_sum;
  54.  
  55.                             //current cell center
  56.                             float posii = ii * _h[0] + _offset[0] + 0.5f*_h[0];
  57.                             float posjj = jj * _h[1] + _offset[1] + 0.5f*_h[1];
  58.                             float poskk = kk * _h[2] + _offset[2] + 0.5f*_h[2];
  59.  
  60.                             float m_mass = at(ii,jj,kk)._mass;
  61.  
  62.                             //interpol
  63.                             for (std::vector<int>::iterator it = at(ii,jj,kk)._particles.begin(); it != at(ii,jj,kk)._particles.end(); it++)
  64.                             {
  65.                                 if (_deleted->at(*it)==1) continue;
  66.  
  67.                                 //pos from array
  68.                                 float px = _px->at(*it);
  69.                                 float py = _py->at(*it);
  70.                                 float pz = _pz->at(*it);
  71.  
  72.                                 float p_mass = m_mass*tent(px-posii,_h[0])*tent(py-posjj,_h[1])*tent(pz-poskk,_h[2]);
  73.                                 _alpha->at(*it) += p_mass;                         
  74.                             }
  75.                            
  76.                         }
  77.  
  78.             }
  79.         }
  80.     }
  81.  
  82.     //send corrected vector to gpu
  83.     data->alpha->copy_all_data(*_alpha);
Add Comment
Please, Sign In to add comment