CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   define_het_rxn_rate (http://www.cfd-online.com/Forums/fluent-udf/73152-define_het_rxn_rate.html)

 coalgas February 28, 2010 23:02

define_het_rxn_rate

Hello Everyone,
Anybody has any experience with macro "define_het_rxn_rate"?
for writing heterogeneous reaction rate for multiphase model.
I have some problems to understand few things.
any help will be appreciated .
Thanks
chetan

 mighelone March 2, 2010 04:33

Quote:
 Originally Posted by coalgas (Post 247837) Hello Everyone, Anybody has any experience with macro "define_het_rxn_rate"? for writing heterogeneous reaction rate for multiphase model. I have some problems to understand few things. any help will be appreciated . Thanks chetan
I have a little experience on writing multiphase udf, what kind of problem do you have?

 coalgas March 2, 2010 08:59

Thanks Michele,
I am trying to model, char gasification in 'packed bed' with Eulerian Granular model. While defining phase interaction reaction between phases, i need to write a UDF with macro "DEFINE_HET_RXN_RATE" to return heterogeneous reaction rate. I have a simple reaction with C+0.5O2->CO. And i wish to use random pore model which is rr=kp*(1-x)*sqrt[(1-x)*const] where x is carbon conversion. And Kp is reaction rate constant which is given as kp= A*exp(-E/RT)*Po2^n where is reaction order Po2 is partial pressure of Oxygen. If we know A, E, T, Po2, n and const we can calculate kp. Now only problem is about x. To calculate x, rr UDF is required, i did that but whenever i run my model, solver diverges. I want to confirm whether my UDF has problem or i need to refine my model by changing boundary conditions and parameters?

 mighelone March 2, 2010 09:22

coalgas,

I have the same problem of divergence, using eulerian-eulerian multiphase model with reaction defined by udf.

Have you tried to debug your udf printing the value of the variables inside the fuction, using the command Message.

However, multiphase problems give a lot of convergence problem. Are you considering time-dependant simulations? It could help your convergence.

At the moment I leave Fluent and I'm using another CFD code to perform coal gasification fixed bed simulation, MFIX.

 coalgas March 2, 2010 09:38

Thanks Michele,

Yes, its time dependent flow simulation. well, can you please elaborate on debugging udf by printing the value of the variables inside the fuction, using the command Message. How can i perform debugging?

Thanks again and regards
Chetan

 mighelone March 2, 2010 09:59

You can define at the beginning of tour udf file the following pre-processor command:

Code:

`#define DEBUG TRUE`
and inside the DEFINE_HET_RATE macro:

Code:

```#if DEBUG Message("x=%f\n",x); #endif```
in this way, when you enable the DEBUG with the key TRUE, every time the value of the varibale x is printed in fluent and you can verify if everything is ok.

 prishor March 4, 2013 12:08

access violation

hi everyone,

i am using a udf using macro define_het_rxn_rate for the phase interaction in heterogeneous reaction for multiphase grannular flow in fluidized bed gasifier.
i have compiled and loaded udfs in fluent 12. but after initializing it shows some error given below
Error:
1. Note exact events leading to error.
2. Save case/data under new name.
3. Exit program and restart to continue.
Error Object: #f
can anyone tell me what is the problem
one of my udf code is given below
/*for the reaction C+H2O --> CO+H2*/

#include "udf.h"

static const real Arrhenius = 200;
static const real E_Activation = 6000;
#define SMALL_S 1.e-29

DEFINE_HET_RXN_RATE(heterogeneous2,c,t,hr,mw,yi,rr ,rr_t)
{
Domain **domain_reactant = hr->domain_reactant;
real *stoich_reactant = hr->stoich_reactant;
int *reactant = hr->reactant;
int i;
int sp_id;
int dindex;
real ci;
real T = C_T(c,t); /* should obtain from cell */

/* instead of compute rr directly, compute log(rr) and then
take exp */

*rr = 0;
for (i=0; i < hr->n_reactants; i++)
{
sp_id = reactant[i]; /* species ID to access mw and yi */

if (sp_id == -1) sp_id = 0; /* if phase does not have species,
mw, etc. will be stored at index 0 */

dindex = DOMAIN_INDEX(domain_reactant[i]);
/* domain index to access mw & yi */

/* get conc. */
ci = yi[dindex][sp_id]*C_R(c,t_reactant)/mw[dindex][sp_id];

ci = MAX(ci,SMALL_S);

*rr += stoich_reactant[i]*log(ci);
}

*rr += log(Arrhenius + SMALL_S) -
(E_Activation/T);

/* 1.e-40 < rr < 1.e40 */
*rr = MAX(*rr,-40);
*rr = MIN(*rr,40);

*rr = exp(*rr);
}

thanks and regards,
prishor p k

 thanhndb September 13, 2013 00:26

Quote:
 Originally Posted by mighelone (Post 248054) I have a little experience on writing multiphase udf, what kind of problem do you have?
Dear Chetan,

I am also trying a simulation with a heterogeneous reaction using Eulerian-granular model in Fluent. The reaction is CaSO4(s) + 4H2(g) -> CaS(s) + 4H2O(g). I used a shrinking-core mode where the reaction rate is rr=const*k*pH2 where k =A*exp(-E/RT) and pH2 is partial pressure of H2.
To create the materials for the simulation for the gas phase I use species transport mode where this gas phase consists of H2, H2O and N2. The solid phase is only CaSO4 (of course it is defined from a fluid material). To account for the heterogeneous reaction between the two phase I used a UDF.

I wrote a UDF for DEFINE_HET_RXN_RATE with the content:

/*Heterogeneous net reaction*/

# include "udf.h"
//# include "mem.h"
//# include "sg_mphase.h"
# define FLUID_ZONE_ID 2 /*Zone ID of Reaction*/
# define R 8.31434 /*Gas Constant J/mol-K*/
# define Pre 4.3e3 /*Pre-exponential factor, 1/s-kPa*/
# define E1 151e5 /*Activation Energy, J/mol*/
# define rho_caso4 21.74 /*Molar density of CaSO4, kgmol/m3*/
DEFINE_HET_RXN_RATE(het_rxn_rate,c,t,r,mw,yi,rr,rr _t)
{
//int zone_id;
real T_SEC = C_T(c,sec_t); /*Phase secondary temperature, K*/
real P = C_P(c,prim_t)/1000; /*Static pressure of the primary phase, kPa*/
real y_h2 = C_YI(c,prim_t,0); /*Mass fraction of gas species in primary phase*/
real y_h2o = C_YI(c,prim_t,1);
real y_n2 = C_YI(c,prim_t,2);
real Nsum;
y_h2 *= 1/mw[0][0];
y_h2o *= 1/mw[0][1];
y_n2 *= 1/mw[0][2];
Nsum = y_h2 + y_h2o + y_n2;
y_h2 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_n2 *= 1/Nsum;

*rr = rho_caso4*P*y_h2*Pre*exp(-E1/(R*T_SEC));
}

The UDF was compiled successfully however it seems not work even I did setup the reaction in Phases>Interactions...>Reaction tab.

I know you have experience on CFD simulation of mutiphase reaction. Could you tell me what is wrong with my simulation and how can I solve it.

Thank you very much in advance and I am looking forward to hearing from you.

Thanh

 thanhndb September 13, 2013 00:30

Quote:
 Originally Posted by coalgas (Post 248116) Thanks Michele, I am trying to model, char gasification in 'packed bed' with Eulerian Granular model. While defining phase interaction reaction between phases, i need to write a UDF with macro "DEFINE_HET_RXN_RATE" to return heterogeneous reaction rate. I have a simple reaction with C+0.5O2->CO. And i wish to use random pore model which is rr=kp*(1-x)*sqrt[(1-x)*const] where x is carbon conversion. And Kp is reaction rate constant which is given as kp= A*exp(-E/RT)*Po2^n where is reaction order Po2 is partial pressure of Oxygen. If we know A, E, T, Po2, n and const we can calculate kp. Now only problem is about x. To calculate x, rr UDF is required, i did that but whenever i run my model, solver diverges. I want to confirm whether my UDF has problem or i need to refine my model by changing boundary conditions and parameters?

Dear Chetan,

I am also trying a simulation with a heterogeneous reaction using Eulerian-granular model in Fluent. The reaction is CaSO4(s) + 4H2(g) -> CaS(s) + 4H2O(g). I used a shrinking-core mode where the reaction rate is rr=const*k*pH2 where k =A*exp(-E/RT) and pH2 is partial pressure of H2.
To create the materials for the simulation for the gas phase I use species transport mode where this gas phase consists of H2, H2O and N2. The solid phase is only CaSO4 (of course it is defined from a fluid material). To account for the heterogeneous reaction between the two phase I used a UDF.

I wrote a UDF for DEFINE_HET_RXN_RATE with the content:

/*Heterogeneous net reaction*/

# include "udf.h"
//# include "mem.h"
//# include "sg_mphase.h"
# define FLUID_ZONE_ID 2 /*Zone ID of Reaction*/
# define R 8.31434 /*Gas Constant J/mol-K*/
# define Pre 4.3e3 /*Pre-exponential factor, 1/s-kPa*/
# define E1 151e5 /*Activation Energy, J/mol*/
# define rho_caso4 21.74 /*Molar density of CaSO4, kgmol/m3*/
DEFINE_HET_RXN_RATE(het_rxn_rate,c,t,r,mw,yi,rr,rr _t)
{
//int zone_id;
real T_SEC = C_T(c,sec_t); /*Phase secondary temperature, K*/
real P = C_P(c,prim_t)/1000; /*Static pressure of the primary phase, kPa*/
real y_h2 = C_YI(c,prim_t,0); /*Mass fraction of gas species in primary phase*/
real y_h2o = C_YI(c,prim_t,1);
real y_n2 = C_YI(c,prim_t,2);
real Nsum;
y_h2 *= 1/mw[0][0];
y_h2o *= 1/mw[0][1];
y_n2 *= 1/mw[0][2];
Nsum = y_h2 + y_h2o + y_n2;
y_h2 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_n2 *= 1/Nsum;

*rr = rho_caso4*P*y_h2*Pre*exp(-E1/(R*T_SEC));
}

The UDF was compiled successfully however it seems not work even I did setup the reaction in Phases>Interactions...>Reaction tab.

I know you have experience on CFD simulation of mutiphase reaction. Could you tell me what is wrong with my simulation and how can I solve it.

Thank you very much in advance and I am looking forward to hearing from you.

Thanh

 mrfive90 July 15, 2014 03:31

Quote:
 Originally Posted by thanhndb (Post 451447) Dear Chetan, I am also trying a simulation with a heterogeneous reaction using Eulerian-granular model in Fluent. The reaction is CaSO4(s) + 4H2(g) -> CaS(s) + 4H2O(g). I used a shrinking-core mode where the reaction rate is rr=const*k*pH2 where k =A*exp(-E/RT) and pH2 is partial pressure of H2. To create the materials for the simulation for the gas phase I use species transport mode where this gas phase consists of H2, H2O and N2. The solid phase is only CaSO4 (of course it is defined from a fluid material). To account for the heterogeneous reaction between the two phase I used a UDF. I wrote a UDF for DEFINE_HET_RXN_RATE with the content: /*Heterogeneous net reaction*/ # include "udf.h" //# include "mem.h" //# include "sg_mphase.h" # define FLUID_ZONE_ID 2 /*Zone ID of Reaction*/ # define R 8.31434 /*Gas Constant J/mol-K*/ # define Pre 4.3e3 /*Pre-exponential factor, 1/s-kPa*/ # define E1 151e5 /*Activation Energy, J/mol*/ # define rho_caso4 21.74 /*Molar density of CaSO4, kgmol/m3*/ DEFINE_HET_RXN_RATE(het_rxn_rate,c,t,r,mw,yi,rr,rr _t) { //int zone_id; Thread **pt = THREAD_SUB_THREADS(t); Thread *prim_t = pt[0]; /*Thread for primary Phase*/ Thread *sec_t = pt[1]; /*Thread for secondary Phase*/ real T_SEC = C_T(c,sec_t); /*Phase secondary temperature, K*/ real P = C_P(c,prim_t)/1000; /*Static pressure of the primary phase, kPa*/ real y_h2 = C_YI(c,prim_t,0); /*Mass fraction of gas species in primary phase*/ real y_h2o = C_YI(c,prim_t,1); real y_n2 = C_YI(c,prim_t,2); real Nsum; y_h2 *= 1/mw[0][0]; y_h2o *= 1/mw[0][1]; y_n2 *= 1/mw[0][2]; Nsum = y_h2 + y_h2o + y_n2; y_h2 *= 1/Nsum; y_h2o *= 1/Nsum; y_n2 *= 1/Nsum; *rr = rho_caso4*P*y_h2*Pre*exp(-E1/(R*T_SEC)); } The UDF was compiled successfully however it seems not work even I did setup the reaction in Phases>Interactions...>Reaction tab. I know you have experience on CFD simulation of mutiphase reaction. Could you tell me what is wrong with my simulation and how can I solve it. Thank you very much in advance and I am looking forward to hearing from you. Thanh
Your unit of "rr" is not consistent with kmol/(m3s),and i wonder about the molar concentration should replace ur mole fraction!gud9t!!!

 All times are GMT -4. The time now is 23:11.