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 Community New Posts Updated Threads Search

Like Tree2Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 8, 2015, 06:22
Default
  #21
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
That error message most probably tells you that C_WALL_DIST(c,t) has not been assigned a value (so that you receive an access violation when you try to retrieve it). I haven't worked with this macro for many years now, but I would seem to recall that it is mainly used in conjunction with near-wall turbulence modelling, so perhaps the Viscous model of choice may influence whether it is used by the solver or not. You might also want to try to plot the cell wall distance and/or the cell coordinates in a graphical window to make sure that the appropriate loops have been performed.
HenrikS is offline   Reply With Quote

Old   January 8, 2015, 16:52
Default
  #22
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17
macfly is on a distinguished road
After a search in the UDF manual it seems that C_WALL_DIST doesn't exist anymore. I'd be curious to know how we can retrieve the distance between a cell centroid and the nearest wall.
pratikddhoot likes this.
macfly is offline   Reply With Quote

Old   January 9, 2015, 04:56
Default
  #23
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
I don't think that these macros were ever covered by the manual. I just had a look in the source files for Fluent 15.0.7 and all of the following are there still:
C_WALL_DIST(c,t)
C_WALL_DIST_G(c,t)
C_WALL_DIST_RG(c,t)
C_WALL_NORMAL(c,t)
However, depending on your situation it might be "safer" to construct your own macro. All you need then is a UDM and to loop once and use the standard (and well documented) macros for cell and face centroid locations, plus the aforementioned boolean macro to judge if the cell is next to a boundary.
Hope this helps!
HenrikS is offline   Reply With Quote

Old   January 9, 2015, 14:24
Default
  #24
New Member
 
Mohamed Refaat
Join Date: Jan 2015
Location: Egypt
Posts: 11
Rep Power: 11
Mohamed Refaat is on a distinguished road
Thank you very much HenrikS
Mohamed Refaat is offline   Reply With Quote

Old   March 19, 2015, 08:28
Default Define_wall_function
  #25
New Member
 
WangW
Join Date: Mar 2012
Posts: 2
Rep Power: 0
wwhblue is on a distinguished road
Quote:
Originally Posted by Mohamed Refaat View Post
Thank you very much HenrikS
wwhblue is offline   Reply With Quote

Old   March 19, 2015, 08:30
Default Udf DEFINE_WALL_FUNCTION
  #26
New Member
 
WangW
Join Date: Mar 2012
Posts: 2
Rep Power: 0
wwhblue is on a distinguished road
Quote:
Originally Posted by HenrikS View Post
I don't think that these macros were ever covered by the manual. I just had a look in the source files for Fluent 15.0.7 and all of the following are there still:
C_WALL_DIST(c,t)
C_WALL_DIST_G(c,t)
C_WALL_DIST_RG(c,t)
C_WALL_NORMAL(c,t)
However, depending on your situation it might be "safer" to construct your own macro. All you need then is a UDM and to loop once and use the standard (and well documented) macros for cell and face centroid locations, plus the aforementioned boolean macro to judge if the cell is next to a boundary.
Hope this helps!

dear HenrikS,
i need the turbulece production at the near wall cell, but i don't know which UDF macro to use.
pls help me.

kind regards.
wwhblue is offline   Reply With Quote

Old   March 19, 2015, 16:47
Default
  #27
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Turbulent kinetic energy: C_K(c,t) and turbulent kinetic energy dissipation rate: C_D(c,t).
`e` is offline   Reply With Quote

Old   March 20, 2015, 04:38
Default
  #28
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
There's an undocumented macro called that might be useful (see below). However, I wouldn't recommend using something like this unless you know what you're doing. The safest bet is probably to define your own macro, then you will know exactly what you are calculating . Good luck!

Get_Wall_k_Prod(face_t f, Thread *t, cell_t c0, Thread *t0,
real ks, real rkcon, real yp, real uStar, real up,
real rho, real mu,
real alpha, real beta, real gamma, real vwPlus,
int ictyp);

HenrikS is offline   Reply With Quote

Old   April 11, 2016, 12:26
Default
  #29
New Member
 
Pratik Dhoot
Join Date: Mar 2016
Location: Boston, MA
Posts: 20
Rep Power: 10
pratikddhoot is on a distinguished road
Quote:
Originally Posted by rr123 View Post
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.
Hi,
How do you find out the closest wall in a 2D model?
pratikddhoot is offline   Reply With Quote

Old   April 13, 2016, 17:40
Default
  #30
New Member
 
Pratik Dhoot
Join Date: Mar 2016
Location: Boston, MA
Posts: 20
Rep Power: 10
pratikddhoot is on a distinguished road
Quote:
Originally Posted by HenrikS View Post
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
Dear Henrik,

By using C_WALL_DISTANCE(c,t); as a macro, FLUENT fails to initialize the solution. I do not understand what is the error in this.
pratikddhoot is offline   Reply With Quote

Old   April 14, 2016, 19:25
Default
  #31
New Member
 
Mohamed Refaat
Join Date: Jan 2015
Location: Egypt
Posts: 11
Rep Power: 11
Mohamed Refaat is on a distinguished road
I have the same problem too.
Mohamed Refaat is offline   Reply With Quote

Old   April 18, 2016, 11:36
Default
  #32
New Member
 
Pratik Dhoot
Join Date: Mar 2016
Location: Boston, MA
Posts: 20
Rep Power: 10
pratikddhoot is on a distinguished road
Quote:
Originally Posted by rr123 View Post
thanks for helping me henrik and max !
i gratefully acknowledge your support.
i keep you informed of this.
Has your code worked (interpreted without errors and solution initialized without errors)?
If yes, Do you mind sharing the wall distance part of it. I am struggling to find the wall distance from a cell (centroid).
pratikddhoot is offline   Reply With Quote

Old   April 18, 2016, 18:21
Default
  #33
New Member
 
Mohamed Refaat
Join Date: Jan 2015
Location: Egypt
Posts: 11
Rep Power: 11
Mohamed Refaat is on a distinguished road
Unfortunately, the macros
C_WALL_DIST(c,t)
C_WALL_DIST_G(c,t)
C_WALL_DIST_RG(c,t)
C_WALL_NORMAL(c,t)
did not worked in my code so that, I have used a constant cell wall distance when generating the grid by using the inflation technique in the grid generation near the wall.
I wish I could help you
Mohamed Refaat is offline   Reply With Quote

Old   December 19, 2016, 18:34
Default
  #34
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Mohamed,

This is because fluent recently has removed C_WALL_DIST from its macros and for that reason we cannot use it anymore.
Do you by any chance have found a solution for this? I am having the same problem and I cannot find an alternate solution.
Any kind of help is much appreciated
alinik is offline   Reply With Quote

Old   December 21, 2016, 10:44
Default
  #35
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 alinik View Post
Mohamed,

This is because fluent recently has removed C_WALL_DIST from its macros and for that reason we cannot use it anymore.
Do you by any chance have found a solution for this? I am having the same problem and I cannot find an alternate solution.
Any kind of help is much appreciated
Dear Ali,

I suggest using a constant height of an inflation layer near the wall, so that you knows the height of the first cell centroid and it is also constant. you can now use it in your application.


Another solution in to know the thread ID and use the macro
C_CENTROID(c,f,t);
y = x[1]; to get the y-distance for each cell
Mohamed Refaat is offline   Reply With Quote

Old   December 21, 2016, 12:36
Default
  #36
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Thank you Mohamed,

You mean in the equations for F1 and F2 as you see in this picture, you used a constant value for y? and that constant value is the thickness of the first layer?
Attached Images
File Type: png Screen Shot 2016-12-21 at 10.32.33 AM.png (39.1 KB, 55 views)
alinik is offline   Reply With Quote

Old   December 22, 2016, 13:52
Default
  #37
New Member
 
Mohamed Refaat
Join Date: Jan 2015
Location: Egypt
Posts: 11
Rep Power: 11
Mohamed Refaat is on a distinguished road
the value in the equations are the first cell centroid distance from the wall, isn't it?

So, you can use a constant value or the second method to get every distance for the wall adjacent cells for non-uniform grids near the wall


Hope it will help
Mohamed Refaat is offline   Reply With Quote

Old   December 23, 2016, 03:53
Default
  #38
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Quote:
Originally Posted by Mohamed Refaat View Post
the value in the equations are the first cell centroid distance from the wall, isn't it?
I am not sure. Are you sure about this?
alinik is offline   Reply With Quote

Old   March 13, 2017, 14:34
Default
  #39
Senior Member
 
ali
Join Date: Oct 2009
Posts: 318
Rep Power: 18
alinik is on a distinguished road
Mohamed,

I recently got in touch with a person who is an expert in Fluent UDF and he told me that C_WALL_DIST(c,t) is still available. It just has to be filled. He sent me this code and said that it contains one way that this macro could be filled.
I do not understand what this code is doing and how I can fill it and then use it.
Do you mind taking a closer look at this code?

#include "udf.h"
#include "prox.h"

static cxboolean wall_dist_set = FALSE;

DEFINE_ON_DEMAND(set_wall_dist_udm0)
{
#if !RP_HOST

Domain *domain;
Thread *t;
cell_t c;

if (! wall_dist_set)
{
domain = Get_Domain(ROOT_DOMAIN_ID);

Alloc_Storage_Vars(domain, SV_RTMP_0, SV_NULL);

Calc_Cell_Wall_Distance_New(domain, SV_RTMP_0);

thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = C_TMP0(c,t);
}
end_c_loop(c,t)
}

wall_dist_set = TRUE;
}
#endif /* !RP_HOST */
}

DEFINE_ON_DEMAND(reset_udm0)
{
#if !RP_HOST

Domain *domain;
Thread *t;
cell_t c;

domain = Get_Domain(ROOT_DOMAIN_ID);

thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = 0.0;
}
end_c_loop(c,t)
}

#endif /* !RP_HOST */

wall_dist_set = FALSE;
}
alinik is offline   Reply With Quote

Old   March 14, 2017, 02:41
Default
  #40
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
HenrikS is on a distinguished road
Hi,

The code in question will introduce two Define-on-Demand functions:
set_wall_dist_udm0
reset_udm0
that use the user-defined memory location 0 to store the wall distances.

The second one will initialize UDM0 to zero everywhere, the first one will use an undocumented built-in function
Calc_Cell_Wall_Distance_New
to fill it with the wall distance.

I don't know whether this works in practice, but it looks fine. Don't forget to activate the user-defined memory or the code will crash for you

/Henrik
HenrikS 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
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 21:41.