TAGGED: parallelization, udf-fluent
-
-
July 27, 2022 at 2:56 pmm.shafiee1374Subscriber
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.
-
July 28, 2022 at 2:05 pmAmine Ben Hadj AliAnsys 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.
Â
-
July 29, 2022 at 11:49 amm.shafiee1374Subscriber
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.ÂÂ
-
July 29, 2022 at 12:17 pmAmine Ben Hadj AliAnsys 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.
Â
Â
-
- The topic ‘finding a cell closest to a point in domain (in parallel mode)’ is closed to new replies.
- Non-Intersected faces found for matching interface periodic-walls
- Unburnt Hydrocarbons contour in ANSYS FORTE for sector mesh
- Help: About the expression of turbulent viscosity in Realizable k-e model
- Cyclone (Stairmand) simulation using RSM
- error udf
- Script error Code: 800a000d
- Fluent fails with Intel MPI protocol on 2 nodes
- Diesel with Ammonia/Hydrogen blend combustion
- Mass Conservation Issue in Methane Pyrolysis Shock Tube Simulation
- Encountering Error in Heterogeneous Surface Reaction
-
1191
-
513
-
488
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.