
[Sponsors] 
June 28, 2011, 09:42 
0 or 0.0 in udf

#1 
Senior Member
raymond
Join Date: Nov 2009
Posts: 149
Rep Power: 9 
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 

June 29, 2011, 11:34 

#2 
Senior Member
Micael Boulet
Join Date: Mar 2009
Location: Quebec, Canada
Posts: 118
Rep Power: 11 
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 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; 

June 29, 2011, 12:39 

#3  
Senior Member
raymond
Join Date: Nov 2009
Posts: 149
Rep Power: 9 
Quote:
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; /* selfdefined variable for convenience */ real D; /* selfdefined 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 = 1T/Tc; /* selfdefined variable for convenience */ D = pow(C, n); /* selfdefined 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; /* selfdefined 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; /* selfdefined 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; /* selfdefined variable for convenience */ real D; /* selfdefined variable for convenience */ real E; /* selfdefined 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 = 1T/Tc; /* selfdefined variable for convenience */ D = pow(C, n); /* selfdefined variable for convenience */ E = A + B*D; /* selfdefined 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 

June 29, 2011, 13:45 

#4 
Senior Member
Micael Boulet
Join Date: Mar 2009
Location: Quebec, Canada
Posts: 118
Rep Power: 11 
Yes, all the same. It can be put more compact like this:
Code:
c=1./2; Code:
const real n = 2/7; /* dimensionless regression coeficient */ Otherwise your code looks good. 

June 29, 2011, 15:03 

#5  
Senior Member
raymond
Join Date: Nov 2009
Posts: 149
Rep Power: 9 
Quote:
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 

June 29, 2011, 16:27 

#6 
Senior Member
Micael Boulet
Join Date: Mar 2009
Location: Quebec, Canada
Posts: 118
Rep Power: 11 
const means it is not modifiable after declaration. It does not really add something usefull in the present situation.


Thread Tools  
Display Modes  


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 