 ## Fluids

Topics relate to Fluent, CFX, Turbogrid and more

• Yuya.S
Subscriber

Hello there.
I am a newbie who recently started simulating membrane reactors for CO2 methanation(CO2 + 4H2 → CH4 + 2H2O) in Fluent.
I would like to apply the chemical reaction rate to a 3D porous media surface. Below is the actual code I wrote by looking and copying from the UDF guide and the information I found online. This reaction rate equation requires using partial pressures of chemical species, but how to express partial pressures is unclear to me.

#include "udf.h"

#define R 8.314       /* Gas constant */
#define E_a 56000     /* Activation Energy of each constant  */
#define E_eq 158.7
#define E_OH 89000
#define k_a0 21.7     /* Pre-exponential of each constant  */
#define k_OH0 6.8e+7
#define k_eq0 137

DEFINE_SR_RATE(methanation,f,t,r,mw,yi,rr)
{

cell_t c0 = F_C0(f,t);

real y_h2o = yi;
real y_ch4 = yi;    /* Species numbers that match order in ANSYS FLUENT dialog box */
real y_h2 = yi;
real y_co2 = yi;

y_h2o *= 1/mw;
y_ch4 *= 1/mw;
y_h2 *= 1/mw;
y_co2 *= 1/mw;

real Nsum = y_h2o + y_ch4 + y_h2 + y_co2 ;

y_h2o *= 1/Nsum;
y_ch4 *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co2 *= 1/Nsum;

real T_w = F_T(f,t);

real K_a = k_a0*exp(-E_a/(R*T_w));
real K_OH = k_OH0*exp(-E_OH/(R*T_w));
real K_eq = k_eq0*pow(R*T_w, -3.998)*exp(E_eq/(R*T_w));

real TP = C_P(c0,t0);  /*Mabe this is one of the causes. I want partial pressures of species */

*rr = (K_a* pow(TP*y_h2, 0.49) * pow(TP*y_co2, 0.42) / (1 + K_OH * TP*y_h2o * pow(TP*y_h2, -0.5))) * (1 - (TP*ch4 * pow(TP*y_h2o, 2) / (pow(TP*y_h2, 4) * TP*y_co2 * K_eq)));

}

It compiles successfully, but when I start the calculation after initialization, it crashes immediately after displaying the following error.

===============================================
= RANK 0 PID 2500 RUNNING AT desktop-
= EXIT STATUS: -1 (ffffffff)
===============================================

===============================================
= RANK 2 PID 1764 RUNNING AT desktop
= EXIT STATUS: -1 (ffffffff)
===============================================

===============================================
= RANK 3 PID 11488 RUNNING AT desktop
= EXIT STATUS: -1 (ffffffff)
===============================================

I believe it is caused by the UDF, as this error disappears when I unhook the UDF. Can someone please help me? Thank you.

• Atharva Nagarkar
Subscriber

Hello

The C_P macro defines the total pressure and not the partial pressure. There is no separate variable for partial pressure. You can define the partial pressures from total pressure and species mole fraction by taking a product of the two. Mole fraction will need to be defined from the mass fraction and the molecular weight.

Here is an example from the UDF Manual for accessing molecular weights: 2.5. Discrete Phase Model (DPM) DEFINE Macros (ansys.com). Check section 2.5.6.3.

Here is a link of a similar thread related to partial pressure: Fluent – species – density – UDF (ansys.com)

If you are not able to access the link, please refer to this forum discussion: Using Help with links (ansys.com)

• Yuya.S
Subscriber

I'm probably not even expressing the mole fraction correctly, am I?
Also, is the way I define real TP = C_P(c0,t0) in the macro correct?
Am I correct in understanding that if the mole fraction of each chemical species can be defined correctly, then the partial pressure can be expressed as mole fraction * TP?

• Yuya.S
Subscriber

Here is the modified macro.

#include "udf.h"
DEFINE_SR_RATE(my_rate,f,t,r,mw,yi,rr)
{
cell_t c0=F_C0(f,t);
/*mass fraction of species i at the wall*/
real y_h2=yi;
real y_co2=yi;
real y_ch4=yi;
real y_h2o=yi;
real Nsum, R, A1, A2, E1, E2, k1, k2, Keq, T_w, TP, r1;

/*calculate species i in the unit of kmol i/kg mix*/
y_h2 *= 1/mw;
y_co2 *= 1/mw;
y_ch4 *= 1/mw;
y_h2o *= 1/mw;
/*total mole number per kg mix */
Nsum = y_h2o + y_ch4 + y_h2 + y_co2;

/*calculate mole fraction of species i in the unit of kgmol i/kgmol mix*/
y_h2o *= 1/Nsum;
y_ch4 *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co2 *= 1/Nsum;
/*gas constant, J/molK */
R=8.314;
/*equilibrium constant calculated by the empirical formula*/
T_w=F_T(f,t);

Keq=137*pow(T_w,-3.998)/exp(158.7e+3/R/T_w);
/*reaction rate constant, need to be guessed, trial-and-error*/
A1=3.47e+4, A2=6.80e+7;
E1=56.0e+3, E2=89.0e+3;          /*J/mol*/
k1=A1*exp(-E1/R/T_w);
k2=A2*exp(-E2/R/T_w);

/*total pressure in the cell near wall, bar*/
TP=C_P(c0,t0)/1.0e+5;

r1 = (k1*pow(TP*y_h2, 0.49)*pow(TP*y_co2, 0.42) / (1 + k2*TP*y_h2o*pow(TP*y_h2, -0.5)))*(1 - (TP*y_ch4*pow(TP*y_h2o, 2)) / pow(TP*y_h2, 4)*TP*y_co2 * Keq);

*rr = r1;
}

At least the error is resolved and the computation itself works correctly after hooking the UDF. However, the key products, methane and water vapor, are not produced at all. I would be happy to take advice from anyone.

• Atharva Nagarkar
Subscriber

Hello

The macro real TP is correctly defined. Your understanding is also correct that the partial pressure can be defined by the product of the appropriate mole fraction and total pressure. 