mutationpp / Mutationpp

The MUlticomponent Thermodynamic And Transport library for IONized gases in C++
GNU Lesser General Public License v3.0
103 stars 58 forks source link

Stoichiometric coefficients #162

Closed koendev closed 3 years ago

koendev commented 3 years ago

Dear,

I'm sorry for asking a basic question, but I haven't been able to find the method for obtaining the stoichiometric coefficients. How can I obtain the stoichiometric coefficients of all the species of all the reactions occurring in the mixture? And how would the output of such a method be ordered?

Thank you for your help! Koen Devesse

jbscoggi commented 3 years ago

Hi @koendev,

Good question! I think you are right that this information is not readily available. I think perhaps the easiest way to do this is the following:

  1. Assuming you have loaded/created a mixture called mix
  2. Get the list of reactions associated with the mixture using mix.reactions()
  3. Loop over the list of reactions and obtain the reactant indices and product indices with reactants() and products()

For example, here is a simple code to print the reactants and indices:

for (const auto& reaction : mix.reactions())
{
    std::cout << "Reaction: " << reaction.formula();
    std::cout << "\n    reactants =";
    for (const auto& i : reaction.reactants()) std::cout << ' ' << i;
    std::cout << "\n    products =";
    for (const auto& i : reaction.products()) std::cout << ' ' << i;
    std::cout << '\n';
}   

Note that indices will be repeated if the species has a stoichiometric coefficient greater than 1. If you just want the actual stoichiometric coefficient for a given species index, then you can use the reactant(index) and product(index) functions of Reaction. For example:

auto N2_nu_f = reaction.reactant(mix.speciesIndex("N2"));
auto N2_nu_b = reaction.product(mix.speciesIndex("N2"));

If you need this information a lot, I suggest that you cache the values. You may also want to take a look at the StoichiometryManager class, which performs common "stoichiometric" operations.

koendev commented 3 years ago

Hi @jbscoggi,

Thank you for the quick reaction! It seems to work for now, thank you very much! I might open some other issues for other questions I had.

Best, Koen Devesse