CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

DEFINE_SOURCE reaction

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 15, 2015, 23:59
Question DEFINE_SOURCE reaction
  #1
Member
 
Tleja
Join Date: Sep 2013
Posts: 40
Rep Power: 13
Tleja is on a distinguished road
Hello everyone!
I'm studying combustion reaction 2D. I'm really new in UDF field.

At the moment,I wrote UDF about methane combustion reaction. Species in this system consist of N2,CH4,O2,CO2,H2O.
As my UDF file, I have been trying to write UDF mass balance of each species for methane reaction.

I could interpreted my UDF to fluent ,and I hooked my UDF to mass source of each specie like this file i attached.

http://postimg.org/image/dilxz6uxh/

After that, I found the big problem that CO2 and H2O didn't generate in my system. I don't know why they didn't generate. Therefore, I also tried to simulate that system without UDF ,and then my new result was the same the old one .

How can i solve this problem?
i need to know why this new result is the same to the old one.

My reaction is shown as below:

CH4 + 2O2 ----k----> CO2 + 2H2O


where k is function of temperature according to Arhenius law.

My UDF was shown as below:
Code:
#include "udf.h"
#include "mem.h"
#include "sg_mphase.h" 
#define PreKiM 2.119e11		/*unit m^3solid/kmol.s*/
#define Ea 2.027e8		/*unit kj/kmol*/
#define R 8.31434		/*Gas Constant J/mol-K*/
#define mw_n2	28.0134		/*kg/kmol*/
#define mw_ch4	16.04303	/*kg/kmol*/
#define mw_h2o	18.01534	/*kg/kmol*/
#define mw_co2	44.00995	/*kg/kmol*/
#define mw_o2	31.9988		/*kg/kmol*/


DEFINE_SOURCE(CH4_balance,c,tp,dS,eqn) /*kg/s.m^3
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp))); /*Arhenius law*/
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=-KiM*mw_ch4*ch4*o2*o2;
	dS[eqn]=-KiM*(C_R(c,tp)/mw_ch4)*o2*o2;
	
	return source;
}
DEFINE_SOURCE(o2_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=-0.5*KiM*ch4*mw_o2*mw_o2*o2*o2;
	dS[eqn]=-*KiM*ch4*C_R(c,tp)/mw_o2;
	
	return source;
}
DEFINE_SOURCE(co2_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=KiM*mw_ch4*ch4*o2*o2;
	dS[eqn]=KiM*(C_R(c,tp)/mw_ch4)*o2*o2;
	
	return source;
}
DEFINE_SOURCE(h2o_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=0.5*KiM*ch4*mw_o2*mw_o2*o2*o2;
	dS[eqn]=KiM*ch4*C_R(c,tp)/mw_o2;
	
	return source;
}
Please help me!! i have had this problem for many week.
Best regard
Tleja

Last edited by Tleja; April 4, 2015 at 02:34.
Tleja is offline   Reply With Quote

Old   March 16, 2015, 00:36
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Have you checked all the units and orders of magnitudes in those equations? Perhaps try setting a large arbitrary constant for the source terms to check if these UDFs are sending anything to the solver. If CO2 and H2O is then formed, perhaps the interaction is over a very long time frame (longer than you're currently running the simulations for), or the equations are incorrect. Also, try compiling the UDF instead of interpreting the source files.
`e` is offline   Reply With Quote

Old   March 16, 2015, 05:31
Default
  #3
Member
 
Tleja
Join Date: Sep 2013
Posts: 40
Rep Power: 13
Tleja is on a distinguished road
Thank you for your response,'e'

I already tried to simulate this system by using the same kinetic parameter in volume species transport reaction model without UDF. And, i could get the result from volume species transport reaction model.

As my reaction, I simulated that system in steady-state approach. I guess if reaction is work, Product(H2O,CO2) should generate at least.

According to your mention about increasing kinetic parameter, i already increased PreKiM from 2.119e11 to 2.119e20, the product didn't generate yet.

I could interpreted this UDF code but i couldn't compile this code yet.

When i compile, the error massage show as below

Quote:
Error at Node 0: The UDF library you are trying to load (libudf) is not compiled for parallel use on the current platform (win64).

The system cannot find the file specified.
In my condition, I have no idea how i should do next.
Please give me some idea

Best regard
Tleja
Tleja is offline   Reply With Quote

Old   March 16, 2015, 05:47
Default
  #4
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
The first thing is to ensure that Fluent can compile the UDF because if it can't, perhaps interpreting the UDF isn't doing much either. Have a read of the Fluent FAQ on compilers, I'm assuming you can't compile other UDFs either.
`e` is offline   Reply With Quote

Old   March 17, 2015, 23:20
Default
  #5
Member
 
Tleja
Join Date: Sep 2013
Posts: 40
Rep Power: 13
Tleja is on a distinguished road
Hi 'e'

I saw your advice. I tried to compile my UDF file to fluent

At the moment, I have been able to compile my UDF to fluent. But my product(CO2,H2O) didn't generate yet. I don't know where the problem is

Please give me some idea

Best regard
Tleja
Tleja is offline   Reply With Quote

Old   April 2, 2015, 13:26
Default
  #6
Member
 
Tleja
Join Date: Sep 2013
Posts: 40
Rep Power: 13
Tleja is on a distinguished road
Hi !!

According to my last response, I have solved compiling problem.
At the moment, I can solve the last problem that is my product didn't generate by adjusting temperature at feed inlet from 300 to 1000. The product can little generate.

Actually, the real system shouldn't operate at this temperature i defined.
I think i should include energy source (heat of reaction) UDF to this case.

In my understanding,
Heat of reaction = rate of reaction*(summation Enthalpy of product- summation enthalpy of reactant)

I have been trying to write UDF. But, It didn't work yet.
My product generation don't make sense like this
http://postimg.org/image/99rsab0lv

I tried to operate this reaction by using the built-in volumetric reaction feature in fluent.
The product generation is ok like this
http://postimg.org/image/mtzp2keft

I think if my source UDF file is work, it should be similar to another one.
I have no idea why the result from my UDF source is totally different to using the built-in volumetric reaction feature.

The last UDF version is shown as below:
Code:
#include "udf.h"
#include "mem.h"
#include "sg_mphase.h" 
#define PreKiM 2.119e11	/*unit m^3solid/kmol.s*/
#define Ea 2.027e8	/*unit kj/kmol*/
#define R 8.31434	/*Gas Constant J/mol-K*/
#define mw_n2	28.0134	/*kg/kmol*/
#define mw_ch4	16.04303	/*kg/kmol*/
#define mw_h2o	18.01534	/*kg/kmol*/
#define mw_co2	44.00995	/*kg/kmol*/
#define mw_o2	31.9988	/*kg/kmol*/
#define Hch4	-7.489518e4		/*kj/kmol*/
#define Ho2		0			/*kj/kmol*/
#define Hco2	-3.935324e5	/*kj/kmol*/
#define Hh2o	-2.418379e5	/*kj/kmol*/


DEFINE_SOURCE(CH4_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=-KiM*mw_ch4*ch4*o2*o2;
	dS[eqn]=-KiM*(C_R(c,tp)/mw_ch4)*o2*o2;
	
	return source;
}
DEFINE_SOURCE(o2_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=-0.5*KiM*ch4*mw_o2*mw_o2*o2*o2;
	dS[eqn]=-KiM*ch4*o2*C_R(c,tp)/mw_o2;
	
	return source;
}
DEFINE_SOURCE(co2_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=KiM*mw_ch4*ch4*o2*o2;
	dS[eqn]=0;
	
	return source;
}
DEFINE_SOURCE(h2o_balance,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	source=0.5*KiM*ch4*mw_o2*mw_o2*o2*o2;
	dS[eqn]=0;
	
	return source;
}
DEFINE_SOURCE(HXR,c,tp,dS,eqn)
{
	real source;
	real KiM;
	real delH,ch4,o2,co2,h2o;
	KiM=PreKiM*exp(-Ea/(R*C_T(c,tp)));
	ch4=C_YI(c,tp,0)*C_R(c,tp)/mw_ch4;		/*kmol/m3*/
	o2=C_YI(c,tp,1)*C_R(c,tp)/mw_o2;
	co2=C_YI(c,tp,2)*C_R(c,tp)/mw_co2;
	h2o=C_YI(c,tp,3)*C_R(c,tp)/mw_h2o;
	delH=(2*Hh2o+Hco2-Hch4);                     /*kj/kmol*/
	source=KiM*ch4*o2*o2*delH;                   /*kj/m3s*/
	dS[eqn]=0;
	return source;
}
Please help me!! i have been trying to solve this problem for many week.

Best Regard
Tleja
Tleja is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PaSR + infinite reaction rate in reactingFoam --> no reactions occurring tatu OpenFOAM Running, Solving & CFD 3 June 2, 2024 11:04
Having problems setting up surface reaction, catalyst, adsorption and desorption Juun FLUENT 12 February 8, 2017 12:03
Defining reaction rate with multiple surface reaction Fred Marias FLUENT 1 September 12, 2013 05:56
Segmentation fault in running alternateSteadyReactingFoam,why? NewKid OpenFOAM 18 January 20, 2011 17:55
chemical reaction - decompostition La S. Hyuck CFX 1 May 23, 2001 01:07


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