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

UDF for volume fraction

Register Blogs Community New Posts Updated Threads Search

Like Tree12Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 23, 2014, 06:54
Default UDF for volume fraction
  #1
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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 15:20.
sirpolar is offline   Reply With Quote

Old   August 26, 2014, 04:17
Default
  #2
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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!
6863523 likes this.
Sun is offline   Reply With Quote

Old   August 26, 2014, 15:13
Default
  #3
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
Quote:
Originally Posted by Sun View Post
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 .
sirpolar is offline   Reply With Quote

Old   August 27, 2014, 02:58
Default
  #4
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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!
Sun is offline   Reply With Quote

Old   August 27, 2014, 16:53
Default
  #5
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
Quote:
Originally Posted by Sun View Post
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"
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*/
Nartasan likes this.
sirpolar is offline   Reply With Quote

Old   August 28, 2014, 03:18
Default
  #6
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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!
Tleja, pakk, soheil_r7 and 1 others like this.
Sun is offline   Reply With Quote

Old   August 28, 2014, 13:06
Default
  #7
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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)
}
}
sirpolar is offline   Reply With Quote

Old   August 29, 2014, 03:16
Default
  #8
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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!
Sun is offline   Reply With Quote

Old   August 31, 2014, 08:03
Default
  #9
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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
sirpolar is offline   Reply With Quote

Old   September 1, 2014, 08:27
Default
  #10
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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!
Sun is offline   Reply With Quote

Old   September 1, 2014, 12:16
Default
  #11
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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:

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







sirpolar is offline   Reply With Quote

Old   September 1, 2014, 12:54
Default
  #12
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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"?
Sun is offline   Reply With Quote

Old   September 1, 2014, 14:36
Default
  #13
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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.
sirpolar is offline   Reply With Quote

Old   September 1, 2014, 16:02
Default
  #14
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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.
Sun is offline   Reply With Quote

Old   September 1, 2014, 16:20
Default
  #15
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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
sirpolar is offline   Reply With Quote

Old   September 2, 2014, 03:32
Default
  #16
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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!
Sun is offline   Reply With Quote

Old   September 2, 2014, 05:13
Default
  #17
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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 is offline   Reply With Quote

Old   September 2, 2014, 15:50
Default
  #18
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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])
}
sirpolar is offline   Reply With Quote

Old   September 2, 2014, 16:44
Default
  #19
Sun
Senior Member
 
Sun's Avatar
 
Join Date: Nov 2010
Posts: 103
Rep Power: 16
Sun is on a distinguished road
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])
Sun is offline   Reply With Quote

Old   September 5, 2014, 15:20
Default
  #20
Member
 
Ebrahim
Join Date: Feb 2014
Posts: 57
Rep Power: 12
sirpolar is on a distinguished road
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])
}
}
artawina likes this.
sirpolar is offline   Reply With Quote

Reply


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
udf: volume fraction gradient in eulerian model jwwang FLUENT 22 April 15, 2015 07:27
Conversion of mass fraction to mole fraction in FLUENT prince_pahariaa FLUENT 0 August 26, 2014 09:08
interDyMFoam - change in volume fraction gopala OpenFOAM Running, Solving & CFD 0 April 27, 2009 11:46
UDF for Species mass fraction daniel FLUENT 3 June 22, 2005 09:40
Species Mass Fraction inside UDF using PDF? Daniel Schneider FLUENT 0 September 20, 2000 07:34


All times are GMT -4. The time now is 13:38.