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

Define source on boundary cells in UDF

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

Like Tree7Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 8, 2011, 18:26
Smile Define source on boundary cells in UDF
  #1
Member
 
Ming Cai
Join Date: Mar 2011
Posts: 50
Rep Power: 15
mingersai is on a distinguished road
Hi, friends

I want to define a mass source on the boundary cells with udf, here's my code,
I don't know why it doesn't work, can any of you guys kindly give me some suggestions?
I'm new to udf...

Thanks in advance!

# include "udf.h"

DEFINE_SOURCE(mass_source,c,t,dS,eqn)
{
real x[ND_ND];
real source;
Domain *domain = Get_Domain(1);
face_t f;
Thread *tb = Lookup_Thread(domain,2); /* Get boundary thread, wall zone id is 2 */
if(c = F_C0(f,tb)) /* if cell is wall boundary cell */
{
source = 10000;
dS[eqn]=0;
}
else
{
source = 0;
dS[eqn]=0;
}
return source;
}

Thank you very much!

Last edited by mingersai; August 9, 2011 at 10:32.
mingersai is offline   Reply With Quote

Old   August 9, 2011, 10:33
Default
  #2
Member
 
Ming Cai
Join Date: Mar 2011
Posts: 50
Rep Power: 15
mingersai is on a distinguished road
need help.......
mingersai is offline   Reply With Quote

Old   August 9, 2011, 15:47
Default
  #3
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
your if-clause is not right ...
one easy way is to store source values in temporary memory (UDM) and then use it in this macro; another way is to separate adjacent boundary cells to get new thread ID and then use that ...
mingersai and sso like this.
__________________
Amir
Amir is offline   Reply With Quote

Old   August 10, 2011, 11:04
Default
  #4
Member
 
Ming Cai
Join Date: Mar 2011
Posts: 50
Rep Power: 15
mingersai is on a distinguished road
Hi, Amir

Thanks for your help. Would you please tell me why the if statement is not correct?
How to implement this with UDM?
Because my problem is not suitable to go with separate zone method, I'll have to stick with the first way....

Thank you very much!



Quote:
Originally Posted by Amir View Post
your if-clause is not right ...
one easy way is to store source values in temporary memory (UDM) and then use it in this macro; another way is to separate adjacent boundary cells to get new thread ID and then use that ...
mingersai is offline   Reply With Quote

Old   August 10, 2011, 11:35
Default
  #5
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Quote:
Originally Posted by mingersai View Post
Hi, Amir

Thanks for your help. Would you please tell me why the if statement is not correct?
How to implement this with UDM?
Because my problem is not suitable to go with separate zone method, I'll have to stick with the first way....

Thank you very much!
Hi,

first, your idea about this case is not right; your macro retrieves cell ID and doesn't recognize f; i.e. you just define unreferenced face index (f)!
indeed, you need logical statement in if-clause; if(c == F_C0(f,tb)) ...
Easier way is to use another macro like on demand forms then, loop over your desired thread and store your source value to temporary volume scalar field (UDM) then use this UDM in above UDF.
sso likes this.
__________________
Amir
Amir is offline   Reply With Quote

Old   August 10, 2011, 16:17
Default
  #6
Member
 
Ming Cai
Join Date: Mar 2011
Posts: 50
Rep Power: 15
mingersai is on a distinguished road
Thanks a lot! I learnt a lot from this!

Would you please tell me the difference between different IDs showed in the pic? Why there's two different IDs for wall? what is each ID?

Thanks


Last edited by mingersai; August 10, 2011 at 23:45.
mingersai is offline   Reply With Quote

Old   August 11, 2011, 04:21
Default
  #7
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Quote:
Originally Posted by mingersai View Post
Thanks a lot! I learnt a lot from this!

Would you please tell me the difference between different IDs showed in the pic? Why there's two different IDs for wall? what is each ID?

Thanks
As I know, we may find 2 IDs for some threads, one of them in boundary condition panel and another in (surface->manage) which have different applications.
ID which is in BC panel refer to realistic threads of your grid (consist of nodes, faces,...) and has to be used in, for example, loops over desired thread and so on; on the other hand, the IDs in surface panel have to be used in some calculations such as property integrations over that; note that these surfaces or volumes which are visible in this panel are not necessarily part of your numerical grid, they may be created as virtual surfaces or volumes for post-processing and I usually use then in TUI as a part of journal files. In your case, thread ID=12 refers to realistic part of your grid and ID=2 refers to virtual surface coincides with your realistic one.
these are 2 types of IDs which I find in FLUENT 6.3, maybe there would be created other types in later versions.


Bests,
mingersai, sso and yashganatra like this.
__________________
Amir
Amir is offline   Reply With Quote

Old   August 11, 2011, 18:43
Default
  #8
Member
 
Ming Cai
Join Date: Mar 2011
Posts: 50
Rep Power: 15
mingersai is on a distinguished road
Thanks, Amir
I got it work now!
I'm using both DPM and VOF model,
The source term I want to define in those cells are function of particle mass.
Do you have any idea about how to access DPM particle data in those cells?

Thanks~

Quote:
Originally Posted by Amir View Post
As I know, we may find 2 IDs for some threads, one of them in boundary condition panel and another in (surface->manage) which have different applications.
ID which is in BC panel refer to realistic threads of your grid (consist of nodes, faces,...) and has to be used in, for example, loops over desired thread and so on; on the other hand, the IDs in surface panel have to be used in some calculations such as property integrations over that; note that these surfaces or volumes which are visible in this panel are not necessarily part of your numerical grid, they may be created as virtual surfaces or volumes for post-processing and I usually use then in TUI as a part of journal files. In your case, thread ID=12 refers to realistic part of your grid and ID=2 refers to virtual surface coincides with your realistic one.
these are 2 types of IDs which I find in FLUENT 6.3, maybe there would be created other types in later versions.


Bests,
mingersai is offline   Reply With Quote

Old   August 12, 2011, 04:12
Default
  #9
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Quote:
Originally Posted by mingersai View Post
Thanks, Amir
I got it work now!
I'm using both DPM and VOF model,
The source term I want to define in those cells are function of particle mass.
Do you have any idea about how to access DPM particle data in those cells?

Thanks~
Yes, you can do that by implementing another UDF which converts data from lagrangian model to eulerian one, here, you should take care of mass flow rate of each stream; for more info refer to:
Experimental measurements and numerical simulations of particle transport and distribution in ventilated rooms; Z. Zhang, Q. Chen; Atmospheric Environment 40 (2006) 3396–3408

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   August 12, 2011, 06:23
Default
  #10
Member
 
Ming Cai
Join Date: Mar 2011
Posts: 50
Rep Power: 15
mingersai is on a distinguished road
Hi, Amir

Do you know specific UDF code we need to use in order to get the particle data in the chosen cells? I can't find it in Fluent documentation, and the paper you mentioned seems have not mentioned that.

Thanks!

Quote:
Originally Posted by Amir View Post
Yes, you can do that by implementing another UDF which converts data from lagrangian model to eulerian one, here, you should take care of mass flow rate of each stream; for more info refer to:
Experimental measurements and numerical simulations of particle transport and distribution in ventilated rooms; Z. Zhang, Q. Chen; Atmospheric Environment 40 (2006) 3396–3408

Bests,
mingersai is offline   Reply With Quote

Old   August 12, 2011, 06:38
Default
  #11
Senior Member
 
Amir's Avatar
 
Amir
Join Date: May 2009
Location: Montreal, QC
Posts: 735
Blog Entries: 1
Rep Power: 23
Amir is on a distinguished road
Quote:
Originally Posted by mingersai View Post
Hi, Amir

Do you know specific UDF code we need to use in order to get the particle data in the chosen cells? I can't find it in Fluent documentation, and the paper you mentioned seems have not mentioned that.

Thanks!
Hi,
The information in mentioned paper is enough! you need a relation to compute particle concentration in your domain i.e. equation (7); there is not your desired UDF in documantation, but you can use them in your algorithm.

Bests,
__________________
Amir
Amir is offline   Reply With Quote

Old   October 30, 2012, 23:34
Default surface heat flux
  #12
New Member
 
Praneetha
Join Date: Dec 2009
Posts: 7
Rep Power: 16
Praneetha is on a distinguished road
I am trying to do something similar, I am calculating surface integral over boundary which has zone id 15 and trying to use tohis as source for domain (cell zone). the code compiles and loads without any errors. But after 1st iteration nothing happens. It just hovers over 1st iteration. looks like it is going into infinite loop. But cannot figure out how?

#include "udf.h"
#define C 1.7e-8
#define V 5.7e-4
DEFINE_SOURCE(source3, c, t, dS, i)
{
real flux=0;
real ID=15;
face_t f;
Domain *d;
d=Get_Domain(1);
t=Lookup_Thread(d, ID);
begin_f_loop(f,t)
{
flux += ((pow(F_T(f,t),4))-(pow(297,4)))*(-C)/V;
}
end_f_loop(f,t)
dS[i]=0;
return flux;
}
Praneetha is offline   Reply With Quote

Old   February 24, 2015, 09:05
Default Source term UDF
  #13
Member
 
Baradwaj B S
Join Date: Jan 2015
Posts: 75
Rep Power: 11
Bharadwaj B S is on a distinguished road
Hi all,

Bharadwaj here, My case has also very similar requirement. I have to assign about 1kg of mass to a sphere surface. which is present in a fluid flow domain (cylindrical).

QUESTION:

If I use DEFINE_SOURCE UDF, will that be specifying mass directly to a domain or will the UDF just adds a source term to the governing equation. And if it adds the value as mass, how to verify that in FLUENT?

Any help by Amir and others are of great use for me. Thanks in advance.

Regards,
Bharadwaj
Bharadwaj B S is offline   Reply With Quote

Old   July 7, 2015, 12:56
Default Fatal segmentation error
  #14
New Member
 
Lokanath Mohanta
Join Date: Jun 2015
Posts: 1
Rep Power: 0
Lokanath is on a distinguished road
I have a similar problem in which I would like to define mass and momentum source in the cells close to one surface. UDF gets compiled and I can hook the sources with the volumes. But whenever I start running the fluent, it says Fatal segementation error. Any suggestions ?



Here is my UDF
--------------------------
# include "udf.h"
DEFINE_SOURCE(mass_source, c,t, dS, eqn)
{
real source;
Domain *domain = Get_Domain(17);
face_t f;
Thread *tb = Lookup_Thread(domain,24); /* Get boundary thread, wall zone id is 30 */
if(c == F_C0(f,tb)) /* if cell is wall boundary cell */
{
source = 10;
dS[eqn]=0.0;
}
else
{
source = 0;
dS[eqn]=0.0;
}
return source;
}
DEFINE_SOURCE(momentum_source, c,t, dS, eqn)
{
real momnt_source;
Domain *domain = Get_Domain(17);
face_t f;
Thread *tb = Lookup_Thread(domain,24); /* Get boundary thread, wall zone id is 30 */
if(c == F_C0(f,tb)) /* if cell is wall boundary cell */
{
momnt_source = 0.002;
dS[eqn]=0.0;
}
else
{
momnt_source = 0;
dS[eqn]=0.0;
}
return momnt_source;
}
Lokanath is offline   Reply With Quote

Old   March 12, 2016, 13:38
Default
  #15
New Member
 
VISHNU
Join Date: Jan 2016
Posts: 13
Rep Power: 10
vishnuambali@gmail.com is on a distinguished road
I have to provide an actuation which is base on CL.

How to retrieve CL to my UDF FLUENT from solver??
Which command??
vishnuambali@gmail.com is offline   Reply With Quote

Old   March 15, 2016, 10:42
Default
  #16
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
What is CL???

If you want your question answered, be as clear as you can be. Using abbreviations does not help.
pakk is offline   Reply With Quote

Old   January 26, 2017, 22:11
Default
  #17
Member
 
Howard
Join Date: Jun 2012
Posts: 43
Rep Power: 14
twcp0104 is on a distinguished road
I have been able to do this... problem is fluent seems to compute source terms on a cell-zone basis. That way you can't really choose which cells to apply the source. Well, you can, and it works, but the pressure drop that results is always a bit wrong. between 50-20% of what you would expect. I've been working on this for a few months now, and the best solution I've found is to create a separate cellzone for the sourceterm during mesh generation. The resulting pressure drop is nice and consistent
THA SEANGHAI likes this.
twcp0104 is offline   Reply With Quote

Old   June 27, 2017, 16:41
Default segmentation fault
  #18
Member
 
sebastian bergman
Join Date: Mar 2017
Location: seattle
Posts: 52
Rep Power: 9
Tushar_Telmasre is on a distinguished road
In my momentum equation owing to density difference i have to write a source term udf. the source term is,

source term= - ρl.(1+∝).u ⃗ .∂fl/∂t

where ∝ = the volume of fraction variable
fl = liquid fraction
ul = Velocity vector
ρl and ρs = liquid and solid density respectively


I did write a udf for it

-----for x-momentum----
#include "udf.h"
#define rho_l 1544.0
#define rho_s 1648.0

DEFINE_SOURCE(x_momentum_source,c,t,dS,eqn)
{
real source;
source = -(rho_l*(1+C_VOF(c,t))*C_U(c,t)*((C_LIQF(c,t)-C_LIQF_M1(c,t))/CURRENT_TIMESTEP));
dS[eqn] = 0;
return source;
}

----for y-momentum-----
#include "udf.h"
#define rho_l 1544.0
#define rho_s 1648.0

DEFINE_SOURCE(y_momentum_source,c,t,dS,eqn)
{
real source;
source = -(rho_l*(1+C_VOF(c,t))*C_V(c,t)*((C_LIQF(c,t)-C_LIQF_M1(c,t))/CURRENT_TIMESTEP));
dS[eqn] = 0;
return source;
}


i hooked it in the cell zone section. i was using the VOF module.
IT is giving me a segmentation fault.
I am not able to understand the mistake here. can anybody help?
Tushar_Telmasre is offline   Reply With Quote

Old   October 20, 2017, 10:06
Default
  #19
New Member
 
Hooman
Join Date: Jan 2016
Posts: 19
Rep Power: 10
hooman.esl is on a distinguished road
hi amir,
I have written this code for momentum source term for a two-phase VOF model but I faced this error:
Error: received a fatal signal (Segmentation fault).
what wrong is with it?
do you have any idea which parameter is undefined?
thank you.

Quote:
#include "udf.h"
#define porosity 0.183 /*soil property porosity*/
#define sat_0_w 0.3 /*soil property residual water saturation*/
#define sat_0_g 0.1 // *************************shahab gerami page 134(table)**************************************** ******
#define k_abs 0.9671e-13 /* k: (intrinsic) permeability [L2] K: hydraulic conductivity [l/T ]=k rho gravity/nu */
DEFINE_SOURCE(source,c,t,dS,eqn)
{
Thread *mix_th, *water_th;
real k_avrg, rel_k_m, source, sat_w, relsat_w, rel_k_w;
mix_th = THREAD_SUPER_THREAD(t);
water_th = THREAD_SUB_THREAD(mix_th, 0);
sat_w = C_VOF(c,water_th);
relsat_w = (sat_w-sat_0_w)/(1-sat_0_g-sat_0_w);
rel_k_w = pow(relsat_w,4);
rel_k_m = (1-pow(relsat_w,2))*pow((1-relsat_w),(2));
k_avrg = rel_k_w*sat_w+rel_k_m*(1-sat_w); //volume-fraction-averaged permeability
source = -1*C_U(c,t)*C_MU_L(c,t)/(k_abs*k_avrg);
dS[eqn] = -1*C_MU_L(c,t)/(k_abs*k_avrg);
return source;
}
hooman.esl is offline   Reply With Quote

Old   October 20, 2017, 10:08
Default
  #20
New Member
 
Hooman
Join Date: Jan 2016
Posts: 19
Rep Power: 10
hooman.esl is on a distinguished road
Quote:
Originally Posted by Amir View Post
Hi,
The information in mentioned paper is enough! you need a relation to compute particle concentration in your domain i.e. equation (7); there is not your desired UDF in documantation, but you can use them in your algorithm.

Bests,
hi amir,
I have written this code for momentum source term for a two-phase VOF model but I faced this error:
Error: received a fatal signal (Segmentation fault).
what wrong is with it?
do you have any idea which parameter is undefined?
thank you.


Quote:
#include "udf.h"
#define porosity 0.183 /*soil property porosity*/
#define sat_0_w 0.3 /*soil property residual water saturation*/
#define sat_0_g 0.1 // *************************shahab gerami page 134(table)**************************************** ******
#define k_abs 0.9671e-13 /* k: (intrinsic) permeability [L2] K: hydraulic conductivity [l/T ]=k rho gravity/nu */
DEFINE_SOURCE(source,c,t,dS,eqn)
{
Thread *mix_th, *water_th;
real k_avrg, rel_k_m, source, sat_w, relsat_w, rel_k_w;
mix_th = THREAD_SUPER_THREAD(t);
water_th = THREAD_SUB_THREAD(mix_th, 0);
sat_w = C_VOF(c,water_th);
relsat_w = (sat_w-sat_0_w)/(1-sat_0_g-sat_0_w);
rel_k_w = pow(relsat_w,4);
rel_k_m = (1-pow(relsat_w,2))*pow((1-relsat_w),(2));
k_avrg = rel_k_w*sat_w+rel_k_m*(1-sat_w); //volume-fraction-averaged permeability
source = -1*C_U(c,t)*C_MU_L(c,t)/(k_abs*k_avrg);
dS[eqn] = -1*C_MU_L(c,t)/(k_abs*k_avrg);
return source;
}
hooman.esl 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
Robin B.C. Yu FLUENT 3 May 27, 2012 05:19
help:uds source added to boundary cells FredPacheo FLUENT 5 September 5, 2008 06:45
UDF to define source term at every grid point Ralf Schmidt FLUENT 0 September 21, 2006 12:32
Free surface boudary conditions with SOLA-VOF Fan Main CFD Forum 10 September 9, 2006 13:24
Ignore cells on partition boundary Karl FLUENT 7 May 11, 2002 23:12


All times are GMT -4. The time now is 12:23.