| 599 | } |
| 600 | |
| 601 | int 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); |
no test coverage detected