CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

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

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree2Likes
  • 1 Post By vinerm
  • 1 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 9, 2020, 13:00
Default UDF for mass-flow calculation does not print any value into console
  #1
New Member
 
Jakub
Join Date: Mar 2018
Posts: 13
Rep Power: 4
jakub_ is on a distinguished road
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
jakub_ is offline   Reply With Quote

Old   May 10, 2020, 12:17
Default Domain and Zone
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,547
Blog Entries: 1
Rep Power: 28
vinerm will become famous soon enough
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.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared on the Forum
vinerm is online now   Reply With Quote

Old   May 10, 2020, 13:34
Default
  #3
New Member
 
Jakub
Join Date: Mar 2018
Posts: 13
Rep Power: 4
jakub_ is on a distinguished road
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
jakub_ is offline   Reply With Quote

Old   May 10, 2020, 13:45
Default Hooking
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,547
Blog Entries: 1
Rep Power: 28
vinerm will become famous soon enough
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_ likes this.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared on the Forum
vinerm is online now   Reply With Quote

Old   May 10, 2020, 13:49
Default
  #5
New Member
 
Jakub
Join Date: Mar 2018
Posts: 13
Rep Power: 4
jakub_ is on a distinguished road
Great, it works now!
Thank you.
jakub_ is offline   Reply With Quote

Old   May 11, 2020, 03:41
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,205
Rep Power: 20
AlexanderZ will become famous soon enough
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_ likes this.
__________________
best regards


******************************
press LIKE if this message helped you

How to ask questions:
https://www.cfd-online.com/Forums/si...tml#post612025
AlexanderZ is offline   Reply With Quote

Old   May 11, 2020, 06:24
Default
  #7
New Member
 
Jakub
Join Date: Mar 2018
Posts: 13
Rep Power: 4
jakub_ is on a distinguished road
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
jakub_ is offline   Reply With Quote

Reply

Tags
fluent, get_domain, lookup_thread, mass-flow, udf

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get Sutherland and JANAF coefficients of air? immortality OpenFOAM Running, Solving & CFD 63 September 19, 2018 06:27
UDF for Mass Flow at the Outlet: ERROR ACCESS VIOLATION I-mech Fluent UDF and Scheme Programming 1 May 23, 2014 12:37
UDF problems with porous flow Nicolastheterminator Fluent UDF and Scheme Programming 0 April 8, 2014 09:12
initialization of flow field in a transient flow calculation zhengjg FLUENT 1 January 15, 2014 06:01
fluid flow fundas ram Main CFD Forum 5 June 17, 2000 21:31


All times are GMT -4. The time now is 07:47.