-
-
February 22, 2020 at 6:54 am
anshs
SubscriberThe 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, ("C
Users/Anshuman/Desktop/this.c")
Registering Udflib, ("D
November/liq_liq reaction/liq_liq_reaction_files/dp0/FFF-8/Fluent/libudf")
Â
Calculation complete.
Â
Â
** I have taken this UDF from a previous post.Â
-
February 24, 2020 at 6:41 am
Amine Ben Hadj Ali
Ansys EmployeeCheck if you have defined an UDM in Fluent.
-
February 26, 2020 at 12:31 pm
anshs
Subscriberyes, I have defined that memory!
-
February 26, 2020 at 11:12 pm
anshs
SubscriberFor 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? -
February 27, 2020 at 5:47 am
Amine Ben Hadj Ali
Ansys EmployeeArea2 is wrong. Area1 is one of the known formulation among many for area density -
February 27, 2020 at 9:36 am
anshs
Subscriber1. 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!
Â
-
February 27, 2020 at 11:56 am
Amine Ben Hadj Ali
Ansys EmployeeIs 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.
Â
-
February 27, 2020 at 12:42 pm
anshs
Subscriberyeah, 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? -
February 27, 2020 at 1:13 pm
Amine Ben Hadj Ali
Ansys EmployeeVolume integral can be used there. Volume Integral of interfacial area density.
Our support on questions going beyond the usage of software is limited.
-
February 27, 2020 at 1:26 pm
anshs
SubscriberI 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)
Â
}
Â
Â
-
February 27, 2020 at 3:53 pm
Amine Ben Hadj Ali
Ansys EmployeeYou 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.
-
February 29, 2020 at 2:04 am
anshs
SubscriberI 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!

Â
-
March 2, 2020 at 4:10 pm
Rob
Forum ModeratorWhy would those macros give you an area?Â
-
March 2, 2020 at 4:56 pm
Amine Ben Hadj Ali
Ansys EmployeeAre 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.) -
March 3, 2020 at 10:37 am
anshs
Subscriberbecause 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 -
March 3, 2020 at 11:21 am
-
March 3, 2020 at 11:21 am
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)
Â
}
-
March 3, 2020 at 1:22 pm
Amine Ben Hadj Ali
Ansys EmployeeYou need to integrate over the volume so sum of UDMI*volume or volume integral. And yes that will be depend on the mesh resolution.
-
March 3, 2020 at 1:32 pm
anshs
SubscriberA_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? -
March 4, 2020 at 10:03 am
Amine Ben Hadj Ali
Ansys EmployeeYou 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.
-
March 4, 2020 at 11:16 am
anshs
SubscriberYes! 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!
-
March 4, 2020 at 5:53 pm
Amine Ben Hadj Ali
Ansys EmployeeI just use step 1 udmi and volume integral in Fluent.
Step 2 requires global reductions and parallelizing steps -
March 5, 2020 at 3:54 am
anshs
SubscriberBoth 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 -
March 5, 2020 at 6:06 am
Amine Ben Hadj Ali
Ansys EmployeeI mentioned that I'm my first response: parallelization and global reduction. More to be found in the customization Manual. -
March 5, 2020 at 11:55 am
anshs
SubscriberWill this formulation work on 2 dimensional geometry? or any modification required?
-
March 5, 2020 at 3:50 pm
Amine Ben Hadj Ali
Ansys EmployeeIt should but you might have issues interpreting the 2d planar results. I have not done that yet. -
March 5, 2020 at 4:07 pm
anshs
SubscriberMay 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!
-
- The topic ‘help with UDF error’ is closed to new replies.
-
5074
-
1797
-
1387
-
1248
-
1021
© 2026 Copyright ANSYS, Inc. All rights reserved.

