CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   Continuing User Defined Real Gas Model issues (

aeroman October 19, 2010 23:00

Continuing User Defined Real Gas Model issues
I am trying to model a gun blast in fluent. I am not modeling the round, rather I am patching the barrel to known internal pressure, temperature and velocity distributions. I can supply two different "materials", one to the air domain and one to the gun domain (i.e. molecular weights and Cp). My domain is a quarter section. I am interested in implementing a new equation of state (abel-nobel) and have written and successfully compiled a user defined real gas model that runs fine in serial and parallel.

The issue is that as far as I can tell I can only specify one molecular weight and Cp when using the UDRGM. So the question is, is there any way that I can specify two different molecular weights and CP's when using a UDRGM? I know it must be a possibility since examples such as this:

are not difficult to come by.

Thanks in advance for any help on this one.

Here is my UDRGM, I have just modified the real gas example given in the fluent documentation:

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

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

#define covolume 0.0010044
#define TDatum 288.15
#define PDatum 1.01325e5
#define rDatum 1.2941
#define MW 23

/* 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)+(covolume*press)); /* Density at Temp & press */
return r; /* (Kg/m^3) */

double IDEAL_specific_heat(double Temp, double density, double P, double yi[])
double cp= 1807.39;
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) */

double IDEAL_entropy(double Temp, double density, double P, double yi[])
double CV=RGAS/IDEAL_specific_heat(Temp, density, P, yi);
double gamma=IDEAL_specific_heat(Temp, density, P, yi)/CV;
double s=CV*log(fabs(Temp/TDatum))+
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 CV=RGAS/IDEAL_specific_heat(Temp, density, P, yi);
double gamma=IDEAL_specific_heat(Temp, density, P, yi)/CV;
return sqrt(Temp*RGAS*gamma)*(1.0/(1.0-(covolume*density))); /* 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=((covolume*density*density)-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-(density*covolume))*(1.0-(density*covolume)))/(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 covolume ;

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 */
/************************************************** ************/

aeroman October 21, 2010 15:13

Perhaps not the problem
It turns out that I may be attacking my problem the wrong way. Perhaps somebody can help me out with what I think will answer this question.

From the first post, I have two types of gas one is the gun gas and one is just air. So, since air is already avaiable, I made a new material called "gun_gas" which included my required cp and mw and changed the cell zone for the gun to include the new material. I then patched the gun to the pressure, temperature and velocity distributions as described.

However, it would appear that I have forced the "cell zones" associated with the gun to always be the material I have described..

So the question is now, how do I specify an initial condition in the gun that has a different cp molecular weight (gamma, R etc), pressure, temperature, and velocity distribution than in the fluid domain?

I suppose this must be similar to forcing some species of gas into the ambient, sort of like a venting tank. Yet I don't seem to be able to find any exmples of this.

aeroman October 22, 2010 15:28

Problem Solved

I'll do my usual trick and answer this question in case anybody is interested in the answer. For this you need to write a user defined multispecies real gas model (example provided in Fluent documentation). In my case, I had two species of gas. When you initialize the problem you can set the mas fraction of gas in each fluid zone that was specified in the UDRGM.

timclark11 April 29, 2015 10:56

Hi Aeroman,

I don't know if you're still active on these forums but it'd be great if you were. I'm trying to tackle almost exactly the same problem as you, I initially tried to solve it use a dynamic mesh but that proved way to computationally intensive so I've moved onto to trying to implement the same solution as you. I was just wondering if you'd be able to shed any more light on how you solved this problem? Did you work on a 64 bit system? I've been trying to compile a real gas UDF and have gotten absolutely nowhere.

aeroman April 29, 2015 20:34

Wow this was a while ago. I'm not sure "active" is the right word for it, but I still use the site primarily as a resource. I'd be happy to help if i can. I ended up getting very good results as compared to experimental data and wrote a paper and presented the results. However it was important in my case that I used both multiple species as well as dynamic adaptive meshing. This helped achieve the blast wave propagated appropriatly and that the peak pressure at the shock was not reduced due to smearing across cells. I used a high performance computing cluster for this work. I'd have to double check specifics. It may be easier if you email me to discuss.

timclark11 May 1, 2015 02:57

Cheers Aeroman I'd really appreciate it, I've sent you a pm with a little more info and my contact information

putti007 April 8, 2016 03:34

Hi Aeroman and timclark11,

i am facing the same problem can you please help me i have tried to do adaptive meshing but with no success. o can u plz sen me the details on how you tackled the problem. my mail id is-
waiting for your reply. thanking you in advance.

All times are GMT -4. The time now is 12:07.