Guest User

Untitled

a guest
Jun 17th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1.     for (int pi = 0; pi < _px.size(); pi++)
  2.     {
  3.         if (_weights[pi] == 0.f) continue;
  4.  
  5.         //pos from array
  6.         float px = _px.at(pi);
  7.         float py = _py.at(pi);
  8.         float pz = _pz.at(pi);
  9.  
  10.         //index of cell particle belongs to
  11.         int i = (_px.at(pi)-_offset[0])/_h[0];
  12.         int j = (_py.at(pi)-_offset[1])/_h[1];
  13.         int k = (_pz.at(pi)-_offset[2])/_h[2];
  14.  
  15.         //mass to distribute
  16.         float p_mass = _h_part_density[pi];
  17.         float weight = _weights[pi];
  18.  
  19.         //bounds
  20.         int low_i = std::max(0,i-1);
  21.         int low_j = std::max(0,j-1);
  22.         int low_k = std::max(0,k-1);
  23.  
  24.         int high_i = std::min(i+1,_nx-1);
  25.         int high_j = std::min(j+1,_ny-1);
  26.         int high_k = std::min(k+1,_nz-1);
  27.  
  28.         //+1/-1 support
  29.         for (int ii = low_i; ii <= high_i; ii++)
  30.             for (int jj = low_j; jj <= high_j; jj++)
  31.                 for (int kk = low_k; kk <= high_k; kk++)
  32.                 {
  33.                     //target cell center
  34.                     float posii = ii * _h[0] + _offset[0] + 0.5f*_h[0];
  35.                     float posjj = jj * _h[1] + _offset[1] + 0.5f*_h[1];
  36.                     float poskk = kk * _h[2] + _offset[2] + 0.5f*_h[2];
  37.  
  38.                     float mass = p_mass * tent(px-posii,_h[0])*tent(py-posjj,_h[1])*tent(pz-poskk,_h[2]) / weight;
  39.  
  40.                     //sum mass to target particle
  41.                     _h_density->at(ii,jj,kk) += mass;
  42.                 }
  43.  
  44.     }
Add Comment
Please, Sign In to add comment