CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   UDF for Reaction Rate (https://www.cfd-online.com/Forums/fluent-udf/227361-udf-reaction-rate.html)

Vidushi May 26, 2020 14:54

UDF for Reaction Rate
 
1 Attachment(s)
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.

vinerm May 26, 2020 15:43

Error
 
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.

Vidushi May 26, 2020 16:11

Quote:

Originally Posted by vinerm (Post 772041)
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?

vinerm May 26, 2020 16:38

Bug
 
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.

Vidushi May 27, 2020 08:23

1 Attachment(s)
Quote:

Originally Posted by vinerm (Post 772059)
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.

vinerm May 27, 2020 08:48

Species Divergence
 
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.


All times are GMT -4. The time now is 04:28.