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

Volume of Fluid UDF for coordinates

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 8, 2015, 15:00
Unhappy Volume of Fluid UDF for coordinates
  #1
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
Hello guys!
I need to write UDF that will return x and y (and z for 3D) coordinates of place where there is fractional quantity of phase (black box region at the picture).
As I'm quite new to the all multiphase things I've used code from this forum. After few changes it's look like:
Code:
#include "udf.h"

DEFINE_SOURCE(source,c,t,dS,eqn)
{
real source, alpha, xc[ND_ND];
Thread *mixture_thread;
Thread **pt;
Domain *domain; 
int zoneid = 2;
domain = Get_Domain(1);
mixture_thread = Lookup_Thread(domain,zoneid);
pt = THREAD_SUB_THREADS(mixture_thread);

alpha = C_VOF(c,pt[1]);
Message("cell volume fraction = %f \n xc = %f \n yc = %f \n",alpha, xc[0], xc[1]);
source =2;
dS[eqn] = 0;
return source;
}
Sadly, the messages in Fluent console returns only:
Quote:
cell volume fraction = 0.000000
xc = 0.000000
yc = 0.000000
cell volume fraction = 1.000000
xc = 0.000000
yc = 0.000000
few times.
My fluid zone ID taken from GUI is 2. I have two phases:
  • argon phase (ID 2)
  • air phase (ID 3)
Could someone give me some hint?
Attached Images
File Type: png nt.png (7.8 KB, 42 views)
vekh is offline   Reply With Quote

Old   June 9, 2015, 04:56
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Congratulations on your UDF, it is a good start.

What you missed: you never assigned xc. Before you print xc[0] and xc[1], you should make them have the position of the cell:

Code:
C_CENTROID(xc,c,t);
This should at least solve the problem that all your coordinates appear to be (0,0).
pakk is offline   Reply With Quote

Old   June 9, 2015, 05:34
Default
  #3
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
Thank You for comment. I've noticed that mistake today. I've reworked my code:
Code:
 #include "udf.h"
 #include "sg_mphase.h" 

DEFINE_SOURCE(src, cell, mix_th, dS, eqn)
{
    Thread *pri_th, *sec_th;
    real m_dot;
    real xc[ND_ND],xx,yy;
    pri_th = THREAD_SUB_THREAD(mix_th, 0);
    sec_th = THREAD_SUB_THREAD(mix_th, 1);
    C_CENTROID(xc,cell, pri_th);
    xx=xc[0];
    yy=xc[1];
            Message("cell volume fraction = %f \n %f \n %f \n",C_VOF(cell,pri_th), xx, yy);
    return 1; 
}
But there is one more issue. In the picture inside black box there is interfacial area, where there is a fractional value of given phase (1>alpha>0) but C_VOF returns only binary 0 or 1 value for phase fraction.
vekh is offline   Reply With Quote

Old   June 9, 2015, 05:39
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
But the fractions in your solution really are 0 and 1...
You ask fluent for the values in the cell centers. Notice how there are now cell centers in your "interface area". Fluent draws a green line, because it calculates the face values as the average of the bordering cells, but your solution only has values 0 and 1, just as your udf shows. Argon and air did not mix.
pakk is offline   Reply With Quote

Old   June 9, 2015, 09:04
Default
  #5
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
This is somewhat confusing because fluent plot shows that there is fractional phase quantity in the region between phases. Thank You for answer
vekh is offline   Reply With Quote

Old   June 23, 2015, 00:39
Default
  #6
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 16
mvee is on a distinguished road
Hi Rafal

You have defined in your code pri_th and sec_th which points out to primary fluid or secondary fluid, correct?
Your code does not understand how to treat interface? Which pointer to consider? Hence I believe that it is only dividing into 1 and 0, no fraction.

I donot know wheter I am correct or not but you may get direction from this.

Best wishes
Vaze
mvee is offline   Reply With Quote

Old   June 23, 2015, 05:33
Default
  #7
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
In fact 0-1 thing happtens only at first step. In dam break case at later time steps there are also fractional quantities.
vekh is offline   Reply With Quote

Old   June 24, 2015, 00:28
Default
  #8
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 16
mvee is on a distinguished road
what volume fraction value does message shows at t=0 at interface?
mvee is offline   Reply With Quote

Old   June 24, 2015, 10:40
Default
  #9
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
Only 0 or 1
vekh is offline   Reply With Quote

Old   June 26, 2015, 06:19
Default
  #10
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
Maybe outcome from:
Code:
fprintf(fout,"%f %f %f\n", xx, yy, C_VOF(cell,pri_th));
command will be more explicit:
Code:
x        y        C_VOF
0.000050 0.003950 1.000000
0.000050 0.003850 1.000000
0.000050 0.003750 1.000000
0.000050 0.003650 1.000000
0.000050 0.003550 1.000000
0.000050 0.003450 1.000000
0.000050 0.003350 1.000000
0.000050 0.003250 1.000000
0.000050 0.003150 1.000000
0.000050 0.003050 1.000000
0.000050 0.002950 1.000000
0.000050 0.002850 1.000000
0.000050 0.002750 1.000000
0.000050 0.002650 1.000000
0.000050 0.002550 1.000000
0.000050 0.002450 1.000000
0.000050 0.002350 1.000000
0.000050 0.002250 1.000000
0.000050 0.002150 1.000000
0.000050 0.002050 1.000000
0.000050 0.001950 0.000000
0.000050 0.001850 0.000000
0.000050 0.001750 0.000000
0.000050 0.001650 0.000000
0.000050 0.001550 0.000000
0.000050 0.001450 0.000000
0.000050 0.001350 0.000000
0.000050 0.001250 0.000000
0.000050 0.001150 0.000000
0.000050 0.001050 0.000000
0.000050 0.000950 0.000000
0.000050 0.000850 0.000000
0.000050 0.000750 0.000000
0.000050 0.000650 0.000000
0.000050 0.000550 0.000000
0.000050 0.000450 0.000000
0.000050 0.000350 0.000000
0.000050 0.000250 0.000000
0.000050 0.000150 0.000000
0.000050 0.000050 0.000000
That's only for constant x=0.00005 and variable y. Full outcome is too long, but repeats for next x's.
I am still dissatisfied due to to the fact that only after some changes in phase interface (e.g. after one time step in dam break case) there are fractional values that could allow to designate actual phase interface coordinates.
vekh is offline   Reply With Quote

Old   June 26, 2015, 07:02
Default
  #11
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 16
mvee is on a distinguished road
Can you patch three zones with volume fraction of 0, 0.5 and 1?
and check printf during first iteration? Is it show value of 0.5?
mvee is offline   Reply With Quote

Old   June 26, 2015, 10:41
Default
  #12
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
For better insight. I have two phases: first is air and second one is water (ice). During initialization water volume fraction is set to zero. Then I'm patching certain area with water.
Now for Your request. For patching one area with fraction = 0.5
Code:
x            y            VOF
0.000050 0.003950 1.000000
0.000050 0.003850 1.000000
0.000050 0.003750 1.000000
0.000050 0.003650 1.000000
0.000050 0.003550 1.000000
0.000050 0.003450 1.000000
0.000050 0.003350 1.000000
0.000050 0.003250 1.000000
0.000050 0.003150 1.000000
0.000050 0.003050 1.000000
0.000050 0.002950 1.000000
0.000050 0.002850 1.000000
0.000050 0.002750 1.000000
0.000050 0.002650 1.000000
0.000050 0.002550 1.000000
0.000050 0.002450 1.000000
0.000050 0.002350 1.000000
0.000050 0.002250 1.000000
0.000050 0.002150 1.000000
0.000050 0.002050 1.000000
0.000050 0.001950 0.500000
0.000050 0.001850 0.500000
0.000050 0.001750 0.500000
0.000050 0.001650 0.500000
0.000050 0.001550 0.500000
0.000050 0.001450 0.500000
0.000050 0.001350 0.500000
0.000050 0.001250 0.500000
0.000050 0.001150 0.500000
0.000050 0.001050 0.500000
0.000050 0.000950 0.500000
0.000050 0.000850 0.500000
0.000050 0.000750 0.500000
0.000050 0.000650 0.500000
0.000050 0.000550 0.500000
0.000050 0.000450 0.500000
0.000050 0.000350 0.500000
0.000050 0.000250 0.500000
0.000050 0.000150 0.500000
0.000050 0.000050 0.500000
And for two different areas with 0, 0.5, 1:
Code:
x            y            VOF
0.000050 0.003950 1.000000
0.000050 0.003850 1.000000
0.000050 0.003750 1.000000
0.000050 0.003650 1.000000
0.000050 0.003550 1.000000
0.000050 0.003450 1.000000
0.000050 0.003350 1.000000
0.000050 0.003250 1.000000
0.000050 0.003150 1.000000
0.000050 0.003050 1.000000
0.000050 0.002950 1.000000
0.000050 0.002850 1.000000
0.000050 0.002750 1.000000
0.000050 0.002650 1.000000
0.000050 0.002550 1.000000
0.000050 0.002450 1.000000
0.000050 0.002350 1.000000
0.000050 0.002250 1.000000
0.000050 0.002150 1.000000
0.000050 0.002050 1.000000
0.000050 0.001950 0.500000
0.000050 0.001850 0.500000
0.000050 0.001750 0.500000
0.000050 0.001650 0.500000
0.000050 0.001550 0.500000
0.000050 0.001450 0.500000
0.000050 0.001350 0.500000
0.000050 0.001250 0.500000
0.000050 0.001150 0.500000
0.000050 0.001050 0.500000
0.000050 0.000950 0.000000
0.000050 0.000850 0.000000
0.000050 0.000750 0.000000
0.000050 0.000650 0.000000
0.000050 0.000550 0.000000
0.000050 0.000450 0.000000
0.000050 0.000350 0.000000
0.000050 0.000250 0.000000
0.000050 0.000150 0.000000
0.000050 0.000050 0.000000
vekh is offline   Reply With Quote

Old   June 26, 2015, 10:43
Default
  #13
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
So it does what would be expected. Mvee, why did you give Vekh this task?
pakk is offline   Reply With Quote

Old   June 28, 2015, 23:55
Default
  #14
Senior Member
 
Vaze
Join Date: Jun 2009
Posts: 172
Rep Power: 16
mvee is on a distinguished road
I supect thread pointer. It was only showing 0 and 1 due to its defination in THREAD_SUB_THREAD(mix_th, 0) becasue phase index does not understand the presence of interface and hence it only displays primary phase or secondary phase.
mvee is offline   Reply With Quote

Old   June 29, 2015, 05:25
Default
  #15
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
Quote:
Originally Posted by mvee View Post
I supect thread pointer. It was only showing 0 and 1 due to its defination in THREAD_SUB_THREAD(mix_th, 0) becasue phase index does not understand the presence of interface and hence it only displays primary phase or secondary phase.
Hmmm... OK. So is there any other method to get what i want?
vekh is offline   Reply With Quote

Old   June 29, 2015, 06:18
Default
  #16
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by mvee View Post
I supect thread pointer. It was only showing 0 and 1 due to its defination in THREAD_SUB_THREAD(mix_th, 0) becasue phase index does not understand the presence of interface and hence it only displays primary phase or secondary phase.
It was showing 0 and 1 because the values were only 0 and 1. The values were initialized to 0 and 1, and no further calculation had taken place, so the UDF should output 0 and 1. It would be very strange if the UDF would output different values.

All signs indicate that the UDF is doing exactly what vekh wants, so don't make it more complicated than it is.
pakk is offline   Reply With Quote

Old   June 29, 2015, 11:25
Default
  #17
Member
 
Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 12
vekh is on a distinguished road
So it seems that I should activate if C_VOF<1 statement after few timesteps.
vekh is offline   Reply With Quote

Old   June 29, 2015, 11:42
Default
  #18
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Quote:
Originally Posted by vekh View Post
So it seems that I should activate if C_VOF<1 statement after few timesteps.
I have no idea why you draw that conclusion...
pakk is offline   Reply With Quote

Old   June 29, 2015, 11:51
Default
  #19
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
If you want to show/print the position of the interface, you should first define what you mean with "interface".

Some choices that make at least some sense:
  1. all cells with VOF between 0.4 and 0.6.
  2. all cells with VOF<0.5 on one side and VOF>0.6 on another side
  3. all cells where the VOF changes a lot, to be exact gradient of more than 1000 (1/m).

The drawbacks of each choice are:
  1. If your interval (0.4 to 0.6 here) is too small, you have no cells, if it is too large, you have too many cells.
  2. This is computationally difficult.
  3. If your gradient threshold is too small, your region will to be too large, if it is too large you might see no cells at all.

Option 1 is easiest to program:
Code:
if ((0.4<C_VOF(cell,pri_th))&&(C_VOF(cell,pri_th)<0.6)) {...}
Option 3 is, I believe:
Code:
if (C_VOF(cell,pri_th)>1000) {...}
And, as I said, option 2 is too difficult to write down in one line.
pakk is offline   Reply With Quote

Old   October 7, 2015, 06:12
Default did you figure out the interface tracking ?
  #20
New Member
 
logan
Join Date: Feb 2012
Posts: 10
Rep Power: 14
wolverine is on a distinguished road
i have a similar pbm
__________________
I am a lost sheep... but survival is a necessity
wolverine is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
how to set periodic boundary conditions Ganesh FLUENT 15 November 18, 2020 06:09
multiphase turbulance case floating error harsha_kulkarni OpenFOAM Running, Solving & CFD 3 February 18, 2016 05:06
Multiphase simulation of bubble rising Niru CFX 5 November 25, 2014 13:57
[blockMesh] BlockMesh FOAM warning gaottino OpenFOAM Meshing & Mesh Conversion 7 July 19, 2010 14:11
fluid hot volume in fluid cold volume zahid FLUENT 4 June 1, 2002 09:11


All times are GMT -4. The time now is 01:23.