CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for Specific Heat - Problem (http://www.cfd-online.com/Forums/fluent-udf/115861-udf-specific-heat-problem.html)

Hamjaj April 8, 2013 13:11

UDF for Specific Heat - Problem
 
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.:)

ghost82 April 9, 2013 09:25

Quote:

Originally Posted by Hamjaj (Post 419158)
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.:)

Hi!
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

In addition:
why this?
Code:

Temp_K = C_T(c,t)+273
C_T(c,t) already returns temperature in K.

Daniele

Hamjaj April 10, 2013 11:48

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..

ghost82 April 10, 2013 12:31

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

mdakbari April 18, 2014 10:19

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;
}

http://upload7.ir/imgs/2014-04/51072664768343189552.jpg

ghost82 April 19, 2014 07:24

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?

mdakbari April 19, 2014 12:00

Quote:

Originally Posted by ghost82 (Post 487029)
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?

hi Mr. Daniele, i really appreciate ur help and that u accepted my request to come here and answer my question.

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?

ghost82 April 20, 2014 03:59

1 Attachment(s)
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

ghost82 April 20, 2014 06:02

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;
}


mdakbari April 22, 2014 02:49

A problem
 
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

http://upload7.ir/imgs/2014-04/59626825848091859990.jpg


PIC2-NANOFLUID

http://upload7.ir/imgs/2014-04/31798431275535786671.jpg

ghost82 April 22, 2014 06:00

math.h is header necessary for atan (arctan); macro DEFINE_SPECIFIC_HEAT has to be compiled, not interpreted.

Daniele

mdakbari April 22, 2014 07:51

pordon
 
Quote:

Originally Posted by ghost82 (Post 487469)
math.h is header necessary for atan (arctan); macro DEFINE_SPECIFIC_HEAT has to be compiled, not interpreted.

Daniele

with interpret i meant the interpret in fluent.but pordon me what do u mean about complie?with what program?

ghost82 April 22, 2014 10:46

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:

  • Install Visual Studio. Most of the time the Visual C++ 2008 Express Edition [3] is recommended. On my system it even works with the new Visual Studio 2010 Professional Release Candidate [4].

  • Set the correct environment variables. Browse your way  through the Windows system control to 'System'. There you will find a  section 'Advanced system settings'. In the following dialog go to the  'Advanced' tabulator and click on 'Environment variables' (lower right  corner). Go through the 'System variables' list and search for the  'Path' entry. Add the following to the variable: C:\Program Files  (x86)\Microsoft Visual Studio 10.0\Common7\Tools;C:\Program Files  (x86)\Microsoft Visual Studio 10.0\VC\bin;C:\Program Files\ANSYS  Inc\v120\fluent\ntbin\win64. Adjust this entry to your system  concerning the installation directories! The Visual Studio entry should  point to the location where 'nmake' is located.

  • Install a Software Development Kit (SKD) for 64bit systems.  This may be the difference between 32bit and 64bit systems. I have used  the .NET Framework 2.0 Software Development Kit (SDK) (x64) from 2006 [5] because it is explicitly for 64bit systems and I was not sure if more recent versions are for 64bit systems as well.

  • Start FLUENT from the SDK command prompt. Do not use the Visual Studio command prompt, use the SDK command prompt! Go to the directory your case is in and type 'fluent'.



mdakbari April 23, 2014 11:23

ok
 
Ok dear daniele I'll do that. tnx so much

macfly April 24, 2014 07:05

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).


All times are GMT -4. The time now is 22:32.