CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > FLUENT

0 or 0.0 in udf

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
Old   June 28, 2011, 09:42
Default 0 or 0.0 in udf
  #1
Senior Member
 
raymond
Join Date: Nov 2009
Posts: 149
Rep Power: 7
wlt_1985 is on a distinguished road
I would like to write an udf and i referred few of the samples. I confused with the value of "0 and 0.0". Can pls help in making them clear?What are the differences between them?Pls help.

Best regards
wlt_1985 is offline   Reply With Quote

Old   June 29, 2011, 11:34
Default
  #2
Member
 
Micael Boulet
Join Date: Mar 2009
Location: Quebec, Canada
Posts: 95
Rep Power: 9
Micael is on a distinguished road
It is not about FLUENT nor much about zero, but about the C language. Lets see an example:

Code:
 
real c;
c = 1/2;
In that case, value of c is zero. Why? Because 1 and 2 are integers. The arithmetic on two integers produce another integer (the integer part of 1/2 is zero). Of course, since c is real, the result will be promoted to real, but that does not recover the lost precision.

In any case, you should be aware of that rule. One remedy is to simply add ".0" after at least one number, so that arithmetic will be done on real instead of integer (any integer in the arithmetic will be promoted to real before the calculation):

Code:
 
real c;
c = 1/2.0;
Micael is offline   Reply With Quote

Old   June 29, 2011, 12:39
Default
  #3
Senior Member
 
raymond
Join Date: Nov 2009
Posts: 149
Rep Power: 7
wlt_1985 is on a distinguished road
Quote:
Originally Posted by Micael View Post
It is not about FLUENT nor much about zero, but about the C language. Lets see an example:

Code:
 
real c;
c = 1/2;
In that case, value of c is zero. Why? Because 1 and 2 are integers. The arithmetic on two integers produce another integer (the integer part of 1/2 is zero). Of course, since c is real, the result will be promoted to real, but that does not recover the lost precision.

In any case, you should be aware of that rule. One remedy is to simply add ".0" after at least one number, so that arithmetic will be done on real instead of integer (any integer in the arithmetic will be promoted to real before the calculation):

Code:
 
real c;
c = 1/2.0;

Thanks Micael. You totally help me a lot. May I have one more question?
Is the result of c=1.0/2.0 or c=1.00/2.000 similar to c=1/2.0?
I wrote udf and not sure whether was it correct or not. Can pls help to a look on it? Thanks a lot.

DEFINE_PROPERTY(acetic_acid_density, c, t)
{
real C; /* self-defined variable for convenience */
real D; /* self-defined variable for convenience */
real rho; /* calculated density in unit kg/m3 */
real T = C_T(c,t); /* temperature in unit kelvin, K */
const real A = 0.35182; /* dimensionless regression coeficient */
const real B = 0.26954; /* dimensionless regression coeficient */
const real n = 0.26843; /* dimensionless regression coeficient */
const real Tc = 592.71; /* critical temperature in unit kelvin, K */
C = 1-T/Tc; /* self-defined variable for convenience */
D = pow(C, n); /* self-defined variable for convenience */
rho = A*(pow(B, -D))*1000; /* calculated density in unit kg/m3 */
return rho;
}

DEFINE_PROPERTY(acetic_acid_viscosity, c, t)
{
real E; /* self-defined variable for convenience */
real mu; /* calculated viscosity in unit kg/m.s */
real T = C_T(c,t); /* temperature in unit kelvin, K */
const real A = -3.8937; /* dimensionless regression coeficient */
const real B = 784.82; /* dimensionless regression coeficient */
const real C = 0.006665; /* dimensionless regression coeficient */
const real D = -0.0000075606; /* dimensionless regression coeficient */
E = A + B/T + C*T + D*T*T; /* self-defined variable for convenience */
mu = 0.001*pow(10, E); /* calculated viscosity in unit kg/m.s */
return mu; /* calculated viscosity in unit kg/m.s */
}

DEFINE_PROPERTY(acetic_acid_thermal_conductivity, c, t)
{
real C; /* self-defined variable for convenience */
real D; /* self-defined variable for convenience */
real E; /* self-defined variable for convenience */
real ktc; /* calculated thermal conductivity in unit W/m.K */
real T = C_T(c,t); /* temperature in unit kelvin, K */
const real A = -1.2836; /* dimensionless regression coeficient */
const real B = 0.5893; /* dimensionless regression coeficient */
const real Tc = 592.71; /* critical temperature in unit kelvin, K*/
const real n = 2/7; /* dimensionless regression coeficient */
C = 1-T/Tc; /* self-defined variable for convenience */
D = pow(C, n); /* self-defined variable for convenience */
E = A + B*D; /* self-defined variable for convenience */
ktc = pow(10, E); /* calculated thermal conductivity in unit W/m.K */
return ktc;
}

Thanks to have a look. Your opinion will be appreciated.

Best regards
wlt_1985 is offline   Reply With Quote

Old   June 29, 2011, 13:45
Default
  #4
Member
 
Micael Boulet
Join Date: Mar 2009
Location: Quebec, Canada
Posts: 95
Rep Power: 9
Micael is on a distinguished road
Quote:
Originally Posted by wlt_1985 View Post
Is the result of c=1.0/2.0 or c=1.00/2.000 similar to c=1/2.0?
Yes, all the same. It can be put more compact like this:
Code:
 
c=1./2;
Following this, there is an obvious problem here:
Code:
 
const real n = 2/7; /* dimensionless regression coeficient */
n is clearly zero.

Otherwise your code looks good.
Micael is offline   Reply With Quote

Old   June 29, 2011, 15:03
Default
  #5
Senior Member
 
raymond
Join Date: Nov 2009
Posts: 149
Rep Power: 7
wlt_1985 is on a distinguished road
Quote:
Originally Posted by Micael View Post
Yes, all the same. It can be put more compact like this:
Code:
 
c=1./2;
Following this, there is an obvious problem here:
Code:
 
const real n = 2/7; /* dimensionless regression coeficient */
n is clearly zero.

Otherwise your code looks good.
Thanks Micael. Sorry to trouble you again.
What are the differences between real and const real?Can I just put
real n=2./7, instead of
const real n=2./7?

Best regards
wlt_1985 is offline   Reply With Quote

Old   June 29, 2011, 16:27
Default
  #6
Member
 
Micael Boulet
Join Date: Mar 2009
Location: Quebec, Canada
Posts: 95
Rep Power: 9
Micael is on a distinguished road
const means it is not modifiable after declaration. It does not really add something usefull in the present situation.
Micael is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
DieselFoam spray thumthae OpenFOAM Running, Solving & CFD 98 December 24, 2014 16:55
Correction of KIVA ITAPE hama Main CFD Forum 1 December 2, 2011 14:47
Giving patch names within stl files Nik_ OpenFOAM Native Meshers: snappyHexMesh and Others 2 October 27, 2010 13:41
STONE'S STRONGLY IMPLICIT SOLVER anybody Main CFD Forum 8 August 18, 2006 10:01
correction of KIVA Itape hama Main CFD Forum 0 May 2, 2006 03:41


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