-
-
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   /* 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)
{
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 NagarkarAnsys Employee
Â
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, 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);
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 NagarkarAnsys Employee
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.
-
January 11, 2024 at 11:56 amå¼ çº¯ å¼ çº¯Subscriber
Hello, I also wrote the UD of the surface reaction, although the compilation was successful, but there is no generated, have you solved this problem now?
-
- The topic ‘UDF for surface reaction rate〈Please help a beginner〉’ is closed to new replies.
- Non-Intersected faces found for matching interface periodic-walls
- Unburnt Hydrocarbons contour in ANSYS FORTE for sector mesh
- Help: About the expression of turbulent viscosity in Realizable k-e model
- Script error Code: 800a000d
- Cyclone (Stairmand) simulation using RSM
- Fluent fails with Intel MPI protocol on 2 nodes
- error udf
- Diesel with Ammonia/Hydrogen blend combustion
- Mass Conservation Issue in Methane Pyrolysis Shock Tube Simulation
- Script Error
-
1241
-
543
-
523
-
225
-
209
© 2024 Copyright ANSYS, Inc. All rights reserved.