CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for mass-flow calculation does not print any value into console (https://www.cfd-online.com/Forums/fluent-udf/226840-udf-mass-flow-calculation-does-not-print-any-value-into-console.html)

jakub_ May 9, 2020 13:00

UDF for mass-flow calculation does not print any value into console
 
Hi,

I am not good in fluent UDFs and I rarely use fluent to be honest, but I want to do some cross-check of my own code and first need to learn how to do something similar but simpler, e.g., integrate fluxes on the specified faces in fluent. Could anyone help me out with testing and correcting my apparently simple UDF which I am willing to use for integrating the mass-flow on a selected surface? After compiling in fluent v19.5 (without any warnings/errors) on SUSE Linux and running parallel it doesn't display any value in the console.


It should be simple to test this UDF since it fits for most cases by selecting appropriate ID ZONE in the t= Lookup_Thread(d, 8);.



#include "udf.h"
DEFINE_EXECUTE_AT_END(mass_flow)
{
Domain *d;
Thread *t;
face_t f;
real mf=0.;
d = Get_Domain(1);
t = Lookup_Thread(d, 8);
begin_f_loop(f,t)
{
mf+=F_FLUX(f,t);
}
end_f_loop(f,t)
Message("MASS Flow Rate: %g\n",mf);
}

I have also an additional question. How to be sure that 1 and 8 are the ID of the zones that I am interested in? I am asking because when I select my domain in Cell Zone Conditions it appears that ID of the domain is 3. But after reading the forum and manual I found it should be equal to 1 in case of a single phase flow. Anyway it doesn't work with 1 and 3 either.


d = Get_Domain(1);
t= Lookup_Thread(d, 8);

Thank you for your time.
Jakub

vinerm May 10, 2020 12:17

Domain and Zone
 
The argument of Get_Domain is not ID of cell zone but ID of the domain. Domain is superstructure that contains whole of the case, including cell zones, boundary zones, materials, etc. For a single phase case, ID is always 1. Therefore, Get_Domain(1) is correct. However, the second argument of Lookup_Thread needs to be the ID of the boundary for which you want the mass flux. So, if 8 is the ID of the boundary, say, inlet or outlet, then the code should return a value. However, if 8 is the ID of the a cell zone, then it won't. So, go to Boundary Conditions and check the ID displayed for the boundary for which you want flow rate to be reported.

jakub_ May 10, 2020 13:34

Vinerm thank you for your interest.


Actually I did as you mentioned and as logic tells, however my udf does not run properly. Maybe I am asking for too much, but would you be able to compile my udf and run it by yourself to see if it works.


Im am also attaching screenshots of the procedure I follow, maybe I do some mistake somewhere.


https://i.ibb.co/xHxnWPj/cfdonline.png

vinerm May 10, 2020 13:45

Hooking
 
You need to hook the UDF library at appropriate location. Go to User-Defined Functions > Hooks and Hook the library that you compiled. Then run it.

jakub_ May 10, 2020 13:49

Great, it works now!
Thank you.

AlexanderZ May 11, 2020 03:41

most likely your code has problems, try this one
Code:

#include "udf.h"
DEFINE_EXECUTE_AT_END(mass_flow)
{
Domain *d;
Thread *t;
face_t f;
real mf=0.;
d = Get_Domain(1);
t = Lookup_Thread(d, 8);
begin_f_loop(f,t)
{
mf+=F_FLUX(f,t);
}
end_f_loop(f,t)
#if RP_NODE
mf = PRF_GRSUM1(mf);
#endif
Message0("MASS Flow Rate: %f\n",mf);
}


jakub_ May 11, 2020 06:24

Thank you AlexanderZ,

you are right. Actually, I know this already, since I studied manual extensively yesterday, btw. I must say that fluent’s UDF manual is just great and very self-explanatory. I did some progress and now my UDF is able to calculate the mass flow rate, integrated volumetric flow rate and the area of a specified surface. I share my code with extensive comments (which are maybe not always 100% precise, but they show the idea behind) if someone find this useful would be great. This I tested on parallel 3d case.



Quote:

#include "udf.h"
#include "para.h"

# define I_AM_NODE_ZERO_P (myid == node_zero)

real mfr; /* defined outside will be accessible for all DEFINE_*/
real mfr_glob;
real area_glob;
real vfr_magn;

DEFINE_EXECUTE_AT_END(mass_flow)
{

#if !RP_HOST /* the host is excluded, only nodes are included, if host is added the area of surface will be thread=0 since host does not contain mesh related info*/

Domain *d; /* pointer to domain ID */
Thread *t, *t0, *t1; /* pointer to face thread ID */
face_t f; /* specific integer over faces */
cell_t c0, c1;
d = Get_Domain(1); /* assign the address of a domain ID to pointer *d */
t = Lookup_Thread(d,2); /* assign the address of a face thread to pointer *t */
mfr =0.;
mfr_glob =0.;
area_glob =0.;
vfr_magn =0.;
real area[ND_ND] ={0}; /* ND_ND building a vector of a dimension 3 in 3d case */
real vfr[ND_ND] ={0};

begin_f_loop(f,t)
{
/* If this is the node to which face "officially" belongs,*/
if (PRINCIPAL_FACE_P(f,t)) /* Always TRUE in serial version, tests if the face is the principle face, because there are duplicate faces on nodes boundaries */
{
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = F_C1_THREAD(f,t);

F_AREA(area,f,t);

vfr[0] = (C_U(c0,t0)+C_U(c1,t1))/2.;
vfr[1] = (C_V(c0,t0)+C_V(c1,t1))/2.;
vfr[2] = (C_W(c0,t0)+C_W(c1,t1))/2.;
vfr_magn += NV_DOT(vfr,area);
area_glob += NV_MAG(area); /* NV_MAG - magnitude of a vector, single normal vector of a selected surface in this case over which the begin_f_loop sums */
mfr +=F_FLUX(f,t);
}
}
end_f_loop(f,t)


#if RP_NODE /* if the operation is need to be done on nodes without host */
mfr_glob = PRF_GRSUM1(mfr); /* sum over CPUs */
area_glob = PRF_GRSUM1(area_glob);
vfr_magn = PRF_GRSUM1(vfr_magn);
#endif /* RP_NODE */

if (I_AM_NODE_ZERO_P) /* to be displayed only once on 0-node */
{
Message("*********** Mass flow rate: %g [kg/s]\n",mfr_glob);
Message("*********** Volumetric flow rate: %g [m3/s]\n",vfr_magn);
Message("*********** Total area: %g [m2]\n",area_glob);
}

#endif /* !RP_HOST */
}




Best regards,
Jakub


All times are GMT -4. The time now is 09:33.