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/)
-   -   Problem in UDF (https://www.cfd-online.com/Forums/fluent-udf/165631-problem-udf.html)

cfd^2 January 21, 2016 17:06

Problem in UDF
 
Hi,

I have had a problem with a UDF. When writing

C_UDMI(c,t,0) = C_UDSI_G(c,t,0)[0];

it works perfectly, but when I write the inverse of the gradient component (or even the magnitue of the gradient) like that

C_UDMI(c,t,0) = 1/C_UDSI_G(c,t,0)[0];

I get the error:

Error: cx-set-real-entry: wta[2](float)
Error Object: 1.#inf

Could someone help me to clarify this issue?

`e` January 21, 2016 17:46

The C_UDMI macro is expecting a real value (float or double depending on single or double precision). Try using a trailing dot for the numerator (makes that value a real number instead of an integer):

Code:

C_UDMI(c,t,0) = 1./C_UDSI_G(c,t,0)[0];

cfd^2 January 21, 2016 18:26

Quote:

Originally Posted by `e` (Post 582007)
The C_UDMI macro is expecting a real value (float or double depending on single or double precision). Try using a trailing dot for the numerator (makes that value a real number instead of an integer):

Code:

C_UDMI(c,t,0) = 1./C_UDSI_G(c,t,0)[0];


Thank you. But didn't work... Any other tip?

`e` January 21, 2016 19:50

Then it's probably another line at fault (unless C_UDSI_G(c,t,0)[0] is returning zero in at least one of the cells; which might explain your error of "1.#inf"). Try only using that line within the UDF and add in a Message(); function to output the value of C_UDSI_G(c,t,0)[0] and 1./C_UDSI_G(c,t,0)[0]; to the command line. You may want to perform this debugging on a mesh with fewer cells to avoid excess messages being printed to the screen.

If you find that there are cells with zero gradient values (generally the case for the first iteration, regardless) then you could add a conditional statement to avoid the error:

Code:

if (C_UDSI_G(c,t,0)[0] == 0.)
{
    // gradient is zero, don't try to divide by zero!
}
else
{
    // gradient is nonzero, now you can divide
}


cfd^2 January 21, 2016 19:53

Quote:

Originally Posted by `e` (Post 582015)
Then it's probably another line at fault (unless C_UDSI_G(c,t,0)[0] is returning zero in at least one of the cells; which might explain your error of "1.#inf"). Try only using that line within the UDF and add in a Message(); function to output the value of C_UDSI_G(c,t,0)[0] and 1./C_UDSI_G(c,t,0)[0]; to the command line. You may want to perform this debugging on a mesh with fewer cells to avoid excess messages being printed to the screen.

I got it! I was interpreting the UDF. I compiled it and it worked using you tip (./)! Thank you very much!


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