
[Sponsors] 
November 28, 2010, 22:36 
UDF for specific heat

#1 
New Member
Join Date: Nov 2010
Posts: 8
Rep Power: 12 
Hi,
Does anybody know why user defined functions dont work with defining specific heat (Cp) in fluent? I need to siulate critcal flows in which specific heat dramatically varies, and there is no way but to use UDFs. piecewise linear method is not that accurate and is very timeconsuming as well. I welcome any suggestion. 

December 3, 2010, 21:57 

#2 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 13 
UDFs for specific heat have been implemented in Fluent 12. If you're using Fluent < 12, use a piecewise polynomial, and curve fit your data in Excel or some other similar tool. A good one is www.zunzun.com. How significantly do your pressures and temperatures change?
ComputerGuy 

December 14, 2010, 02:51 

#3 
New Member
Join Date: Nov 2010
Posts: 8
Rep Power: 12 
Thnx for reply. I have Ansys 12.1 but I still can not use define_property macro for Cp. There is also another macro named define_specific_heat which I could not use it, since this macro do not get information for every cell (unlike define_property macro); rather it gets a Temperature from solver which is always constant and equal to zero. In fact the arguments of the 2 functions are totally different. I do not know if I could used the latter for finding Cp at each cell and iteration as a function of cell's temoerature, and could not find a good guid.
Specific heat varies by near 10 times in a 2030 degree temperature range so I can not neglect it. Pieacewise polinomial also does not work since in my version it only accepts 3 pieces, which is not enough for an accurate approximation in my proble. 

December 14, 2010, 07:49 

#4 
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 13 
What information are you trying to get about the cell other than the temperature, and why is the cell temperature 0? 0 Kelvin?
Send me a private message with that data you're trying to fit, and I'll see if I can find a 3piece polynomial that will do it. 

December 14, 2010, 22:17 

#5 
New Member
Join Date: Nov 2010
Posts: 8
Rep Power: 12 
The specific heat is only function of temperature. My udf is as follows:
DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi) { real cp; real TT=T273.16; if (T < 33.) cp = 1000/(.41710.0000008225*pow(TT,3.)); else if (T <37.) cp = 5730.+23590./(1+pow((TT35.33)/(0.9414),2.)); else cp = 1000/(0.9288190.14/pow(TT,1.5)); *h = cp*(TTTref); return cp; } I wrote it according to Ansys 12.0 UDF manual. (of course the way for calculating h must be modified in the udf, but that is not the source of problem.) According to the manual, the macro gets T (temperature), T_ref (some reference temperature) and yi, from the solver and returns specific heat. h is enthalpy. But when I run software with this udf interpreted, the resulted C_p is constant for all cells and equals the value corresponding to 0 (Kelvin), and enthalpy is also some constant negative value. It seems that the solver only gives a constant temperature of zero to the macro. It should be added that the syntax of define_specific_heat macro is different with define_property macro; the latter gets cell and tread as input arguments while the former only get a temperature. 

December 14, 2010, 23:14 

#6  
Senior Member
Real Name :)
Join Date: Jan 2010
Location: United States
Posts: 192
Rep Power: 13 
p_agoodboy,
A couple things: 1) I'd suggest ensuring that all of your values are written floats/doubles. There are 3 values (1000, 1, 1000) that don't have this. It just helps debugging later. 2) Most importantly (I think) is this statement: Code:
*h = cp*(TTTref); Code:
real TT=T273.16; If your code compiles as expected, try and add: Code:
TT=TT+273.16; Code:
*h = cp*(TTTref); For clarity, here's the code as I would write it: Code:
DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi) { real cp; real TT=T273.16; if (T < 33.) { cp = 1000./(.41710.0000008225*pow(TT,3.)); } else if (T <37.) { cp = 5730.+23590./(1.+pow((TT35.33)/(0.9414),2.)); } else { cp = 1000./(0.9288190.14/pow(TT,1.5)); } TT=TT+273.16; *h = cp*(TTTref); return cp; } Best, ComputerGuy Quote:
Last edited by ComputerGuy; December 14, 2010 at 23:29. Reason: added code 

January 29, 2011, 23:46 

#7 
New Member
Tinnaphop
Join Date: Jun 2010
Posts: 1
Rep Power: 0 
why don't you use complying instead of interpreting. the complied UDF is recommended for DEFINE_SPECIFIC_HEAT.


December 18, 2012, 19:12 
Did you guys figure it out?

#8 
Member
Abhijeet Shrawage
Join Date: Feb 2012
Posts: 31
Rep Power: 11 
@ Computer Guy & p_agoodboy
Did you guys figure the UDF for Cp out? I have created the following UDF for Cp of water at 24MPa and Temp varying from 350C to 450C Here is the UDF, I am getting Temperature limited to 1K in many cells (>19,000 cells). Can you guys help me out? #include "udf.h" /* Date: 11/15/2012 Specific heat of supercritcal water at pressure line of 24MPa*/ DEFINE_SPECIFIC_HEAT(specific_heat, T, Tref, h, yi) { real cp; int i; int N1 = 8; real aa[8]={9.731592783661666e+015, 1.074681034976496e+014, 5.086001403165526e+011, 1.337146166142533e+009, 2.109165058548607e+006, 1.996050543970421e+003, 1.049392685740774, 2.364317464886547e004}; int N2 = 5; real bb[5]={1.362812606162869e+016, 8.330882640185808e+013, 1.909751859195201e+011, 1.945719052198394e+008, 7.433859903690445e+004}; int N3 = 8; real cc[8]={7.705464178099725e+012, 7.521528195313355e+010, 3.145122808193584e+008, 7.302941362683474e+005, 1.016975967814141e+003, 0.849330125970483, 3.938872500273441e004, 7.825155875904535e008}; /* Inorder to prevent the solution to collapse in case the temperature of the system goes below the ranges provided the following steps were taken to limit the values to a constant quantity*/ if (T < 618.0) { cp = 6730.0; *h = cp*(TTref); } else if (T > 773.0) { cp = 3634.0; *h = cp*(TTref); } /* Finally the curve fits are implemented in the following way for the three temperature ranges*/ if (T >= 618 && T <= 653.86) { cp = aa[7]; for (i=N12; i>=0; i) cp = cp*T + aa[i]; *h = 0.000029553968311081836302205150257549*(pow(T,8)pow(Tref,8))  0.14991324082011057784922871048496*(pow(T,7)(Tref,7)) + 332.67509066173681731015676632524*(pow(T,6)pow(Tref,6))  421833.01170972138643264770507813*(pow(T,5)pow(Tref,5)) + 334286541.53563326597213745117188*(pow(T,4) pow(Tref,4))  169533380105.51753743489583333333*(pow(T,3)pow(Tref,3)) + 53734051748824.796875*(pow(T,2)pow(Tref,2))  9731592783661666.0*(TTref); } else if (T > 653.86 && T <= 654.96) { cp = bb[4]; for (i= N22; i>=0; i) cp = cp*T + bb[i]; *h = 14867.719807380888960324227809906*(pow(T,5)pow(Tref,5))  48642976.304959848523139953613281*(pow(T,4)pow(Tref,4)) + 63658395306.506703694661458333333*(pow(T,3)pow(Tref,3))  41654413200929.0390625*(pow(T,2)pow(Tref,2)) + 13628126061628690.0*(TTref); } else if (T > 654.96 && T <= 773) { cp = cc[7]; for (i= N32; i>=0; i) cp = cp*T + cc[i]; *h = 0.0000000097814448448806689168386557060517*(pow(T, 8)pow(Tref,8)) + 0.000056269607146763441313043672766168*(pow(T,7)pow(Tref,7))  0.14155502099508049385079289095302*(pow(T,6)pow(Tref,6))+ 203.39519356282819444459164515138*(pow(T,5)pow(Tref,5))  182573.53406708684633485972881317*(pow(T,4)pow(Tref,4)) + 104837426.93978613615036010742188*(pow(T,3)pow(Tref,3))  37607640976.5667724609375*(pow(T,2)pow(Tref,2)) + 7705464178099.724609375*(TTref); } /* Return the value of specific heat calculated by the curve fits*/ return cp; } There is no issue with compiling.. It hooked successfully. Thank you Abhijeet 

July 19, 2013, 10:20 
udf function

#9  
Member
Vjoess
Join Date: Oct 2012
Posts: 54
Rep Power: 10 
Quote:
can you tell me from where this formula for Cp is taken. Actually i want to know it for my simulation. Do we need to input this Cp in the Cp property of material menu in fluent as UDF. 

November 26, 2014, 10:58 

#10 
New Member
carla menale
Join Date: Nov 2014
Posts: 3
Rep Power: 8 
Hello!
I need to introduce in FLUENT 6.3.26 a UDF of Cp. There is not the possibility in this version. I tried to introduce a piecewise polynomial, but I need to introduce 4 ranges, and the maximum number is 3! Is there a way to introduce more ranges?? 

Thread Tools  Search this Thread 
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
Heat source UDF, please  Sasha  Fluent UDF and Scheme Programming  4  October 14, 2014 01:32 
Constant velocity of the material  Sas  CFX  15  July 13, 2010 08:56 
Specific Heat (Cp) cannot be calculated by UDF???  João Fernandes  FLUENT  0  October 16, 2008 18:58 
UDF for heat transfer  ranjit  FLUENT  13  January 18, 2007 10:36 
heat transfer coefficient udf  nam su  FLUENT  0  March 25, 2005 02:28 