CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Fluent UDF and Scheme Programming

UDF for Specific Heat - Problem

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

Like Tree4Likes
  • 1 Post By ghost82
  • 1 Post By ghost82
  • 1 Post By ghost82
  • 1 Post By ghost82

Reply
 
LinkBack Thread Tools Display Modes
Old   April 8, 2013, 13:11
Default UDF for Specific Heat - Problem
  #1
New Member
 
Petter Östlund
Join Date: Mar 2013
Posts: 3
Rep Power: 4
Hamjaj is on a distinguished road
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.
Hamjaj is offline   Reply With Quote

Old   April 9, 2013, 09:25
Default
  #2
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
Quote:
Originally Posted by Hamjaj View Post
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

Last edited by ghost82; April 10, 2013 at 02:39.
ghost82 is offline   Reply With Quote

Old   April 10, 2013, 11:48
Default
  #3
New Member
 
Petter Östlund
Join Date: Mar 2013
Posts: 3
Rep Power: 4
Hamjaj is on a distinguished road
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..
Hamjaj is offline   Reply With Quote

Old   April 10, 2013, 12:31
Default
  #4
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
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
ghost82 is offline   Reply With Quote

Old   April 18, 2014, 10:19
Default
  #5
New Member
 
mdakbari's Avatar
 
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 3
mdakbari is on a distinguished road
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 13:22.
mdakbari is offline   Reply With Quote

Old   April 19, 2014, 07:24
Default
  #6
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
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 likes this.
ghost82 is offline   Reply With Quote

Old   April 19, 2014, 12:00
Post
  #7
New Member
 
mdakbari's Avatar
 
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 3
mdakbari is on a distinguished road
Quote:
Originally Posted by ghost82 View Post
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?
__________________
Best RegarDs
mdakbari is offline   Reply With Quote

Old   April 20, 2014, 03:59
Default
  #8
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
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
Attached Images
File Type: jpg enthalpy.jpg (31.0 KB, 36 views)
mdakbari likes this.

Last edited by ghost82; April 20, 2014 at 06:04.
ghost82 is offline   Reply With Quote

Old   April 20, 2014, 06:02
Default
  #9
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
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 likes this.
ghost82 is offline   Reply With Quote

Old   April 22, 2014, 02:49
Default A problem
  #10
New Member
 
mdakbari's Avatar
 
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 3
mdakbari is on a distinguished road
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
mdakbari is offline   Reply With Quote

Old   April 22, 2014, 06:00
Default
  #11
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
math.h is header necessary for atan (arctan); macro DEFINE_SPECIFIC_HEAT has to be compiled, not interpreted.

Daniele
ghost82 is offline   Reply With Quote

Old   April 22, 2014, 07:51
Default pordon
  #12
New Member
 
mdakbari's Avatar
 
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 3
mdakbari is on a distinguished road
Quote:
Originally Posted by ghost82 View Post
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?
__________________
Best RegarDs
mdakbari is offline   Reply With Quote

Old   April 22, 2014, 10:46
Default
  #13
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 908
Rep Power: 15
ghost82 will become famous soon enough
Yes,
in fluent you can interpret or compile a udf.
To compile a udf you need visual studio installed.

Read here for more information:
Interepreted Vs. Compiled UDFs


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 likes this.
ghost82 is offline   Reply With Quote

Old   April 23, 2014, 11:23
Default ok
  #14
New Member
 
mdakbari's Avatar
 
m.akbari
Join Date: Apr 2014
Posts: 14
Rep Power: 3
mdakbari is on a distinguished road
Ok dear daniele I'll do that. tnx so much
__________________
Best RegarDs
mdakbari is offline   Reply With Quote

Old   April 24, 2014, 07:05
Default
  #15
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 366
Rep Power: 8
macfly is on a distinguished road
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).
macfly 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
UDF for heat generation prince_pahariaa FLUENT 4 July 11, 2011 02:58
problem in compoile UDF h.daniyel FLUENT 5 June 12, 2008 05: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 19:01
parallel UDF problem kerem FLUENT 2 June 20, 2006 06:56


All times are GMT -4. The time now is 18:28.