Exemple #1
0
int map_position_node_array(double pos[3])
{
  int i, im[3]={0,0,0};
  double f_pos[3];

  for (i = 0; i < 3; i++)
    f_pos[i] = pos[i];

#ifdef LEES_EDWARDS  
  double vel_scratch[3]={0.,0.,0.};  
  fold_position(f_pos, vel_scratch, im);
#else
  fold_position(f_pos, im);
#endif

  for (i = 0; i < 3; i++) {
    im[i] = (int)floor(node_grid[i]*f_pos[i]*box_l_i[i]);
    if (im[i] < 0)
      im[i] = 0;
    else if (im[i] >= node_grid[i])
      im[i] = node_grid[i] - 1;
  }

  return map_array_node(im);
}
Exemple #2
0
int map_position_node_array(double pos[3])
{
  int i, im[3]={0,0,0};
  double f_pos[3];

  for (i = 0; i < 3; i++)
    f_pos[i] = pos[i];
  
  fold_position(f_pos, im);

  for (i = 0; i < 3; i++) {
    im[i] = (int)floor(node_grid[i]*f_pos[i]*box_l_i[i]);
    if (im[i] < 0)
      im[i] = 0;
    else if (im[i] >= node_grid[i])
      im[i] = node_grid[i] - 1;
  }

  return map_array_node(im);
}
Exemple #3
0
int calc_node_neighbors(int node)
{

  int  dir, neighbor_count; 
#ifdef LEES_EDWARDS
  node_neighbors     = (int *)realloc(node_neighbors, 6 * sizeof(int));
  node_neighbor_lr   = (int *)realloc(node_neighbor_lr, 6 * sizeof(int));
  node_neighbor_wrap = (int *)realloc(node_neighbor_wrap, 6 * sizeof(int));
#endif  
 
  map_node_array(node,node_pos);
  for(dir=0;dir<3;dir++) {
    int buf;
    
    /* Writes to node_neighbors[] the integer rank of that neighbor
     * ... the 'buf' stores own rank, which is discarded. */
    if( node_pos[dir] % 2 == 0 ){
        MPI_Cart_shift(comm_cart, dir, -1, &buf, &(node_neighbors[2*dir]));
        MPI_Cart_shift(comm_cart, dir, 1, &buf,  &(node_neighbors[2*dir + 1]));

#ifdef LEES_EDWARDS
        node_neighbor_lr[2*dir]   = 0;
        node_neighbor_lr[2*dir+1] = 1;
#endif

    }else{
        MPI_Cart_shift(comm_cart, dir, 1, &buf, &(node_neighbors[2*dir]));
        MPI_Cart_shift(comm_cart, dir, -1, &buf,  &(node_neighbors[2*dir + 1]));

#ifdef LEES_EDWARDS
        node_neighbor_lr[2*dir]   = 1;
        node_neighbor_lr[2*dir+1] = 0;
#endif
    }

    /* left boundary ? */
    if (node_pos[dir] == 0) {
      boundary[2*dir] = 1;
    }
    else {
      boundary[2*dir] = 0;
    }
    /* right boundary ? */
    if (node_pos[dir] == node_grid[dir]-1) {
      boundary[2*dir+1] = -1;
    }
    else {
      boundary[2*dir+1] = 0;
    }
  }
  
  
  neighbor_count = 6;
#ifdef LEES_EDWARDS
   if( boundary[2] == 1 || boundary[3] == -1 ){

      int x_index, abs_coords[3];

      abs_coords[2] = node_pos[2]; /* z constant */

      if( ( boundary[2] == 1 && boundary[3] != -1) || ( boundary[3] == -1 && boundary[2] != 1) ){
        node_neighbors      = (int *)realloc(node_neighbors, (neighbor_count + node_grid[0] - 1)*sizeof(int));
        node_neighbor_lr    = (int *)realloc(node_neighbor_lr, (neighbor_count + node_grid[0] - 1)*sizeof(int));
        node_neighbor_wrap  = (int *)realloc(node_neighbor_wrap, (neighbor_count + node_grid[0] - 1)*sizeof(int)); 
      }else if( boundary[3] == -1 && boundary[2] == 1){
        node_neighbors      = (int *)realloc(node_neighbors, (neighbor_count + 2 * node_grid[0] - 2)*sizeof(int));
        node_neighbor_lr    = (int *)realloc(node_neighbor_lr, (neighbor_count + 2 * node_grid[0] - 2)*sizeof(int));
        node_neighbor_wrap  = (int *)realloc(node_neighbor_wrap, (neighbor_count + 2 * node_grid[0] - 2)*sizeof(int)); 
      }


      for( x_index = 0; x_index < node_grid[0]; x_index++){
        if( x_index != node_pos[0] ){
            abs_coords[0] = x_index;
            if( x_index > node_pos[0] ){
                if( boundary[2] == 1 ){
                    abs_coords[1] = node_grid[1] - 1; /* wraps to upper y */
                    node_neighbors[neighbor_count] = map_array_node(abs_coords);
                    node_neighbor_lr[neighbor_count]   = 0;
                    neighbor_count++;
                } 
                if( boundary[3] == -1 ){
                    abs_coords[1] = 0;           /* wraps to lower y */
                    node_neighbors[neighbor_count] = map_array_node(abs_coords);
                    node_neighbor_lr[neighbor_count]   =  1;
                    neighbor_count++;
                }
            }else{
                if( boundary[3] == -1 ){
                    abs_coords[1] = 0;           /* wraps to lower y */
                    node_neighbors[neighbor_count] = map_array_node(abs_coords);
                    node_neighbor_lr[neighbor_count]   =  1;
                    neighbor_count++;
                }
                if( boundary[2] == 1 ){
                    abs_coords[1] = node_grid[1] - 1; /* wraps to upper y */
                    node_neighbors[neighbor_count] = map_array_node(abs_coords);
                    node_neighbor_lr[neighbor_count]   = 0;
                    neighbor_count++;
                } 
            }   
        }
      }
   }    
#else
  GRID_TRACE(printf("%d: node_grid %d %d %d, pos %d %d %d, node_neighbors ", this_node, node_grid[0], node_grid[1], node_grid[2], node_pos[0], node_pos[1], node_pos[2]));
#endif


#ifdef LEES_EDWARDS
  my_neighbor_count = neighbor_count;/* set the global neighbor count */
  for(neighbor_count = 0; neighbor_count < my_neighbor_count; neighbor_count++ ){

        if( neighbor_count < 6 ) dir = neighbor_count / 2;
        else dir = 1;
  
        if( boundary[2*dir] == 1 && node_neighbor_lr[neighbor_count] == 0 ){
            node_neighbor_wrap[neighbor_count] =  1;
        }
        else if(boundary[2*dir + 1] == -1 && node_neighbor_lr[neighbor_count] == 1 ){
            node_neighbor_wrap[neighbor_count] = -1;
        }else{
            node_neighbor_wrap[neighbor_count] = 0;
        }

  }
   GRID_TRACE(
   for( dir=0; dir < my_neighbor_count; dir++){ fprintf(stderr, "%d: neighbour %d -->  %d lr: %i wrap: %i\n", this_node, dir,node_neighbors[dir],node_neighbor_lr[dir],node_neighbor_wrap[dir]);}
   );