![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Overview and Limitations of the User-Defined Real Gas Model
The user-defined real gas model (UDRGM) has been developed to allow you to write your own custom real gas model to fit your particular modeling needs. It also allows you to simulate a single-species flow, multiple-species mixture flow, or volumetric reactions.
The following limitations exist for the User-Defined real gas model:
The UDRGM requires a library of functions written in the C programming language. Moreover, there are certain coding requirements that need to be followed when writing these functions. Sample real gas function libraries are provided to assist you in writing your own UDRGM. When UDRGM functions are compiled, they will be grouped in a shared library which later will be loaded and linked with the ANSYS FLUENT executable. The procedure for using the UDRGM is defined below:
If a single-species UDRGM to be used, then the text command menu is:
> define/user-defined/real-gas-models/user-defined-real-gas-model use user defined real gas? [no] yes |
On the other hand, if you are simulating multiple-species UDRGM flow, then the text command menu to use is:
> define/user-defined/real-gas-models/user-defined-multispecies-real-gas-model use user multispecies defined real gas? [no] yes |
Upon activating the UDRGM, the function library will now supply the fluid material properties for your case.
You can access the Species Model by selecting Models from the navigation pane and double-clicking Species in the task page.
In the Species Model dialog box
|
Note that the fluid materials and their properties, appearing in the
Create/Edit Materials dialog box, are the ones defined in your real gas UDF. You cannot modify the materials via this dialog box, however, you can set up the volumetric reaction. If you would like to modify the mixture materials and their properties, this should be done in the real gas UDF. The volumetric reactions for your real gas mixture are defined in the same way as for any
ANSYS FLUENT mixture. For details, refer to Section
15.1.3.
|
Alternatively, the chemical reactions can be set up using the define/models/ species and define/materials text command.
|
Note that the chemical reactions should be activated after your real gas UDF has been built and loaded. It is also recommended to test and validate your real gas UDF, running the cold flow calculation prior to attempting to solve the reacting flow. Also, make sure that the applicability range of the real gas functions in your UDF fully covers the temperature and pressure range of the reacting flow calculation.
|
When using the UDRGM the robustness of the solver and the speed of flow convergence will largely depend on the complexity of the material properties you have defined in your UDF. It is important to understand the operational range of the property functions you are coding so you can simulate the flow within that range.
Writing the UDRGM C Function Library
Creating a UDRGM C function library is reasonably straightforward; however, your code must make use of specific function names and macros, which will be described in detail below. The basic library requirements are as follows:
Below, the UDRGM function names and argument lists are listed, followed by a short description of the function. Function inputs from the ANSYS FLUENT solver consist of one or more of the following variables:
![]() |
= | Temperature, K | |
![]() |
= | Pressure, Pa | |
![]() |
= | Density, kg/m
![]() | |
![]() |
= | Species mass fraction |
|
![]() ![]() ![]()
|
|
Since this function is called numerous times during each solver iteration, it is important to make this function as numerically efficient as possible.
|
At the end of the code you must define a structure of type RGAS_Function whose members are pointers to the principal functions listed above. The structure is of type RGAS_Function and its name is RealGasFunctionList.
|
It is imperative that the sequence of function pointers shown below be followed. Otherwise, your real gas model will not load properly into the
ANSYS FLUENT code.
|
UDF_EXPORT RGAS_Functions RealGasFunctionList = { ANYNAME_Setup, /* Setup initialize */ ANYNAME_density, /* density */ ANYNAME_enthalpy, /* sensible enthalpy */ ANYNAME_entropy, /* entropy */ ANYNAME_specific_heat, /* specific_heat */ ANYNAME_mw, /* molecular_weight */ ANYNAME_speed_of_sound, /* speed_of_sound */ ANYNAME_viscosity, /* viscosity */ ANYNAME_thermal_conductivity, /* thermal_conductivity */ ANYNAME_rho_t, /* drho/dT |const p */ ANYNAME_rho_p, /* drho/dp |const T */ ANYNAME_enthalpy_t, /* dh/dT |const p */ ANYNAME_enthalpy_p /* dh/dp |const T */ ANYNAME_enthalpy_prime /* enthalpy */ }; |
|
If volumetric reactions are not being simulated, then the function
ANYNAME_enthalpy_prime can be removed or ignored from the
RealGasFunctionList structure shown above.
|
The principal set of functions shown above are the only functions in the UDRGM that will be interacting directly with the ANSYS FLUENT code. In many cases, your model may require further functions that will be called from the principal function set. For example, when multiple-species real gas model UDFs are written, the principal functions will return the mixture thermodynamic properties based on some specified mixing-law. Therefore, you may want to add further functions that will return the thermodynamic properties for the individual species. These auxiliary functions will be called from the principal set of functions. See this section in the separate UDF Manual for examples that clearly illustrate this strategy.
Compiling Your UDRGM C Functions and Building a Shared Library File
|
To build UDRGM library you will use the compiled UDF utilities. However, you will not use the UDF utilities to load the library. A separate loading area for the UDRGM library will be used.
|
Compiling the UDRGM Using the Graphical Interface
If the build is successful, then the compiled library will be placed in the appropriate architecture folder (e.g., ntx86/2d). By default the library name is libudf.so ( libudf.dll on Windows).
More information on compiled UDFs and building libraries using the ANSYS FLUENT graphical user interface can be found in the separate UDF Manual.
Compiling the UDRGM Using the Text Interface
The UDRGM library can be compiled in the text command interface as follows:
define
user-defined
compiled-functions
.
|
The name given here is the name of the folder where the shared library (e.g.,
libudf) will reside. For example, if you hit
![]() ![]()
|
|
Ideally you should place all of your functions into a single file. However, you can split them into separate files if desired.
|
ANSYS FLUENT will then start compiling the UDRGM C code and put it in the appropriate architecture folder.
Example:
> define/user-defined/compiled-functions load OR compile ? [load]> compile Compiled UDF library name: ["libudf"] my_lib Make sure that UDF source files are in the folder that contains your case and data files. If you have an existing libudf folder, please remove this folder to ensure that latest files are used. Continue?[yes] <RETURN> Give C-Source file names: First file name: [""] my_c_file.c <RETURN> Next file name: [""] <RETURN> Give header file names: First file name: [""] my_header_file.h <RETURN> |
Loading the UDRGM Shared Library File
To load the UDRGM library:
define
user-defined
real-gas-models
For single-species:
use user defined real gas? [no] yes |
For multiple-species:
use multispecies user defined real gas? [no] yes |
ANSYS FLUENT will ask for the location of the user-defined real gas library. You can enter either the name of the folder where the UDRGM shared library is called or the entire path to the UDRGM shared library.
If the loading of the UDRGM library is successful you will see a message similar to the following:
Opening user-defined realgas library "RealgasLibraryname"... Library "RealgasDirName/lnx86/2d/libudf.so" opened Setting material "air" to a real-gas... Loading Real-RealGasPrefexLable Library: |
UDRGM Example: Ideal Gas Equation of State
This section describes an example of a user-defined real gas model. You can use this example as the basis for your own UDRGM code. In this simple example, the standard ideal gas equation of state is used in the UDRGM. See
this section in the separate UDF Manual for more examples of UDRGM functions, including multi-species real gas and reacting real-gas examples.
![]() |
= | pressure | |
![]() |
= | temperature | |
![]() |
= | specific heat | |
![]() |
= | enthalpy | |
![]() |
= | entropy | |
![]() |
= | density | |
![]() |
= | speed of sound | |
![]() |
= | universal gas constant/molecular weight |
The ideal gas equation of state can be written in terms of pressure and temperature as
![]() |
(8.16-20) |
The specific heat is defined to be constant
= 1006.42.
The enthalpy is, therefore, defined as
![]() |
(8.16-21) |
and entropy is given by
![]() |
(8.16-22) |
where
= 288.15 K and
= 101325 Pa
The speed of sound is simply defined as
![]() |
(8.16-23) |
The density derivatives are:
![]() |
(8.16-24) |
![]() |
(8.16-25) |
The enthalpy derivatives are:
![]() |
(8.16-26) |
![]() |
(8.16-27) |
When you activate the real gas model and load the library successfully into ANSYS FLUENT, you will be using the equation of state and other fluid properties from this library rather than the one built into the ANSYS FLUENT code; therefore, the access to the Create/Edit Materials dialog box will be restricted.
Ideal Gas UDRGM Code Listing
/**********************************************************************/ /* User Defined Real Gas Model : */ /* For Ideal Gas Equation of State */ /* */ /**********************************************************************/ #include "udf.h" #include "stdio.h" #include "ctype.h" #include "stdarg.h" #define MW 28.966 /* molec. wt. for single gas (Kg/Kmol) */ #define RGAS (UNIVERSAL_GAS_CONSTANT/MW) static int (*usersMessage)(char *,...); static void (*usersError)(char *,...); DEFINE_ON_DEMAND(I_do_nothing) { /* This is a dummy function to allow us to use */ /* the Compiled UDFs utility */ } void IDEAL_error(int err, char *f, char *msg) { if (err) usersError("IDEAL_error (%d) from function: %s\n%s\n",err,f,msg); } void IDEAL_Setup(Domain *domain, cxboolean vapor_phase, char *filename, int (*messagefunc)(char *format, ...), void (*errorfunc)(char *format, ...)) { /* Use this function for any initialization or model setups*/ usersMessage = messagefunc; usersError = errorfunc; usersMessage("\nLoading Real-Ideal Library: %s\n", filename); } double IDEAL_density(double Temp, double press, double yi[]) { double r = press/(RGAS*Temp); /* Density at Temp & press */ return r; /* (Kg/m^3) */ } double IDEAL_specific_heat(double Temp, double density, double P, double yi[]) { double cp=1006.43; return cp; /* (J/Kg/K) */ } double IDEAL_enthalpy(double Temp, double density, double P, double yi[]) { double h=Temp*IDEAL_specific_heat(Temp, density, P, yi); return h; /* (J/Kg) */ } #define TDatum 288.15 #define PDatum 1.01325e5 |
double IDEAL_entropy(double Temp, double density, double P, double yi[]) { double s=IDEAL_specific_heat(Temp,density,P,yi)*log(fabs(Temp/TDatum))+ RGAS*log(fabs(PDatum/P)); return s; /* (J/Kg/K) */ } double IDEAL_mw(double yi[]) { return MW; /* (Kg/Kmol) */ } double IDEAL_speed_of_sound(double Temp, double density, double P, double yi[]) { double cp=IDEAL_specific_heat(Temp,density,P,yi); return sqrt(Temp*cp*RGAS/(cp-RGAS)); /* m/s */ } double IDEAL_viscosity(double Temp, double density, double P, double yi[]) { double mu=1.7894e-05; return mu; /* (Kg/m/s) */ } double IDEAL_thermal_conductivity(double Temp, double density, double P, double yi[]) { double ktc=0.0242; return ktc; /* W/m/K */ } double IDEAL_rho_t(double Temp, double density, double P, double yi[]) { /* derivative of rho wrt. Temp at constant p */ double rho_t=-density/Temp; return rho_t; /* (Kg/m^3/K) */ } |
double IDEAL_rho_p(double Temp, double density, double P, double yi[]) { /* derivative of rho wrt. pressure at constant T */ double rho_p=1.0/(RGAS*Temp); return rho_p; /* (Kg/m^3/Pa) */ } double IDEAL_enthalpy_t(double Temp, double density, double P, double yi[]) { /* derivative of enthalpy wrt. Temp at constant p */ return IDEAL_specific_heat(Temp, density, P, yi); } double IDEAL_enthalpy_p(double Temp, double density, double P, double yi[]) { /* derivative of enthalpy wrt. pressure at constant T */ /* general form dh/dp|T = (1/rho)*[ 1 + (T/rho)*drho/dT|p] */ /* but for ideal gas dh/dp = 0 */ return 0.0 ; } UDF_EXPORT RGAS_Functions RealGasFunctionList = { IDEAL_Setup, /* initialize */ IDEAL_density, /* density */ IDEAL_enthalpy, /* enthalpy */ IDEAL_entropy, /* entropy */ IDEAL_specific_heat, /* specific_heat */ IDEAL_mw, /* molecular_weight */ IDEAL_speed_of_sound, /* speed_of_sound */ IDEAL_viscosity, /* viscosity */ IDEAL_thermal_conductivity, /* thermal_conductivity */ IDEAL_rho_t, /* drho/dT |const p */ IDEAL_rho_p, /* drho/dp |const T */ IDEAL_enthalpy_t, /* dh/dT |const p */ IDEAL_enthalpy_p /* dh/dp |const T */ }; /**************************************************************/ |
Additional UDRGM Examples
You can find the following additional UDRGM examples in the separate UDF Manual :
this section in the separate UDF Manual for details.
this section in the separate UDF Manual for details.
this section in the separate UDF Manual for details.