CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   Problems with the C_FACE, C_FACE_THREAD, F_C0, and THREAD_C0 functions (

cMichael May 18, 2012 09:21

Problems with the F_CENTROID not producing unique values for unique faces

I am working on a project with the goal of accessing a cell some distance from a wall. I start with the handle to a face thread and loop through the faces in it, take the cell those faces are adjacent to and then access the face on the other side of the cell and repeat until I am far enough away. I have constructed sample code (which crashes) below


#include "udf.h"
#define HEAT_ID 6
        Thread *t;
        Domain *d;
        face_t f;
        face_t adjFace;
        Thread *adjFaceThread;
        cell_t adjCell;
        Thread *adjCellThread;
        real Ts;
        real adjCellTemp;
        real adjFaceTemp;
        d = Get_Domain(1);
        t = Lookup_Thread(d,HEAT_ID);
        begin_f_loop(f, t){
                Ts = F_T(f,t); //get cell temperature ts
                printf("Ts= %f\n f = %d\n",Ts,f);
                adjCell = F_C0(f,t);
                adjCellThread = THREAD_T0(t);
                adjFace = C_FACE(adjCell,adjCellThread,3);
                adjFaceThread = C_FACE_THREAD(adjCell,adjCellThread,3);
                adjCellTemp = C_T(adjCell,adjCellThread);
                printf("adjCellTemp = %f\n",adjCellTemp);
                adjFaceTemp = F_T(adjFace,adjFaceThread);
                printf("T-adj-cell = %f,    T-adj-face3 = %f,\n",adjCellTemp,adjFaceTemp);

This code crashes towards the end when it attempts to read the adjFaceTemp using F_T(f,t), interestingly enough if I substitute adjCellThread for adjFaceThread it works (with some ridiculous temperatures). This is not the behavior I think is indicated in the documentation, it seems that the function F_T needs a face thread not a cell thread. Can someone tell me why these macros are behaving as they are? It would be a great help.

cMichael May 18, 2012 11:30

I am saying that F_T(f,ft); works if you substitute ft which is a face thread when you use a cell thread instead

cMichael May 24, 2012 16:02

So C is an all around terrible language (if your trying to debug using the interpreted function compiler) so I got fed up with it and decided to break the problem into two programs, one program to extract the data i needed from fluent (thus minimizing the amount of time spent in c) and one program in java to do the heavy lifting with multiple threads and the like.

The java program is finished and well tested with example cases and I cant figure out why it wouldn't work. Then I took a closer look at the output from my c function.

Right now thread is hard coded to be the surface i want to extract data from.

here is an exerp.

                        printf("next thread loop started\n");
                        printf("Extracting faces from thread %d\n",THREAD_ID(t));
                        begin_f_loop(f, t)
                                temperature = F_T(f,t);
                                area = NV_MAG(normalVec);

Which produces output similar to this:


The problem is if i highlight any one of the centroids (the first 3 numbers on each line separated by commas "x,y,z/") I get 18 duplicate results.

for example here are some of line 1's duplicates:

in groups of 4 evenly throughout all the faces in the face thread (about 23000 of them)

I guess my question now is shouldn't F_CENTROID produce a unique result for each face?

Someone please help! no one has replied!

Daniel Tanner May 25, 2012 03:45

Are you running this simulation in parallel? Does the number of duplicates equal the number of cpu?

cMichael May 25, 2012 08:31

Thank you for answering.

Originally Posted by Daniel Tanner (Post 363041)
Are you running this simulation in parallel? Does the number of duplicates equal the number of cpu?

No this is a DEFINE_ON_DEMAND function, this is all post processing. I run the c function and then load it's output into the java program later. This is all steady state stuff. And I wish that were the case but my cpu only has 12 threads, for stability reasons i only use 4 for processing. The psu is under powered so it likes to crash under a full load. Also each thread is only processing the output from the c program, the c program is not multi-threaded.

The other thing I had considered was the geometry I was testing, it is a heat sink with 16 fins, also not a numerical match.

cMichael May 25, 2012 09:30

Interesting developement
While stepping through code in my Java program I noticed an interesting pattern between each face and its closest cell.




It seems an interesting pattern has developed in that the closest cell to any face seems to be on some other plain entirely (a shift of .003125). This pattern holds true for all faces in my domain.

cMichael May 25, 2012 13:58

Problem solved!
In my definition for the centroid values i used

real centroid[2];

because I am working on something where there will never be a 2d case so i figured it would be ok to hard code it as a 3d case to make sure whoever used this code after me wouldn't make the mistake that it could be.

our of curiosity I tried

real centroid[ND_ND];

it now returns much more reasonable values (as in there are no more duplicates). For some reason unknown to me the ND_ND constant appears to be of some great importance.

I hope this prevents someone else from wasting as much time on this problem as i did.:D

moun139 May 27, 2012 04:38


I dont inderstand one thing ,how fluent calculate gradient in cell at boundary condition ,and what is the difference between gradient and reconstruction macro (i read the udf manual but i didnt inderstood )

thank you a lot

cMichael May 29, 2012 08:35


Originally Posted by moun139 (Post 363292)

I dont inderstand one thing ,how fluent calculate gradient in cell at boundary condition ,and what is the difference between gradient and reconstruction macro (i read the udf manual but i didnt inderstood )

thank you a lot

Hey sorry I don't know what your asking, if you can be more clear I will try to help but it sounds right now like you posted in the wrong thread.

All times are GMT -4. The time now is 19:43.