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

 murthy October 23, 2001 21:47

Problem with UDF

Hi, I have developed a code for finding the centroids of each individual cells in a fluid zone.But I run into the error when i try to print out the centroids of the cells, if remove that part from the code the code runs fine.If any body could help me with tis problem would greatly be appreciated. The code runs this way: # include "udf.h" FILE *fout; int id =5;//id of the fluid domain extern Domain *domain; DEFINE_ON_DEMAND(get_coords) {

cell_t c;

face_t f;

real x[ND_ND];

double vol;

int i;

fout = fopen("coordinate.out","w");

i=0;

/*if(fout==NULL)

{

printf("error");

}*/

{

i = i+1;

{

fprintf(fout,"%d %g \n",i,x[0]);

i =i+1;

}

}

fclose(fout); } Thanks in advance, Murthy

 keith October 24, 2001 10:02

Re: Problem with UDF

A simple workaround might be to copy the centroid x,y, and z values into the u,v,w velocity arrays:

{

{

}

}

Then just export the "velocity" field. This might not be exactly what you're looking for.

Regards,

Keith

 murthy October 24, 2001 14:12

Re: Problem with UDF

Hi, The function runs fine with the C_CENTROID(x,c,thread) part,but when I assign an value of x[0] to another variable, it shows me an error called segmentation violation when this program is run as an compiled/interpreted code.The domain consists of 90 2D quadrilateral cells and Iam able to loop through all the cells.The variable x is defined as real x[2]. Thanks in advance, Murthy

 keith October 24, 2001 14:53

Re: Problem with UDF

Just to check, are you initializing the flowfield before you run your ON DEMAND function? It may not have any arrays for u and v yet. I usually get seg faults when I try and assign something that has not been initialized yet.

 murthy October 24, 2001 19:08

Re: Problem with UDF

Hi, Thanks for the reply.Apart from the aforesaid I had to include the metric.h header file and sg.h header file to get the results.Once agin thanks for every one who has contributed to my problem. Murthy

 All times are GMT -4. The time now is 09:18.