[Fluent Inc. Logo] return to home search
next up previous contents index

8.16.2 The User-Defined Real Gas Model



Overview and Limitations of the User-Defined Real Gas Model


The user-defined real gas model (UDRGM) has been developed for the FLUENT density-based solvers to allow you to write your own custom real gas model to fit your particular modeling needs. The user defined real gas model allow the user to simulate a single-specie flow or multiple-species mixture flow.

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 FLUENT executable. The procedure for using the UDRGM is defined below:

1.   Define the real gas equation of state and all related thermodynamic and transport property equations.

2.   Create a C source code file that conforms to the format defined in this section.

3.   Start FLUENT and set up your case file in the usual way.

4.   Compile your UDRGM C library and build a shared library file (you can use the available compiled UDF utilities in either the graphical user interface or the text command interface).

5.   Load your newly created UDRGM library via the text command menu:

If single-species UDRGM to be used, then the text command menu is:

    > define/user-defined/real-gas/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/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.

6.   Run your 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 FLUENT solver consist of one or more of the following variables:


  $T$ = Temperature, K
  $p$ = Pressure, Pa
  $\rho$ = Density, kg/m $^3$
  $Y_i$[] = Species mass fraction

figure   

$Y_i$[] return value of 1.0 for single-specie flow. while for multiple-species flow return the species mass fractions in order defined by the user setup function.

void ANYNAME_error(int err, char *f, char *msg)   prints error messages.

void ANYNAME_Setup(Domain *domain, char *filename,    int (*messagefunc)(char *format, ...), void (*errorfunc)(char *format, ...))performs model setup and initialization. Can be used to read data and parameters related to your UDRGM. When writing UDF for multiple-species use this function to specify the number of species and the name of the species as shown in the multiple-species example.

double ANYNAME_density(double T, double P, double yi[])   returns the value of density as a function of temperature, pressure and species mass-fraction if applicable. This is your equation of state.

figure   

Since this function is called numerous times during each solver iteration, it is important to make this function as numerically efficient as possible.

double ANYNAME_specific_heat(double T, double Rho, double yi[])   returns the real gas specific heat at constant pressure as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_enthalpy(double T, double Rho, double yi[])   returns the enthalpy as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_entropy(double T, double Rho, double yi[])   returns the entropy as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_mw(double yi[])   returns the fluid molecular weight.

double ANYNAME_speed_of_sound(double T, double Rho, double yi[])   returns the value of speed of sound as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_viscosity(double T, double Rho, double yi[])   returns the value of dynamic viscosity as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_thermal_conductivity(double T, double Rho, double yi[])   returns the value of thermal conductivity as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_rho_t(double T, double Rho, double yi[])   returns the value of $\frac{d\rho}{dT}$ at constant pressure as a function of temperature, density and species mass-fraction if applicable.

double ANYNAME_rho_p(double T, double Rho, double yi[])   returns the value of $\frac{d\rho}{dp}$ at constant temperature as function of temperature, density and species mass-fraction if applicable.

double ANYNAME_enthalpy_t(double T, double Rho, double yi[])   returns the value of $\frac{dh}{dT}$ at constant pressure as function of temperature, density and species mass-fraction if applicable.

double ANYNAME_enthalpy_p(double T, double Rho, double yi[])   returns the value of $\frac{dh}{dp}$ at constant temperature as function of temperature, density and species mass-fraction if applicable.

At the end of the code you must define a structure of type RGAS_Function whose members are pointers to the principle functions listed above. The structure is of type RGAS_Function and its name is RealGasFunctionList.

figure   

It is imperative that the sequence of function pointers shown below be followed. Otherwise, your real gas model will not load properly into the FLUENT code.

UDF_EXPORT  RGAS_Functions RealGasFunctionList =
{
  ANYNAME_Setup,                         /* Setup initialize  */
  ANYNAME_density,                       /* density  */
  ANYNAME_enthalpy,                      /* 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  */
};

The principle set of functions shown above are the only functions in the UDRGM that will be interacting directly with the FLUENT code. In many cases, your model may require further functions that will be called from the principle function set. For example, when multiple-species real gas model UDF are written, the principle 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 principle set of functions. This strategy is clearly illustrated in the multiple-specie real gas model example.



Compiling Your UDRGM C Functions and Building a Shared Library File


This section presents the steps you will need to follow to compile your UDRGM C code and build a shared library file. This process requires the use of a C compiler. Most UNIX operating systems provide a C compiler as a standard feature. If you are using a PC, you will need to ensure that a C ++ compiler is installed before you can proceed (e.g., Microsoft Visual C ++, v6.0 or higher). To use the UDRGM you will need to first build the UDRGM library by compiling your UDRGM C code and then loading the library into the FLUENT code. The UDRGM shared library is built in the same way that the FLUENT executable itself is built. Internally, a script called Makefile is used to invoke the system C compiler to build an object code library that contains the native machine language translation of your higher-level C source code. This shared library is then loaded into FLUENT (either at runtime or automatically when a case file is read) by a process called dynamic loading. The object libraries are specific to the computer architecture being used, as well as to the particular version of the FLUENT executable being run. The libraries must, therefore, be rebuilt any time FLUENT is upgraded, when the computer's operating system level changes, or when the job is run on a different type of computer. The general procedure for compiling UDRGM C code is as follows:

figure   

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

Please refer to the separate UDF Manual for information on compiled UDFs and building libraries using the FLUENT graphical user interface.

If the build is successful, then the compiled library will be placed in the appropriate architecture directory (e.g., ntx86/2d). By default the library name is libudf.so ( libudf.dll on Windows).

Compiling the UDRGM Using the Text Interface

The UDRGM library can be compiled in the text command interface as follows:

FLUENT will then start compiling the UDRGM C code and put it in the appropriate architecture directory.

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 directory
         that contains your case and data files. If you have
         an existing libudf directory, please remove this
         directory 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:



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.


  $p$ = pressure
  $T$ = temperature
  $C_p$ = specific heat
  $H$ = enthalpy
  $S$ = entropy
  $\rho$ = density
  $c$ = speed of sound
  $R$ = universal gas constant/molecular weight

The ideal gas equation of state can be written in terms of pressure and temperature as

 \rho = \frac{p}{RT} (8.16-1)

The specific heat is defined to be constant $C_p$ = 1006.42.

The enthalpy is, therefore, defined as


 H = C_p T (8.16-2)

and entropy is given by


 S = C_p \log\left(\frac{T}{T_{\rm ref}}\right) + R \; \log\left(\frac{p_{\rm ref}}{p}\right) (8.16-3)

where $T_{\rm ref}$ = 288.15 K and $p_{\rm ref}$ = 101325 Pa

The speed of sound is simply defined as


 c= \sqrt{T C_p \frac{R}{(C_p-R)}} (8.16-4)

The density derivatives are:

 \left( \frac{d\rho}{dp} \right)_T= \frac{1}{R T} (8.16-5)


 \left( \frac{d\rho}{dT} \right)_p = - \frac{p}{R T^2} = - \frac{\rho}{T} (8.16-6)

The enthalpy derivatives are:

 \left( \frac{dH}{dT} \right)_p = C_p (8.16-7)


 \left( \frac{dH}{dp} \right)_T = \frac{C_p}{\rho R} \left[1 - \frac{p}{\rho} \frac{d\rho}{dp}\right] = 0 (8.16-8)

When you activate the real gas model and load the library successfully into FLUENT, you will be using the equation of state and other fluid properties from this library rather than the one built into the FLUENT code, therefore, the access to the Materials panel 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, 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 yi[])
{
  double cp=1006.43;

  return cp;                    /* (J/Kg/K) */
}

double IDEAL_enthalpy(double Temp, double density, double yi[])
{
  double h=Temp*IDEAL_specific_heat(Temp, density, yi);

  return h;                     /* (J/Kg) */
}

#define TDatum 288.15
#define PDatum 1.01325e5

double IDEAL_entropy(double Temp, double density, double yi[])
{
  double s=IDEAL_specific_heat(Temp,density,yi)*log(fabs(Temp/TDatum))+
                      RGAS*log(fabs(PDatum/(RGAS*Temp*density)));
  return s;                     /* (J/Kg/K) */
}


double IDEAL_mw(double yi[])
{
  return MW;                    /* (Kg/Kmol) */
}

double IDEAL_speed_of_sound(double Temp, double density, double yi[])
{
  double cp=IDEAL_specific_heat(Temp,density,yi);

  return sqrt(Temp*cp*RGAS/(cp-RGAS));  /* m/s */
}

double IDEAL_viscosity(double Temp, double density, double yi[])
{
  double mu=1.7894e-05;

  return mu;                    /* (Kg/m/s) */
}

double IDEAL_thermal_conductivity(double Temp, double density,
                                                   double yi[])
{
  double ktc=0.0242;

  return ktc;                   /* W/m/K */
}

double IDEAL_rho_t(double Temp, double density, 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 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 yi[])
{
  /* derivative of enthalpy wrt. Temp at constant p */
  return IDEAL_specific_heat(Temp, density, yi);
}

double IDEAL_enthalpy_p(double Temp, double density, 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       */
};
/**************************************************************/



UDRGM Example: Redlich-Kwong Equation of State


This section describes another example of a user-defined real gas model. You can use this example as the basis for your own UDRGM code. In this example, the Redlich-Kwong equation of state is used in the UDRGM.

This section summarizes the equations used in developing the UDRGM for the Redlich-Kwong equation of state. The model is based on a modified form of the Redlich-Kwong equation of state described in [ 14]. The equations used in this UDRGM will be listed in the sections below.

The following nomenclature applies to this section:


  $a(T)$ = Redlich-Kwong temperature function
  $c$ = speed of sound
  $C_p$ = specific heat
  $H$ = enthalpy
  $n$ = exponent in function $a(T)$
  $p$ = pressure
  $R$ = universal gas constant/molecular weight
  $T$ = temperature
  $S$ = entropy
  $V$ = specific volume
  $\rho$ = density

The superscript 0 designates a reference state, and the subscript $c$ designates a critical point property.

Specific Volume and Density

The Redlich-Kwong equation of state can be written in the following form:


 p = \frac{RT}{(V-\tilde{b})} - \frac{a(T)}{V(V+b_0)} (8.16-9)

where

V = \frac{1}{\rho}, \; \; a(T) = a_0\left(\frac{T_c}{T}\right)^n, \; \; a_0 = 0.42747 \frac{R^2T_{c}^{2}}{p_c},


b_0 = 0.08664 \frac{RT_c}{p_c}, \; \; c_0 = \frac{RT_c}{p_c+\frac{a_0}{V_c(V_c+b_0)}}+b_0-V_c, \; \; \tilde{b} = b_0-c_0

Since the real gas model in FLUENT requires a function for density as a function of pressure and temperature, Equation  8.16-9 must be solved for the specific volume (from which the density can be easily obtained). For convenience, Equation  8.16-9 can be written as a cubic equation for specific volume as follows:


 V^{3} +a_1V^{2} +a_2V + a_3 = 0 (8.16-10)

where

a_1 = c_0 - \frac{RT}{p}, \;\; a_2 = -\left(\tilde{b}b_0 + \f... ... \frac{a(T)}{p}\right), \;\; a_3 = -\frac{a(T) \; \tilde{b}}{p}

Equation  8.16-10 is solved using a standard algorithm for cubic equations (see [ 351] for details). In the UDRGM code, the cubic solution is coded to minimize the number of floating point operations. This is critical for optimal performance, since this function gets called numerous times during an iteration cycle.

It should be noted that the value of the exponent, $n$, in the function $a(T)$ will depend on the substance. A table of values can be found in [ 14] for some common substances. Alternatively, [ 14] states that values of $n$ are well correlated by the empirical equation


 n = 0.4986 + 1.1735\omega + 0.475\omega^{2} (8.16-11)

where $\omega$ is the acentric factor, defined as


 \omega = -\log \left(\frac{p_v(T)}{p_c}\right) -1.0 (8.16-12)

In the above equation, $p_v(T)$ is the saturated vapor pressure evaluated at temperature $T=0.7T_c$.

Derivatives of Specific Volume and Density

The derivatives of specific volume with respect to temperature and pressure can be easily determined from Equation  8.16-9 using implicit differentiation. The results are presented below:


$\displaystyle \left(\frac{\partial V}{\partial p}\right)_T$ $\textstyle =$ $\displaystyle -\frac{(a_1)'_p V^{2} + (a_2)'_p V + (a_3)'_p}{3V^{2} + 2a_1V +a_2}$ (8.16-13)
       
$\displaystyle \left(\frac{\partial V}{\partial T}\right)_p$ $\textstyle =$ $\displaystyle -\frac{(a_1)'_T V^{2} + (a_2)'_T V + (a_3)'_T}{3V^{2} + 2a_1V +a_2}$ (8.16-14)

where

(a_1)'_p = \frac{RT}{p^{2}}, \;\; (a_2)'_p = \frac{RTb_0-a(T)}{p^{2}}, \;\; (a_3)'_p = \frac{a(T) \; \tilde{b}}{p^{2}}


(a_1)'_T = -\frac{R}{p}, \;\; (a_2)'_T = \frac{-Rb_0 + \frac{... ... \frac{\tilde{b}}{p}, \;\; \frac{da(T)}{dT} = -n \frac{a(T)}{T}

The derivatives of density can be obtained from the above using the relations


 \left(\frac{\partial \rho}{\partial p}\right)_T = - \rho^2\left(\frac{\partial V}{\partial p}\right)_T (8.16-15)


 \left(\frac{\partial \rho}{\partial T}\right)_p = - \rho^2\left(\frac{\partial V}{\partial T}\right)_p (8.16-16)

Specific Heat and Enthalpy

Following [ 14], enthalpy for a real gas can be written


 H = H^{0}(T) + pV - RT - \frac{a(T)}{b_0}(1+n)\ln \left(\frac{V+b_0}{V}\right) (8.16-17)

where $H^{0}(T)$ is the enthalpy function for a thermally perfect gas (i.e., enthalpy is a function of temperature alone). In the present case, we employ a fourth-order polynomial for the specific heat for a thermally perfect gas [ 252]


 C_{p}^{0}(T) = C_1 + C_2T + C_3T^2 + C_4T^3 + C_5T^4 (8.16-18)

and obtain the enthalpy from the basic relation


 H^{0}(T) = \int_{T_0}^TC_{p}^0(T)dT (8.16-19)

The result is


 H^{0}(T) = C_1T + \frac{1}{2}C_2T^2 + \frac{1}{3}C_3T^3 + \frac{1}{4}C_4T^4 + \frac{1}{5}C_5T^5 - H^{0}(T^{0}) (8.16-20)

Note that $H^{0}(T^{0})$ is the enthalpy at a reference state $(p^{0},T^{0})$, which can be chosen arbitrarily.

The specific heat for the real gas can be obtained by differentiating Equation  8.16-17 with respect to temperature (at constant pressure):


 C_p = \left(\frac{\partial H}{\partial T}\right)_p (8.16-21)

The result is


 C_p = C_{p}^{0}(T) + p\left(\frac{\partial V}{\partial T}\ri... ...)\frac{\left(\frac{\partial V}{\partial T}\right)_p}{V(V+b_0)} (8.16-22)

Finally, the derivative of enthalpy with respect to pressure (at constant temperature) can be obtained using the following thermodynamic relation [ 252]:


 \left(\frac{\partial H}{\partial p}\right)_T = V-T\left(\frac{\partial V}{\partial T}\right)_p (8.16-23)

Entropy

Following [ 14], the entropy can be expressed in the form


 S = S^{0}(T,p^{0}) + R \ln \left(\frac{V-\tilde{b}}{V^{0}}\r... ...(\frac{da(T)}{dT}\right)}{b_0}\ln \left(\frac{V+b_0}{V}\right) (8.16-24)

where the superscript $0$ again refers to a reference state where the ideal gas law is applicable. For an ideal gas at a fixed reference pressure, $p^0$ , the entropy is given by


 S^{0}(T,p^{0}) = S(T^{0},p^{0}) + \int_{T^{0}}^{T}\frac{C_{p}^{0}(T)}{T}dT (8.16-25)

Note that the pressure term is zero since the entropy is evaluated at the reference pressure. Using the polynomial expression for specific heat, Equation  8.16-18, Equation  8.16-25 becomes


 S^{0}(T,p^{0}) = S(T^{0},p^{0}) + C_1\ln(T) + C_2T + \frac{1}{2}C_3T^2 + \frac{1}{3}C_4T^3 + \frac{1}{4}C_5T^4 - f(T^{0}) (8.16-26)

where $f(T^{0})$ is a constant, which can be absorbed into the reference entropy $S(T^0,p^0)$.

Speed of Sound

The speed of sound for a real gas can be determined from the thermodynamic relation


 c^2 = \left(\frac{\partial p}{\partial \rho}\right)_S = - \l... ...ght)\frac{V^{2}}{\left(\frac{\partial V}{\partial p}\right)_T} (8.16-27)

Noting that,


 C_p - C_V = - T \left( \frac{\partial V}{\partial T} \right\... ...t)^{^{^{^{2}}}} \frac{\partial p}{\partial v }\right\vert _{T} (8.16-28)

we can write the speed of sound as


 c = V \sqrt{-\left(\frac{C_p}{C_p-\Delta C}\right)\frac{1}{\left(\frac{\partial V}{\partial p}\right)_T}} (8.16-29)

Viscosity and Thermal Conductivity

The dynamic viscosity of a gas or vapor can be estimated using the following formula from [ 56]:


 \mu(T) = 6.3\times10^{7}\frac{M_w^{0.5} p^{0.6666}_c}{T^{0.1666}_c} \left(\frac{T^{1.5}_r}{T_r+0.8}\right) (8.16-30)

Here, $T_r$ is the reduced temperature


 T_r = \frac{T}{T_c} (8.16-31)

and $M_w$ is the molecular weight of the gas. This formula neglects the effect of pressure on viscosity, which usually becomes significant only at very high pressures.

Knowing the viscosity, the thermal conductivity can be estimated using the Eucken formula [ 93]:


 k = \mu\left(C_p+\frac{5}{4}R\right) (8.16-32)

It should be noted that both Equation  8.16-30 and 8.16-32 are simple relations, and therefore may not provide satisfactory values of viscosity and thermal conductivity for certain applications. You are encouraged to modify these functions in the UDRGM source code if alternate formulae are available for a given gas.

Using the Redlich-Kwong Real Gas UDRGM

Using the Redlich-Kwong Real Gas UDRGM simply requires the modification of the top block of #define macros to provide the appropriate parameters for a given substance. An example listing for CO $_2$ is given below. The parameters required are:


  MWT = Molecular weight of the substance
  PCRIT = Critical pressure (Pa)
  TCRIT = Critical temperature (K)
  ZCRIT = Critical compressibility factor
  VCRIT = Critical specific volume (m $^3$/kg)
  NRK = Exponent of $a(T)$ function
  CC1, CC2, CC3, CC4, CC5 = Coefficients of $C_p(T)$ polynomial curve fit
  P_REF = Reference pressure (Pa)
  T_REF = Reference temperature (K)

The coefficients for the ideal gas specific heat polynomial were obtained from [ 252] (coefficients for other substances are also provided in [ 252]). Once the source listing is modified, the UDRGM C code can be recompiled and loaded into FLUENT in the manner described earlier.

/* The variables below need to be set for a particular gas */

/* CO2 */

/* REAL GAS EQUATION OF STATE MODEL - BASIC VARIABLES */
/* ALL VARIABLES ARE IN SI UNITS! */

#define RGASU UNIVERSAL_GAS_CONSTANT
#define PI    3.141592654

#define MWT 44.01
#define PCRIT 7.3834e6
#define TCRIT 304.21
#define ZCRIT 0.2769
#define VCRIT 2.15517e-3
#define NRK 0.77

/* IDEAL GAS SPECIFIC HEAT CURVE FIT */

#define CC1 453.577
#define CC2 1.65014
#define CC3 -1.24814e-3
#define CC4 3.78201e-7
#define CC5 0.00

/* REFERENCE STATE */

#define P_REF  101325
#define T_REF  288.15

Redlich-Kwong Real Gas UDRGM Code Listing

/**************************************************************/
/*                                                            */
/* User-Defined Function: Redlich-Kwong Equation of State     */
/*                        for Real Gas Modeling               */
/*                                                            */
/*  Author: Frank Kelecy                                      */
/*    Date: May 2003                                          */
/* Version: 1.02                                              */
/*                                                            */
/* This implementation is completely general.                 */
/* Parameters set for CO2.                                    */
/*                                                            */
/**************************************************************/

#include "udf.h"
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"

/* The variables below need to be set for a particular gas */

/* CO2 */

/* REAL GAS EQUATION OF STATE MODEL - BASIC VARIABLES */
/* ALL VARIABLES ARE IN SI UNITS! */

#define RGASU UNIVERSAL_GAS_CONSTANT
#define PI    3.141592654

#define MWT 44.01
#define PCRIT 7.3834e6
#define TCRIT 304.21
#define ZCRIT 0.2769
#define VCRIT 2.15517e-3
#define NRK 0.77

/* IDEAL GAS SPECIFIC HEAT CURVE FIT */

#define CC1 453.577
#define CC2 1.65014
#define CC3 -1.24814e-3
#define CC4 3.78201e-7
#define CC5 0.00

/* REFERENCE STATE */

#define P_REF  101325
#define T_REF  288.15

/* OPTIONAL REFERENCE (OFFSET) VALUES FOR ENTHALPY AND ENTROPY */

#define H_REF  0.0
#define S_REF  0.0

static int  (*usersMessage)(char *,...);
static void (*usersError)(char *,...);

/* Static variables associated with Redlich-Kwong Model */

static double rgas, a0, b0, c0, bb, cp_int_ref;


DEFINE_ON_DEMAND(I_do_nothing)
{
  /* this is a dummy function to allow us */
  /* to use the compiled UDFs utility     */
}


/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_error                                      */
/*------------------------------------------------------------*/

void RKEOS_error(int err, char *f, char *msg)
{
  if (err)
     usersError("RKEOS_error (%d) from function: %s\n%s\n",err,f,msg);
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_Setup                                      */
/*------------------------------------------------------------*/

void RKEOS_Setup(Domain *domain, char *filename,
                 void (*messagefunc)(char *format, ...),
                 void (*errorfunc)(char *format, ...))
{

   rgas = RGASU/MWT;
   a0 = 0.42747*rgas*rgas*TCRIT*TCRIT/PCRIT;
   b0 = 0.08664*rgas*TCRIT/PCRIT;
   c0 = rgas*TCRIT/(PCRIT+a0/(VCRIT*(VCRIT+b0)))+b0-VCRIT;
   bb = b0-c0;
   cp_int_ref = CC1*log(T_REF)+T_REF*(CC2+
              T_REF*(0.5*CC3+T_REF*(0.333333*CC4+0.25*CC5*T_REF)));

   usersMessage = messagefunc;
   usersError = errorfunc;
   usersMessage("\nLoading Redlich-Kwong Library: %s\n", filename);
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_pressure                                   */
/*           Returns density given T and density              */
/*------------------------------------------------------------*/

double RKEOS_pressure(double temp, double density)
{
   double v = 1./density;
   double afun = a0*pow(TCRIT/temp,NRK);
   return rgas*temp/(v-bb)-afun/(v*(v+b0));
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_spvol                                      */
/*           Returns specific volume given T and P            */
/*------------------------------------------------------------*/

double RKEOS_spvol(double temp, double press)
{
   double a1,a2,a3;
   double vv,vv1,vv2,vv3;
   double qq,qq3,sqq,rr,tt,dd;
   double afun = a0*pow(TCRIT/temp,NRK);

   a1 = c0-rgas*temp/press;
   a2 = -(bb*b0+rgas*temp*b0/press-afun/press);
   a3 = -afun*bb/press;

   /* Solve cubic equation for specific volume */

   qq = (a1*a1-3.*a2)/9.;
   rr = (2*a1*a1*a1-9.*a1*a2+27.*a3)/54.;
   qq3 = qq*qq*qq;
   dd = qq3-rr*rr;

   /* If dd < 0, then we have one real root */
   /* If dd >= 0, then we have three roots -> choose largest root */

   if (dd < 0.) {
     tt = sqrt(-dd)+pow(fabs(rr),0.333333);
     vv = (tt+qq/tt)-a1/3.;
   } else {
     tt = acos(rr/sqrt(qq3));
     sqq = sqrt(qq);
     vv1 = -2.*sqq*cos(tt/3.)-a1/3.;
     vv2 = -2.*sqq*cos((tt+2.*PI)/3.)-a1/3.;
     vv3 = -2.*sqq*cos((tt+4.*PI)/3.)-a1/3.;
     vv = (vv1 > vv2) ? vv1 : vv2;
     vv = (vv > vv3) ? vv : vv3;
   }

   return vv;
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_density                                    */
/*           Returns density given T and P                    */
/*------------------------------------------------------------*/

double RKEOS_density(double temp, double press, double yi[])
{
   return 1./RKEOS_spvol(temp, press); /* (Kg/m3) */
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_dvdp                                       */
/*           Returns dv/dp given T and rho                    */
/*------------------------------------------------------------*/

double RKEOS_dvdp(double temp, double density)
{
   double a1,a2,a1p,a2p,a3p,v,press;
   double afun = a0*pow(TCRIT/temp,NRK);

   press = RKEOS_pressure(temp, density);
   v = 1./density;

   a1 = c0-rgas*temp/press;
   a2 = -(bb*b0+rgas*temp*b0/press-afun/press);
   a1p = rgas*temp/(press*press);
   a2p = a1p*b0-afun/(press*press);
   a3p = afun*bb/(press*press);

   return -(a3p+v*(a2p+v*a1p))/(a2+v*(2.*a1+3.*v));
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_dvdt                                       */
/*           Returns dv/dT given T and rho                    */
/*------------------------------------------------------------*/

double RKEOS_dvdt(double temp, double density)
{
   double a1,a2,dadt,a1t,a2t,a3t,v,press;
   double afun = a0*pow(TCRIT/temp,NRK);

   press = RKEOS_pressure(temp, density);
   v = 1./density;

   dadt = -NRK*afun/temp;
   a1 = c0-rgas*temp/press;
   a2 = -(bb*b0+rgas*temp*b0/press-afun/press);
   a1t = -rgas/press;
   a2t = a1t*b0+dadt/press;
   a3t = -dadt*bb/press;

   return -(a3t+v*(a2t+v*a1t))/(a2+v*(2.*a1+3.*v));
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_Cp_ideal_gas                               */
/*           Returns ideal gas specific heat given T          */
/*------------------------------------------------------------*/

double RKEOS_Cp_ideal_gas(double temp)
{
   return (CC1+temp*(CC2+temp*(CC3+temp*(CC4+temp*CC5))));
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_H_ideal_gas                                */
/*           Returns ideal gas specific enthalpy given T      */
/*------------------------------------------------------------*/

double RKEOS_H_ideal_gas(double temp)
{
   return temp*(CC1+temp*(0.5*CC2+temp*(0.333333*CC3+
               temp*(0.25*CC4+temp*0.2*CC5))));
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_specific_heat                              */
/*           Returns specific heat given T and rho            */
/*------------------------------------------------------------*/

double RKEOS_specific_heat(double temp, double density, double yi[])
{
   double delta_Cp,press,v,dvdt,dadt;
   double afun = a0*pow(TCRIT/temp,NRK);

   press = RKEOS_pressure(temp, density);
   v = 1./density;
   dvdt = RKEOS_dvdt(temp, density);
   dadt = -NRK*afun/temp;
   delta_Cp = press*dvdt-rgas-dadt*(1.+NRK)/b0*log((v+b0)/v)
            + afun*(1.+NRK)*dvdt/(v*(v+b0));

   return RKEOS_Cp_ideal_gas(temp)+delta_Cp;  /* (J/Kg-K) */
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_enthalpy                                   */
/*           Returns specific enthalpy given T and rho        */
/*------------------------------------------------------------*/

double RKEOS_enthalpy(double temp, double density, double yi[])
{
   double delta_h ,press, v;
   double afun = a0*pow(TCRIT/temp,NRK);

   press = RKEOS_pressure(temp, density);
   v = 1./density;
   delta_h = press*v-rgas*temp-afun*(1+NRK)/b0*log((v+b0)/v);

   return H_REF+RKEOS_H_ideal_gas(temp)+delta_h;  /* (J/Kg) */
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_entropy                                    */
/*           Returns entropy given T and rho                  */
/*------------------------------------------------------------*/

double RKEOS_entropy(double temp, double density, double yi[])
{
   double delta_s,v,v0,dadt,cp_integral;
   double afun = a0*pow(TCRIT/temp,NRK);

   cp_integral = CC1*log(temp)+temp*(CC2+temp*(0.5*CC3+
                 temp*(0.333333*CC4+0.25*CC5*temp)))
                 - cp_int_ref;
   v = 1./density;
   v0 = rgas*temp/P_REF;
   dadt = -NRK*afun/temp;
   delta_s = rgas*log((v-bb)/v0)+dadt/b0*log((v+b0)/v);

   return S_REF+cp_integral+delta_s; /* (J/Kg-K) */
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_mw                                         */
/*           Returns molecular weight                         */
/*------------------------------------------------------------*/

double RKEOS_mw(double yi[])
{
   return MWT; /* (Kg/Kmol) */
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_speed_of_sound                             */
/*           Returns s.o.s given T and rho                    */
/*------------------------------------------------------------*/

double RKEOS_speed_of_sound(double temp, double density, double yi[])
{
   double cp = RKEOS_specific_heat(temp, density, yi);
   double dvdt = RKEOS_dvdt(temp, density);
   double dvdp = RKEOS_dvdp(temp, density);
   double v = 1./density;
   double delta_c = -temp*dvdt*dvdt/dvdp;

   return sqrt(cp/((delta_c-cp)*dvdp))*v;  /* m/s */
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_rho_t                                      */
/*------------------------------------------------------------*/

double RKEOS_rho_t(double temp, double density, double yi[])
{
   return -density*density*RKEOS_dvdt(temp, density);
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_rho_p                                      */
/*------------------------------------------------------------*/

double RKEOS_rho_p(double temp, double density, double yi[])
{
   return -density*density*RKEOS_dvdp(temp, density);
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_enthalpy_t                                 */
/*------------------------------------------------------------*/

double RKEOS_enthalpy_t(double temp, double density, double yi[])
{
   return RKEOS_specific_heat(temp, density, yi);
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_enthalpy_p                                 */
/*------------------------------------------------------------*/

double RKEOS_enthalpy_p(double temp, double density, double yi[])
{
   double v = 1./density;
   double dvdt = RKEOS_dvdt(temp, density);

   return v-temp*dvdt;
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_viscosity                                  */
/*------------------------------------------------------------*/

double RKEOS_viscosity(double temp, double density, double yi[])
{
   double mu,tr,tc,pcatm;

   tr = temp/TCRIT;
   tc = TCRIT;
   pcatm = PCRIT/101325.;

   mu = 6.3e-7*sqrt(MWT)*pow(pcatm,0.6666)/pow(tc,0.16666)*
        (pow(tr,1.5)/(tr+0.8));

   return mu;
}

/*------------------------------------------------------------*/
/* FUNCTION: RKEOS_thermal_conductivity                       */
/*------------------------------------------------------------*/

double RKEOS_thermal_conductivity(double temp, double density, double yi[])
{
   double cp, mu;

   cp = RKEOS_Cp_ideal_gas(temp);
   mu = RKEOS_viscosity(temp, density, yi);

   return (cp+1.25*rgas)*mu;
}

/* Export Real Gas Functions to Solver */

UDF_EXPORT RGAS_Functions RealGasFunctionList =
{
   RKEOS_Setup,                 /* initialize           */
   RKEOS_density,               /* density              */
   RKEOS_enthalpy,              /* enthalpy             */
   RKEOS_entropy,               /* entropy              */
   RKEOS_specific_heat,         /* specific_heat        */
   RKEOS_mw,                    /* molecular_weight     */
   RKEOS_speed_of_sound,        /* speed_of_sound       */
   RKEOS_viscosity,             /* viscosity            */
   RKEOS_thermal_conductivity,  /* thermal_conductivity */
   RKEOS_rho_t,                 /* drho/dT |const p     */
   RKEOS_rho_p,                 /* drho/dp |const T     */
   RKEOS_enthalpy_t,            /* dh/dT |const p       */
   RKEOS_enthalpy_p             /* dh/dp |const T       */
};



UDRGM Example: Multiple-Species Real Gas Model


This is a simple example for multiple-species real gas model that provide you with a template which you can use to write a more complex multiple-species UDRGM.

In this example a fluid material is defined in the setup function as a mixture of four species (H20, N2, O2, CO2). The equation of state was the simple ideal gas equation of state. The other thermodynamic properties where defined by an ideal-gas mixing law.

Other auxiliary functions are written to provide individual species property to the principle function set.

The example also provide numerical method of computing $\frac{d\rho}{dT}$, $\frac{d\rho}{dp}$, $\frac{dh}{dT}$, and $\frac{dh}{dp}$ .

/* 
 *sccs id: @(#)real_ideal.c	1.10 Copyright 1900/11/09 Fluent Inc.
 */

/*
 *      Copyright 1988-1998 Fluent Inc.
 *      All Rights Reserved
 *
 *      This is unpublished proprietary source code of Fluent Inc.
 *      It is protected by U.S. copyright law as an unpublished work
 *      and is furnished pursuant to a written license agreement.  It
 *      is considered by Fluent to be confidential and may not be
 *      used, copied, or disclosed to others except in accordance with
 *      the terms and conditions of the license agreement.
 */


/*
 *   NT Warning!!!  Including udf.h is for getting definitions for
 *                  Fluent constructs such as Domain.   You must NOT
 *                  reference any Fluent globals directly from within
 *                  this module nor link this against any Fluent libs,
 *                  doing so will cause dependancies on a specific 
 *                  Fluent binary such as fl551.exe and thus won't
 *                  be version-independent.
 */

#include "udf.h"
#include "stdio.h"
#include "ctype.h"
#include "stdarg.h"

#if RP_DOUBLE
#define SMALL 1.e-20
#else
#define SMALL 1.e-10
#endif

#define NCMAX 20
#define NSPECIE_NAME 80 


static int  (*usersMessage)(char *,...);
static void (*usersError)(char *,...);


static double ref_p, ref_T;
static char   gas[NCMAX][NSPECIE_NAME];
static int    n_specs;

double Mixture_Rgas(double yi[]);
double Mixture_pressure(double Temp, double Rho, double yi[]);
double Mw_i(int i);
double Cp_i(double T, double r, int i);
double K_i(double T, double r, int i);
double Mu_i(double T, double r, int i);
double Rgas_i(double T, double r, int i);
double Gm_i(double T, double r, int i);


DEFINE_ON_DEMAND(I_do_nothing)
{
  /*
    This is a dummy function
    must be included to allow for the use of the
    Fluent UDF compilation utility
  */
}

void Mixture_error(int err, char *f, char *msg)
{
  if (err) 
    usersError("Mixture_error (%d) from function: %s\n%s\n",err,f,msg);
}

/*******************************************************************/
/* Mixture Functions                                               */ 
/* These are the only functions called from Fluent Code            */ 
/*******************************************************************/
void MIXTURE_Setup(Domain *domain, char *specielist,
                   int  (*messagefunc)(char *format, ...),
                   void (*errorfunc)(char *format, ...))
{
  /* This function will be called from Fluent after the
     UDF library has been loaded.
     User must enter the number of species in the mixture
     and the name of the individual species.
  */
  
  int i ;
  usersMessage = messagefunc;
  usersError   = errorfunc;
  ref_p        = ABS_P(RP_Get_Real("reference-pressure"),op_pres);
  ref_T        = RP_Get_Real("reference-temperature");

  if (ref_p == 0.0)
    {
      Message0("\n MIXTURE_Setup: reference-pressure was not set by user \n");
      Message0("\n MIXTURE_Setup: setting reference-pressur to 101325 Pa \n");
      ref_p = 101325.0 ;
    }
  /*====================================================*/
  /*=========   User Input Section =====================*/
  /*====================================================*/
  /*
    Define Number of species & Species name.
    DO NOT use space for naming species
  */
  n_specs = 4 ;     

  (void)strcpy(gas[0],"H2O") ; 
  (void)strcpy(gas[1],"N2")  ; 
  (void)strcpy(gas[2],"O2")  ; 
  (void)strcpy(gas[3],"CO2") ;

  /*====================================================*/
  /*=========   End Of User Input Section ==============*/
  /*====================================================*/

  Message0("\n MIXTURE_Setup: RealGas mixture initialization \n");
  Message0("\n MIXTURE_Setup: Number of Species = %d  \n",n_specs);
  for (i=0; i<n_specs; ++i)
    {      
      Message0("\n MIXTURE_Setup: Specie[%d]         = %s  \n",i,gas[i]);
    }

  /*
    concatenate species name into one string
    and send back to fluent
  */
  strcat(specielist,gas[0]);
  for (i=1; i<n_specs; ++i)
    {
      strcat(specielist," ");
      strcat(specielist,gas[i]);
    }
}

double MIXTURE_density(double Temp, double P, double yi[])
{
  double Rgas =  Mixture_Rgas(yi) ;
  
  double r    =  P/(Rgas*Temp);	/* Density at Temp & P */

  return r;			/* (Kg/m^3) */
}

double MIXTURE_specific_heat(double Temp, double density, double yi[])
{
  double cp=0.0 ;
  int i ;
    
  for (i=0; i<n_specs; ++i)
    cp += yi[i]*Cp_i(Temp,density,i);
  
  return cp;			/* (J/Kg/K) */
}

double MIXTURE_enthalpy(double Temp, double density, double yi[])
{
  double h=0.0;
  int i ;

  for (i=0; i<n_specs; ++i)
    h  += yi[i]*(Temp*Cp_i(Temp,density,i));
  
  return h;			/* (J/Kg) */
}

double MIXTURE_entropy(double Temp, double density, double yi[])
{
  double s   = 0.0   ;
  double Rgas=0.0 ;

  Rgas = Mixture_Rgas(yi);
  
  s    = MIXTURE_specific_heat(Temp,density,yi)*log(Temp/ref_T) -
         Rgas*log(density*Rgas*Temp/ref_p) ;

  return s;			/* (J/Kg/K) */
}

double MIXTURE_mw(double yi[])
{
  double MW, sum=0.0 ;
  int i ;

  for (i=0; i<n_specs; ++i)
    sum += (yi[i]/Mw_i(i)) ;

  MW = 1.0/MAX(sum,SMALL)      ;
  
  return MW;			/* (Kg/Kmol) */
}

double MIXTURE_speed_of_sound(double Temp, double density, double yi[])
{
  double a, cp, Rgas ;
  
  cp   = MIXTURE_specific_heat(Temp,density,yi) ;
  Rgas = Mixture_Rgas(yi) ;


  a    = sqrt(Rgas*Temp* cp/(cp-Rgas) ) ;

  return a ;  /* m/s */
}

double MIXTURE_viscosity(double Temp, double density, double yi[])
{
  double mu=0;
  int i ;

  for (i=0; i<n_specs; ++i)
    mu += yi[i]*Mu_i(Temp,density,i);

  return mu;			/* (Kg/m/s) */
}

double MIXTURE_thermal_conductivity(double Temp, double density, double yi[])
{
  double kt=0;
  int i ;

  for (i=0; i<n_specs; ++i)
    kt += yi[i]*K_i(Temp,density,i);
  
  return kt;			/* W/m/K */
}

double MIXTURE_rho_t(double Temp, double density, double yi[])
{

  double drdT   ;	/* derivative of rho wrt. Temp */
  double p      ;
  double dT=0.01;

  p     = Mixture_pressure(Temp,density, yi);
  drdT  = (MIXTURE_density(Temp+dT,p,yi) - MIXTURE_density(Temp,p,yi) ) /dT;

  return drdT;			/* (Kg/m^3/K) */
}

double MIXTURE_rho_p(double Temp, double density, double yi[])
{
  double drdp    ;
  double p       ;
  double dp= 5.0 ;
  
  p     = Mixture_pressure(Temp,density, yi);
  drdp = (MIXTURE_density(Temp,p+dp,yi) - MIXTURE_density(Temp,p,yi) ) /dp;
  
  return drdp;			/* (Kg/m^3/Pa) */
}

double MIXTURE_enthalpy_t(double Temp, double density, double yi[])
{
  double dhdT     ;
  double p        ;
  double rho2     ;
  double dT= 0.01 ;

  p     = Mixture_pressure(Temp,density, yi);
  rho2  = MIXTURE_density(Temp+dT,p,yi)     ;

  dhdT  = (MIXTURE_enthalpy(Temp+dT,rho2,yi) - MIXTURE_enthalpy(Temp,density,yi)) /dT ;
    
 
  return dhdT ; /* J/(Kg.K) */
}

double MIXTURE_enthalpy_p(double Temp, double density, double yi[])
{
  double dhdp     ;
  double p        ;
  double rho2     ;
  double dp= 5.0  ;

  p     = Mixture_pressure(Temp,density, yi);
  rho2  = MIXTURE_density(Temp,p+dp,yi)     ;

  dhdp  = (MIXTURE_enthalpy(Temp,rho2,yi) - MIXTURE_enthalpy(Temp,density,yi)) /dp;


  return dhdp ;  /* J/ (Kg.Pascal) */ 
}


/*******************************************************************/
/* Auxiliary Mixture Functions                                      */
/*******************************************************************/


double Mixture_Rgas(double yi[])
{
  double Rgas=0.0 ;
  int i ;

  for (i=0; i<n_specs; ++i)
    Rgas += yi[i]*(UNIVERSAL_GAS_CONSTANT/Mw_i(i)) ;
  
  return Rgas ; 
}

double Mixture_pressure(double Temp, double Rho, double yi[])
{
  double Rgas =  Mixture_Rgas(yi) ;
  
  double P    =  Rho*Rgas*Temp    ;  /* Pressure at Temp & P */

  return P;			/* (Kg/m^3) */
}




/*******************************************************************/
/* Species Property Functions                                      */ 
/*******************************************************************/
double Mw_i(int i)
{
  double mi[20];

  mi[0] = 18.01534 ; /*H2O*/
  mi[1] = 28.01340 ; /*N2 */
  mi[2] = 31.99880 ; /*O2 */
  mi[3] = 44.00995 ; /*CO2*/
  
  return mi[i] ;
}

double Cp_i(double T, double r, int i)
{
  double cpi[20] ;
  
  cpi[0] = 2014.00 ; /*H2O*/
  cpi[1] = 1040.67 ; /*N2 */
  cpi[2] =  919.31 ; /*O2 */
  cpi[3] =  840.37 ; /*CO2*/

  return cpi[i] ;
}

double K_i(double T, double r, int i)
{
  double ki[20] ;
  
  ki[0] = 0.02610 ; /*H2O*/
  ki[1] = 0.02420 ; /*N2 */
  ki[2] = 0.02460 ; /*O2 */
  ki[3] = 0.01450 ; /*CO2*/

  return ki[i] ;
}

double Mu_i(double T, double r, int i)
{
  double mui[20] ;
  
  mui[0] = 1.340E-05 ; /*H2O*/
  mui[1] = 1.663E-05 ; /*N2 */
  mui[2] = 1.919E-05 ; /*O2 */
  mui[3] = 1.370E-05 ; /*CO2*/

  return mui[i] ;
}

double Rgas_i(double T, double r, int i)
{
  double Rgasi ;

  Rgasi =  UNIVERSAL_GAS_CONSTANT/Mw_i(i) ;
  
  return Rgasi ;  
}

double Gm_i(double T, double r, int i)
{
  double gammai ;

  gammai =  Cp_i(T,r,i)/(Cp_i(T,r,i) - Rgas_i(T,r,i));
  
  return gammai ;
  
}



/*******************************************************************/
/* Mixture Functions Structure                                     */ 
/*******************************************************************/
UDF_EXPORT RGAS_Functions RealGasFunctionList = 
{
  MIXTURE_Setup,			/* initialize		  */
  MIXTURE_density,       		/* density	       	  */
  MIXTURE_enthalpy,		        /* enthalpy  		  */
  MIXTURE_entropy,		        /* entropy  		  */
  MIXTURE_specific_heat,		/* specific_heat	  */
  MIXTURE_mw,		        	/* molecular_weight  	  */
  MIXTURE_speed_of_sound,		/* speed_of_sound  	  */
  MIXTURE_viscosity,		        /* viscosity		  */
  MIXTURE_thermal_conductivity,	        /* thermal_conductivity	  */
  MIXTURE_rho_t,			/* drho/dT |const p 	  */
  MIXTURE_rho_p,			/* drho/dp |const T 	  */
  MIXTURE_enthalpy_t,	        	/* dh/dT |const p 	  */
  MIXTURE_enthalpy_p		        /* dh/dp |const T 	  */
};

/*******************************************************************/
/*******************************************************************/


next up previous contents index Previous: 8.16.1 The NIST Real
Up: 8.16 Real Gas Models
Next: 9. Modeling Basic Fluid
© Fluent Inc. 2006-09-20