From 4783da7bfed79c95f94e0620fe8ec7dc5b0c3aad Mon Sep 17 00:00:00 2001 From: Jongyoon Bae Date: Mon, 12 Sep 2022 15:12:29 -0400 Subject: [PATCH] Remove redundant variables in initThermo --- .../thermo/CoverageDependentSurfPhase.h | 8 +- src/thermo/CoverageDependentSurfPhase.cpp | 75 +++++++------------ 2 files changed, 32 insertions(+), 51 deletions(-) diff --git a/include/cantera/thermo/CoverageDependentSurfPhase.h b/include/cantera/thermo/CoverageDependentSurfPhase.h index 95db64d70b0..8cf1d07c234 100644 --- a/include/cantera/thermo/CoverageDependentSurfPhase.h +++ b/include/cantera/thermo/CoverageDependentSurfPhase.h @@ -134,8 +134,10 @@ class CoverageDependentSurfPhase : public SurfPhase //! @param entropy_map_ map of as a key-value pair of //! coverage [dimensionless] and entropy [J/kmol/K] InterpolativeDependency(size_t k_, size_t j_, - std::map enthalpy_map_, - std::map entropy_map_): + std::map enthalpy_map_ = {{0.0, 0.0}, + {1.0, 0.0}}, + std::map entropy_map_ = {{0.0, 0.0}, + {1.0, 0.0}}): k(k_), j(j_), enthalpy_map(enthalpy_map_), entropy_map(entropy_map_){} @@ -169,7 +171,7 @@ class CoverageDependentSurfPhase : public SurfPhase //! @param cpcov_a_ log model coefficient a [J/kmol/K] //! @param cpcov_b_ log model coefficient b [J/kmol/K] HeatCapacityDependency(size_t k_, size_t j_, - double cpcov_a_, double cpcov_b_): + double cpcov_a_ = 0.0, double cpcov_b_ = 0.0): k(k_), j(j_), cpcov_a(cpcov_a_), cpcov_b(cpcov_b_) {} HeatCapacityDependency() {} diff --git a/src/thermo/CoverageDependentSurfPhase.cpp b/src/thermo/CoverageDependentSurfPhase.cpp index 18547f8f3c8..748290f9043 100644 --- a/src/thermo/CoverageDependentSurfPhase.cpp +++ b/src/thermo/CoverageDependentSurfPhase.cpp @@ -144,47 +144,33 @@ void CoverageDependentSurfPhase::initThermo() m_PolynomialDependency.push_back(poly_deps); // For piecewise linear model } else if (cov_map2["model"] == "piecewise-linear") { - std::map hmap, smap; - vector_fp hcovs = {0.0, 0.5, 1.0}; - vector_fp enthalpies = {0.0, 0.0, 0.0}; - vector_fp scovs = {0.0, 0.5, 1.0}; - vector_fp entropies = {0.0, 0.0, 0.0}; - if (cov_map2.hasKey("enthalpy-low")) { - hcovs[1] = cov_map2["enthalpy-change"].as(); - enthalpies[1] = cov_map2.convert("enthalpy-low", "J/kmol") - * hcovs[1]; - enthalpies[2] = (1.0 - hcovs[1]) * - cov_map2.convert("enthalpy-high", "J/kmol") - + enthalpies[1]; - for (size_t i = 0; i < hcovs.size(); i++) { - hmap.insert({hcovs[i], enthalpies[i]}); - } - } else { - hmap.insert({0.0, 0.0}); - hmap.insert({1.0, 0.0}); + InterpolativeDependency int_deps(k, j); + if (cov_map2.hasKey("enthalpy-low") || + cov_map2.hasKey("enthalpy-change") || + cov_map2.hasKey("enthalpy-high")) { + auto cov_change = cov_map2["enthalpy-change"].as(); + int_deps.enthalpy_map[cov_change] = + cov_map2.convert("enthalpy-low", "J/kmol") * cov_change; + int_deps.enthalpy_map[1.0] = (1.0 - cov_change) * + cov_map2.convert("enthalpy-high", "J/kmol") + + int_deps.enthalpy_map[cov_change]; } - - if (cov_map2.hasKey("entropy-low")) { - scovs[1] = cov_map2["entropy-change"].as(); - entropies[1] = cov_map2.convert("entropy-low", "J/kmol/K") - * scovs[1]; - entropies[2] = (1.0 - scovs[1]) * - cov_map2.convert("entropy-high", "J/kmol/K") - + entropies[1]; - for (size_t i = 0; i < scovs.size(); i++) { - smap.insert({scovs[i], entropies[i]}); - } - } else { - smap.insert({0.0, 0.0}); - smap.insert({1.0, 0.0}); + if (cov_map2.hasKey("entropy-low") || + cov_map2.hasKey("entropy-change") || + cov_map2.hasKey("entropy-high")) { + auto cov_change = cov_map2["entropy-change"].as(); + int_deps.entropy_map[cov_change] = + cov_map2.convert("entropy-low", "J/kmol/K") * cov_change; + int_deps.entropy_map[1.0] = (1.0 - cov_change) * + cov_map2.convert("entropy-high", "J/kmol/K") + + int_deps.entropy_map[cov_change]; } - InterpolativeDependency int_deps(k, j, hmap, smap); setInterpolativeDependency(int_deps); // For interpolative model } else if (cov_map2["model"] == "interpolative") { - std::map hmap, smap; - if (cov_map2.hasKey("enthalpy-coverages") && + InterpolativeDependency int_deps(k, j); + if (cov_map2.hasKey("enthalpy-coverages") || cov_map2.hasKey("enthalpies")) { auto hcovs = cov_map2["enthalpy-coverages"].as(); vector_fp enthalpies = cov_map2.convertVector("enthalpies", @@ -196,13 +182,10 @@ void CoverageDependentSurfPhase::initThermo() not equal."); } for (size_t i = 0; i < hcovs.size(); i++) { - hmap.insert({hcovs[i], enthalpies[i]}); + int_deps.enthalpy_map[hcovs[i]] = enthalpies[i]; } - } else { - hmap.insert({0.0, 0.0}); - hmap.insert({1.0, 0.0}); } - if (cov_map2.hasKey("entropy-coverages") && + if (cov_map2.hasKey("entropy-coverages") || cov_map2.hasKey("entropies")) { auto scovs = cov_map2["entropy-coverages"].as(); vector_fp entropies = cov_map2.convertVector("entropies", @@ -214,14 +197,10 @@ void CoverageDependentSurfPhase::initThermo() not equal."); } for (size_t i = 0; i < scovs.size(); i++) { - smap.insert({scovs[i], entropies[i]}); + int_deps.entropy_map[scovs[i]] = entropies[i]; } - } else { - smap.insert({0.0, 0.0}); - smap.insert({1.0, 0.0}); } - InterpolativeDependency int_deps(k, j, hmap, smap); setInterpolativeDependency(int_deps); } else { throw InputFileError("CoverageDependentSurfPhase::initThermo", @@ -231,10 +210,10 @@ void CoverageDependentSurfPhase::initThermo() } // For coverage-dependent heat capacity parameters, if present if (cov_map2.hasKey("heat-capacity-a")) { - double cpcov_a = cov_map2.convert("heat-capacity-a", "J/kmol/K"); - double cpcov_b = cov_map2.convert("heat-capacity-b", "J/kmol/K"); + HeatCapacityDependency cpcov_deps(k, j); + cpcov_deps.cpcov_a = cov_map2.convert("heat-capacity-a", "J/kmol/K"); + cpcov_deps.cpcov_b = cov_map2.convert("heat-capacity-b", "J/kmol/K"); - HeatCapacityDependency cpcov_deps(k, j, cpcov_a, cpcov_b); m_HeatCapacityDependency.push_back(cpcov_deps); } }