CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for volume fraction (https://www.cfd-online.com/Forums/fluent-udf/140797-udf-volume-fraction.html)

 sirpolar August 23, 2014 05:54

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

 Sun August 26, 2014 03:17

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!

 sirpolar August 26, 2014 14:13

Quote:
 Originally Posted by Sun (Post 507801) 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!
Dear Sun
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 .

 Sun August 27, 2014 01:58

Now I understand your question better. I think you can use
Code:

`C_VOF(cell,cell_thread)`
cell macro to get the volume fraction of each phase.
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) {     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*/```
something like this might help you, but cross-check the syntax first.
cheers!

 sirpolar August 27, 2014 15:53

Quote:
 Originally Posted by Sun (Post 507938) Now I understand your question better. I think you can use Code: `C_VOF(cell,cell_thread)` cell macro to get the volume fraction of each phase. 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) {     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*/``` something like this might help you, but cross-check the syntax first. cheers!

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"
{
Real Source, F;
int phase_domain_index;
cell_t cell;
Domain *subdomain;

sub_domain_loop(subdomain, mixture_domain, phase_domain_index)
{
{
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*/

 Sun August 28, 2014 02:18

If you are defining a source term
Code:

`DEFINE_SOURCE`
you need the derivatives of the source term. this is the syntax for source:
Code:

`DEFINE_SOURCE( name, c, t, dS, eqn)`
you also need the pointer to the mixture domain, because i don't think DEFINE_SOURCE is getting it directly from solver. And one minor thing is that if F = Source, there is no need to store it in an UDMI you can simply return it at the end of your code.

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!

 sirpolar August 28, 2014 12:06

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"
{
real a, b;
{
cell_t cell;
{
a = C_VOF(cell, pt[1]);
b = 1- ((0.95-a)-0.25)^3;
}
}
}

 Sun August 29, 2014 02:16

I am not sure what is:
Code:

`mp_thread_loop_c(thread, domain, pt)`
and if it needs a closing like end_mp_thread_loop.
Please try this one instead of line 13:
Code:

`b = 1- ((0.95-C_VOF(cell, pt[1]))-0.25)^3;`
and even better, if you want to monitor "b" just store it in an UDMI, so you'll have its contour and etc.
Also put cell_t cell outside the thread loop, it is being defined every time that solver loops through the thread.
cheers!

 sirpolar August 31, 2014 07:03

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

 Sun September 1, 2014 07:27

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!

 sirpolar September 1, 2014 11:16

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)}
where 1/α is viscous resistance.
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

 Sun September 1, 2014 11:54

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"?

 sirpolar September 1, 2014 13:36

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.

 Sun September 1, 2014 15:02

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.

 sirpolar September 1, 2014 15:20

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

 Sun September 2, 2014 02:32

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!

 sirpolar September 2, 2014 04:13

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

 sirpolar September 2, 2014 14:50

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"
{
cell_t cell;
Domain *mixture_domain;
{
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])
}

 Sun September 2, 2014 15:44

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])

 sirpolar September 5, 2014 14:20

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"
{
real visc;
cell_t cell;
Domain *mixture_domain;
{
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 05:39.