Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

finding a cell closest to a point in domain (in parallel mode)

    • m.shafiee1374
      Subscriber

      Hello,

      I've been using this code to read the velocity of flow from a cell thats closest to the point "x" in serial mode:

      DEFINE_ADJUST(name,dom) {

      real c[3], Vx, d =1, d_new ;

      real x[3] = {1,2,3} ; /*just an example*/

      Thread *c_thread ;

      cell_t cell ;



      thread_loop_c(c_thread, dom)

      {

          begin_c_loop(cell,c_thread)

            {

      C_CENTROID(c,cell,c_thread) ;

               d_new = sqrt(pow(c[0]-x[0],2)+pow(c[1]-x[1],2)+pow(c[2]-x[2],2)) ;

                 if (d_new < d )

                 {

                      d = d_new ;

                    Vx = C_U(cell,c_thread) ;

                  }         

            } end_c_loop_int(cell,c_thread)

      }

      }

      But on a parallel session, every node loops over its own partition of the domain and this algorithm wil find the closest cell on each node locally. Unfortunately I'm struggling to make it work in parallel mode and appreciate any help on how to do it.

    • Amine Ben Hadj Ali
      Ansys Employee

      Yes every node will do its job so you need at the End to do a Global Reduction to find the smallest d_new, get the id of the cell and from that and then anything else.

       

    • m.shafiee1374
      Subscriber

      So I changed my code like this:

      DEFINE_ADJUST(name,dom) {
      real c[3], Vx, d =1, d_new, d_min ;
      real x[3] = {1,2,3} ; /*just an example*/
      Thread *c_thread, *ct_min ;
      cell_t cell, c_min ;

      thread_loop_c(c_thread, dom)
      {
          begin_c_loop_int(cell,c_thread)
         {
      C_CENTROID(c,cell,c_thread) ;
               d_new = sqrt(pow(c[0]-x[0],2)+pow(c[1]-x[1],2)+pow(c[2]-x[2],2)) ;
               if (d_new < d )
               {
                    d = d_new ;
                    ct_min = c_thread ;
      c_min = cell ;

               }       
          } end_c_loop_int(cell,c_thread)
      }
      d_min = PRF_GRLOW1(d) ;
      if (d == d_min && I_AM_NODE_ZERO_P)           /*this is only true on the compute node with the closest cell*/
      {
      Vx = C_U(c_min,ct_min) ;

      }
      if (d == d_min && !I_AM_NODE_ZERO_P)
      {
      Vx = C_U(c_min,ct_min) ;
      PRF_CSEND_REAL(node_zero, &Vx, 1, myid) ;
      }
      node_to_host_real_1(Vx) ; /*Send values from node zero to host*/
      }


      Now the problem is that there should be a PRF_CRECV command on node zero to recieve "Vx" from the sending compute node and then send it to host, but I have no idea which node will be sending the value of "Vx" and I can't loop over all the compute nodes since only one of them is sending the value of "Vx".
      In other words the "from" arguement in "PRF_CRECV_REAL(from, &Vx, 1,tag)" is not known. 

       

    • Amine Ben Hadj Ali
      Ansys Employee

      I cannot comment on User Defined Functions on this open platform. What I can say is that, If have the cell index of the minimum distance I store it first. Now I do the reduction to have the minimum of all distances. That should be done without any Host or Node restrictions. All nodes transfer that to the host. Now back again on only nodes (all of them), I now create a dummy vector to store the centroid of the cell with the index I found in the first step, ensure that the distance to the input point - dmin is smaller than a very small threshold: if this is true: we store the coordinates and you can do all the rest. Now back on All Nodes and Host, I transfer the vector with cell coordinate using reduction (PRF_GRHIGH) and do transfer from node to host the real vector

       

      I will do the cell loop on all cells not only internals.

       

       

Viewing 3 reply threads
  • The topic ‘finding a cell closest to a point in domain (in parallel mode)’ is closed to new replies.