CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for specific heat as function of pressure (https://www.cfd-online.com/Forums/fluent-udf/130339-udf-specific-heat-function-pressure.html)

ghobold February 24, 2014 13:02

UDF for specific heat as function of pressure
 
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.

ghobold March 2, 2014 07:14

I'm still very interested in this problem, so if someone has a suggestion, it would be more than welcome.

aestas March 3, 2014 09:58

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.

ghobold March 5, 2014 11:36

Quote:

Originally Posted by aestas (Post 477754)
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.

ghost82 March 5, 2014 12:35

Quote:

Originally Posted by ghobold (Post 478352)
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.

ghobold March 5, 2014 12:56

Quote:

Originally Posted by ghost82 (Post 478356)
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.

pakk March 6, 2014 07:24

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.

ghobold March 6, 2014 07:57

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!

pakk March 6, 2014 08:27

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 March 6, 2014 09:02

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!

macfly March 9, 2014 18:57

Hi,

Maybe you could use the DEFINE_PROPERTY macro? I guess you can retrieve cell pressure and temperature within this macro.

ghobold March 9, 2014 20:30

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

macfly March 9, 2014 20:45

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.

estevaotolentino June 13, 2017 13:07

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.

Allen_ayt August 22, 2019 00:09

Hi!


I also came across the same problem, so how did you solve the 'undefined symbol' problem in parallel condition?


Thanks!

AlexanderZ August 22, 2019 00:36

show your code

best regards

Allen_ayt August 22, 2019 00:42

The code has been deleted.

AlexanderZ August 22, 2019 01:15

when did you get this error? are you sure your code is compiled well without errors?

best regards

Allen_ayt August 22, 2019 04:12

The code could be compiled and implemented well on my workstation. However, on the super computer Linux platform, there's an error like this when the EXECUTE_AT_END macro is implemented after the first step calculation.



Thanks!

AlexanderZ August 22, 2019 07:10

I have no experience on simulations in Linux. You do better to ask technical support from Ansys

From my point of view, it seems, there are some problems with mpi libraries on linux machine.
Try to remove EXCHANGE_SVAR_MESSAGE_EXT macro and check, how it works.

Frankly speaking, I'm not sure, that you really need it here

best regards


All times are GMT -4. The time now is 15:43.