UDF for volume fraction
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 |
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! |
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 . |
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 sub-domains (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) cheers! |
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*/ |
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! |
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.95-a)-0.25)^3; } end_c_loop_int(cell, thread) } } |
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.95-C_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! |
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 |
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! |
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 Navier-Stokes 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: http://www.cfd-online.com/Forums/dat...AASUVORK5CYII=http://www.cfd-online.com/Forums/dat...AASUVORK5CYII= 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 |
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"?
|
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. |
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.
|
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 |
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 pressure-based 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! |
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 |
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]) } |
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]) |
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]) } } |
All times are GMT -4. The time now is 11:25. |