CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   How are chemical reactions stored after parsing? (https://www.cfd-online.com/Forums/openfoam-programming-development/171933-how-chemical-reactions-stored-after-parsing.html)

DanielW May 20, 2016 05:04

How are chemical reactions stored after parsing?
 
Hi everyone,

I'm currently trying to implement an enhancement for the modifiedReactingFoam-Solver to allow it to properly calculate surface reactions defined by the user.
I want the solver to allow for surface reactions to be defined and "attached" to any boundary within the domain and I want them to be proper chemical reactions that can for example create surface adsorbed species that stick to the boundaries or to generate reaction products which go right back into the adjecent fluid domain.

In order to do this, I need to solve some equations to get the reaction rates right and that's where I'm currently running into trouble.

Does somebody, by any chance, know how the chemical reactions and species are stored after parsing? I'm less interested in the storage of arrhenius parameters for now. I rather need to know how and where a chemical reaction and it's stoichometric coefficients are stored, so the solver later knows which of the species actually react within a given reaction.

Let's say I have five species:
A, B, C, D, E

and two reactions:
1) A + B = C
2) A + 2*D = B + E

The best case scenario for me would be if, upon parsing, the reactions from the reactions dictionary would generate a structure looking like this:

lhs (2x5):
Code:

1 1 0 0 0
1 0 0 2 0

rhs (2x5):
Code:

0 0 1 0 0
0 1 0 0 1

with lhs and rhs being matrices that store the left hand sides and right hand sides of reactions, each line corresponding to one reaction (equal to the reactions ID after parsing) and, most importantly, each column corresponding to the species according to some species ID-list.

The key feature I am asking for here is some structure that stores the chemical reactions in a way that has each reaction contain stoichometric coefficients for all species whether they are actually affected by the reaction or not. If a specie doesn't occur in a certain reaction it simply gets stoichometric cofficient 0 as would be the case for specie D in the first reaction in my example above.The first reaction rewritten with what I have in mind would look something like this:
1*A + 1*B + 0*C + 0*D + 0*E = 0*A + 0*B + 1*C + 0*D + 0*E

So if anybody knows whether reactions are already stored like that and where I can find them, that would be really helpful. Otherwise I will implement some code that arranges them in a scheme similar to that myself, but I don't want to implement something that's already there just because I can't find it ;)

Many thanks in advance. Even if somebody can tell me that this is currently not the case, but can tell me how chemical reactions are stored instead, that would be much appreciated.

Thanks to anyone reading the whole post,
Daniel

marupio May 20, 2016 11:27

Try looking into the ODE reaction solvers. They need to figure that out. I'm thinking chemistrySolver, chemistryModel. Look for where they implement derivatives and jacobian. Just off the top of my head.

DanielW May 20, 2016 12:05

Quote:

Originally Posted by marupio (Post 600986)
Try looking into the ODE reaction solvers. They need to figure that out. I'm thinking chemistrySolver, chemistryModel. Look for where they implement derivatives and jacobian. Just off the top of my head.

Hi, thanks for the reply.

I did examine the chemistryModel and EulerImplicit, which is used to build and solve the differential equation from the chemical reactions.
The algorithm in place iterates through all the reactions and sorts the coefficients "by hand" on each iteration to build the jacobian however.

From what I saw in the code and found through testing (Info << is my friend) it seems that the reactions are stored in a list and each element of this list has a component "rhs" and "lhs" which in itself is a list (containing the species that are present in this reactions' rhs/lhs), which contains yet another list for each specie appearing on the left/right hand side, which then contains the specie-ID and stoichometric coefficient.

So while I was able to rebuild each chemical reaction from those elements, it was not in a format I'd prefer. The problem I have with this is that I first need to determine whether a reaction affects a certain specie or not, if I want to calculate anything like net consumption rates for individual species.

I decided to build my own function for now, which creates the matrices I described above before any calculations are done at all, so I have to deal with this sorting process only once. So for now I have a solution and can continue my work and if I don't stumble upon something already implemented in OF, I'll just leave it in :)

raunakbardia June 7, 2018 14:39

Hi,

How were you able to access the information in the reactions() function? Could you share that code? I have not been able to figure out how to access the details stored in the reactions function for quite some time now. I would really appreciate some help.

Thanks.


All times are GMT -4. The time now is 07:08.