Ansys Assistant will be unavailable on the Learning Forum starting January 30. An upgraded version is coming soon. We apologize for any inconvenience and appreciate your patience. Stay tuned for updates.
Fluids

Fluids

Topics related to Fluent, CFX, Turbogrid and more.

help with UDF error

    • anshs
      Subscriber

      The following UDF is showing this error: The UDF is meant to calculate the interfacial area between 2 phases.



      UDF :



       


      #include "udf.h"


       


      DEFINE_ADJUST(area_density, d)


      {


      Thread *t, **pt; 


      cell_t c;


      real A_inter= 0.0;


      // Allocate storage to store the gradients 


      Domain *pDomain = DOMAIN_SUB_DOMAIN(d, 0); 


      {


      Alloc_Storage_Vars(pDomain, SV_VOF_RG, SV_VOF_G, SV_NULL);


      Scalar_Reconstruction(pDomain, SV_VOF, -1, SV_VOF_RG, NULL);


      Scalar_Derivatives(pDomain, SV_VOF, -1, SV_VOF_G, SV_VOF_RG, Vof_Deriv_Accumulate);


      }


      Message("nn hello_fluent 1"); 


      // Loop over all the cells in the domain


      mp_thread_loop_c(t, d, pt)


      Message("nn hello_fluent 2");


      if (FLUID_THREAD_P(t)) // Check for threads which are fluid


      {


      Thread *ppt = pt[0];


      Message("hello_fluent 3");


      begin_c_loop(c, t) // Loop over all the cells in the thread


      {


      Message("hello_fluent 4");


      if (C_VOF(c, ppt) != 0.0 && C_VOF(c, ppt) != 1.0) // Check for threads which have interface


      {


      Message("hello_fluent 5");


      C_UDMI(c, t, 0) = NV_MAG(C_VOF_G(c, ppt)); // Store the magnitude of gradient of VOF 


      Message("n Cell Index=%i : Volume fraction=%f: Area Density= %fn", c, C_VOF(c, ppt), C_UDMI(c, t, 0));


      A_inter += C_VOF(c, ppt) * C_UDMI(c, t, 0);


      }


      }


      end_c_loop(c, t)


          }


          Message("nn hello_fluent 6");


          Message("n A_inter= %fn",  A_inter );


      Free_Storage_Vars(pDomain, SV_VOF_RG, SV_VOF_G, SV_NULL); // Free the storage


      }



       


      Consol:


       


       hello_fluent 1


       


      hello_fluent 2


       


      hello_fluent 2


      Error: received a fatal signal (Segmentation fault).


       


      Error: received a fatal signal (Segmentation fault).


      Error Object: #f


      Registering UdfSource, ("CUsers/Anshuman/Desktop/this.c")


      Registering Udflib, ("DNovember/liq_liq reaction/liq_liq_reaction_files/dp0/FFF-8/Fluent/libudf")


       


      Calculation complete.


       


       


      ** I have taken this UDF from a previous post. 

    • Amine Ben Hadj Ali
      Ansys Employee

      Check if you have defined an UDM in Fluent.

    • anshs
      Subscriber

      yes, I have defined that memory!

    • anshs
      Subscriber

      For the same previous problem I have revised my udf in the following way :



      #include "udf.h"


      #define CON 1


      DEFINE_ADJUST(store_gradient, domain)


      {


       


      Thread *t;


      Thread **pt;


      cell_t c;


      real A_inter1 =0.0;


      real A_inter2 =0.0;


       


      int phase_domain_index = 0.;


      Domain *pDomain = DOMAIN_SUB_DOMAIN(domain,phase_domain_index);


      {


      Alloc_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NULL);


      Scalar_Reconstruction(pDomain, SV_VOF,-1,SV_VOF_RG,NULL);


      Scalar_Derivatives(pDomain,SV_VOF,-1,SV_VOF_G,SV_VOF_RG,


      Vof_Deriv_Accumulate);


      }


      mp_thread_loop_c (t,domain,pt)


      if (FLUID_THREAD_P(t))


      {


       


      Thread *ppt = pt[phase_domain_index];


      begin_c_loop (c,t)


      {


      C_UDMI(c,t,0) = NV_MAG(C_VOF_G(c,ppt)) ;


      A_inter1 += C_VOF(c, ppt) * C_UDMI(c, t, 0);


      A_inter2 += C_VOF(c,ppt) * C_UDMI(c, t, 0)*C_VOLUME(c, ppt);


      }


      end_c_loop (c,t)


      }


      Message("nn  Area1 = %fn", A_inter1);


      Message("nn  Area2 = %fn", A_inter2);


      Free_Storage_Vars(pDomain,SV_VOF_RG,SV_VOF_G,SV_NULL);


       


      }



       


      But the results are not satisfactory:


      Defining

      Area1 = C_VOF(c, ppt) * C_UDMI(c, t, 0)
      Area2 = C_VOF(c,ppt) * C_UDMI(c, t, 0)*C_VOLUME(c, ppt)


      Area1 = 900.000000
      Area2 = 0.003750


      The geometry is defined as: 



      Are the results correct?

    • Amine Ben Hadj Ali
      Ansys Employee
      Area2 is wrong. Area1 is one of the known formulation among many for area density
    • anshs
      Subscriber

      1. Now how to convert Area1(area density) into the interphase area? The answer should be Area= 0.01m, since it's in 2D, the area should come as a line!

      2. Is my patching correct? Why is it not showing a sharp interface, although I have used a sharp interface!


       

    • Amine Ben Hadj Ali
      Ansys Employee

      Is this something you require in Fluent: We can help here on things related to usage and deployment of our software.


      For point 2: interfacial area is well spread over interfacial cells. For VOF always show cell values. Your grid is anyhow very coarse.


       

    • anshs
      Subscriber

      yeah, I want to find the interfacial area in fluent while using the fluent's VOF model, but I'm not getting the correct results! You may be knowing the correct conversion of area density to an area! I'll be very thankful for your help because I'm stuck in this problem for quite a few whiles now!

      Shall I improve my meshing?

      For correction shall I multiply area1 with edge length?

    • Amine Ben Hadj Ali
      Ansys Employee

      Volume integral can be used there. Volume Integral of interfacial area density.


      Our support on questions going beyond the usage of software is limited.

    • anshs
      Subscriber

      I did something like that in my UDF: for reference, are you talking about something like this 



      From Fluent's UDF Manual

      /********************************************************************   
      UDF for integrating turbulent dissipation and displaying it in the console
      *********************************************************************/


       #include "udf.h"


       DEFINE_ADJUST(my_adjust,d) {   


        Thread *t;    /* Integrate dissipation. */   


        real sum_diss=0.; 


        cell_t c;


          thread_loop_c(t,d)


          {     begin_c_loop(c,t)


            sum_diss += C_D(c,t)* C_VOLUME(c,t);


           end_c_loop(c,t)    }


          printf("Volume integral of turbulent dissipation: %gn", sum_diss);


      }


       



      My code: (as written in the above comment)


      begin_c_loop (c,t)


      {


      C_UDMI(c,t,0) = NV_MAG(C_VOF_G(c,ppt)) ;


      A_inter1 += C_VOF(c, ppt) * C_UDMI(c, t, 0);


      A_inter2 += C_VOF(c,ppt) * C_UDMI(c, t, 0)*C_VOLUME(c, ppt);


      }


      end_c_loop (c,t)


       


      }


       


       

    • Amine Ben Hadj Ali
      Ansys Employee

      You do need to highlight what you are asking from the beginning and not changing the scope several times within the same thread. I thought you are asking after interfacial area density.


      Yes that is it but you require precautions as you are running in parallel.

    • anshs
      Subscriber

      I apologize if the thread was misleading! But I have always stated about interphase surface area, right from the first post! Finally, I am using this formula to find the interfacial area in my given problem:



      Thread *ppt = pt[phase_domain_index];


       begin_c_loop (c,t)


       {


       C_UDMI(c,t,0) = NV_MAG(C_VOF_G(c,ppt)) ;


       A_inter +=  C_UDMI(c, t, 0)*C_VOLUME(c, ppt) ;


       }


       end_c_loop (c,t)



      But I'm getting some errors, may you please look at this table: ( I've checked my UDF on 3 different geometries but the result are not coming correct! ), Can you help me with this! Thanks!


       

    • Rob
      Forum Moderator

      Why would those macros give you an area? 

    • Amine Ben Hadj Ali
      Ansys Employee
      Are you running the cases in parallel can you make a cell counter dummy? Can you just sum the udmi in Fluent directly? I am in solved in a project where interfacial area is well predicted ( with some more lines it matches better.)
    • anshs
      Subscriber

      because I was advised to do something like this in the thread above! So I think it will give the interfacial area between the phases! 

      Thanks

    • anshs
      Subscriber

       Area = 0.000049,  (It's from case 3, where previously it was around 0.000056 but then I refined the mesh so it comes to a bit different )


       


       


      sum = 59081855.621884 ( sum of UDMI )


       


       


       


      count = 106926 ( counter )


       


    • anshs
      Subscriber





       



      if (FLUID_THREAD_P(t))


      {


       


      Thread *ppt = pt[phase_domain_index];


       


      begin_c_loop (c,t)


      {


       


      C_UDMI(c,t,0) = NV_MAG(C_VOF_G(c,ppt)) ;


       


       


      A_inter +=  C_UDMI(c, t, 0)*C_VOLUME(c, ppt) ;


      ncount +=1;


      sum = sum + C_UDMI(c,t,0);


       


      }


       


      end_c_loop (c,t)


       


      }


    • Amine Ben Hadj Ali
      Ansys Employee

      You need to integrate over the volume so sum of UDMI*volume or volume integral. And yes that will be depend on the mesh resolution.

    • anshs
      Subscriber

      A_inter +=  C_UDMI(c, t, 0)*C_VOLUME(c, ppt) ;  


      I have used this formula and summed it over the required domain, but the answer is not coming correct!

      Shall I post my complete UDF here?

    • Amine Ben Hadj Ali
      Ansys Employee

      You take the UDMI for VOF Gradient Magnitude and then in Fluent You integrate over the Volume. And the result as I said will be dependent on the mesh resolution. 


      In our current work which will be published we are getting good values.

    • anshs
      Subscriber

      Yes! Can you please check my steps and relate whether I am doing it the way you are explaining.


      1. C_UDMI(c,t,0) = NV_MAG(C_VOF_G(c,ppt)) ;             VOF Gradient Magnitude
      2. 
      A_inter +=  C_UDMI(c, t, 0)*C_VOLUME(c, ppt) ;         Integration over the Volume


      Is this correct? Thanks for the help!

    • Amine Ben Hadj Ali
      Ansys Employee
      I just use step 1 udmi and volume integral in Fluent.
      Step 2 requires global reductions and parallelizing steps
    • anshs
      Subscriber

      Both are giving the same value of Integral

      1. A_inter +=  C_UDMI(c, t, 0)*C_VOLUME(c, ppt) ;         Integration over the Volume  = 0.000158
      2. Reports -> Volume Integral -> = 
      Net 0.00015750136    

      Hey, now it's actually computing the correct interfacial area! Is it by any luck or something? Because I was computing it in the exact same way but it was not giving me the correct value at all! The only difference I did was to compute the simulation in Series!

      In parallel , the UDMI is getting correctly calculated and The volume integral inside the fluent is also correct, but this step 'A_inter +=  C_UDMI(c, t, 0)*C_VOLUME(c, ppt) ;'    is not coming correctly!

      Please say something about this! Thanks

    • Amine Ben Hadj Ali
      Ansys Employee
      I mentioned that I'm my first response: parallelization and global reduction. More to be found in the customization Manual.
    • anshs
      Subscriber

      Will this formulation work on 2 dimensional geometry?  or any modification required?

    • Amine Ben Hadj Ali
      Ansys Employee
      It should but you might have issues interpreting the 2d planar results. I have not done that yet.
    • anshs
      Subscriber

      May you suggest something on how to implement this in parallel? 

      With parallel I mean to say that, I'm performing this simulation on my PC and with parallel I mean to use the different cores of my PC. Not running this program on a cluster!

      I click on parallel just after I click the setup on my workbench!

Viewing 26 reply threads
  • The topic ‘help with UDF error’ is closed to new replies.
[bingo_chatbox]