CFD Online Discussion Forums

CFD Online Discussion Forums (
-   Fluent UDF and Scheme Programming (
-   -   "a variable = C_UDMI(c,t,0)" does not work. (

jm86groove September 26, 2018 00:39

"a variable = C_UDMI(c,t,0)" does not work.
Lift force on bubble is Zero in this macro. Other variables to compute "FL" have their own numbers. Not zero.

I have no idea why "FL" goes to zero on each cell. C_UDMI problem?

Would you give me any advices to fix this issue? Thanks in advance.



real source;

real sum_vv;

real sum_fa_top;

real sum_fa_bot;

real Re;

real CL;

real sum_fa;

real Gs;

real FL;

real db;

real M;

real xc[ND_ND];

real mu = 3.994e-4;

real Uz = 1.4;

real rho = 1615;

sum_vv = C_UDMI(c,tc,0);

sum_fa_top = C_UDMI(c,tc,1);

sum_fa_bot = C_UDMI(c,tc,2);

sum_fa = sum_fa_top + sum_fa_bot;

Thread **pt = THREAD_SUB_THREADS(tc);

Thread *ts = pt[1];

if(sum_vv > 0. && sum_fa > 0.)


if(C_VOF(c,ts) >= 0.5)


db = sum_vv/sum_fa;
printf("db: %e\n", db);

Re = rho*C_W(c,tc)*db/mu;
printf("Re: %e\n", Re);

Gs = fabs(C_DWDY(c,tc))*db/2/C_W(c,tc);
printf("Gs: %e\n", Gs);

M = 1/(pow(Re,2))+0.014*pow(Gs,2);
printf("M: %e\n", M);

CL = 3.877*pow(Gs,1/2)*pow(M,1/4);
printf("CL: %e\n", CL);

FL = 3/4*CL*rho*C_W(c,tc)*C_W(c,tc)/db; -----> !!! ISSUE
printf("FL: %e\n", FL);


if(xc[1] < 0.0025)


source = FL;

dS[eqn] = 0;

printf("positive: %e\n", source);


else if(xc[1] > 0.0025)


source = -FL;

dS[eqn] = 0;

printf("negative: %e\n", source);




source = 0;

dS[eqn] = 0;




return source;


AlexanderZ October 1, 2018 04:13

did you define your UDMIs before calculation?

best regards

obscureed October 5, 2018 14:33

Hi jm86groove,

If you think that FL should not be zero, but you get answers that suggest it is, then you can start debugging by printing details:

FL = 3/4*CL*rho*C_W(c,tc)*C_W(c,tc)/db;
if(fabs(FL)<1e-6) {
  Message("Bah! FL is near zero again: %g\n",FL);
  Message("  CL=%g, rho=%g, C_W=%g, db=%g\n",CL,rho,C_W,db);
  /* and eventually you become paranoid: */
  Message("  3/4 = %g\n",3/4);  /* This might well give zero!!!!! */
  Message("  3./4. = %g\n",3./4.);
  Message("  3./4.*CL = %g\n",3./4.*CL);
  Message("  3./4.*CL*rho = %g\n",3./4.*CL*rho);
  Message("  3./4.*CL*rho*C_W(c,tc) = %g\n",3./4.*CL*rho*C_W(c,tc));
  Message("  3./4.*CL*rho*C_W(c,tc)*C_W(c,tc) = %g\n",3./4.*CL*rho*C_W(c,tc)*C_W(c,tc));
  Message("  3./4.*CL*rho*C_W(c,tc)*C_W(c,tc)/db = %g\n",3./4.*CL*rho*C_W(c,tc)*C_W(c,tc)/db);

obscureed October 5, 2018 14:46

If the model is large and that gives an overwhelming amount of text to the screen, you can select some cells arbitrarily: replace

if(fabs(FL)<1e-6) {

if(c%10000==1234 && fabs(FL)<1e-6) {

A couple of points:
-- I would advise always using Message rather than printf.
-- Integer division rounds to the nearest integer, so there is always a risk that "3/4" is calculated to be "0" before it starts being floating-point. The same applies where you have typed "1/2" and "1/4" -- you should never type this! "1./2." is better, and "0.5" is better still. And "sqrt(Gs)" is probably quicker than "pow(Gs,0.5)", but speed is less important than correctness.

-- I picked 1e-6 as a small number, but it might not be small enough for your example -- in that case, try 1e-20 or whatever. But "if(FL==0.0)" is much more specific. Just like alarm bells should ring if you ever type "1/3", you should ask yourself whether a tiny value is just as bad as "(FL==0.0)". Maybe, in the circumstances, you should also ask whether infinity or NaN (not a number) are also possibilities.

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