
[Sponsors] 
August 23, 2014, 05:54 
UDF for volume fraction

#1 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Hi dear all
I want an UDF that computes volume fraction of second phase in two phase flow at each cell as fluid flows. I would be appreciated if you could help me on this Thankyou very much Last edited by sirpolar; August 24, 2014 at 14:20. 

August 26, 2014, 03:17 

#2 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
If you use any multiphase modeling approaches, by default, Fluent will solves one transport equation for the volume fraction. So, you don't need to specifically define a UDF to compute the volume fraction of second phase.
Cheers! 

August 26, 2014, 14:13 

#3  
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Quote:
I want the volume fraction of second or third phase as an input for an equation That I am about to define by UDF. So I should write an UDF to computes volume fraction of phases at different positions and different times at each cell . 

August 27, 2014, 01:58 

#4 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
Now I understand your question better. I think you can use
Code:
C_VOF(cell,cell_thread) The other point that you should consider is to loop over all subdomains (the phases that you need their volume fractions) in the mixture domain. For example, you want to compute F=a*b where b is a constant and a is the secondary phase volume fraction, and F is varying by time and spatial location: Code:
sub_domain_loop(subdomain, mixture_domain, phase_domain_index) { thread_loop_c (cell_thread,subdomain) { begin_c_loop { /* get the secondary phase volume fraction*/ /* compute F = C_VOF(cell,cell_thread)*b */ /*store F in an UDMI */ } } } /*end of subdomain loop*/ cheers! 

August 27, 2014, 15:53 

#5  
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Quote:
Dear Sun For example for the function that multiplies volume fraction of second phase in each cell by 5 as second fluid flows in the domain, would be the following UDF Okay? Please let me know if there is some thing wrong with it. Thank you for your kindness. #include "udf.h" DEFINE_SOURCE (function,cell,thread,mixture_domain, phase_domain_index) { Real Source, F; int phase_domain_index; cell_t cell; Thread *cell_thread; Domain *subdomain; sub_domain_loop(subdomain, mixture_domain, phase_domain_index) { thread_loop_c (cell_thread,subdomain) { begin_c_loop { /* get the secondary phase volume fraction*/ F = C_VOF(c, pt[2])*5 /*store F in an UDMI */ } } } /*end of subdomain loop*/ 

August 28, 2014, 02:18 

#6 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
If you are defining a source term
Code:
DEFINE_SOURCE Code:
DEFINE_SOURCE( name, c, t, dS, eqn) But if all these calculations are not for a source term and you are trying to calculate some term which is dependent on secondary phase volume fraction you can use a general macro like Code:
DEFINE_ADJUST cheers! 

August 28, 2014, 12:06 

#7 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Dear Sun
I am really confused with this UDF I would be appreciated if you could help me more Here is another UDF , please tell me what is wrong with it and correct it if you can Fluent says line 13 parse error #include "udf.h" DEFINE_ADJUST(vis_res, domain) { Thread **pt; Thread *thread; real a, b; mp_thread_loop_c(thread, domain, pt) { cell_t cell; begin_c_loop_int(cell, thread) { a = C_VOF(cell, pt[1]); b = 1 ((0.95a)0.25)^3; } end_c_loop_int(cell, thread) } } 

August 29, 2014, 02:16 

#8 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
I am not sure what is:
Code:
mp_thread_loop_c(thread, domain, pt) Please try this one instead of line 13: Code:
b = 1 ((0.95C_VOF(cell, pt[1]))0.25)^3; Also put cell_t cell outside the thread loop, it is being defined every time that solver loops through the thread. cheers! 

August 31, 2014, 07:03 

#9 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Dear sun
I think we should first clarify which macro is more suitable for my case (define profile define source or define adjust) In fact I am about to write UDF for viscous resistance (a variable) that must be change according to a function that uses volume fraction of second phase in each cell. I would be really appreciated if you could help me more 

September 1, 2014, 07:27 

#10 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
Yes as you said the type of macro you want to use should be defined beforehand. DEFINE_SOURCE, as the name says, is for defining a source term at the RHS of any transport equations. For example, let's say you have some kind of force at the right hand side of momentum equation for which you can use DEFINE_SOURCE. However, DEFINE_ADJUST, is for general computations, for instance you want to calculate some variable which is dependent on the volume fraction of secondary phase. The last macro, DEFINE_PROFILE is for costume boundary conditions.
Since I don't know the details of your simulation and the problem that you are trying to solve, I cannot tell you surely which macro is the optimized choice for your problem. If you can please provide more details, I'll be able to recommend a suitable macro. cheers! 

September 1, 2014, 11:16 

#11 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Dear sun
Thank you for your guidance Here is some explanation about what I am about to do: Modeling of flows through a porous medium requires a modified formulation of the NavierStokes equations, which reduces to their classical form and includes additional body force terms (resistance terms) induced by the porous region (F). For homogenous porous media: F = ((μvi/α) + (C2ρvvi/2)} I want the UDF that uses the volume fraction of secondary phases in each cell as fluids flows in porous region to be inserted to an equation for determination of viscous resistance for example : Viscous resistance = 5 * volume fraction of secondary phase in the cell 

September 1, 2014, 11:54 

#12 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
Just a question, F is the resistance term NOT the force itself, right? but in the calculation of the body force due to porous region you need to have the "F"?


September 1, 2014, 13:36 

#13 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Hello sun
Yes F is a resistance term and its parameters (1/α and C2) should inserted in the FLUENT as constant value or user define function. 

September 1, 2014, 15:02 

#14 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
Alright if "F" is not a force term and it is not supposed to be a source term in N_S equation, I think you can use DEFINE_ADJUST.


September 1, 2014, 15:20 

#15 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
I think the "F" doesnt matter here, beacuse the udf must be written for viscouse resistance (1/α) and this parameter is defined separately. Dont you think so?
Dont you think Define_profile is more suitable? p.s. I found UDF example for viscous resistance in a manual /* Viscous Resistance Profile UDF in a Porous Zone that utilizes F_PROFILE*/ #include "udf.h" DEFINE_PROFILE(vis_res,t,i) { real x[ND_ND]; real a; cell_t c; begin_c_loop(c,t) { C_CENTROID(x,c,t); if(x[1] < (x[0]0.01)) a = 1e9; else a = 1.0; F_PROFILE(c,t,i) = a; } end_c_loop(c,t) } Best regards 

September 2, 2014, 02:32 

#16 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
OK this is perfect, now you have a good example to create your own UDF. But please have a look at the "solution procedure for the pressurebased solver" in the UDF manual. You can see DEFINE_PROFILE is being only calculated outside the time loop. Probably in your case the viscous resistance term is varying by the volume fraction of the second phase and time. So I think DEFINE_ADJUST would be a better choice.
cheers! 

September 2, 2014, 04:13 

#17 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Dear sun
thank you for your useful comment the second step is how to create a loop for second phase determination in each cell and how to define the second phase 

September 2, 2014, 14:50 

#18 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Dear Sun and other friends
would you please tell me what is wrong with this UDF Fluent says: line 13 c_VOF: undeclared variable #include "udf.h" DEFINE_ADJUST(viscouse_function, d) { cell_t cell; Thread **pt; Thread *cell_threads; Domain *mixture_domain; mp_thread_loop_c(cell_threads, mixture_domain, pt) { begin_c_loop(cell,pt[1]) { real visc; visc = 1 ((0.95(c_VOF(c,pt[1])))0.25); } end_c_loop(c,pt[1]) } 

September 2, 2014, 15:44 

#19 
Member
Join Date: Nov 2010
Posts: 89
Rep Power: 7 
required changes:
take out "real visc" from inside the loop and define it outside mp_thread_loop, c_VOF(c,pt[1]) > C_VOF(cell,pt[1]) end_c_loop(c,pt[1]) > end_c_loop(cell,pt[1]) 

September 5, 2014, 14:20 

#20 
Member
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 4 
Dear sun the other friends
I have written the UDF as follows, when I interpreted it to the fluent it is ok But when I want to run (after initialization) the fluent gives this error: FLUENT received fatal signal (ACCESS_VIOLATION) I was wondering if you know what is wrong with it? #include "udf.h" DEFINE_ADJUST(viscouse_function, d) { real visc; cell_t cell; Thread **pt; Thread *cell_threads; Domain *mixture_domain; mp_thread_loop_c(cell_threads, mixture_domain, pt) { begin_c_loop(cell,pt[1]) { visc = 1 ((0.95(C_VOF(cell,pt[1])))0.25); } end_c_loop(cell,pt[1]) } } 

Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
udf: volume fraction gradient in eulerian model  jwwang  FLUENT  22  April 15, 2015 06:27 
Conversion of mass fraction to mole fraction in FLUENT  prince_pahariaa  FLUENT  0  August 26, 2014 08:08 
interDyMFoam  change in volume fraction  gopala  OpenFOAM Running, Solving & CFD  0  April 27, 2009 10:46 
UDF for Species mass fraction  daniel  FLUENT  3  June 22, 2005 08:40 
Species Mass Fraction inside UDF using PDF?  Daniel Schneider  FLUENT  0  September 20, 2000 06:34 