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

calculate distance from wall to neighbourig cell centroid

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

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 1, 2009, 05:24
Default calculate distance from wall to neighbourig cell centroid
  #1
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
dear all,

i need to calculate the distance between the wall and the centroid of the cell touching this wall. my system is 2D.

this is the main code snippet:

begin_c_loop (c,t)
{
c_face_loop(c,t,n)
{
tf = C_FACE_THREAD(c,t,n);
if(THREAD_TYPE(tf) == THREAD_F_WALL)
{
f = C_FACE(c,t,n);
F_CENTROID(x,f,t);
wf = x[1]; /* for 2D */
C_CENTROID(cell,c,t);
nc = cell[1];
dist = FABS(wf-nc);
}
}
}
end_c_loop (c,t)


am i right ? is it correct ordering of the loop structure ?

hopign for a reply.

best regards.
rr123 is offline   Reply With Quote

Old   April 1, 2009, 07:37
Default
  #2
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
I think your code will do what you want, yes. If you have any problems with
if(THREAD_TYPE(tf) == THREAD_F_WALL)
you might consider using
if (BOUNDARY_FACE_THREAD(tf))
although I guess they would work equally well.

Anyway, you could use C_WALL_DIST(c,t) directly instead of looping, I guess?

/Henrik
HenrikS is offline   Reply With Quote

Old   April 1, 2009, 07:41
Default
  #3
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
dear henrik,

i didnt get you clearly with the using of the C_WALL_DIST(c,t).

can you remake the code snippet with your suggestion so that i can try from my end.

sincerely.
rr123 is offline   Reply With Quote

Old   April 1, 2009, 08:07
Default
  #4
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
In your code, you calculate "dist" for every cell next to a wall boundary. My guess is that you want to use this value for some purpose elsewhere in your code. Now, there is a macro called C_WALL_DIST(c,t) which I believe (although I have not verified that) will give you this distance directly.

In your case, your snippet would become:

begin_c_loop (c,t)
{
dist = C_WALL_DISTANCE(c,t);
}
end_c_loop (c,t)

This is probably not only shorter but also quicker. Anyway, I suggest you validate this approach before relying on it. You can store "dist" in a UDM and compare to the cell wall distance in a contour plot in Fluent for example.

/Henrik
HenrikS is offline   Reply With Quote

Old   April 1, 2009, 08:47
Default
  #5
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
dear henrik,

thanks for the reply. so you mean that the c_face_loop which i used, is no more required with your code snippet using C_WALL_DIST(c,t) ?

one more query:
i want to add a source term, S_epsilon in the epsilon eqn in the k-epsilon model. which DEFINE macro must i choose ?

many thanks in advance for the help.
best regards.
rr123 is offline   Reply With Quote

Old   April 1, 2009, 08:56
Default
  #6
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
It was quite some time ago since I worked with wall distances in UDFs, but I seem to remember that the distance between a cell centre and the nearest wall should be available in C_WALL_DISTANCE(c,t). (As you can see, it is available for plotting under Grid...):

"Cell Wall Distance is the distribution of the normal distance of each cell centroid from the wall boundaries. Its unit quantity is length. "

Anyway, if this is what C_WALL_DISTANCE(c,t) returns, then all you need is the cell thread and index (c and t) to obtain it, i.e. no need to loop over faces and compare coordinates yourself.

To add a source term for the epsilon equation (to use inside your domain), write a DEFINE_SOURCE macro and hook it up under the source terms for the boundary conditions of the fluid zone.

Hope this helps!

/Henrik
HenrikS is offline   Reply With Quote

Old   April 1, 2009, 08:58
Default
  #7
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
You would also have to add some kind of check to see whether the current cell is next to a boundary, if you are only interested in boundary cells (which seems the case in your first post).
HenrikS is offline   Reply With Quote

Old   April 1, 2009, 09:05
Default
  #8
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
yes, Henrik you are righ indeed. my only intention is to calculate the distance from the centroid of the cell which touches the wall.
so thats why i intended to use the THREAD_TYPE macro.

so if i use C_WALL_DIST(c,t) macro, what should i write to implement that check ?

sincerely.
rr123 is offline   Reply With Quote

Old   April 1, 2009, 09:11
Default
  #9
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
How about

begin_c_loop(c, t)
{
dist = 0.0;
c_face_loop(c, t, n)
{
if (BOUNDARY_FACE_THREAD_P(C_FACE_THREAD(c,t,n)))
{
dist = C_WALL_DIST(c,t);
}
}
if (dist > 0.0)
{
/* do whatever it is you wish to do with dist here... */
/* if dist = 0.0 then this cell does not touch the boundary */
}
}
end_c_loop(c, t)

or something like that... :-)

/Henrik
HenrikS is offline   Reply With Quote

Old   April 1, 2009, 09:13
Default
  #10
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
henrik, thanks again.

but how do we know that BOUNDARY_FACE_THREAD is the wall ??

sincerely.
rr123 is offline   Reply With Quote

Old   April 1, 2009, 09:23
Default
  #11
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
Hmm... BOUNDARY_FACE_THREAD_P(t) expands to a function that returns TRUE if Thread *t is a boundary face thread. I don't know for sure, maybe this would also include inlets and outlets. Then maybe stick with your initial code or supply an array containing the wall thread IDs, whatever you prefer.
HenrikS is offline   Reply With Quote

Old   April 2, 2009, 04:16
Default
  #12
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
Hello,

there is a macro THREAD_TYPE(tf) which returns an integer for each boundary face thread tf. If the boundary face is a wall this number will be "3"
--> if (THREAD_TYPE(tf)) == 3) can be used to check wether the boundary is a wall.

cheers
coglione is offline   Reply With Quote

Old   April 2, 2009, 04:32
Default
  #13
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
hi,

is

if (THREAD_TYPE(tf)) == 3)

the same as

if(THREAD_TYPE(tf) == THREAD_F_WALL)

thanks very much for your reply.

sincerely.
rr123 is offline   Reply With Quote

Old   April 2, 2009, 04:42
Default
  #14
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
Yes, according to threads.h:

THREAD_F_WALL = 3,

so those should be the same.
HenrikS is offline   Reply With Quote

Old   April 2, 2009, 06:27
Default
  #15
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
thanks Henrik and coglione !!

i have two small queries:

i am trying to add a secondary source term, S to the epsilon eqn of the k-epsilon model.
S = max[0.83(l/l_e)(epsilon/k),0]
where, l tubulence length scale and l_e is the is the near-wall equilibrium length scale.
i am using the DEFINE SOURCE(name,c,t,dS,eqn) macro.

so the query is do i need to define my dS to be ds[eqn] = 0.0 or shall i need to assign an expresison to it ?
i read the UDF manual, but is not clear for me.

and if i need to assign an expresison to dS, then with what should i
differetiate S. With l or with l_e ? i mean, what is the dependent variable in the above for S ?

thanks for your reply.
rr123 is offline   Reply With Quote

Old   April 2, 2009, 07:18
Default
  #16
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
You do not need to specify an expression for dS, you can set it to 0.0. If you have convergence issues, consider adding an expression for dS. As I understand it, dS should then be the derivative with respect to epsilon?
HenrikS is offline   Reply With Quote

Old   April 2, 2009, 08:48
Default
  #17
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
Yes, the dependent variable here is epsilon as the source is defined for this quantity. in this specific case a linearization of the source term will not add stability because this is only true if dS/depsilon is negativ which will never be possible since the definition of source as >0.0 ! Thus dS = 0.0 is the only possibility and FLUENT automatically does so if you do not specify dS at all.

cheers
weidos likes this.
coglione is offline   Reply With Quote

Old   April 2, 2009, 11:25
Default
  #18
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
thanks for helping me henrik and max !
i gratefully acknowledge your support.
i keep you informed of this.
rr123 is offline   Reply With Quote

Old   April 3, 2009, 11:39
Default
  #19
Member
 
R. Roy
Join Date: Mar 2009
Location: India
Posts: 52
Rep Power: 17
rr123 is on a distinguished road
dear henrik and max,

why should the S (in my case) be differentiated w.r.t epsilon ?
i mean, what is the reason behind it ??

because, in some examples i find that for modifying a source term in the omega equation (of k-omega model), the S is differentiated w.r.t. x-velocity.

pls help me catch what i am failing to understand.

kind regards.
rr123 is offline   Reply With Quote

Old   January 7, 2015, 17:56
Default
  #20
New Member
 
Mohamed Refaat
Join Date: Jan 2015
Location: Egypt
Posts: 11
Rep Power: 11
Mohamed Refaat is on a distinguished road
Quote:
Originally Posted by HenrikS View Post
I think your code will do what you want, yes. If you have any problems with
if(THREAD_TYPE(tf) == THREAD_F_WALL)
you might consider using
if (BOUNDARY_FACE_THREAD(tf))
although I guess they would work equally well.

Anyway, you could use C_WALL_DIST(c,t) directly instead of looping, I guess?

/Henrik
dear Henrik
i have the same problem of rr123
when i use this macro C_WALL_DIST(c,t) this message appeared

D:\PROGRA~1\ansys\ANSYSI~1\v145\fluent\fluent14.5. 0\win64\3d\fl1450s.exe received fatal signal (ACCESS_VIOLATION)
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
4. Report error to your distributor.

so please do you have a solution for this?

Last edited by wyldckat; January 8, 2015 at 17:03. Reason: accidental double post
Mohamed Refaat 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
Wall distance? stein lee Main CFD Forum 4 November 15, 2013 22:26
distance between particle and wall Worth FLUENT 2 June 13, 2009 04:04
Errors running allwmake in OpenFOAM141dev with WM_COMPILE_OPTION%3ddebug unoder OpenFOAM Installation 11 January 30, 2008 21:30
Wall function in adverse pressure gradients stephane baralon Main CFD Forum 11 September 2, 1999 05:05
Wall functions Abhijit Tilak Main CFD Forum 6 February 5, 1999 02:16


All times are GMT -4. The time now is 04:36.