Beispiel #1
0
/* Computes the total Coulomb force on a particle exerted from the charges of the corresponding cell */
void computeTotalForce(particle_t p, uint64_t L, double *Qgrid, double *fx, double *fy){
  uint64_t  y, x;
  double   tmp_fx, tmp_fy, rel_y, rel_x, tmp_res_x = 0.0, tmp_res_y = 0.0;

  /* Coordinates of the cell containing the particle */
  y = (uint64_t) floor(p.y);
  x = (uint64_t) floor(p.x);
  rel_x = p.x -  x;
  rel_y = p.y -  y;

  /* Coulomb force from top-left charge */
  computeCoulomb(rel_x, rel_y, p.q, QG(y,x,L), &tmp_fx, &tmp_fy);
  tmp_res_x += tmp_fx;
  tmp_res_y += tmp_fy;

  /* Coulomb force from bottom-left charge */
  computeCoulomb(rel_x, 1.0-rel_y, p.q, QG(y+1,x,L), &tmp_fx, &tmp_fy);
  tmp_res_x += tmp_fx;
  tmp_res_y -= tmp_fy;

  /* Coulomb force from top-right charge */
  computeCoulomb(1.0-rel_x, rel_y, p.q, QG(y,x+1,L), &tmp_fx, &tmp_fy);
  tmp_res_x -= tmp_fx;
  tmp_res_y += tmp_fy;

  /* Coulomb force from bottom-right charge */
  computeCoulomb(1.0-rel_x, 1.0-rel_y, p.q, QG(y+1,x+1,L), &tmp_fx, &tmp_fy);
  tmp_res_x -= tmp_fx;
  tmp_res_y -= tmp_fy;

  (*fx) = tmp_res_x;
  (*fy) = tmp_res_y;
}
Beispiel #2
0
/* Computes the total Coulomb force on a particle exerted from the charges of the corresponding cell */
void computeTotalForce(particle_t p, bbox_t tile, double *grid, double *fx, double *fy)
{
  uint64_t  x, y, n_rows;
  double   tmp_fx, tmp_fy, rel_y, rel_x, tmp_res_x, tmp_res_y;

  n_rows = tile.top-tile.bottom+1;
   
  /* Coordinates of the cell containing the particle */
  y = (uint64_t) floor(p.y);
  x = (uint64_t) floor(p.x);

  rel_x = p.x - x;
  rel_y = p.y - y;
   
  x = x - tile.left;
  y = y - tile.bottom;
   
  computeCoulomb(rel_x, rel_y, p.q, grid[y+x*n_rows], &tmp_fx, &tmp_fy);
   
  tmp_res_x = tmp_fx;
  tmp_res_y = tmp_fy;
   
  /* Coulomb force from bottom-left charge */
  computeCoulomb(rel_x, 1.0-rel_y, p.q, grid[(y+1)+x*n_rows], &tmp_fx, &tmp_fy);
  tmp_res_x += tmp_fx;
  tmp_res_y -= tmp_fy;
   
  /* Coulomb force from top-right charge */
  computeCoulomb(1.0-rel_x, rel_y, p.q, grid[y+(x+1)*n_rows], &tmp_fx, &tmp_fy);
  tmp_res_x -= tmp_fx;
  tmp_res_y += tmp_fy;
   
  /* Coulomb force from bottom-right charge */
  computeCoulomb(1.0-rel_x, 1.0-rel_y, p.q, grid[(y+1)+(x+1)*n_rows], &tmp_fx, &tmp_fy);
  tmp_res_x -= tmp_fx;
  tmp_res_y -= tmp_fy;
   
  (*fx) = tmp_res_x;
  (*fy) = tmp_res_y;
}