|
[Sponsors] |
April 8, 2013, 14:11 |
UDF for Specific Heat - Problem
|
#1 |
New Member
Petter Östlund
Join Date: Mar 2013
Posts: 3
Rep Power: 13 |
Hi all!
Im doing simulations with High temperature and pressure differences for argon and have specified UFD's for the density, Cp, Therm. cond. and viscosity using Multiple Regression in Excel (with respect to both Temp. and pressure). Loading the UFD's works great. No error messages. But when i try to choose "user - defined" in the drop down menu for Cp (Specific heat) in the Materials setup i get the error message: "No user defiend functions have been loaded". For all the other material properties: density, therm cond etc. the loaded UDF's pops up and and i can choose anyone of them with no problem. Im using Fluent v. 14.5. The code im using looks something like this: #include "udf.h" #include "math.h" DEFINE_PROPERTY(cp_ar, c,t) { real p_operating_Pa; real p_pressure_Pa; real abs_pressure_Pa; real Temp_K; Temp_K = C_T(c,t)+273; p_pressure_Pa = C_P(c,t); p_operating_Pa = RP_Get_Real("operating-pressure"); abs_pressure_Pa = p_operating_Pa + p_pressure_Pa; cp_ar = 0.25 + 0.00060 * abs_pressure_Pa - 0.0099 * Temp_K; return cp_ar; } Any help would be great. thx. |
|
April 9, 2013, 10:25 |
|
#2 | |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
Quote:
For specific heat you cannot use define_property but you must use define_specific_heat; however, I think it is not possibile to define specific heat in terms of pressure. You can define cp function of temperature, see the following example: Code:
#include "udf.h" DEFINE_SPECIFIC_HEAT(my_user_cp, T, Tref, h, yi) { real cp=20.*T; /*This is only an example of linear cp*/ *h = cp*(T-Tref); return cp; } Code:
real T: Temperature for the calculation of the specific heat and enthalpy real Tref: Reference temperature for the enthalpy calculation real *h: Pointer to real real *yi: Pointer to array of mass fractions of gas phase species why this? Code:
Temp_K = C_T(c,t)+273 Daniele Last edited by ghost82; April 10, 2013 at 03:39. |
||
April 10, 2013, 12:48 |
|
#3 |
New Member
Petter Östlund
Join Date: Mar 2013
Posts: 3
Rep Power: 13 |
Thx for ze answer! i think i found a way round the problem. Im currently using the DEFINE_SPECIFIC_HEAT marco but with the same code(ish). But since i cant use the C_P(c,t) in my calculations im only using the operating pressure. I think it still might work since the pressure difference in the domain wont change much form the operating pressuer. (around 1700 bars)
Dont know why i hace set the Temp_K=C_T(c,t) + 273.. |
|
April 10, 2013, 13:31 |
|
#4 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
ok, this is right since you can define through fluent udf only specific heat at constant pressure.
Remember to add to your code *h enthalpy calculation. Daniele |
|
April 18, 2014, 11:19 |
|
#5 |
New Member
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 12 |
hello dear friends, recently i got that for defining the specific heat, we need to use DEFINE_SPECIFIC_HEAT macro and so i did it but im not sure if my udf code is right?
can u give me the honor to have a look at it? the code is below and the formula is attached, and just to mention first of all i'd used this code: real temp=C_T(cell,thread) just like other parts and then i deleted it and used the T variable cause i need it in rho_w line, is it the right way? best regards /************************************************** ******************* Fluent UDF Author: Milan all calculations for al2o3 nanoparticles ************************************************** ********************/ #include "udf.h" #define FI 0.01 #define RHO_np 3600 #define SI_1 0.9830 #define SI_2 12.959 #define KTC_np 36 #define TI 5.E4 #define BETA_1 8.4407 #define BETA_2 -1.07304 #define CP_w 4200 #define KA 1.383E-23 #define SIi_1 2.8217E-2 #define SIi_2 3.917E-3 #define SIi_3 -3.0669E-2 #define SIi_4 -3.91123E-3 #define T_0 298.15 #define D_np 59.E-9 #define CP_np 765 DEFINE_PROPERTY(cell_conductivity,cell,thread) { real ktc,ktc_w,temp,f,beta,rho_w; temp = C_T(cell,thread); f = ((SIi_1*FI+SIi_2*temp)/T_0)+(SIi_3*FI+SIi_4); beta = BETA_1*(pow(100*FI,BETA_2)); rho_w = (-3.570*(pow(10,-3))*(pow(temp,2))+(1.88*temp+753.2)); ktc_w = (-8.354*0.000001*(pow(temp,2)))+((6.53*0.001*temp)-0.5981); ktc = ((KTC_np+(2*ktc_w)-2*(ktc_w-KTC_np)*FI)/(KTC_np+(2*ktc_w)+(ktc_w-KTC_np)*FI))+(TI*beta*FI*rho_w*CP_w*(pow(((KA*temp )/(RHO_np*D_np)),0.5))*f); return ktc; } DEFINE_PROPERTY(cell_density,cell,thread) { real temp,rho_w,rho; temp = C_T(cell,thread); rho_w = (-3.570*(pow(10,-3))*(pow(temp,2))+(1.88*temp+753.2)); rho = (FI*RHO_np)+((1-FI)*rho_w); return rho; } DEFINE_PROPERTY(cell_viscosity,cell,thread) { real mu,mu_w,temp; temp = C_T(cell,thread); mu_w = (2.591*(pow(10,-5))*(pow(10,(238.3/(temp-143.2))))); mu = (SI_1*exp(SI_2*FI)*mu_w); return mu; } DEFINE_SPECIFIC_HEAT(specificheat, T, Tref, h, yi) { real cp,rho_w,rho; rho_w = (-3.570*(pow(10,-3))*(pow(T,2))+(1.88*T+753.2)); rho = (FI*RHO_np)+((1-FI)*rho_w); cp = (FI*RHO_np*CP_np)+(((1-FI)*rho_w*CP_w)/rho); return cp; } Last edited by mdakbari; April 18, 2014 at 14:22. |
|
April 19, 2014, 08:24 |
|
#6 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
Hi, I think it's ok, test it.
From the cp formula I think there is a mistake: cp = (FI*RHO_np*CP_np)+(((1-FI)*rho_w*CP_w)/rho); should be changed to: cp = ((FI*RHO_np*CP_np)+((1-FI)*rho_w*CP_w))/rho; Are you sure you don't need to add enthalpy calculation in the Cp part of code? |
|
April 19, 2014, 13:00 |
|
#7 | |
New Member
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 12 |
Quote:
yessss that was the point,small but really important.i modified it and now i can run the calcs without any error or problem, but is there any necessity to add enthalpy equation in this code, since my goal is to calculate cp?
__________________
Best RegarDs |
||
April 20, 2014, 04:59 |
|
#8 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
Hi,
it depends on the model you use; in anyway I would define it in udf; all you have to do is to integrate the cp to have enthalpy. Look at the attached picture for the integrals (you have to sum the blue terms) and implement them in your udf. You can define an arbitrary Tref (reference temperature) in fluent. Daniele Last edited by ghost82; April 20, 2014 at 07:04. |
|
April 20, 2014, 07:02 |
|
#9 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
Try this and remember to define a reference temperature in fluent, under reference values:
Code:
/********************************************************************* Fluent UDF Author: Milan all calculations for al2o3 nanoparticles **********************************************************************/ #include "udf.h" #include "math.h" #define FI 0.01 #define RHO_np 3600.0 #define SI_1 0.9830 #define SI_2 12.959 #define KTC_np 36.0 #define TI 5.E4 #define BETA_1 8.4407 #define BETA_2 -1.07304 #define CP_w 4200.0 #define KA 1.383E-23 #define SIi_1 2.8217E-2 #define SIi_2 3.917E-3 #define SIi_3 -3.0669E-2 #define SIi_4 -3.91123E-3 #define T_0 298.15 #define D_np 59.E-9 #define CP_np 765.0 DEFINE_PROPERTY(cell_conductivity,cell,thread) { real ktc,ktc_w,temp,f,beta,rho_w; temp = C_T(cell,thread); f = ((SIi_1*FI+SIi_2*temp)/T_0)+(SIi_3*FI+SIi_4); beta = BETA_1*(pow(100*FI,BETA_2)); rho_w = (-3.570*(pow(10,-3))*(pow(temp,2))+(1.88*temp+753.2)); ktc_w = (-8.354*0.000001*(pow(temp,2)))+((6.53*0.001*temp)-0.5981); ktc = ((KTC_np+(2*ktc_w)-2*(ktc_w-KTC_np)*FI)/(KTC_np+(2*ktc_w)+(ktc_w-KTC_np)*FI))+(TI*beta*FI*rho_w*CP_w*(pow(((KA*temp )/(RHO_np*D_np)),0.5))*f); return ktc; } DEFINE_PROPERTY(cell_density,cell,thread) { real temp,rho_w,rho; temp = C_T(cell,thread); rho_w = (-3.570*(pow(10,-3))*(pow(temp,2))+(1.88*temp+753.2)); rho = (FI*RHO_np)+((1-FI)*rho_w); return rho; } DEFINE_PROPERTY(cell_viscosity,cell,thread) { real mu,mu_w,temp; temp = C_T(cell,thread); mu_w = (2.591*(pow(10,-5))*(pow(10,(238.3/(temp-143.2))))); mu = (SI_1*exp(SI_2*FI)*mu_w); return mu; } DEFINE_SPECIFIC_HEAT(specificheat, T, Tref, h, yi) { real cp,rho_w,rho; rho_w = (-3.570*(pow(10,-3))*(pow(T,2))+(1.88*T+753.2)); rho = (FI*RHO_np)+((1-FI)*rho_w); cp = ((FI*RHO_np*CP_np)+((1-FI)*rho_w*CP_w))/rho; *h = -1.0/(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5))*(1000.0*FI*CP_np*RHO_np*(atan((0.01*(357.0*Tref*FI-94000.0*FI-357.0*Tref+94000.0))/(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5)))-1.0*atan((0.01*(357.0*T*FI-94000.0*FI-357.0*T+94000.0))/(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5)))))+1.0/(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5))*((1000.0*FI*atan((0.01*(357.0*Tref*FI-94000.0*FI-357.0*Tref+94000.0))/(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5)))*RHO_np-1000.0*FI*atan((0.01*(357.0*T*FI-94000.0*FI-357.0*T+94000.0))/(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5)))*RHO_np+(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5))*T-1.0*(pow(3570.0*FI*FI*RHO_np-3.572524*pow(10,6)*FI*FI-3570.0*FI*RHO_np+7.145048*pow(10,6)*FI-3.572524*pow(10,6),0.5))*Tref)*CP_w); return cp; } |
|
April 22, 2014, 03:49 |
A problem
|
#10 |
New Member
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 12 |
hello dear daniele thank u for ur help that is really kind of u.
but i have some problems: 1- first of all i used my last code(post #7) that needed a correction about parenthesis, without the enthalpy line( u wrote for me), but after running the calcs for a simple tube, and extracted the h diagram in excel, there was an odd diagram about h, it had to be like pic1((attached) for water) but it was very unusual like pic2(attached). 2.when i used the code with ur enthalpy line and interpret it, an error occured about : math.h: No such file or directory any help would be appreciated PIC1-WATER PIC2-NANOFLUID
__________________
Best RegarDs |
|
April 22, 2014, 07:00 |
|
#11 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
math.h is header necessary for atan (arctan); macro DEFINE_SPECIFIC_HEAT has to be compiled, not interpreted.
Daniele |
|
April 22, 2014, 08:51 |
pordon
|
#12 |
New Member
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 12 |
with interpret i meant the interpret in fluent.but pordon me what do u mean about complie?with what program?
__________________
Best RegarDs |
|
April 22, 2014, 11:46 |
|
#13 |
Senior Member
Rick
Join Date: Oct 2010
Posts: 1,016
Rep Power: 27 |
Yes,
in fluent you can interpret or compile a udf. To compile a udf you need visual studio installed. Read here for more information: http://www.cfd-online.com/Forums/flu...iled-udfs.html From the wiki, for win 7 64 bit: Code:
How can I manage to compile my UDF with Windows 7 64bit? Code:
|
|
April 23, 2014, 12:23 |
ok
|
#14 |
New Member
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 12 |
Ok dear daniele I'll do that. tnx so much
__________________
Best RegarDs |
|
April 24, 2014, 08:05 |
|
#15 |
Senior Member
François Grégoire
Join Date: Jan 2010
Location: Canada
Posts: 392
Rep Power: 17 |
Hi,
I have Windows 8.1 64 bit and Fluent 14.5.7 64 bit. I installed Microsoft Visual Studio 10 Ultimate and it worked like a charm, didn't even need to modify the environment variable, I just had to start Fluent from one of the 64 bit Visual Studio 10 command prompt and it compiled/loaded (I almost cried). |
|
February 26, 2016, 06:25 |
UDF for specific heat of water
|
#16 |
Member
Ram Kumar Pal
Join Date: Apr 2015
Posts: 38
Rep Power: 11 |
Dear friends, I have to write udf for specific heat of water as function of temperature. I have written according to DEFINE_PROPERTY macro, but it is not working. Specific heat of water as a function of temperature (in deg Celsius) is as follows:
cp = 4.2174356 - 0.0056181625*temp + 0.0012992528*pow(temp,1.5) - 0.00011535353*pow(temp,2.0) + 4.14964*pow(10.0,-6.0)*pow(temp,2.5) I have seen in UDF manual DEFINE_SPECIFIC_HEAT, but don't understand how can I write for above defined function. Please help me. Thanks in advance |
|
April 4, 2016, 06:01 |
|
#17 |
New Member
Andrew Vella
Join Date: Feb 2015
Posts: 12
Rep Power: 11 |
Hi Daniele,
Dear All, I have just compiled the above UDF for the specific heat of Al2O3 nanofluids in FLUENT. The UDF was compiled and the CASE file was initialised with no errors. However, as soon as I initiated the calculations, I was prompted with a solver error due to a diverging temperature. This was not the case with a constant Cp and with the UDFs for density, conductivity and viscosity. Hence, my suspicion is that the cause of this error is Tref. Hence do we need to specify a reference temperature? Thanks in advance! |
|
June 17, 2017, 02:28 |
|
#18 | |
Member
NGP
Join Date: Mar 2016
Posts: 33
Rep Power: 10 |
Quote:
Dear Daniele How this equation for "h" come? |
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF for heat generation | prince_pahariaa | FLUENT | 4 | July 11, 2011 03:58 |
problem in compoile UDF | h.daniyel | FLUENT | 5 | June 12, 2008 06:06 |
Electrolyte heat transfer problem | fea user | CFX | 0 | November 28, 2006 18:39 |
Basic question: UDF for wall heat flux | Carl | FLUENT | 1 | August 5, 2006 20:01 |
parallel UDF problem | kerem | FLUENT | 2 | June 20, 2006 07:56 |