CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Problem with UDF (http://www.cfd-online.com/Forums/fluent/29647-problem-udf.html)

Senthil April 16, 2002 22:48

Problem with UDF
 
Hi,

I am trying to access the data of neighbhouring cells from a cell. I am looping through all the cells in the domain. Inside this loop, I am looping through all the faces of a cell(say x). From the face of the cell x, I am getting the id and thread of the cells to which this face forms the boundary. Now I will have two cell ids c0 and c1. One of these cells is the original cell x. To determine which one is the original cell x, I am using the C_CENTROID macros.

I was able to compile the following code. But when I run it, I get a segementation violation. And I found out that this error occurs when I try to find the centroid of cell c1. I am confused since I am not trying to access any undefined variable. If anybody could point out any bug in the code, I will be thankful.

DEFINE_ADJUST(filter, d) { Thread *t,*tf,*tc0,*tc1; cell_t c,c0,c1; face_t f; float xcell[3],xcellc0[3],xcellc1[3];

thread_loop_c (t,d) {

begin_c_loop (c,t)

C_CENTROID(xcell,c,t);

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

{

f = C_FACE(c,t,n);

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

c0 = F_C0(f,tf);

tc0 = THREAD_T0(tf);

c1 = F_C1(f,tf);

tc1 = THREAD_T1(tf);

if ((c0!=c)&&(c1==c))

{

C_CENTROID(xcellc0,c0,tc0);

}

else if ((c0==c)&&(c1!=c))

{

C_CENTROID(xcellc1,c1,tc1);

}

}

end_c_loop (c,t) }

}

Thank you senthil

Johnix April 17, 2002 23:39

Can you tell me the name of your project??
 
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN' >

<html> <head>

<title>My Web Site Title</title> </head> <meta name="Description" content="A Short but sharp description of website or web page for search engines"> <meta name="Keywords" content="A list of keywords users may type in a search engine to find website or page"> <meta name="Generator" content="WebSoftware HotHTML 2001 Professional Edition"> <body bgcolor="#FFFFFF" text="#000000" link="#804040" vlink="#008080" alink="#004080">


Suppose I've understood your code ...(There are some syntax errors in your code ...)

try the following:





#include "udf.h"



#define C_NFACES(c,t)(cell_type_nfaces[(int)(C_TYPE((c),(t)))])

DEFINE_ADJUST(filter, d)

{

Thread *t,*tf,*tc0,*tc1;

cell_t c,c0,c1;

face_t f;

float xcell[3],xcellc0[3],xcellc1[3];

int n;



thread_loop_c (t,d) {

begin_c_loop (c,t) {

C_CENTROID(xcell,c,t);

c_face_loop(c,t,n){

f = C_FACE(c,t,n);

tf = C_FACE_THREAD(c,t,n);

c0 = F_C0(f,tf);

tc0 = THREAD_T0(tf);

c1 = F_C1(f,tf);

tc1 = THREAD_T1(tf);



if ((c0!=c)&&(c1==c)<font color="FF0000"> &&tc0!=NULL</font> ) C_CENTROID(xcellc0,c0,tc0); /* Make sure the cell exists */

if ((c0==c)&&(c1!=c)<font color="FF0000"> &&tc1!=NULL</font> ) C_CENTROID(xcellc1,c1,tc1); /* Error occurs when cells are out of the boundary */



}

}end_c_loop (c,t);

}

}



<font color="0010FF">Johnix


</body> </html>


Greg Perkins April 18, 2002 00:08

Re: Problem with UDF
 
You will need to check the type of the face thread, since faces on the boundary only have one adjacent cell - c0.

Look at the fluent 6 udf manual for this or see previous posts - I think I've put this up before.

Greg

Senthil April 18, 2002 22:11

Re: Problem with UDF
 
Thanks Johnix and Greg. I could not find the previous post. But I assume that tc1=null if the face is near a wall, as Johnix pointed out. I am trying to find out the second and fourth derivatives of flow variables. That is why I need to be able to access the adjacent cells. Let me know if there is any easier way of calculating derivatives except using user defined scalars.

I have one more question. What happens when we have a periodic boundary condition at a face. Will both c0 and c1 exist or only c0 exists as in wall boundary. What exactly is a cell identifier,i.e cell macro and thread variable. Fluent UDF manual does not say much about them except how to use them. Thanks Senthil


All times are GMT -4. The time now is 14:02.