CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   Finding out boundary cells in a domain (

Abbas October 9, 2003 13:44

Finding out boundary cells in a domain
I have a simple 2-D channel, and I want to manipulate the cells at channel boundary. I wrote a code for it, but it gives Segmentation Violation when I run it.

Please see if you can see what the problem is with this UDF:


# include "udf.h"

DEFINE_ADJUST (macro_s,d) {

Thread *t, *tf, *tc1;

face_t f;

cell_t c;

cell_t c1;

int n,k;

thread_loop_c (t, d) /*loops over all cell threads in domain*/


begin_c_loop(c, t) /* loops over cells in a cell thread */


c_face_loop(c,t,n) /* loops over all faces on a cell */


f=C_FACE(c,t,n); /* returns the face f for the cell c and Thread t */

tf=C_FACE_THREAD(c,t,n); /* get cell ids c0 and c1 which are adjacent to this face f */

tc1=F_C1_THREAD(tf, t);


if (c1=NULL) ; /*Error occurs when cells are out of the boundary. Have to apply condition to the cell ADJACENT to it */

printf("%f, it's out\n", k);




end_c_loop(c, t)





Andrew Garrard October 10, 2003 04:38

Re: Finding out boundary cells in a domain
OK, I think there are alot of problems with this code. It might be easier if you tell us exactly what you are trying to do and we could suggest a better code. One of the major problems, to my mind, is that you are defining several cell and face threads and not specifying what they are in your geometry. For example, you define a thread *t and then begin a cell loop without telling the code what the thread is. You need a line like:

Thread *t = Lookup_Thread(d, thread_ID);

Where thread_ID is the boundary ID taken from the fluent GUI. What is it that you want your code to do? All I can see is that you are printing the value of k, which is uninitialised anyway.

Abbas October 11, 2003 02:18

Re: Finding out boundary cells in a domain
Thanks Andrew. I'm sorry about the code. Actually, I've just started using Fluent UDFs and, as obvious, am not good at it. :)

I want to get the cells in contact with the upper wall, and define my own velocity for these cells, say, 10 m/s.

Here is how I tried to do it using another code. I use C_U(c,t) to define the x-velocity. Now it appears to be working fine.

Here is the code:

------ # include "udf.h"

DEFINE_ADJUST (macro_s2, domain)


cell_t c0; face_t face; Thread *thread;

int ID=5; /* Zone ID for wall from Boundary Conditions panel */

thread = Lookup_Thread(domain, ID);

begin_f_loop(face, thread) /* loops over faces in a face thread */


c0=F_C0(face, thread); /* F_C1 will be out of boundary */

C_U(c0, thread)=10;

printf("%f\n", C_U(c0, thread)); /* Looking at the velocity value. */


end_f_loop (face, thread)


Mazyar October 12, 2003 16:21

Re: Finding out boundary cells in a domain
Hi, I think another easy way for specifying a velocities to those cells is that you: 1) mark those cells in: adapt/boundary/...=> choose the cell row next to that boundary 2) separate them in: grid/separate/cell... 3)In boundary condition menu, specify mass and momentum source values according to the formula in manual.

another method is using a DEFINE_ADJUST function : 1) loop over the cells of the domain 2) get the center point of the cells using: C_CENTROID( ) 3)Using an IF statement: if(center of the cell is equal to location you want) then C_U(c,t)=10

Good luck

Andrew Garrard October 13, 2003 04:56

Re: Finding out boundary cells in a domain
That piece of code looks alot healthier, glad that it is working.

All times are GMT -4. The time now is 16:00.