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

Please check out my UDF code

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 8, 2011, 20:25
Default Please check out my UDF code
  #1
Member
 
Join Date: Mar 2011
Posts: 38
Rep Power: 15
aleisia is on a distinguished road
Hi! I want to model a filter (but not modeling it as a porous media), in a room I have SO2 and air mixture. First I want to get the SO2 mass flow rate at the inlet surface of the filter, then multiply it by 0.999989, and set the sink rate of the filter volume as -0.999989*(SO2 mass flow rate at the inlet surface)/(Volume of filter). For the outlet of the filter, I set it as "interior", and my simulation is always transient.

Below is my code, please advise.


#include "udf.h"
DEFINE_SOURCE(cell_SO2mass_source,cell,thread,dS,e qn)
{
real x[ND_ND];
real source,
t, massflowrate, volume, vol_tot;
real ti = RP_Get_Real("flow-time");
real NV_VEC(flux), NV_VEC(A); /* declaring vectors flux and A */
face_t face, f
Cell_t cell
Thread *thread
C_CENTROID(x,cell,thread);
x=x[0]; /*****给出每个单元的x坐标*******/
y=x[1]; /*****给出每个单元的y坐标*******/
z=x[2]; /*****给出每个单元的z坐标*******/
d = Get_Domain(1);
t= Lookup_Thread(d, 12); /* defining the inlet surface thread by specifying the Zone_ID*/

begin_f_loop(f,t)
{
NV_D(flux, =, F_U(f,t), F_V(f,t), F_W(f,t)); /* defining flux in terms of velocity field */
NV_S(flux, *=, F_R(f,t)) /* multiplying density to get flux vector */
F_AREA(A,f,t) /* face normal vector returned from F_AREA */
massflowrate+= F_YI(f,t,i)*NV_DOT(flux,A); /* dot product of the inlet surface flux and area vector*/
/* multiplied by the mass fraction of species i */
}
end_f_loop(f,t)
massflowrate= PRF_GRSUM1(massflowrate);

begin_c_loop(cell,thread)
{
volume = C_VOLUME(cell,thread); /* get cell volume */
vol_tot += volume;
}
end_c_loop(cell,thread)
vol_tot = PRF_GRSUM1(vol_tot);

source=-0.999989* massflowrate/vol_tot;
dS[eqn]=0.0;

return source;
}



I actually have 2 question:
1. is "f" the inlet surface corresponding to the "t" that I set? "t" is the thread corresponding to inlet surface.
2. is
C_CENTROID necessary in this case?
3. someone says "cell_t cell" is wrong, only "cell_t c" is correct, but why?
Thanks


Last edited by aleisia; June 9, 2011 at 00:18.
aleisia is offline   Reply With Quote

Old   June 9, 2011, 02:10
Default
  #2
Member
 
john
Join Date: Nov 2010
Posts: 50
Rep Power: 15
johnwinter is on a distinguished road
Hi,
I may not fully answer you.
From your udf i understood that you don't need x[ND_ND], you didn't use it anywhere in the code. So don't define it. i fell C_CENTROID not necessary.
cell_t cell is there you can use it but DEFINE_SOURCE already calling all cells. So, don't define cell_t at all.
Yes, you are calling inlet face "f".
johnwinter is offline   Reply With Quote

Old   June 9, 2011, 13:34
Default
  #3
Member
 
Join Date: Mar 2011
Posts: 38
Rep Power: 15
aleisia is on a distinguished road
Hi! Thanks for the reply and I agree with you.
How about Thread *thread? I guess I don't need to define thread either, because I already called it in the DEFINE_SOURCE

How about the way that I defined the mass flow rate, using dot product? Is that OK? or I can use F_FLUX*F_AREA*F_YI?


Quote:
Originally Posted by johnwinter View Post
Hi,
I may not fully answer you.
From your udf i understood that you don't need x[ND_ND], you didn't use it anywhere in the code. So don't define it. i fell C_CENTROID not necessary.
cell_t cell is there you can use it but DEFINE_SOURCE already calling all cells. So, don't define cell_t at all.
Yes, you are calling inlet face "f".
aleisia is offline   Reply With Quote

Old   June 10, 2011, 04:02
Default
  #4
Member
 
john
Join Date: Nov 2010
Posts: 50
Rep Power: 15
johnwinter is on a distinguished road
Yes, you don't need to define thread also.
It seems to me that
massflowrate+= F_YI(f,t,i)*NV_DOT(flux,A);
is ok.
johnwinter is offline   Reply With Quote

Reply

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
Convergence check in UDF mittal Fluent UDF and Scheme Programming 0 January 22, 2011 22:21
Request for UDF code for forced vibrations jagadeesh putta FLUENT 0 November 21, 2007 21:43
Check UDF stephen e FLUENT 1 April 15, 2004 09:51
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56
UDF Scalar Code: HT 1 Greg Perkins FLUENT 8 October 20, 2000 12:40


All times are GMT -4. The time now is 19:05.