Skip to content

Commit

Permalink
Use std::set instead of std::map when the value is never used
Browse files Browse the repository at this point in the history
  • Loading branch information
speth authored and ischoegl committed Mar 9, 2023
1 parent 36a15fc commit a6196d3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
4 changes: 3 additions & 1 deletion include/cantera/kinetics/ReactionPath.h
Expand Up @@ -283,7 +283,9 @@ class ReactionPathDiagram
std::vector<std::string> m_include;
std::vector<std::string> m_exclude;
std::vector<size_t> m_speciesNumber;
std::map<size_t, int> m_rxns;

//! Indices of reactions that are included in the diagram
set<size_t> m_rxns;
size_t m_local;
};

Expand Down
6 changes: 4 additions & 2 deletions include/cantera/oneD/refine.h
Expand Up @@ -97,9 +97,11 @@ class Refiner
}

protected:
std::map<size_t, int> m_loc;
//! Indices of grid points that need new grid points added after them
set<size_t> m_loc;
std::map<size_t, int> m_keep;
std::map<std::string, int> m_c;
//! Names of components that require the addition of new grid points
set<string> m_c;
std::vector<bool> m_active;
doublereal m_ratio, m_slope, m_curve, m_prune;
doublereal m_min_range;
Expand Down
6 changes: 3 additions & 3 deletions src/kinetics/ReactionPath.cpp
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
}

Expand Down
22 changes: 11 additions & 11 deletions src/oneD/refine.cpp
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a6196d3

Please sign in to comment.