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

Get stoichiometric coefficient with the function product() and reactant() #163

Closed fbonelli84 closed 3 years ago

fbonelli84 commented 3 years ago

I am trying to get the stoichiometric coefficient with the function product() and reactant() but they not seem give the right values. In the following there is an example of the code and of the output

#include <iostream>

#include "mutation++.h"
using namespace Mutation;

void printModel(Mixture& mix)
{
    std::cout << "# of elements: " << mix.nElements() << '\n';
    std::cout << "# of species: " << mix.nSpecies() << ' ';
    std::cout << mix.nGas() << " (gas) " << mix.nCondensed() << " (condensed)\n";
    std::cout << "# of reactions: " << mix.nReactions() << '\n';
    std::cout << "# of temperatures: " << mix.nEnergyEqns() << "\n\n";

    std::cout << "Species:\n";
    for (auto& s: mix.species())
        std::cout << s.name() << ' ';
    std::cout << "\n\n";

    int ss;
    std::cout << "Reactions:\n";
    for (auto& r: mix.reactions()) {
        std::cout << r.formula() << '\n';
        ss = 0;
        for (auto& s: mix.species()) {
            std::cout << " reactant stoichiometric coefficient of: " << s.name() << ": " << r.reactant(ss) << '\n';
            std::cout << " product  stoichiometric coefficient of: " << s.name() << ": " << r.product(ss) << '\n';
            ss = ss + 1;
        }
    }
}

void partOne()
{
    std::cout << "\n\n*** PART ONE ***\n";
    Mixture mix("air_5");
    printModel(mix);

}

int main(int argc, char* argv[])
{
    partOne();

    return 0;
}

OUTPUT:

*** PART ONE ***
# of elements: 2
# of species: 5 5 (gas) 0 (condensed)
# of reactions: 5
# of temperatures: 1

Species:
N O NO N2 O2 

Reactions:
N2+M=2N+M
 reactant stoichiometric coefficient of: N: 0
 product  stoichiometric coefficient of: N: 1
 reactant stoichiometric coefficient of: O: 0
 product  stoichiometric coefficient of: O: 0
 reactant stoichiometric coefficient of: NO: 0
 product  stoichiometric coefficient of: NO: 0
 reactant stoichiometric coefficient of: N2: 1
 product  stoichiometric coefficient of: N2: 0
 reactant stoichiometric coefficient of: O2: 0
 product  stoichiometric coefficient of: O2: 0
O2+M=2O+M
 reactant stoichiometric coefficient of: N: 0
 product  stoichiometric coefficient of: N: 0
 reactant stoichiometric coefficient of: O: 0
 product  stoichiometric coefficient of: O: 1
 reactant stoichiometric coefficient of: NO: 0
 product  stoichiometric coefficient of: NO: 0
 reactant stoichiometric coefficient of: N2: 0
 product  stoichiometric coefficient of: N2: 0
 reactant stoichiometric coefficient of: O2: 1
 product  stoichiometric coefficient of: O2: 0
NO+M=N+O+M
 reactant stoichiometric coefficient of: N: 0
 product  stoichiometric coefficient of: N: 1
 reactant stoichiometric coefficient of: O: 0
 product  stoichiometric coefficient of: O: 0
 reactant stoichiometric coefficient of: NO: 1
 product  stoichiometric coefficient of: NO: 0
 reactant stoichiometric coefficient of: N2: 0
 product  stoichiometric coefficient of: N2: 0
 reactant stoichiometric coefficient of: O2: 0
 product  stoichiometric coefficient of: O2: 0
N2+O=NO+N
 reactant stoichiometric coefficient of: N: 0
 product  stoichiometric coefficient of: N: 1
 reactant stoichiometric coefficient of: O: 1
 product  stoichiometric coefficient of: O: 0
 reactant stoichiometric coefficient of: NO: 0
 product  stoichiometric coefficient of: NO: 1
 reactant stoichiometric coefficient of: N2: 1
 product  stoichiometric coefficient of: N2: 0
 reactant stoichiometric coefficient of: O2: 0
 product  stoichiometric coefficient of: O2: 0
NO+O=O2+N
 reactant stoichiometric coefficient of: N: 0
 product  stoichiometric coefficient of: N: 1
 reactant stoichiometric coefficient of: O: 1
 product  stoichiometric coefficient of: O: 0
 reactant stoichiometric coefficient of: NO: 1
 product  stoichiometric coefficient of: NO: 0
 reactant stoichiometric coefficient of: N2: 0
 product  stoichiometric coefficient of: N2: 0
 reactant stoichiometric coefficient of: O2: 0
 product  stoichiometric coefficient of: O2: 1
jbscoggi commented 3 years ago

Hi @fbonelli84, indeed you have found a bug! Notice anything wrong here?

https://github.com/mutationpp/Mutationpp/blob/d053e207d1859bf3a8c8daeeac3d2331b261bf85/src/kinetics/Reaction.h#L186-L191

I'll work on a PR to fix this right away.

jbscoggi commented 3 years ago

Hi @fbonelli84, this bug is fixed in the most recent PR. We can reopen this issue if you still have problems.