# Volume of Fluid UDF for coordinates

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

June 8, 2015, 15:00
Volume of Fluid UDF for coordinates
#1
Member

Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 6
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];
Domain *domain;
int zoneid = 2;
domain = Get_Domain(1);

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
 nt.png (7.8 KB, 25 views)

 June 9, 2015, 04:56 #2 Senior Member   Join Date: Nov 2013 Posts: 1,136 Rep Power: 15 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).

 June 9, 2015, 05:34 #3 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 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.

 June 9, 2015, 05:39 #4 Senior Member   Join Date: Nov 2013 Posts: 1,136 Rep Power: 15 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.

 June 9, 2015, 09:04 #5 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 This is somewhat confusing because fluent plot shows that there is fractional phase quantity in the region between phases. Thank You for answer

 June 23, 2015, 00:39 #6 Senior Member   Vaze Join Date: Jun 2009 Posts: 160 Rep Power: 10 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

 June 23, 2015, 05:33 #7 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 In fact 0-1 thing happtens only at first step. In dam break case at later time steps there are also fractional quantities.

 June 24, 2015, 00:28 #8 Senior Member   Vaze Join Date: Jun 2009 Posts: 160 Rep Power: 10 what volume fraction value does message shows at t=0 at interface?

 June 24, 2015, 10:40 #9 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 Only 0 or 1

 June 26, 2015, 06:19 #10 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 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.

 June 26, 2015, 07:02 #11 Senior Member   Vaze Join Date: Jun 2009 Posts: 160 Rep Power: 10 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?

 June 26, 2015, 10:41 #12 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 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```

 June 26, 2015, 10:43 #13 Senior Member   Join Date: Nov 2013 Posts: 1,136 Rep Power: 15 So it does what would be expected. Mvee, why did you give Vekh this task?

 June 28, 2015, 23:55 #14 Senior Member   Vaze Join Date: Jun 2009 Posts: 160 Rep Power: 10 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.

June 29, 2015, 05:25
#15
Member

Rafal
Join Date: Aug 2013
Location: CK
Posts: 36
Rep Power: 6
Quote:
 Originally Posted by mvee 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?

June 29, 2015, 06:18
#16
Senior Member

Join Date: Nov 2013
Posts: 1,136
Rep Power: 15
Quote:
 Originally Posted by mvee 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.

 June 29, 2015, 11:25 #17 Member   Rafal Join Date: Aug 2013 Location: CK Posts: 36 Rep Power: 6 So it seems that I should activate if C_VOF<1 statement after few timesteps.

June 29, 2015, 11:42
#18
Senior Member

Join Date: Nov 2013
Posts: 1,136
Rep Power: 15
Quote:
 Originally Posted by vekh So it seems that I should activate if C_VOF<1 statement after few timesteps.
I have no idea why you draw that conclusion...

 June 29, 2015, 11:51 #19 Senior Member   Join Date: Nov 2013 Posts: 1,136 Rep Power: 15 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:all cells with VOF between 0.4 and 0.6. all cells with VOF<0.5 on one side and VOF>0.6 on another side all cells where the VOF changes a lot, to be exact gradient of more than 1000 (1/m). The drawbacks of each choice are: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. This is computationally difficult. 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.41000) {...}` And, as I said, option 2 is too difficult to write down in one line.

 October 7, 2015, 06:12 did you figure out the interface tracking ? #20 New Member   logan Join Date: Feb 2012 Posts: 10 Rep Power: 7 i have a similar pbm __________________ I am a lost sheep... but survival is a necessity

 Thread Tools Display Modes Linear Mode

 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 OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post harsha_kulkarni OpenFOAM Running, Solving & CFD 3 February 18, 2016 06:06 Niru CFX 5 November 25, 2014 14:57 Ganesh FLUENT 13 January 22, 2014 05:11 gaottino OpenFOAM Native Meshers: blockMesh 7 July 19, 2010 14:11 zahid FLUENT 4 June 1, 2002 09:11

All times are GMT -4. The time now is 10:45.