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

Area weighted average

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 5, 2018, 06:32
Default Area weighted average
  #1
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
hello all dear

I want to calculate area weighted average of heat flux along the surface, so I write a udf to calculate temperature gradientin every cell adjacent to the surface, but it is wrong because the answer of ansys fluent is different
my udf is :

DEFINE_EXECUTE_AT_END(Direct)
{
int i,ID,zone[7] = { 10,9,8,7,6,5,4 };
float T_i=300.0,T_f=500.0;
float ds, A_by_es, flux,DTX=0.0,DTY=0.0;
float H_flux[7], A[ND_ND], es[ND_ND], dr0[ND_ND];
face_t f;
cell_t c0,c;
Thread *t0, *t;
Domain *d = Get_Domain(1);
FILE *fp;
fp = fopen("Data.txt", "w");
for (i = 0;i < 1;i++){
flux = 0.0;
ID = zone[i];
t = Lookup_Thread(d, ID);

begin_f_loop(f, t)
{
BOUNDARY_FACE_GEOMETRY(f, t, A, ds, es, A_by_es, dr0);
c0 = F_C0(f, t);
t0 = THREAD_T0(t);
C_T_RG(c0, t0);
DTX += C_T_RG(c0, t0)[0];
DTY+= C_T_RG(c0, t0)[1];
flux += fabs(C_T_RG(c0, t0)[0] * es[0]) + fabs(C_T_RG(c0, t0)[1] * es[1]);
}
end_f_loop(f, t)
H_flux[i] = (202.4*flux);

please help
Saman95 is offline   Reply With Quote

Old   March 5, 2018, 07:17
Default
  #2
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Saman95,

A few points:
(1) You are only calculating the first zone in the current UDF, because of "for (i = 0;i < 1;i++){".
(2) We cannot see what you do with the data, because you have not included the end of the UDF. Don't forget to fclose.
(3) I think that fabs is inappropriate here.
(4) You are not currently getting an area-weighted average, nor a total integrated flux, because you are not making any use of the face area. "es" is a unit vector.
(5) I'm not sure where 202.4 comes from -- something to do with conductivity?
(6) The flux through the boundary face is not guaranteed to be related exactly to the temperature gradient in the cell, though you might hope that they would be closely correlated. Things get more complicated with turbulence, since a boundary-adjacent cell can contain both bulk fluid and a boundary layer -- but maybe your case is laminar (since you are using a single value of conductivity)?

If Fluent's calculations are what you want, then you will save yourself all sorts of trouble by using Fluent's version.

Good luck,
Ed
obscureed is offline   Reply With Quote

Old   March 5, 2018, 13:50
Default
  #3
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
Thanks
1-202.4 is conductivity.
2- my case is laminar.
3-I want to show just for one face,not all, so i use "for (i = 0;i < 1;i++)"
4-also, I use fclose and I finish my udf by }.(I wrote only main program)
Saman95 is offline   Reply With Quote

Old   March 5, 2018, 13:52
Default
  #4
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
It's better to show my udf file:

#include"udf.h"
#include"sg.h"

DEFINE_EXECUTE_AT_END(Direct)
{
int i, ID, zone[7] = { 14,12,11,10,9,8,7 };
double ds, A_by_es, flux,DTX,DTY,Area;
double H_flux[7], A[ND_ND], es[ND_ND], dr0[ND_ND];
face_t f;
cell_t c0,c;
Thread *t0, *t;
Domain *d = Get_Domain(1);
FILE *fp;
fp = fopen("Data.txt", "w");
for (i = 0;i < 1;i++){
flux = 0.0;
DTX = 0.0;
DTY = 0.0;
Area = 0.0;
ID = zone[i];
t = Lookup_Thread(d, ID);

begin_f_loop(f, t)
{
BOUNDARY_FACE_GEOMETRY(f, t, A, ds, es, A_by_es, dr0);
Area += NV_MAG(A);
c0 = F_C0(f, t);
t0 = THREAD_T0(t);
C_T_RG(c0, t0);
DTX += C_T_RG(c0, t0)[0] * es[0] * NV_MAG(A);
DTY+= C_T_RG(c0, t0)[1] * es[1] * NV_MAG(A);
fprintf(fp, "%f\t %f\n", DTX,DTY);
flux += (C_T_RG(c0, t0)[0] * es[0]+ C_T_RG(c0, t0)[1] * es[1])* NV_MAG(A);
}
end_f_loop(f, t)
DTX /= Area;
DTY /= Area;
flux /= Area;
H_flux[i] = (202.4*flux);
Message("Wall %d:\t DTX=%f\t DTY=%f\t heat flux=%f\n", ID, DTX, DTY, H_flux[i]);
//fprintf(fp, "%f\n", H_flux[i]);
}
fclose(fp);
}


please give your Idea about this
Saman95 is offline   Reply With Quote

Old   March 6, 2018, 04:09
Default
  #5
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
I think, bearing in mind my point (6), you should investigate BOUNDARY_HEAT_FLUX(f,t).
obscureed is offline   Reply With Quote

Old   March 6, 2018, 09:38
Default
  #6
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
Thank u

can u tell me how I can find this macro in ansys help. I can't find it.

where is it?

please write it's part
Saman95 is offline   Reply With Quote

Old   March 6, 2018, 12:40
Default
  #7
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Saman95,

Unfortunately, it is not documented anywhere. I found it by looking in the Fluent header files -- it is in sg_mem.h.

I think you will find that it contains the thermal power [in watts] entering through the face, not a flux [in W/m2]. If you are aiming for a sum in parallel, you should only look at threads that pass the test:
Code:
if (BOUNDARY_FACE_THREAD_P(t) && !(THREAD_TYPE(t) == THREAD_F_JUMP)) { ... }
and you should only count the faces that pass the test:
Code:
if (PRINCIPAL_FACE_P(f, t)) { ... }
Obviously you need to check that it gives results that match Fluent's. (If your model is axi-symmetric, you might or might not need to multiply by a factor of 2*M_PI to get it to match.) Good luck!

Ed
obscureed is offline   Reply With Quote

Old   March 7, 2018, 10:57
Default
  #8
Member
 
Join Date: Nov 2017
Posts: 54
Rep Power: 9
Saman95 is on a distinguished road
ok

I can't find it and have two questions

1- can u tell me how i can find (Fluent header files -- it is in sg_mem.h.)

2- Do u know how fluent calculate Area weighted average of heat flux o a wall, I saw theory guide of fluent for this, But my answer is different
Saman95 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
Average weighted value calc at specific plane Mark JIN OpenFOAM 6 July 13, 2018 16:16
Area weighted average Temperature surface monitors av147@snu.edu.in FLUENT 3 March 20, 2017 21:16
PLOTING weighted average vs distance Vorch FLUENT 0 May 28, 2012 17:29
volume weighted average lindner OpenFOAM 2 July 15, 2010 04:47
area weighted average Sireesha Pasari FLUENT 1 April 4, 2004 14:06


All times are GMT -4. The time now is 19:56.