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

UDF for specific heat as function of pressure

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

Like Tree2Likes
  • 1 Post By ghobold
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Display Modes
Old   February 24, 2014, 14:02
Default UDF for specific heat as function of pressure
  #1
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
Hello,

I am trying to make an UDF to obtain specific heat as a function of temperature and other state variable (either pressure or density, hopefully). The problem is that the default macro for specific heat DEFINE_SPECIFIC_HEAT passes only temperature as a state variable and does not inform on the cell or thread. This is what I have tried to do in order to obtain the pressure in the cell:

Code:
#include "udf.h"

const char* FLUID = "CarbonDioxide";
const real gauge = 101325; //operating pressure in pascal (as defined in fluent)

double Props (char*, char, double, char, double, char*);

/* other macros here */

DEFINE_SPECIFIC_HEAT(cell_specificHeat, temperature, Tref, enthalpy, yi)
{	 
	real pressure;
	 
	 Domain *domain = Get_Domain(1);
	 Thread *t;
	 cell_t c;
	 thread_loop_c(t, domain)
	 {
	 	begin_c_loop(c, t)
	 	{
	 		pressure = C_P(c, t);
	 	}end_c_loop(c, t)
	 }
	
	real specificHeat;
	
	specificHeat = Props((char*)"C",'T', temperature, 'P', pressure, (char*)FLUID)*1000;
	*enthalpy = specificHeat*(temperature-Tref);
	return specificHeat;
}
Props(), in this case, is a function from a loaded library Coolprop (Coolprop works fine with Fluent, by the way, I'm using it to obtain other real gas properties and it works just fine). Whenever I initialize a solution using the code above, the following error pops up:

Code:
/home/ansys_inc/v145/fluent/fluent14.5.7/lnamd64/2ddp_node/fluent_mpi.14.5.7: symbol lookup error: libudf/lnamd64/2ddp_node/libudf.so: undefined symbol: _Z10Get_Domaini
/home/ansys_inc/v145/fluent/fluent14.5.7/lnamd64/2ddp_node/fluent_mpi.14.5.7: symbol lookup error: libudf/lnamd64/2ddp_node/libudf.so: undefined symbol: _Z10Get_Domaini
/home/ansys_inc/v145/fluent/fluent14.5.7/lnamd64/2ddp_node/fluent_mpi.14.5.7: symbol lookup error: libudf/lnamd64/2ddp_node/libudf.so: undefined symbol: _Z10Get_Domaini
/home/ansys_inc/v145/fluent/fluent14.5.7/lnamd64/2ddp_node/fluent_mpi.14.5.7: symbol lookup error: libudf/lnamd64/2ddp_node/libudf.so: undefined symbol: _Z10Get_Domaini
/home/ansys_inc/v145/fluent/fluent14.5.7/lnamd64/2ddp_node/fluent_mpi.14.5.7: symbol lookup error: libudf/lnamd64/2ddp_node/libudf.so: undefined symbol: _Z10Get_Domaini
/home/ansys_inc/v145/fluent/fluent14.5.7/lnamd64/2ddp_node/fluent_mpi.14.5.7: symbol lookup error: libudf/lnamd64/2ddp_node/libudf.so: undefined symbol: _Z10Get_Domaini
MPI Application rank 1 exited before MPI_Finalize() with status 127

999999 (../../src/mpsystem.c@1172): mpt_read: failed: errno = 104

999999: mpt_read: error: read failed trying to read 4 bytes: Connection reset by peer
 The fluent process could not be started.
It seems like the UDF does not recognize the function Get_Domain() and is trying to look for it in the compiled Coolprop library instead of the default Fluent library. Am I doing something wrong or is there another (and hopefully faster, computational time wise) way to do this?

I'm running Fluent 14.5.7 on Fedora 19, in case that's relevant.
ghost82 likes this.
ghobold is offline   Reply With Quote

Old   March 2, 2014, 08:14
Default
  #2
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
I'm still very interested in this problem, so if someone has a suggestion, it would be more than welcome.
ghobold is offline   Reply With Quote

Old   March 3, 2014, 10:58
Default
  #3
Member
 
Peter Aestas
Join Date: Dec 2013
Posts: 64
Rep Power: 5
aestas is on a distinguished road
i never have this problem,but it's clear the loop is wrong:
thread_loop_c(t, domain)
{
begin_c_loop(c, t)
{
pressure = C_P(c, t);
}end_c_loop(c, t)
}
this will only make pressure equal the last cell value it loops.
aestas is offline   Reply With Quote

Old   March 5, 2014, 12:36
Default
  #4
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
Quote:
Originally Posted by aestas View Post
i never have this problem,but it's clear the loop is wrong:
thread_loop_c(t, domain)
{
begin_c_loop(c, t)
{
pressure = C_P(c, t);
}end_c_loop(c, t)
}
this will only make pressure equal the last cell value it loops.
Thanks for your reply. How should I structure the loop in a way I can grab the cell's pressure value? I still have no idea on how to deal with those loops, so if you have any source it would be welcome. The manual doesn't seem to provide a clear explanation.
ghobold is offline   Reply With Quote

Old   March 5, 2014, 13:35
Default
  #5
Senior Member
 
ghost82's Avatar
 
Daniele
Join Date: Oct 2010
Location: Italy
Posts: 998
Rep Power: 17
ghost82 will become famous soon enough
Quote:
Originally Posted by ghobold View Post
Thanks for your reply. How should I structure the loop in a way I can grab the cell's pressure value? I still have no idea on how to deal with those loops, so if you have any source it would be welcome. The manual doesn't seem to provide a clear explanation.
It's not possible with macro DEFINE_SPECIFIC_HEAT.

Maybe your idea is good to load external library.
ghost82 is offline   Reply With Quote

Old   March 5, 2014, 13:56
Default
  #6
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
Quote:
Originally Posted by ghost82 View Post
It's not possible with macro DEFINE_SPECIFIC_HEAT.

Maybe your idea is good to load external library.
My plan is to load an external library. A Fluent wrapper for the open-source thermodynamic library Coolprop is under development and I am using it in my implementation.

As mentioned in the UDF I posted, Props() is a C function that will get the value of specific heat as a function of two state properties (such as temperature and pressure, or temperature and density). The problem is that the DEFINE_SPECIFIC_HEAT does not pass the cell value of pressure or density, so I am not able to consult the external library. So that's why I am trying to find a way to get the value of pressure in the cell. Is there any other macro that would help me in defining specific heat as a function of temperature and other thermodynamic property?

I have also noticed that the bult-in NIST REFPROP library in Fluent does not compute specific heat as a function of pressure, only temperature.
ghobold is offline   Reply With Quote

Old   March 6, 2014, 08:24
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,074
Rep Power: 14
pakk will become famous soon enough
When the udf DEFINE_SPECIFIC_HEAT is called by Fluent, Fluent does not give information about density or pressure. You already saw that.

However, Fluent also does not give information about which cell it currently is. Within the udf DEFINE_SPECIFIC_HEAT, there is no way to find the density of the cell of interest, because the udf can not know what the cell of interest is.

It is possible to do a loop over all domains and find out what the average density is (I think a small modification of your code would do about that) but that is not what you want.

What you want is not possible with this udf. I would consider this to be a design flaw of Fluent, but maybe they have a reason for this.
pakk is offline   Reply With Quote

Old   March 6, 2014, 08:57
Default
  #8
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
Thanks, so it is not possible. Are you aware if OpenFOAM (or any other open source CFD code) is able to compute thermophysical (mainly density, conductivity, viscosity and specific heat) properties from the cell's pressure and temperature (or any two other state properties, really)?

What about enthalpy in the DEFINE_SPECIFIC_HEAT, does it pass any kind of information on the cell's enthalpy? Because I could use that to calculate specific heat. But anyways, I am guessing Fluent does not calculate enthalpy as a function of pressure either.

Thanks for your support!
ghobold is offline   Reply With Quote

Old   March 6, 2014, 09:27
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,074
Rep Power: 14
pakk will become famous soon enough
I don't know about what OpenFoam or other codes can do in this aspect...


Fluent makes the assumption that specific heat is completely determined by temperature (and the mass fractions if you have a mixture). As far as I see, there is no possibility to remove that assumption. Usually, this works fine, although there might be situations (I guess at extremely high pressures?) where the pressure is also relevant.

By the way, you can not use the enthalpy in that UDF to get any information about the cell, because the enthalpy is output of the function, not input. Your udf should also calculate the enthalpy based on the specific heat that it provides.
ghobold likes this.
pakk is offline   Reply With Quote

Old   March 6, 2014, 10:02
Default
  #10
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
That is what I thought.

In my case, the specific heat dependance on pressure is extremely relevant, as I am going to work very close to the critical point, where there's a sudden jump in specific heat with respect to pressure (or density, or any other state property, for that matter).

I will consider coding a CFD code myself for now, at least for some simple geometries.

Thanks for your support!
ghobold is offline   Reply With Quote

Old   March 9, 2014, 19:57
Default
  #11
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 389
Rep Power: 10
macfly is on a distinguished road
Hi,

Maybe you could use the DEFINE_PROPERTY macro? I guess you can retrieve cell pressure and temperature within this macro.
macfly is offline   Reply With Quote

Old   March 9, 2014, 21:30
Default
  #12
New Member
 
Gustavo
Join Date: Jun 2013
Posts: 26
Rep Power: 6
ghobold is on a distinguished road
Altough the DEFINE_PROPERTY does retrieve cell information, it is not possible to define specific heat with this macro (when choosing user-defined specific heat in the Materials tab, it is not possible to choose from DEFINE_PROPERTY UDFs).
ghobold is offline   Reply With Quote

Old   March 9, 2014, 21:45
Default
  #13
Senior Member
 
François Grégoire
Join Date: Jan 2010
Location: Laval University, Canada
Posts: 389
Rep Power: 10
macfly is on a distinguished road
That's a shame. Once again, that kind of problem reflects how it can be complicated to do simple things in Fluent. That's the kind of stuff that takes 5 minutes to figure out in Comsol for example.
macfly is offline   Reply With Quote

Old   June 13, 2017, 13:07
Default
  #14
New Member
 
Estêvão Lannes Tolentino
Join Date: Oct 2016
Posts: 9
Rep Power: 2
estevaotolentino is on a distinguished road
Hi,

I'm having a similar problem and I would like to know if this issue has been solved. If so, how was it solved? Thank you.
estevaotolentino is offline   Reply With Quote

Reply

Tags
coolprop, fluent, pressure, specific heat, udf

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
Question about heat transfer coefficient setting for CFX Anna Tian CFX 1 June 16, 2013 06:28
non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Native Meshers: blockMesh 7 April 17, 2013 05:42
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
BlockMesh FOAM warning gaottino OpenFOAM Native Meshers: blockMesh 7 July 19, 2010 14:11
Convective Heat Transfer - Heat Exchanger Mark CFX 6 November 15, 2004 16:55


All times are GMT -4. The time now is 02:52.