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

Volumetric flow rate UDF

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 14, 2015, 21:52
Default Volumetric flow rate UDF
  #1
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Dear colleagues!

I have tried everything and I also cannot find any information about that subject. I would like to hear your suggestion how can I solve me problem.
I am trying to write UDF which will calculate volumetric flow [m^3/s] in z direction (3-D simulation) at certain elevations (or areas) along pipe.

tab_len[0] =0; /*For this areas I need to find out what is volumetric flow rate*/
for (n = 1; n <= 10; n++)
{
tab_len[n] = tab_len[n - 1] + length / 10;
}

I have 10 areas for which I would like to know volumetric flow. I used this tab_len[n] for choosing a cell, if it is contain in one of the areas. For this purpose I created macro (of course all variables are declared):

thread_loop_c(t, super_domain)
{
face_t f;
begin_c_loop_int(c, t)
{
C_CENTROID(x, c, t);
y = x[2];
n = 0;
do{
n++;
if (y <= tab_len[n])
{
/* here should be a code to calculate volumetric flow of one cell*/
}
} while (tab_len[n] <= y);

}
end_c_loop_int(c, t)
}

I tested all of the functions which I know, and nothing seems to work well. The problem is that I use tetrahedral mesh, so faces has some inclinations which make a problem complicated.
Maybe the direction of this UDF is wrong and you could suggest me a better way to do it.
Harry321 is offline   Reply With Quote

Old   January 15, 2015, 10:41
Default
  #2
Senior Member
 
Andrew Kokemoor
Join Date: Aug 2013
Posts: 122
Rep Power: 13
Kokemoor is on a distinguished road
Do you need this information available for another UDF? If not, a UDF probably isn't the easiest way to measure flow through sections. Check out the Fluent User's Guide Chapter 30 (in particular, section 30.6) for creating surfaces. Reporting the volumetric flow through a created surface should be simple.
Kokemoor is offline   Reply With Quote

Old   January 15, 2015, 10:59
Default
  #3
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Thanks a lot for your suggestion. Base on volumetric flow for every area I will choose proper model which I will use during calculation, so I am not sure about the idea with a surface.
Harry321 is offline   Reply With Quote

Old   January 15, 2015, 11:07
Default
  #4
Senior Member
 
Andrew Kokemoor
Join Date: Aug 2013
Posts: 122
Rep Power: 13
Kokemoor is on a distinguished road
I see. If you separate your domain into multiple bodies with an interface at each location you want to measure, you could loop across that interior face with F_FLUX(f,t).
Kokemoor is offline   Reply With Quote

Old   January 15, 2015, 11:13
Default
  #5
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
The idea for small domain will work, but at the and I will have domain with around 500 areas.
I think it is still possible to make it using surfaces but I though there is a more automatic way to do it.
Harry321 is offline   Reply With Quote

Old   January 15, 2015, 11:46
Default
  #6
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Ok so I add some lines of code:

thread_loop_c(t, super_domain)
{

face_t f;
begin_c_loop_int(c, t)
{
C_CENTROID(x, c, t);
y = x[2];
n = 0;
do{
n++;
if (y <= tab_len[n])
{

c_face_loop(c, t, i)
{
t112 = C_FACE_THREAD(c, t, i);
f = C_FACE(c, t, i);
F_AREA(A, f, t112);
NV_D(psi_vec1, = , C_U(c, t), C_V(c, t), C_W(c, t));
flux1 = NV_DOT(psi_vec1, A);
if (flux1 > 0) flux2 += flux1;

}
mass_flowf[n - 1] += flux2;
count++;
flux2 = 0;
}

} while (tab_len[n] <= y);

}
end_c_loop_int(c, t)
}

But the flux2 is 0 all the time. The velocity at BS is 0.62 m/s.
Harry321 is offline   Reply With Quote

Old   January 18, 2015, 20:41
Default
  #7
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Never mind, I was able to solve this problem.
Harry321 is offline   Reply With Quote

Old   January 26, 2015, 04:38
Default
  #8
New Member
 
Artem Ponikarov
Join Date: Jan 2015
Posts: 3
Rep Power: 11
Enhort is on a distinguished road
Hello, i have a same problems, Please can you help me?
I should write the UDF to calculate the volumetric flow, in different planes. In order for changing variable value of the source. Please help me!
Sorry my bad english.
Enhort is offline   Reply With Quote

Old   January 26, 2015, 11:36
Default
  #9
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Sure, no problem.

You need to combain the macros which I have showed already. You need to use the idea of choosing the plane base one the algorithm which I have show for cells, but it needs to be done for faces. Then just use:
F_CENTROID(x, c, t);
y = x[2]; // for z direction, it could be misleading that I use y instead of z // but this is just variable

it will be area of a face reflected on z plane.

I used:
c0 = F_C0(f, t);
c1 = F_C1(f, t);

to get cells on both sides of face and then from this I used C_W (c,t) to get velocities on both sides. Then you need to get average which will give velocity on face (I don't remember if I tried F_W but I am quiet sure that Fluent will not store values of velocities on faces on interior, but I can be wrong so you can check it, I used F_W on boundary)

When you get the velocity on face, just multiply its value with y from example and you will get volumetric flow in z direction on one of the face, you need to add them all together to get the values on specific plane.
Harry321 is offline   Reply With Quote

Old   January 27, 2015, 04:26
Default
  #10
New Member
 
Artem Ponikarov
Join Date: Jan 2015
Posts: 3
Rep Power: 11
Enhort is on a distinguished road
Hello, thank you very much! But unfortunately, I'm not good at English, we have a bad level of education. If this is not difficult to you please, post here full udf code, or that part you can, thank you!
Enhort is offline   Reply With Quote

Old   January 29, 2015, 03:46
Default
  #11
New Member
 
Artem Ponikarov
Join Date: Jan 2015
Posts: 3
Rep Power: 11
Enhort is on a distinguished road
Harry321, hello. Thank you for helping! Please if you have an article in journal, or something like this, give me a link. If you do not mind, I want to refer to your article.
Enhort is offline   Reply With Quote

Old   January 30, 2015, 01:30
Default
  #12
New Member
 
mostafa
Join Date: Jun 2013
Posts: 22
Rep Power: 12
mostafa_zeynalabedini is on a distinguished road
Hi everybody.
I have a question:
I want to compute the surrounding area of a cell in a mass change define macro.
I write this UDF but FLUENT doesn’t interpret this UDF. Its error is :
line 23: structure reference not implemented
I tested 2 ways but both are wrong!
Would you help me please?
This is my UDF:

#include"udf.h"
DEFINE_MASS_TRANSFER(LargeBubbles2SmallBubbles, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real TotalArea;
real NV_VEC(area);
int n, i;
int phase1_domain_index = 0;
Thread *ContinuousPhaseThread = THREAD_SUB_THREAD(thread,phase1_domain_index);
face_t f;
Thread *tf;
/*first way */
for (i==0 ; i<6 ; i++)
{
tf = C_FACE_THREAD(cell,ContinuousPhaseThread,i);
f = C_FACE(cell,ContinuousPhaseThread,i);
F_AREA(area,f,tf);
total_area +=NV_MAG(area);
}
/*
/*second way*/
c_face_loop(cell,ContinuousPhaseThread,n)
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
}
begin_f_loop(f,tf)
{
F_AREA(area,f,t);
total_area +=NV_MAG(area);
}
end_f_loop(f,t)
}
mostafa_zeynalabedini is offline   Reply With Quote

Old   January 30, 2015, 10:21
Default
  #13
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Hi,

what kind of multiphase model and what kind of mesh do you use?

Try to comment this part:
int phase1_domain_index = 0;
Thread *ContinuousPhaseThread = THREAD_SUB_THREAD(thread,phase1_domain_index);

and use:

tf = C_FACE_THREAD(cell,thread,i);
f = C_FACE(cell,thread,i);

In my opinion if you want area of faces on specific cells, it is better to use this:

c_face_loop(cell,thread,n)
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
}

but you need to remember, if you are going to use it for defining a mass flux, looping over a cell (for mass flux) should give you 0 for mass flux, which comes from conservation of mass, so you need to loop only on positive or negative fluxes.

And one more advice. If you want localize where is an error in your code you can comment some lines of a code to see if the macro will run without specific line, or add Message (""); with some text between some line to see where macro will stop.

Btw. Enhort have you received my message on privet? I have sent you one.
Harry321 is offline   Reply With Quote

Old   January 30, 2015, 11:47
Default
  #14
New Member
 
mostafa
Join Date: Jun 2013
Posts: 22
Rep Power: 12
mostafa_zeynalabedini is on a distinguished road
hi harry.
I got your message and thank you.
my multiphase model is VOF and I run my setup on a structured mesh.
unfortunately What you said doesn't work OR I can't understand your answer well.
I want to compute the surrounding area of each cell.
my DEFINE_MACRO is "DEFINE_MASS_TRANSFER".

#include "udf.h"
DEFINE_MASS_TRANSFER(name, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real TotalArea,
NV_VEC(area);
int n, i;
Thread *ContinuousPhaseThread = THREAD_SUB_THREAD(thread,0);

my question is from later part :

I used these two ways but both are wrong. whould you tell me what is the correct form and which way is better:

face_t f;
Thread *tf;

first way:

for (i==0 ; i<6 ; i++)
{
tf = C_FACE_THREAD(cell,ContinuousPhaseThread,i);
f = C_FACE(cell,ContinuousPhaseThread,i);
F_AREA(area,f,tf);
total_area +=NV_MAG(area);
}

Second way:

c_face_loop(cell,ContinuousPhaseThread,n)
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
}
begin_f_loop(f,tf)
{
F_AREA(area,f,t);
total_area +=NV_MAG(area);
}
end_f_loop(f,t)
return (...);
}
mostafa_zeynalabedini is offline   Reply With Quote

Old   January 30, 2015, 12:26
Default
  #15
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
@ Enhort check your privet messages.

@mostafa_zeynalabedin

Just use :

c_face_loop(cell,thread,n)
{

/* Here you are "inside" one cell and you are looping over ALL faces but only in this one specific cell */

f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);

/* Here you should put a code to calculate area of a face and sum all of them together. Notice that n is a number id of a face specific for this one cell and program will automatically now how many faces are "sign" to this cell*/

}


This macro is used only for ONE cell, so you need to also loop over all cells from the thread (for example interior) for which you desire to have total area of all cells. This loop should be inside a loop for looping over all cells.

Using this loop you don't need to use looping over faces.

I hope this is clear If no, just ask more question. You can also look at examples from fluent documentations
Harry321 is offline   Reply With Quote

Old   January 30, 2015, 14:17
Default
  #16
New Member
 
mostafa
Join Date: Jun 2013
Posts: 22
Rep Power: 12
mostafa_zeynalabedini is on a distinguished road
Thank you very much harry.
I have used it, but I got surprised that it doesn't work.
I got confused! every thing is OK, but the FLUENT doesn't interpret this UDF.
I make the UDF very simple but it doesn't work again.

UDF :

#include "udf.h"
DEFINE_MASS_TRANSFER(name, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real TotalArea, NV_VEC(area);
int n;
face_t f;
Thread *tf;
c_face_loop(cell,thread,n) /*line8*/
{
f = C_FACE(cell,thread,n);
tf = C_FACE_THREAD(cell,thread,n);
F_AREA(area,f,tf);
total_area +=NV_MAG(area);
}
return (0);
}


the error is :

line 8: structure reference not implemented

I also checked this one :

#include "udf.h"
DEFINE_MASS_TRANSFER(name, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real TotalArea, NV_VEC(area);
int n;
face_t f;
Thread *tf;
c_face_loop(cell,thread,n) /*line8*/
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
F_AREA(area,f,tf);
total_area +=NV_MAG(area);
}
return (0);
}

I also checked this very very simple one:

#include "udf.h"
DEFINE_MASS_TRANSFER(name, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
int n;
c_face_loop(cell,thread,n)
{
}
}
but it still doesn't interpret!
help me please
mostafa_zeynalabedini is offline   Reply With Quote

Old   January 30, 2015, 14:34
Default
  #17
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
DEFINE_MASS_TRANSFER(name, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
int n;
c_face_loop(cell,thread,n)
{
}
}

This one for sure will not work, like I wrote in previous post this macro is only for one cell in thread. Fluent doesn't know for which one, you need to specify what to do.

Check my example in previous posts
Here is an example which should work

DEFINE_MASS_TRANSFER(name, c, t, from_index, from_species_index, to_index, to_species_index)
{
int i;
face_t f;
thread *t112;
real A[ND_ND];
begin_c_loop_int(c, t)
{
c_face_loop(c, t, i)
{
t112 = C_FACE_THREAD(c, t, i);
f = C_FACE(c, t, i);
F_AREA(A, f, t112);
}
}
}


and in case of a problems try this method for debugging:

#include "udf.h"
DEFINE_MASS_TRANSFER(name, cell, thread, from_index, from_species_index, to_index, to_species_index)
{
real TotalArea, NV_VEC(area);
int n;
face_t f;
Thread *tf;
c_face_loop(cell,thread,n) /*line8*/
{
f = C_FACE(c,t,n);
tf = C_FACE_THREAD(c,t,n);
/*
F_AREA(area,f,tf);
total_area +=NV_MAG(area); this lines are commented so if it will interprate without this, the problem is in this lines, if not try to comment next lines until you will find which line is incorrect */

}
return (0);
}
Harry321 is offline   Reply With Quote

Old   January 30, 2015, 15:20
Default
  #18
New Member
 
mostafa
Join Date: Jun 2013
Posts: 22
Rep Power: 12
mostafa_zeynalabedini is on a distinguished road
dear harry.
I checked your example too, but unfortunately none of them works.
and the error is still the same. the problem is about the loop function over the faces of a cell, I mean "c_face_loop(c, t, i)". Maybe this loop is not available in this DEFINE_MACRO, because in each composition the error is the same.
I know that the problem is about the c_face_loop but I don't know what is the problem!
you said that I should use this function in a cell loop. but I don't want to compute the surrounding area of all cells. I want to do that cell by cell, means that in each cell that this MACRO is called for that cell (just 1 cell) I should compute the surrounding area and the next time for another cell. I think (but I doubt) that FLUENT calls this MACRO in each cell so it knows on which cell should do computation.
mostafa_zeynalabedini is offline   Reply With Quote

Old   January 30, 2015, 20:42
Default
  #19
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Could you check if it will run after compilation?
Harry321 is offline   Reply With Quote

Old   February 7, 2015, 20:02
Default
  #20
Member
 
Join Date: Dec 2014
Posts: 38
Rep Power: 11
Harry321 is on a distinguished road
Hi Mostafa,

Have you been able to solve your problem?
I got another error with ACCESS VIOLATION when my macro loop over a faces in one cell. Now I use DEFINE_SOURCE
DEFINE_SOURCE(source, c, t, dS, eqn)
{
int i;
real a = 0;
real b = 0, cc = 0, d = 0, ee = 0, ff = 0, gg = 0;
real hh = 0, test=0, test2=0, test3=0;
FILE *fp2;
face_t f;
Thread *t112;
Thread **t11;
Thread *t13;
Thread *t12;
Thread *t14;
real vec[ND_ND], A[ND_ND], vec2[ND_ND];
real cent0[ND_ND], cent1[ND_ND];

Domain *superdomain= Get_Domain(1);

Thread *tm = THREAD_SUPER_THREAD(t);
Thread *fluid_thread = THREAD_SUB_THREAD(tm, 0);
Thread *phase1_thread = THREAD_SUB_THREAD(tm, 1);/*which shows the thread of a phase to which macro is attached, but the integer is very strange*/
c_face_loop(c, t, i)
{
f = C_FACE(c, t, i);
t112 = C_FACE_THREAD(c, t, i);
F_AREA(A, f, t112);
t11 = THREAD_SUB_THREADS(tm);
t12 = t11[0];
t13 = t11[1];
NV_D(vec2, = , F_U(f, t), F_V(f, t), F_W(f, t));
}
}
I use Euler model and I attached this source to second phase.

It seems that not all values are stored on faces. I put some Messages to print out ID's of all threads which I declared and values for velocities and non of them show me the ID of a boundary. After producing some numbers for thread ID's and velocities and after some iteration there is ACCESS VIOLATION. What is more t12 and t13 IDs show the same number, ID of the t112 shows integer of a interior and tm, fluid_thread, phase1_thread IDs shows very strange numbers.
I try to figure out how to check if values for F_U and F_V are stored for a face but I don't know how to check this. Maybe other colleagues will help to solve this problem .
Harry321 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
Convergence problem with target mass flow rate ADL FLUENT 2 May 29, 2012 21:11
UDF for inlet mass flow rate rahulsuresh89 Fluent UDF and Scheme Programming 1 October 16, 2010 17:06
UDF mass flow rate Juan FLUENT 2 December 22, 2007 09:29
particle, parcel and mass flow rate balance flybird FLUENT 0 May 24, 2007 10:44
How to define mass flow rate using UDF? SAMUEL FLUENT 0 December 16, 2004 02:55


All times are GMT -4. The time now is 21:27.