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

Troubles with implementing UDF into Fluent 17

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 20, 2016, 08:44
Default Troubles with implementing UDF into Fluent 17
  #1
New Member
 
Join Date: Feb 2016
Posts: 4
Rep Power: 10
flappy is on a distinguished road
Hello,

I'm new to UDFs as well as to C programming and need help for my university work. I'm working on a fixed-bed reactor model with chemical reactions (Methane Steam Reforming) in a porous zone and want to implement the kinetic model of Xu and Froment as an UDF.

I'm using Fluent 17.0 and Microsoft Visual Studio 2015 for compiling on a 64-Bit Windows 7 Enterprise System.

apparently there is a mistake in my code. Fluent tells me: received a fatal signal (segmentation fault) - which i read in other forum threads is a sign that there is a mistake in the code.

here's my code:

Quote:
/*User-defined function used in the model of steam reforming*/
#include "udf.h"
DEFINE_SR_RATE(msr,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*/
double y_co2=yi[0];
double y_n2=yi[1];
double y_co=yi[2];
double y_h2=yi[3];
double y_ch4=yi[4];
double y_h2o=yi[5];
double Nsum,R,TP,temp,k1,k2,k3,Keq1,Keq2,Keq3,K_h2,K_co,K _h2o,K_ch4,DEN,r1,r2,r3;
/*calculate species i in the unit of kgmol i/kg mix*/
y_co2 *= 1/mw[0];
y_n2 *= 1/mw[1];
y_co *= 1/mw[2];
y_h2 *= 1/mw[3];
y_ch4 *= 1/mw[4];
y_h2o *= 1/mw[5];
/*total mole number per kg mix */
Nsum = y_ch4 + y_h2o + y_h2 + y_co + y_co2 + y_n2;
/*calculate mole fraction of species i in the unit of kgmol
i/kgmol mix*/
y_ch4 *= 1/Nsum;
y_h2o *= 1/Nsum;
y_h2 *= 1/Nsum;
y_co *= 1/Nsum;
y_co2 *= 1/Nsum;
y_n2 *= 1/Nsum;
/*gas constant, J/molK */
R=8.314;
/*equilibrium constant calculated by the empirical formula*/
temp=C_T(f,t);
Keq1=10266.76*exp(-26.83/temp+30.11);
Keq2=exp(4400/temp-4.063);
Keq3=Keq1*Keq2;
/*reaction rate constant*/
k1=4.225e+15*exp(-240.1/(R*temp));
k2=4.39e+4*exp(-67.13/(R*temp));
k3=2.29e16*exp(-243.9/(R*temp));
/*adsorption coefficients*/
K_h2=0.0296*exp(82.9/R*(1/temp-1/648));
K_co=40.91*exp(70.65/R*(1/temp-1/648));
K_h2o=0.4152*exp(88.68/R*(1/temp-1/823));
K_ch4=0.1791*exp(38.28/R*(1/temp-1/823));
/*total pressure in the cell near wall, bar*/
TP=C_P(c0,t0)/1.0e+5;
/*constant DEN factor for rate equations*/
DEN=1+TP*(K_ch4*y_ch4+K_co*y_co+K_h2*y_h2)+K_h2o*y _h2o/y_h2;
r1=(k1/pow(TP*y_h2,2.5)*(pow(TP,2)*y_ch4*y_h2o-pow(TP,4)*pow(y_h2,3)*y_co/Keq1))/pow(DEN,2);
r2=(k2/(TP*y_h2)*(pow(TP,2)*y_co*y_h2o-pow(TP,2)*y_h2*y_co2/Keq2))/pow(DEN,2);
r3=(k3/pow(TP*y_h2,3.5)*(pow(TP,3)*y_ch4*pow(y_h2o,2)-pow(TP,5)*pow(y_h2,4)*y_co2/Keq3))/pow(DEN,2);
if (STREQ(r->name, "reaction-1")){
*rr=r1;}
else if (STREQ(r->name, "reaction-2")){
*rr=r2;}
else if (STREQ(r->name, "reaction-3")){
*rr=r3;
}
}
I'd be enormously happy if anyone is willing to take some time and help me with my case. As i already mentioned, i hardly have any experience with the C programming language and am happy for any kind of advice given.

Kind regards,
f.
flappy is offline   Reply With Quote

Old   May 20, 2016, 18:27
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
First for debugging purposes, simplify your code (cut out sections) until you determine the location of the error. Alternatively, use message functions and print to the screen every few lines.

Segmentation faults are generally caused from trying to access a variable that doesn't exist. Have you got the correct number of species and other parameters? For example, accessing mw[5] when mw only has four entries may cause this error.
`e` is offline   Reply With Quote

Old   May 24, 2016, 05:19
Default
  #3
New Member
 
Join Date: Feb 2016
Posts: 4
Rep Power: 10
flappy is on a distinguished road
Thanks very much 'e', good advice! The problem was the usage of Define_SR and a porous system, which apparently doesn't work together. I have now changed to a Volume Reaction and simplified the code and it's working.
flappy is offline   Reply With Quote

Old   November 1, 2020, 01:31
Default
  #4
New Member
 
AJITH
Join Date: Jan 2013
Posts: 10
Rep Power: 13
ajithjec is on a distinguished road
Quote:
Originally Posted by flappy View Post
Thanks very much 'e', good advice! The problem was the usage of Define_SR and a porous system, which apparently doesn't work together. I have now changed to a Volume Reaction and simplified the code and it's working.

Hi, I am also trying the same, do you change the Define_SR and adopt Define_VR for working in a porous medium. ?
I am a beginner in using UDF in Fluent. Can you please suggest to me some tutorials or references for learning? I am simulating a Steam methane reforming reactor for hydrogen generation. Having a catalyst layer in the reformer tube. I am also working with Define_VR udf. Kindly help.
ajithjec is offline   Reply With Quote

Old   November 1, 2020, 05:52
Default
  #5
New Member
 
AJITH
Join Date: Jan 2013
Posts: 10
Rep Power: 13
ajithjec is on a distinguished road
Quote:
Originally Posted by flappy View Post
Thanks very much 'e', good advice! The problem was the usage of Define_SR and a porous system, which apparently doesn't work together. I have now changed to a Volume Reaction and simplified the code and it's working.

Hi, I am also trying the same, do you change the Define_SR and adopt Define_VR for working in a porous medium. ?
I am a beginner in using UDF in Fluent. Can you please suggest to me some tutorials or references for learning? I am simulating a Steam methane reforming reactor for hydrogen generation. Having a catalyst layer in the reformer tube. I am also working with Define_VR udf. Kindly help.
ajithjec is offline   Reply With Quote

Old   November 2, 2020, 06:04
Default
  #6
New Member
 
khedidja
Join Date: Mar 2020
Posts: 6
Rep Power: 6
khadi is on a distinguished road
Quote:
Originally Posted by ajithjec View Post
Hi, I am also trying the same, do you change the Define_SR and adopt Define_VR for working in a porous medium. ?
I am a beginner in using UDF in Fluent. Can you please suggest to me some tutorials or references for learning? I am simulating a Steam methane reforming reactor for hydrogen generation. Having a catalyst layer in the reformer tube. I am also working with Define_VR udf. Kindly help.
hi, ajithjec
I studie numericaly thermochemical solar reactor based on volumetric porous receiver. however I found lot of difficulties during the modeling of reactor via Ansys-Fluent software, and I'm unsure about simulation detail.
I'll be very thankful if you can willing to give me hand.

best regard
khadi is offline   Reply With Quote

Old   November 6, 2020, 06:39
Smile
  #7
New Member
 
AJITH
Join Date: Jan 2013
Posts: 10
Rep Power: 13
ajithjec is on a distinguished road
Quote:
Originally Posted by flappy View Post
Thanks very much 'e', good advice! The problem was the usage of Define_SR and a porous system, which apparently doesn't work together. I have now changed to a Volume Reaction and simplified the code and it's working.
I have 3 reaction rate equations and it is converted to UDF file. I am trying DEFINE_VR_RATE. The catalyst inside was modeled as a porous zone, with defined porosity. The question arises when the user inputs are providing to fluent reaction window. Even iam defining rate of reactions by UDF, the Arrhenius rate equation window ask for values of Pre exp factor and activation energy, also temperature exponent. Do the values need again? Does it overwrite the reaction rates which already defines by UDF? Can you provide a solution to this issue.
ajithjec is offline   Reply With Quote

Old   November 17, 2020, 03:51
Default
  #8
New Member
 
AJITH
Join Date: Jan 2013
Posts: 10
Rep Power: 13
ajithjec is on a distinguished road
Quote:
Originally Posted by flappy View Post
Hello,

I'm new to UDFs as well as to C programming and need help for my university work. I'm working on a fixed-bed reactor model with chemical reactions (Methane Steam Reforming) in a porous zone and want to implement the kinetic model of Xu and Froment as an UDF.

I'm using Fluent 17.0 and Microsoft Visual Studio 2015 for compiling on a 64-Bit Windows 7 Enterprise System.

apparently there is a mistake in my code. Fluent tells me: received a fatal signal (segmentation fault) - which i read in other forum threads is a sign that there is a mistake in the code.

here's my code:



I'd be enormously happy if anyone is willing to take some time and help me with my case. As i already mentioned, i hardly have any experience with the C programming language and am happy for any kind of advice given.

Kind regards,
f.

Use this before defining reaction , then it will allow reaction only in fluid domain with porous wall. In the cell zone condition, define porous zone with it properties and provide surface area to volume ratio.

if (FLUID_THREAD_P(t) && THREAD_VAR(t).fluid.porous)
ajithjec is offline   Reply With Quote

Reply

Tags
fixed bed, fluent 17.0, surface reaction rate, udf code


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
Fluent Radiation/porous media Schmitt pierre-Louis FLUENT 26 September 1, 2016 11:29
Problem running fluent with udf on batch tobi b. Fluent UDF and Scheme Programming 3 April 14, 2016 14:54
Running UDF with Supercomputer roi247 FLUENT 4 October 15, 2015 14:41
fluent UDF external library lapack problem Rick FLUENT 0 May 7, 2008 11:16
UDF problem caused by various version of Fluent Yurong FLUENT 3 January 15, 2006 11:57


All times are GMT -4. The time now is 22:09.