Fluids

Fluids

How to parallelize a serial UDF (single core) in Ansys Fluent?

    • Sashank Gautam
      Subscriber

      **Here is a code that calculates the electrostatic field and the x-component of force from the scalar potential solved in fluent. This works fine in single core,

      #include "udf.h"
      #include "mem.h"
      #include 
      #include 
      
      #define Q 60.e-06 
      #define e0 8.854e-12
      
      enum
      {
          phi,        /* 0 - Electric potential*/                    
          E,          /* 1 - Electric field*/                         
          Fdix,       /* 2 - x-component Dielectrophoretic force*/    
      };  
      
      DEFINE_ADJUST(Adjust_fun, domain)
      {
          cell_t c;
          face_t f;
          real dp= 300.0e-09;             
          real ep = 4.6;                  
          Thread *t; ;  
          
          thread_loop_c(t,domain)  
          {
              begin_c_loop_int(c,t)      
              {
                  C_UDSI(c,t,E) = NV_MAG(C_UDSI_G(c,t,phi));
              if(C_UDSI(c,t,E)<=0.0) 
              C_UDSI(c,t,E)=0.0;  
              if(C_UDSI(c,t,E)>(Q/e0))
                  C_UDSI(c,t,E) = Q/e0;  
              
              C_UDSI(c,t,Fdix) = (2.*coff*C_UDSI(c,t,E)*(C_UDSI_G(c,t,E)[0]));
              }
              end_c_loop_int(c,t)
          }
      
          thread_loop_f(t,domain)  
          {
              begin_f_loop(f,t)  
              {
              if(NULL !=THREAD_STORAGE(t, SV_UDS_I(phi)) && NULL != T_STORAGE_R_NV(t->t0,SV_UDSI_G(phi)))
                  F_UDSI(f,t,E)=C_UDSI(F_C0(f,t), t->t0, E);      
              if(NULL != THREAD_STORAGE(t,SV_UDS_I(E))&& NULL != T_STORAGE_R_NV(t->t0, SV_UDSI_G(E)))
              {
                  if PRINCIPAL_FACE_P(f,t)
                  F_UDSI(f,t,Fdix)=C_UDSI(F_C0(f,t), t->t0, Fdix);
              }
              }
              end_f_loop(f,t) 
    • SRP
      Subscriber

      Hi,

      I recommend you to please check ansys customization manual: 7.3. Parallelizing Your Serial UDF (ansys.com)

      If you are not able to access the link, please refer to this forum discussion: https://forum.ansys.com/forums/topic/using-help-with-links/#latest

      Thank you

      • Sashank Gautam
        Subscriber

        Thank you for the suggestion.

        Yes, I have referred to the parallel computing chapter of the Ansys help document. The challenge is that the examples/information is targeted toward computing a single value from all the computation nodes assigned to the solver. For example, calculating the average pressure drop across the entire domain. Here they record the pressure drop values in all the cells from individual nodes and then pass it to node-0 which calculates the final answer.
         
        My challenge is that I am working with UDS values on every cell. My result relies on accurate values of these UDS on the cells at the end (when the individual nodes pass the values to node-0). I tried message-passing commands such as PRF_CRECV_INT(i, UDSI(c,t,0), 1, i), however, the results do not match the results obtained from a single core. It would be really helpful to see examples suitable for my case or a couple of lines of codes I could work from.
         
    • Rob
      Ansys Employee

      The operation will be at the same level for all cases: ie the loops. So the other examples should hold. What surface/zone are you comparing? https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v231/en/flu_udf/flu_udf_sec_cell_face_partition_boundaries.html may be relevent if you're looking at interior surfaces. 

      • Sashank Gautam
        Subscriber

        I am looking to get the values in the entire domain. Just like plotting a vector field of velocity requires the correct values of the velocity vector of each cell, I need the correct values of the Electrostatic force (Calculated through UDF) in each cell. Each computing node has some "overlapping" exterior cells, so, I want to know how I can extract/pass the values from each node properly such that a "compiled" domain made of all of the nodes merged together represents the resulting domain with each cells having the correct values (the overlapping cells being merged correctly I guess).

        Hence, in the end, when I plot a contour of a plane running alongside the length of the entire domain, I get the same values as in a single-core setup. 

        PS I cannot open the link that you mentioned above, It sends me to the signup page for the customer portal.

        Thank you for your reply Rob.

         

         

    • Rob
      Ansys Employee

      Click on Help in Fluent and then paste the link into the browser: the software adds a token/cookie/biscuit to the browser until you close the browser. 

      You should just need to deal with the thread loops as in the examples in the manual: basically that's what RP_HOST and RP_NODE are for. There are a couple of other bits to be careful with if you have interior zone partition faces, but again it's all covered. 

    • Sashank Gautam
      Subscriber

      Based on the example 7.3.3 and 7.3.5 I have used the RP_NODE and RP_HOST in the code. However, the values are unaffected. I also tried to only loop over principal faces only using PRINCIPAL_FACE_P(face,thread). This also did not change the results. I have attached the updated code here.

      My goal is to just get the right values of the Electric field and forces of the entire domain (compiled from all the cells and faces from each node). I am not sure if I have to pass the C_UDSI(c,t,E) and F_UDSI(f,t,Fdix) from the compute nodes to node-0. 

      So, do I have to use the PRF_CRECV_REAL(node_zero, array, size, node_zero) command here (As in the example from 7.4.2)?

      It would be helpful if you could point out which example would be more suitable for my case.

      Thank you.

       
       
    • Rob
      Ansys Employee

      You're looping over cell and face threads, so I'd start here  https://ansyshelp.ansys.com/account/Secured?returnurl=/Views/Secured/corp/v231/en/flu_udf/flu_udf_ChapParallelUDFUsage.html   Note, we can't give much advice on UDFs. 

    • Sashank Gautam
      Subscriber

      Thank you for your suggestions, Rob.

Viewing 6 reply threads
  • You must be logged in to reply to this topic.