

June 29, 2023 at 4:25 pmYuya.SSubscriber
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 /* Preexponential of each constant */
#define k_OH0 6.8e+7
#define k_eq0 137DEFINE_SR_RATE(methanation,f,t,r,mw,yi,rr)
{
Thread *t0 = THREAD_T0(t);cell_t c0 = F_C0(f,t);
real y_h2o = yi[0];
real y_ch4 = yi[1]; /* Species numbers that match order in ANSYS FLUENT dialog box */
real y_h2 = yi[2];
real y_co2 = yi[3];y_h2o *= 1/mw[0];
y_ch4 *= 1/mw[1];
y_h2 *= 1/mw[2];
y_co2 *= 1/mw[3];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 */
if (FLUID_THREAD_P(t) && THREAD_VAR(t).fluid.porous)
*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.
===============================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= RANK 0 PID 2500 RUNNING AT desktop
= EXIT STATUS: 1 (ffffffff)
===============================================
===============================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= RANK 2 PID 1764 RUNNING AT desktop
= EXIT STATUS: 1 (ffffffff)
===============================================
===============================================
= BAD TERMINATION OF ONE OF YOUR APPLICATION PROCESSES
= 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.

June 30, 2023 at 1:02 pmAtharva NagarkarSubscriber
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)

June 30, 2023 at 8:17 pmYuya.SSubscriber
Thank you for your reply!
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? 
July 3, 2023 at 7:03 amYuya.SSubscriber
Here is the modified macro.
#include "udf.h"
DEFINE_SR_RATE(my_rate,f,t,r,mw,yi,rr)
{
Thread *t0=THREAD_T0(t);
cell_t c0=F_C0(f,t);
/*mass fraction of species i at the wall*/
real y_h2=yi[0];
real y_co2=yi[1];
real y_ch4=yi[2];
real y_h2o=yi[3];
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[0];
y_co2 *= 1/mw[1];
y_ch4 *= 1/mw[2];
y_h2o *= 1/mw[3];
/*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, trialanderror*/
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);
if(FLUID_THREAD_P(t) && THREAD_VAR(t).fluid.porous)
*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. 
July 3, 2023 at 9:09 amAtharva NagarkarSubscriber
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.

 You must be logged in to reply to this topic.
Boost Ansys Fluent Simulations with AWS
Computational Fluid Dynamics (CFD) helps engineers design products in which the flow of fluid components is a significant challenge. These different use cases often require large complex models to solve on a traditional workstation. Click here to join this event to learn how to leverage Ansys Fluids on the cloud, thanks to Ansys Gateway powered by AWS.
Earth Rescue – An Ansys Online Series
The climate crisis is here. But so is the human ingenuity to fight it. Earth Rescue reveals what visionary companies are doing today to engineer radical new ideas in the fight against climate change. Click here to watch the first episode.
Ansys Blog
Subscribe to the Ansys Blog to get great new content about the power of simulation delivered right to your email on a weekly basis. With content from Ansys experts, partners and customers you will learn about product development advances, thought leadership and trends and tips to better use Ansys tools. Sign up here.
 Floating point exception in Fluent
 What are the differences between CFX and Fluent?
 Heat transfer coefficient
 Difference between Kepsilon and Komega Turbulence Model
 Getting graph and tabular data from result in workbench mechanical
 The solver failed with a nonzero exit code of : 2
 Suppress Fluent to open with GUI while performing in journal file
 Mesh Interfaces in ANSYS FLUENT
 Time Step Size and Courant Number
 error: Received signal SIGSEGV

7658

4476

2957

1433

1322
© 2023 Copyright ANSYS, Inc. All rights reserved.