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/)
-   -   Define source on boundary cells in UDF (https://www.cfd-online.com/Forums/fluent-udf/91363-define-source-boundary-cells-udf.html)

mingersai August 8, 2011 17:26

Define source on boundary cells in UDF
 
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!

mingersai August 9, 2011 09:33

need help.......

Amir August 9, 2011 14:47

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 August 10, 2011 10:04

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 (Post 319515)
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 ...


Amir August 10, 2011 10:35

Quote:

Originally Posted by mingersai (Post 319627)
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.

mingersai August 10, 2011 15:17

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

https://lh4.googleusercontent.com/-1...yU/Capture.PNG

Amir August 11, 2011 03:21

Quote:

Originally Posted by mingersai (Post 319645)
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 August 11, 2011 17:43

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 (Post 319689)
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,


Amir August 12, 2011 03:12

Quote:

Originally Posted by mingersai (Post 319800)
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,

mingersai August 12, 2011 05:23

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 (Post 319838)
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 August 12, 2011 05:38

Quote:

Originally Posted by mingersai (Post 319867)
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,

Praneetha October 30, 2012 22:34

surface heat flux
 
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;
}

Bharadwaj B S February 24, 2015 08:05

Source term UDF
 
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

Lokanath July 7, 2015 11:56

Fatal segmentation error
 
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;
}

vishnuambali@gmail.com March 12, 2016 12:38

I have to provide an actuation which is base on CL.

How to retrieve CL to my UDF FLUENT from solver??
Which command??

pakk March 15, 2016 09:42

What is CL???

If you want your question answered, be as clear as you can be. Using abbreviations does not help.

twcp0104 January 26, 2017 21:11

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

Tushar_Telmasre June 27, 2017 15:41

segmentation fault
 
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?

hooman.esl October 20, 2017 09:06

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 October 20, 2017 09:08

Quote:

Originally Posted by Amir (Post 319871)
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;
}

pakk October 23, 2017 04:41

You asked the same question here.


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