From a6196d374472a85ac1813f4a9a69d56ae702be37 Mon Sep 17 00:00:00 2001 From: Ray Speth Date: Sun, 5 Mar 2023 14:46:47 -0500 Subject: [PATCH] Use std::set instead of std::map when the value is never used --- include/cantera/kinetics/ReactionPath.h | 4 +++- include/cantera/oneD/refine.h | 6 ++++-- src/kinetics/ReactionPath.cpp | 6 +++--- src/oneD/refine.cpp | 22 +++++++++++----------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/include/cantera/kinetics/ReactionPath.h b/include/cantera/kinetics/ReactionPath.h index dfb4e884ec..2896ce8ae8 100644 --- a/include/cantera/kinetics/ReactionPath.h +++ b/include/cantera/kinetics/ReactionPath.h @@ -283,7 +283,9 @@ class ReactionPathDiagram std::vector m_include; std::vector m_exclude; std::vector m_speciesNumber; - std::map m_rxns; + + //! Indices of reactions that are included in the diagram + set m_rxns; size_t m_local; }; diff --git a/include/cantera/oneD/refine.h b/include/cantera/oneD/refine.h index ad074e9a8c..b2a884d87e 100644 --- a/include/cantera/oneD/refine.h +++ b/include/cantera/oneD/refine.h @@ -97,9 +97,11 @@ class Refiner } protected: - std::map m_loc; + //! Indices of grid points that need new grid points added after them + set m_loc; std::map m_keep; - std::map m_c; + //! Names of components that require the addition of new grid points + set m_c; std::vector m_active; doublereal m_ratio, m_slope, m_curve, m_prune; doublereal m_min_range; diff --git a/src/kinetics/ReactionPath.cpp b/src/kinetics/ReactionPath.cpp index 6a138577cc..31faa7b2fd 100644 --- a/src/kinetics/ReactionPath.cpp +++ b/src/kinetics/ReactionPath.cpp @@ -128,13 +128,13 @@ vector_int ReactionPathDiagram::reactions() for (const auto& rxn : path(i)->reactionMap()) { double flxratio = rxn.second/flmax; if (flxratio > threshold) { - m_rxns[rxn.first] = 1; + m_rxns.insert(rxn.first); } } } vector_int r; for (const auto& rxn : m_rxns) { - r.push_back(int(rxn.first)); + r.push_back(int(rxn)); } return r; } @@ -397,7 +397,7 @@ void ReactionPathDiagram::linkNodes(size_t k1, size_t k2, size_t rxn, m_pathlist.push_back(ff); } ff->addReaction(rxn, value, legend); - m_rxns[rxn] = 1; + m_rxns.insert(rxn); m_flxmax = std::max(ff->flow(), m_flxmax); } diff --git a/src/oneD/refine.cpp b/src/oneD/refine.cpp index d91a301ad2..eae9dbac64 100644 --- a/src/oneD/refine.cpp +++ b/src/oneD/refine.cpp @@ -111,8 +111,8 @@ int Refiner::analyze(size_t n, const doublereal* z, for (size_t j = 0; j < n-1; j++) { doublereal r = fabs(v[j+1] - v[j])/dmax; if (r > 1.0 && dz[j] >= 2 * m_gridmin) { - m_loc[j] = 1; - m_c[name] = 1; + m_loc.insert(j); + m_c.insert(name); } if (r >= m_prune) { m_keep[j] = 1; @@ -135,9 +135,9 @@ int Refiner::analyze(size_t n, const doublereal* z, doublereal r = fabs(s[j+1] - s[j]) / (dmax + m_thresh/dz[j]); if (r > 1.0 && dz[j] >= 2 * m_gridmin && dz[j+1] >= 2 * m_gridmin) { - m_c[name] = 1; - m_loc[j] = 1; - m_loc[j+1] = 1; + m_c.insert(name); + m_loc.insert(j); + m_loc.insert(j+1); } if (r >= m_prune) { m_keep[j+1] = 1; @@ -155,8 +155,8 @@ int Refiner::analyze(size_t n, const doublereal* z, for (size_t j = 1; j < n-1; j++) { // Add a new point if the ratio with left interval is too large if (dz[j] > m_ratio*dz[j-1]) { - m_loc[j] = 1; - m_c[fmt::format("point {}", j)] = 1; + m_loc.insert(j); + m_c.insert(fmt::format("point {}", j)); m_keep[j-1] = 1; m_keep[j] = 1; m_keep[j+1] = 1; @@ -165,8 +165,8 @@ int Refiner::analyze(size_t n, const doublereal* z, // Add a point if the ratio with right interval is too large if (dz[j] < dz[j-1]/m_ratio) { - m_loc[j-1] = 1; - m_c[fmt::format("point {}", j-1)] = 1; + m_loc.insert(j-1); + m_c.insert(fmt::format("point {}", j-1)); m_keep[j-2] = 1; m_keep[j-1] = 1; m_keep[j] = 1; @@ -215,12 +215,12 @@ void Refiner::show() m_domain->id()+".\n" +" New points inserted after grid points "); for (const auto& loc : m_loc) { - writelog("{} ", loc.first); + writelog("{} ", loc); } writelog("\n"); writelog(" to resolve "); for (const auto& c : m_c) { - writelog(string(c.first)+" "); + writelog(c + " "); } writelog("\n"); writeline('#', 78);