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

how to use UDF to obtain the thred of the interface between the liquid and the wall?

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

Like Tree1Likes
  • 1 Post By hellowqy

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 13, 2015, 04:42
Default how to use UDF to obtain the thred of the interface between the liquid and the wall?
  #1
New Member
 
Qiong-yao Wang
Join Date: Apr 2014
Posts: 18
Rep Power: 9
hellowqy is on a distinguished road
hi, everyone, i'm using FLUENT two-phase flow model to simulate liquid sloshing in circle tank. i want to use UDF to obtain the boundary thread of the interface between the liquid and the wall(the red line in the figure),the interface(red line) will change all the time during sloshing, so it is difficulty for me to obtain the boundary thread of the interface, in fact, i obtained the whole circle wall instead of the interface!
please help me, thanks a lot!
(PS:the following is a part of my UDF,which must have some problems.please help me to modify it. thanks.)

Domain *subdomain= Get_Domain(3);
thread_loop_f(tf1,subdomain)
{
int zone_ID = THREAD_ID(tf1);
if(zone_ID==3)
{
begin_f_loop(f, tf1)
{
xv[0]=1; xv[1]=0; yv[0]=0; yv[1]=1;
F_AREA (A, f, tf1);
F_CENTROID(x,f,tf1);

F_X_FORCE+=F_P(f, tf1)*NV_DOT(A,xv);
F_Y_FORCE+=F_P(f, tf1)*NV_DOT(A,yv);
F_FORCE+=F_P(f, tf1)*NV_MAG(A);

Ax=Ax+A[0];
Ay=Ay+A[1];

fprintf(fout55,"%g,%g\n",x[0],x[1]);
}
end_f_loop(f, tf1)
}

55.png
morteza1361 likes this.
hellowqy is offline   Reply With Quote

Old   December 15, 2015, 08:07
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,864
Rep Power: 23
pakk will become famous soon enough
Quote:
Originally Posted by hellowqy View Post
hi, everyone, i'm using FLUENT two-phase flow model to simulate liquid sloshing in circle tank. i want to use UDF to obtain the boundary thread of the interface between the liquid and the wall(the red line in the figure),the interface(red line) will change all the time during sloshing, so it is difficulty for me to obtain the boundary thread of the interface, in fact, i obtained the whole circle wall instead of the interface!
please help me, thanks a lot!
(PS:the following is a part of my UDF,which must have some problems.please help me to modify it. thanks.)

Domain *subdomain= Get_Domain(3);
thread_loop_f(tf1,subdomain)
{
int zone_ID = THREAD_ID(tf1);
if(zone_ID==3)
{
begin_f_loop(f, tf1)
{
xv[0]=1; xv[1]=0; yv[0]=0; yv[1]=1;
F_AREA (A, f, tf1);
F_CENTROID(x,f,tf1);

F_X_FORCE+=F_P(f, tf1)*NV_DOT(A,xv);
F_Y_FORCE+=F_P(f, tf1)*NV_DOT(A,yv);
F_FORCE+=F_P(f, tf1)*NV_MAG(A);

Ax=Ax+A[0];
Ay=Ay+A[1];

fprintf(fout55,"%g,%g\n",x[0],x[1]);
}
end_f_loop(f, tf1)
}

Attachment 44059
I can't figure out the idea behind your code. How did you think this code would only get the red line and not the full circle? I was expecting that somewhere you try to detect if the face is "wet" or "dry", but I don't see where you try that...
pakk is offline   Reply With Quote

Old   December 15, 2015, 21:09
Default
  #3
New Member
 
Qiong-yao Wang
Join Date: Apr 2014
Posts: 18
Rep Power: 9
hellowqy is on a distinguished road
Quote:
Originally Posted by pakk View Post
I can't figure out the idea behind your code. How did you think this code would only get the red line and not the full circle? I was expecting that somewhere you try to detect if the face is "wet" or "dry", but I don't see where you try that...
Dear pakk:
Tank you very much for your replying.In fact, I am very anxious these days.Well, for my research,I want to calculating liquid sloshing force exerted on the tank wall(the red line part in the figure),however,my code is in fact calculating the force exerted on the whole circle boudary instead of the red line part.Well, if the air pressure is not high, there is not big differences between the two cases, because the air pressure exerted on the tank can be ignored when compared to the dynamic liquid pressure, but there must be big diferences when under high air pressure condition.So,my problem is that I can not detect wet area(the red line part in the figure). My code is just detecting the whole circle.So, could you help me to detect the wet area!Tank you very much and best wishes!
(sorry for my poor english that lead to your misunderstanding,if any question,please tell me. PS:attached the whole code and a more clear figure.tanks again.)
sloshing .png
# include "udf.h"
DEFINE_EXECUTE_AT_END(force)
{
cell_t c;
face_t f;
real F_Y_FORCE=0.0; /*lateral force */
real F_Z_FORCE=0.0; /* vertical force */
real F_FORCE=0.0; /* resultant force */
real MOMENT_X=0.0;

real x[ND_ND];
real NV_VEC(A);

real Ay=0; /*projected area in lateral direction, used for validating the code */
real Az=0; /* projected area in lateral direction , used for validating the code */

real cy,cz;
real wcy=0.0;
real wcz=0.0;
real va_liq=0.0;
real z[ND_ND];


FILE *fout;
FILE *fout2;
FILE *fout3;
FILE *fout4;


FILE *fout11;
FILE *fout22;

FILE *fout33;/*Ay*/
FILE *fout44;/*Az*/

FILE *fout55;



Thread *t;
Thread *tf1;

Domain *subdomain= Get_Domain(3); /*get the liquid phase domain*/
fout55 = fopen("COORDINATE.txt", "a");

thread_loop_f(tf1,subdomain)
{
int zone_ID = THREAD_ID(tf1); /*get the zone_ID of the thread*/

if(zone_ID==3) /* the zone_ID of the wall is 3(I think this is the problem)*/
{
begin_f_loop(f, tf1)
{

F_AREA (A, f, tf1);
F_CENTROID(x,f,tf1);

F_Y_FORCE+=F_P(f, tf1)*A[0]; /*calculate lateral force*/
F_Z_FORCE+=F_P(f, tf1)*A[1]; /* calculate vertical force */
F_FORCE+=F_P(f, tf1)*NV_MAG(A); /* calculate resultant force */

MOMENT_X+=(-F_P(f,tf1)*NV_DOT(A,yv)*x[0]+F_P(f, tf1)*NV_DOT(A,xv)*(x[1]+1.015));/*pitch moment*/

Ay=Ay+A[0];
/* calculate projected area in lateral direction, used for validating the code: if the code is indeed detecting the wet area, A[0] should not be always zero during liquid sloshing. however, the results I got were the constant zero, which show that my code is in fact detecting the whole circle instead of the wet area, because circle is a symmetric figure, projected area in lateral direction should always be zero. */
Az=Az+A[1];
/* calculate projected area in vertical direction, used for validating the code: if the code is indeed detecting the wet area, A[1] should be always negative value during liquid sloshing. Because the projected area in vertical direction is along outside the normal direction, however, the results I got were the constant zero, which show that my code is in fact detecting the whole circle instead of the wet area, because circle is a symmetric figure, projected area in vertical direction should be always zero. */

fprintf(fout55,"%g,%g\n",x[0],x[1]);
/*get the coordinate value of each cell at the wall boundary, x[0], x[1],used for validating the code: if the code is indeed detecting the wet area, I can plot the trajectory of the wet area use the coordinates of the all cells at the wet area. But, in fact, the trajectory I got was always a circle, this further show that this must be something wrong with my code. */
}
end_f_loop(f, tf1)
}

}

/*the following code is calculating the center of gravity of the liquid*/
thread_loop_c(t,subdomain)
{
begin_c_loop(c, t)
{
if(0<C_VOF(c,t)&&C_VOF(c,t)<=1.0)
{
va_liq = va_liq + C_VOLUME(c,t);
C_CENTROID(z,c,t);
wcy = wcy + z[0]*C_VOLUME(c,t);
wcz = wcz + z[1]*C_VOLUME(c,t);
}
}
end_c_loop(c, t)
}
cy=wcy/va_liq;
cz=wcz/va_liq;

fout = fopen("F_Y_FORCE.txt", "a");
fout2 = fopen("F_Z_FORCE.txt", "a");
fout3 = fopen("F_FORCE.txt", "a");
fout4 = fopen("MOMENT_X.txt", "a");

fout11 = fopen("Y-centroid of liquid.txt", "a");
fout22 = fopen("Z-centroid of liquid.txt", "a");

fout33 = fopen("Area in X.txt", "a");
fout44 = fopen("Area in Y.txt", "a");


fprintf(fout,"%g,%g\n",CURRENT_TIME,F_Y_FORCE);
fprintf(fout2,"%g,%g\n",CURRENT_TIME,F_Z_FORCE);
fprintf(fout3,"%g,%g\n",CURRENT_TIME,F_FORCE);
fprintf(fout4,"%g,%g\n",CURRENT_TIME,MOMENT_X);

fprintf(fout11,"%g,%g\n",CURRENT_TIME,cy);
fprintf(fout22,"%g,%g\n",CURRENT_TIME,cz);

fprintf(fout33,"%g,%g\n",CURRENT_TIME,Ax);
fprintf(fout44,"%g,%g\n",CURRENT_TIME,Ay);


fclose(fout);
fclose(fout2);
fclose(fout3);
fclose(fout4);


fclose(fout11);
fclose(fout22);

fclose(fout33);
fclose(fout44);
fclose(fout55);

Message("\n F_Y_FORCE = %g\n", F_Y_FORCE);
Message("\n F_Z_FORCE = %g\n", F_Z_FORCE);
Message("\n F_FORCE = %g\n", F_FORCE);
Message("\n MOMENT_X = %g\n", MOMENT_X);

Message("\n Y-centroid of liquid = %g\n", cy);
Message("\n Z-centroid of liquid = %g\n", cz);
}
hellowqy is offline   Reply With Quote

Old   December 16, 2015, 05:05
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,864
Rep Power: 23
pakk will become famous soon enough
If I would give you a face on the wall, how would you know if it is part of the 'dry wall' or part of the 'wet wall'?

Knowing the answer to this question is the first step in getting your program fixed.
pakk is offline   Reply With Quote

Old   December 16, 2015, 10:20
Default help:how to use UDF to get the wet area thread in FLUENT software
  #5
New Member
 
Qiong-yao Wang
Join Date: Apr 2014
Posts: 18
Rep Power: 9
hellowqy is on a distinguished road
Hi, everyone, I'm using FLUENT two-phase flow model to simulate liquid sloshing in circle tank. I want to calculate liquid sloshing force exerted on the tank wall, the force I get is by integration of dynamic liquid pressure exerted on wet area(the red line part in the figure), however, my code is in fact calculating the force by integration of pressure exerted on the whole circle boundary instead of the red line part. Well, if the air pressure is not high, there is not big differences between the two cases, because the air pressure exerted on the tank can be ignored when compared to the dynamic liquid pressure, but there must be big differences when under high air pressure condition. So, my problem is that I can not detect wet area(the red line part in the figure, wet area is changing with time during liquid sloshing). My code is just detecting the whole circle. So, could you help me to detect the wet area! Thank you very much. Best wishes!
sloshing .png

# include "udf.h"
DEFINE_EXECUTE_AT_END(force)
{
cell_t c;
face_t f;
real F_Y_FORCE=0.0; /*lateral force */
real F_Z_FORCE=0.0; /* vertical force */
real F_FORCE=0.0; /* resultant force */
real MOMENT_X=0.0;

real x[ND_ND];
real NV_VEC(A);

real Ay=0; /*projected area in lateral direction, used for validating the code */
real Az=0; /* projected area in lateral direction , used for validating the code */

real cy,cz;
real wcy=0.0;
real wcz=0.0;
real va_liq=0.0;
real z[ND_ND];


FILE *fout;
FILE *fout2;
FILE *fout3;
FILE *fout4;


FILE *fout11;
FILE *fout22;

FILE *fout33;/*Ay*/
FILE *fout44;/*Az*/

FILE *fout55;



Thread *t;
Thread *tf1;

Domain *subdomain= Get_Domain(3); /*get the liquid phase domain*/
fout55 = fopen("COORDINATE.txt", "a");

thread_loop_f(tf1,subdomain)
{
int zone_ID = THREAD_ID(tf1); /*get the zone_ID of the thread*/

if(zone_ID==3) /* the zone_ID of the wall is 3(I think this is the problem)*/
{
begin_f_loop(f, tf1)
{

F_AREA (A, f, tf1);
F_CENTROID(x,f,tf1);

F_Y_FORCE+=F_P(f, tf1)*A[0]; /*calculate lateral force*/
F_Z_FORCE+=F_P(f, tf1)*A[1]; /* calculate vertical force */
F_FORCE+=F_P(f, tf1)*NV_MAG(A); /* calculate resultant force */

MOMENT_X+=(-F_P(f,tf1)*NV_DOT(A,yv)*x[0]+F_P(f, tf1)*NV_DOT(A,xv)*(x[1]+1.015));/*pitch moment*/

Ay=Ay+A[0];
/* calculate projected area in lateral direction, used for validating the code: if the code is indeed detecting the wet area, A[0] should not be always zero during liquid sloshing. however, the results I got were the constant zero, which show that my code is in fact detecting the whole circle instead of the wet area, because circle is a symmetric figure, projected area in lateral direction should always be zero. */
Az=Az+A[1];
/* calculate projected area in vertical direction, used for validating the code: if the code is indeed detecting the wet area, A[1] should be always negative value during liquid sloshing. Because the projected area in vertical direction is along outside the normal direction, however, the results I got were the constant zero, which show that my code is in fact detecting the whole circle instead of the wet area, because circle is a symmetric figure, projected area in vertical direction should be always zero. */

fprintf(fout55,"%g,%g\n",x[0],x[1]);
/*get the coordinate value of each cell at the wall boundary, x[0], x[1],used for validating the code: if the code is indeed detecting the wet area, I can plot the trajectory of the wet area use the coordinates of the all cells at the wet area. But, in fact, the trajectory I got was always a circle, this further show that this must be something wrong with my code. */
}
end_f_loop(f, tf1)
}

}

/*the following code is calculating the center of gravity of the liquid*/
thread_loop_c(t,subdomain)
{
begin_c_loop(c, t)
{
if(0<C_VOF(c,t)&&C_VOF(c,t)<=1.0)
{
va_liq = va_liq + C_VOLUME(c,t);
C_CENTROID(z,c,t);
wcy = wcy + z[0]*C_VOLUME(c,t);
wcz = wcz + z[1]*C_VOLUME(c,t);
}
}
end_c_loop(c, t)
}
cy=wcy/va_liq;
cz=wcz/va_liq;

fout = fopen("F_Y_FORCE.txt", "a");
fout2 = fopen("F_Z_FORCE.txt", "a");
fout3 = fopen("F_FORCE.txt", "a");
fout4 = fopen("MOMENT_X.txt", "a");

fout11 = fopen("Y-centroid of liquid.txt", "a");
fout22 = fopen("Z-centroid of liquid.txt", "a");

fout33 = fopen("Area in X.txt", "a");
fout44 = fopen("Area in Y.txt", "a");


fprintf(fout,"%g,%g\n",CURRENT_TIME,F_Y_FORCE);
fprintf(fout2,"%g,%g\n",CURRENT_TIME,F_Z_FORCE);
fprintf(fout3,"%g,%g\n",CURRENT_TIME,F_FORCE);
fprintf(fout4,"%g,%g\n",CURRENT_TIME,MOMENT_X);

fprintf(fout11,"%g,%g\n",CURRENT_TIME,cy);
fprintf(fout22,"%g,%g\n",CURRENT_TIME,cz);

fprintf(fout33,"%g,%g\n",CURRENT_TIME,Ax);
fprintf(fout44,"%g,%g\n",CURRENT_TIME,Ay);


fclose(fout);
fclose(fout2);
fclose(fout3);
fclose(fout4);


fclose(fout11);
fclose(fout22);

fclose(fout33);
fclose(fout44);
fclose(fout55);

Message("\n F_Y_FORCE = %g\n", F_Y_FORCE);
Message("\n F_Z_FORCE = %g\n", F_Z_FORCE);
Message("\n F_FORCE = %g\n", F_FORCE);
Message("\n MOMENT_X = %g\n", MOMENT_X);

Message("\n Y-centroid of liquid = %g\n", cy);
Message("\n Z-centroid of liquid = %g\n", cz);
}
hellowqy is offline   Reply With Quote

Old   December 17, 2015, 03:28
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,864
Rep Power: 23
pakk will become famous soon enough
Quote:
Originally Posted by pakk View Post
If I would give you a face on the wall, how would you know if it is part of the 'dry wall' or part of the 'wet wall'?

Knowing the answer to this question is the first step in getting your program fixed.
This is a serious question. You have to tell Fluent what is "wet" and what is "dry", and the first step is to define for yourself what is "wet" and what is "dry".
pakk is offline   Reply With Quote

Old   December 17, 2015, 08:21
Default
  #7
New Member
 
Syed Aaquib Hazari
Join Date: Apr 2015
Location: Delft
Posts: 16
Rep Power: 8
hazari.aaquib is on a distinguished road
Dear Pakk,

I have the same problem as hellowqy.
When you say what is 'wet' and what is 'dry' do you mean initialising; THREAD_SUB_THREAD for each phase?

Then the next step would be writing conditional statement where C_VOF would be between 0 & 1?

Please let me know.
Thanks.
hazari.aaquib is offline   Reply With Quote

Old   December 17, 2015, 09:18
Default
  #8
Senior Member
 
Join Date: Nov 2013
Posts: 1,864
Rep Power: 23
pakk will become famous soon enough
Quote:
Originally Posted by hazari.aaquib View Post
Dear Pakk,

I have the same problem as hellowqy.
When you say what is 'wet' and what is 'dry' do you mean initialising; THREAD_SUB_THREAD for each phase?

Then the next step would be writing conditional statement where C_VOF would be between 0 & 1?

Please let me know.
Thanks.
No, I mean it in a completely different way.
Suppose you are Fluent, and you have a numerical solution of this problem, and the only thing that is missing is the info about if a face is 'wet' or 'dry'. How would you decide if a face is 'wet' or 'dry', assuming you have all other data?
Some wrong answers to show the kind of answer I am looking for:

- A face is 'dry' if the temperature is above 350 K.
- A face is 'dry' if the pressure is above 40000 Pa.

These make no sense physically, but from a programming perspective you can define it this way without any problem.

Then the next step would be to include an if-statement in the code. In pseudo-code:
Code:
Loop over all faces {
 if (face is dry) { do nothing }
 else { calculate whatever you want to know }
}
But before you can write such an if-statement, you should know what it means that a face is 'dry'.
pakk is offline   Reply With Quote

Old   December 17, 2015, 10:03
Default
  #9
New Member
 
Syed Aaquib Hazari
Join Date: Apr 2015
Location: Delft
Posts: 16
Rep Power: 8
hazari.aaquib is on a distinguished road
Quote:
Originally Posted by pakk View Post
No, I mean it in a completely different way.
Suppose you are Fluent, and you have a numerical solution of this problem, and the only thing that is missing is the info about if a face is 'wet' or 'dry'. How would you decide if a face is 'wet' or 'dry', assuming you have all other data?
Some wrong answers to show the kind of answer I am looking for:

- A face is 'dry' if the temperature is above 350 K.
- A face is 'dry' if the pressure is above 40000 Pa.

These make no sense physically, but from a programming perspective you can define it this way without any problem.

Then the next step would be to include an if-statement in the code. In pseudo-code:
Code:
Loop over all faces {
 if (face is dry) { do nothing }
 else { calculate whatever you want to know }
}
But before you can write such an if-statement, you should know what it means that a face is 'dry'.
I want to change source the term at the interface.

So if I understood you correctly (for a stratified two phase flow) I can tell fluent to make a distinction between 'wet' and 'dry' based on a certain quantity, I will use density.

If the density lies in between the primary and the secondary phase then I will modify my source term there.

I hope this will work.

Thanks once again Pakk!
hazari.aaquib is offline   Reply With Quote

Reply

Tags
boundary, fluent, interface, udf

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



All times are GMT -4. The time now is 08:35.