CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF interpret error with "C_CENTROID" (https://www.cfd-online.com/Forums/fluent-udf/68436-udf-interpret-error-c_centroid.html)

Jinfeng September 20, 2009 00:15

UDF interpret error with "C_CENTROID"
 
Hi folks,

I wrote a program to calculate the electrical body force with DEFINE_SOURCE macro. Inside the macro, C_CENTROID was used to get the coordinates of the cells (just like the DEFINE_SOURCE example in UDF manual). However, when I try to interpret the code, it gives me an error saying "line 13 C_CENTROID undeclared variable."

I can't figure out why it threw me that error! Does anybody know what's going on? Any help would be greatly appreciated! Thanks.

The following code is the DEFINE_SOURCE part:

#include "udf.h"

DEFINE_SOURCE(xmom_source, c, t, dS, eqn)
{
int i; // index for the nodes
float startx; // x coordinate of nearest node to interpolation node with lower x value
float starty; // y coordinate of nearest node to interpolation node with lower y value
float startz; // z coordinate of nearest node to interpolation node with lower z value
float xinterpfact, yinterpfact, zinterpfact;
float newrho;
float newdvdx, newdvdy, newdvdz;
float xinterp1, xinterp2, xinterp3, xinterp4;
float yinterp1, yinterp2;
real x[ND_ND];
real source;


C_CENTRIOD(x,c,t);

xinc = xdomain/(xdirnodes-1);
yinc = ydomain/(ydirnodes-1);
zinc = zdomain/(zdirnodes-1);
startx = ((
int)(x[0]/xinc))*xinc;
xinterpfact = (x[0] - startx)/xinc;
starty = ((
int)(x[1]/yinc))*yinc;
yinterpfact = (x[1] - starty)/yinc;

startz = ((
int)(x[2]/zinc))*zinc;
zinterpfact = (x[2] - startz)/zinc;

i = xdirnodes*ydirnodes*startz/zinc + xdirnodes*starty/yinc + startx/xinc;

//*** INTERPOLATE RHO ***//
xinterp1 = xinterpfact*(rho[i+1]-rho[i]) + rho[i];
xinterp2 = xinterpfact*(rho[i+xdirnodes+1]-rho[i+xdirnodes])+rho[i+xdirnodes];
xinterp3 = xinterpfact*(rho[i+xdirnodes*ydirnodes+1]-rho[i+xdirnodes*ydirnodes])+rho[i+xdirnodes*ydirnodes];
xinterp4 = xinterpfact*(rho[i+xdirnodes+xdirnodes*ydirnodes+1]-rho[i+xdirnodes+xdirnodes*ydirnodes])+rho[i+xdirnodes+xdirnodes*ydirnodes];

yinterp1 = yinterpfact*(xinterp2-xinterp1)+xinterp1;
yinterp2 = yinterpfact*(xinterp4-xinterp3)+xinterp3;

newrho = zinterpfact*(yinterp2-yinterp1)+yinterp1;

//*** INTERPOLATE DVDX ***//
xinterp1 = xinterpfact*(dvdx[i+1]-dvdx[i]) + dvdx[i];
xinterp2 = xinterpfact*(dvdx[i+xdirnodes+1]-dvdx[i+xdirnodes])+dvdx[i+xdirnodes];
xinterp3 = xinterpfact*(dvdx[i+xdirnodes*ydirnodes+1]-dvdx[i+xdirnodes*ydirnodes])+dvdx[i+xdirnodes*ydirnodes];
xinterp4 = xinterpfact*(dvdx[i+xdirnodes+xdirnodes*ydirnodes+1]-dvdx[i+xdirnodes+xdirnodes*ydirnodes])+dvdx[i+xdirnodes+xdirnodes*ydirnodes];

yinterp1 = yinterpfact*(xinterp2-xinterp1)+xinterp1;
yinterp2 = yinterpfact*(xinterp4-xinterp3)+xinterp3;

newdvdx = zinterpfact*(yinterp2-yinterp1)+yinterp1;

source = newrho*newdvdx;
dS[eqn] = 0.0;

return source;
}

Bernhard September 20, 2009 05:16

It will help when you show the relevant part of your UDF. Now I can only guess for possible errors in your code.

ak6g08 September 25, 2009 10:55

you have spelt C_CENTROID incorrectly...youve got C_CENTRIOD.

Jinfeng September 26, 2009 17:40

Quote:

Originally Posted by ak6g08 (Post 230546)
you have spelt C_CENTROID incorrectly...youve got C_CENTRIOD.

Thank you so much, akour! I just realized how stupid the mistake was! Oh, damn......

khaledhmz November 5, 2020 10:02

this is my udf:

#include "udf.h"
#include "mem.h"
#define Y_CH4_in 0.032
#define Y_O2_in 0.225
DEFINE_PROFILE(mass_fraction, t, i)
{
face_t f;
begin_f_loop(f, t)
{
F_CENTROID(x, f, t);
F_PROFILE(f, t, i) = Y_CH4_in;
F_PROFILE(f, t, i) = Y_O2_in;
}
end_f_loop(f, t)
}

pakk November 6, 2020 06:33

Interesting code, I see that it is still the same as several days ago, so the same problems are there. If you don't understand suggestions, ask for clarification, don't just ignore the help you get and ask the question again...

khaledhmz November 6, 2020 15:38

Quote:

Originally Posted by pakk (Post 786966)
Interesting code, I see that it is still the same as several days ago, so the same problems are there. If you don't understand suggestions, ask for clarification, don't just ignore the help you get and ask the question again...

Hello, I correct some error and it compile but there are other error related to the temperature that why I repulish the new one.I can't change the concentrations of each species.


All times are GMT -4. The time now is 06:17.