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

UDF for Reaction Rate

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 26, 2020, 14:54
Default UDF for Reaction Rate
  #1
New Member
 
Vidushi
Join Date: Sep 2018
Location: Cape Town
Posts: 20
Rep Power: 4
Vidushi is on a distinguished road
Hi everyone

I am working with reversible reactions where I have to write a custom rate law. The reactions I have are:

CO + 2H2 <=> CH2 + H2O (1)
CH2 + H2 <=> CH4 (2)
CH4 + CH2 <=> C2H6 (3)

The reaction rates that I am using for the above reactions are:

𝑟1=𝑘1*(𝑎𝐶𝑂*𝑎𝐻22−𝑎𝐶𝐻2*𝑎𝐻2𝑂/𝐾1)
𝑟2=𝑘2*(𝑎𝐶𝐻2*𝑎𝐻2−𝑎𝐶𝐻4/𝐾2)
𝑟3=𝑘3*(𝑎𝐶𝐻2*𝑎𝐶𝐻4−𝑎𝐶2𝐻6/𝐾3)

The aCO, aCH2, aH2O etc. are activities of the respective species which are calculated using their fugacities and the equilibrium constants are calculated using the Gibbs Free Energies of the 3 rxns.

I have written a UDF for the above reaction rates using the DEFINE_VR_RATE macro in which I have written the formulas for calculating fugacities and activities and then eventually calculate the reaction rates.

The UDF gets compiled and hooked in Ansys, however when I run the simulations, fluent gives me this error:


999999: mpt_accept: error: accept failed
: No error
================================================== ============================

999999: mpt_accept: error: accept failed: No error
================================================== ============================

999999: mpt_accept: error: accept failed: No error

Node 2: Process 7584: Received signal SIGSEGV.



I have not created any user-defined memory in my UDF.
I have tried reinstalling Visual Studio. Still no luck.

I have attached my UDF file. Can somebody please have a look and give any suggestions about fixing the problem? I really need some help.

P.S. The UDF looks lengthy, but it does not contain many algorithms. It is lengthy only because of lots of constants involved and long formulae of Fugacities and Gibbs energies.
Attached Files
File Type: c RateLawUDF.c (15.6 KB, 15 views)
Vidushi is offline   Reply With Quote

Old   May 26, 2020, 15:43
Default Error
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,948
Blog Entries: 1
Rep Power: 31
vinerm will become famous soon enough
If the error comes at the very first instance the function is called, then it would be better to check it in Serial Fluent. Quite possible that the UDF requires parallelization.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 26, 2020, 16:11
Default
  #3
New Member
 
Vidushi
Join Date: Sep 2018
Location: Cape Town
Posts: 20
Rep Power: 4
Vidushi is on a distinguished road
Quote:
Originally Posted by vinerm View Post
If the error comes at the very first instance the function is called, then it would be better to check it in Serial Fluent. Quite possible that the UDF requires parallelization.
Dear Vinerm,

The error does come at the first instance the function is called. I have tried running it in both the serial and the parallel modes, the error remains the same. Is that what you meant by parallelization?
Vidushi is offline   Reply With Quote

Old   May 26, 2020, 16:38
Default Bug
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,948
Blog Entries: 1
Rep Power: 31
vinerm will become famous soon enough
I don't see much of an issue with the code, however, there are two things that could cause the trouble. One is the use of names pressure and volume. Though the names are local to the function, however, if Fluent has such variable names defined as global, it would cause trouble. The error, SIGSEGV, doesn't point towards this, but it would still be better to use different names. Use names that are little uncommon.

Second could be indices for reactant, product, exp_reactant, etc. Since you have multiple reactions, if any one of those don't have size used in for loop, then it would lead to SIGSEGV. So, check for those.

Furthermore, you are using R as 8.314. In SI, value is 8314. It is not syntactical bug but logical error. So, do check for that.

Best way to debug such issues is to use Messages in code and then execute one section at a time.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   May 27, 2020, 08:23
Default
  #5
New Member
 
Vidushi
Join Date: Sep 2018
Location: Cape Town
Posts: 20
Rep Power: 4
Vidushi is on a distinguished road
Quote:
Originally Posted by vinerm View Post
I don't see much of an issue with the code, however, there are two things that could cause the trouble. One is the use of names pressure and volume. Though the names are local to the function, however, if Fluent has such variable names defined as global, it would cause trouble. The error, SIGSEGV, doesn't point towards this, but it would still be better to use different names. Use names that are little uncommon.

Second could be indices for reactant, product, exp_reactant, etc. Since you have multiple reactions, if any one of those don't have size used in for loop, then it would lead to SIGSEGV. So, check for those.

Furthermore, you are using R as 8.314. In SI, value is 8314. It is not syntactical bug but logical error. So, do check for that.

Best way to debug such issues is to use Messages in code and then execute one section at a time.
Dear Vinerm,

I followed your suggestions.

1. I changed my variables pressure, volume and temp to systempress, systemvol and systemtemp respectively.

2. I also removed all loops and indices.

3. The value of R i.e. 8.314 is consistent with my system over here. I have taken care of units of reaction rate towards the end of UDF.

The error that I am getting now is regarding divergence of species, still at the first instance though. I have checked my UDF multiple times, but I am unable to find any problem. Please find attached the screenshot of the error.
Attached Images
File Type: jpg Divergence_error.jpg (86.1 KB, 8 views)
Vidushi is offline   Reply With Quote

Old   May 27, 2020, 08:48
Default Species Divergence
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,948
Blog Entries: 1
Rep Power: 31
vinerm will become famous soon enough
This may or may not be related to UDF. If you are getting this error only with UDF, then look for values of all denominators in your UDF as well as the rate returned by Fluent. Ensure that none of these are 0 under any conditions, say, at the minimum and maximum limits of pressure and temperature.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply

Tags
define vr_rate, error 999999, fluent - udf, reaction rate model, udf code

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
volume flow rate for outlet boundry condition and dfine udf for it raminostadi FLUENT 0 December 24, 2016 02:52
UDF for volumetric reaction rate Boniface Omar Fluent UDF and Scheme Programming 0 July 25, 2016 03:39
Contours of custom surface rate (UDF and UDM) cpassa FLUENT 0 July 5, 2016 12:30
Heterogeneous reaction rate UDF snh Fluent UDF and Scheme Programming 2 February 23, 2013 03:15
UDF mass flow rate Juan FLUENT 2 December 22, 2007 10:29


All times are GMT -4. The time now is 19:16.