MCPcopy Create free account
hub / github.com/Cantera/cantera / init

Method init

src/kinetics/ReactionPath.cpp:601–718  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

599}
600
601int ReactionPathBuilder::init(ostream& logfile, Kinetics& kin)
602{
603 m_transfer.clear();
604 m_elementSymbols.clear();
605 findElements(kin);
606 m_ns = kin.nTotalSpecies();
607 m_nr = kin.nReactions();
608
609 // all reactants / products, even ones appearing on both sides of the
610 // reaction
611 vector<vector<size_t>> allProducts(m_nr);
612 vector<vector<size_t>> allReactants(m_nr);
613 for (size_t i = 0; i < m_nr; i++) {
614 for (size_t k = 0; k < m_ns; k++) {
615 for (int n = 0; n < kin.reactantStoichCoeff(k, i); n++) {
616 allReactants[i].push_back(k);
617 }
618 for (int n = 0; n < kin.productStoichCoeff(k, i); n++) {
619 allProducts[i].push_back(k);
620 }
621 }
622 }
623
624 // m_reac and m_prod exclude indices for species that appear on
625 // both sides of the reaction, so that the diagram contains no loops.
626 m_reac.resize(m_nr);
627 m_prod.resize(m_nr);
628 m_ropf.resize(m_nr);
629 m_ropr.resize(m_nr);
630 m_determinate.resize(m_nr);
631 m_x.resize(m_ns); // not currently used ?
632 m_elatoms.resize(m_nel, m_nr);
633
634 for (size_t i = 0; i < m_nr; i++) {
635 // construct the lists of reactant and product indices, not including
636 // molecules that appear on both sides.
637 m_reac[i].clear();
638 m_prod[i].clear();
639 map<size_t, int> net;
640 size_t nr = allReactants[i].size();
641 size_t np = allProducts[i].size();
642 for (size_t ir = 0; ir < nr; ir++) {
643 net[allReactants[i][ir]]--;
644 }
645 for (size_t ip = 0; ip < np; ip++) {
646 net[allProducts[i][ip]]++;
647 }
648
649 for (size_t k = 0; k < m_ns; k++) {
650 if (net[k] < 0) {
651 size_t nmol = -net[k];
652 for (size_t jr = 0; jr < nmol; jr++) {
653 m_reac[i].push_back(k);
654 }
655 } else if (net[k] > 0) {
656 size_t nmol = net[k];
657 for (size_t jp = 0; jp < nmol; jp++) {
658 m_prod[i].push_back(k);

Callers 2

newKineticsFunction · 0.45
ReactionPathDiagramMethod · 0.45

Calls 8

GroupClass · 0.85
nTotalSpeciesMethod · 0.80
reactantStoichCoeffMethod · 0.80
productStoichCoeffMethod · 0.80
clearMethod · 0.45
nReactionsMethod · 0.45
resizeMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected