diff --git a/include/cantera/thermo/CoverageDependentSurfPhase.h b/include/cantera/thermo/CoverageDependentSurfPhase.h index cfbf2021a..1989c9454 100644 --- a/include/cantera/thermo/CoverageDependentSurfPhase.h +++ b/include/cantera/thermo/CoverageDependentSurfPhase.h @@ -141,12 +141,36 @@ public: * coefficients * @param isLinear boolean indicating whether the dependency is linear */ - PolynomialDependency(size_t k, size_t j, - vector_fp enthalpy_coeffs={0.0, 0.0, 0.0, 0.0, 0.0}, - vector_fp entropy_coeffs={0.0, 0.0, 0.0, 0.0, 0.0}, - bool isLinear=false): - k(k), j(j), enthalpy_coeffs(enthalpy_coeffs), - entropy_coeffs(entropy_coeffs), isLinear(isLinear) {} + PolynomialDependency(size_t k, size_t j, const AnyMap& dep_map): + k(k), + j(j), + enthalpy_coeffs({0.0, 0.0, 0.0, 0.0, 0.0}), + entropy_coeffs({0.0, 0.0, 0.0, 0.0, 0.0}), + isLinear(false) + { + // For linear model + if (dep_map["model"] == "linear") { + if (dep_map.hasKey("enthalpy")) { + enthalpy_coeffs[1] = dep_map.convert("enthalpy", "J/kmol"); + } + if (dep_map.hasKey("entropy")) { + entropy_coeffs[1] = dep_map.convert("entropy", "J/kmol/K"); + } + isLinear = true; + // For polynomial(4th) model + } else if (dep_map["model"] == "polynomial") { + if (dep_map.hasKey("enthalpy-coefficients")) { + enthalpy_coeffs = dep_map.convertVector( + "enthalpy-coefficients", "J/kmol"); + enthalpy_coeffs.insert(enthalpy_coeffs.begin(), 0.0); + } + if (dep_map.hasKey("entropy-coefficients")) { + entropy_coeffs = dep_map.convertVector( + "entropy-coefficients", "J/kmol/K"); + entropy_coeffs.insert(entropy_coeffs.begin(), 0.0); + } + } + } //! index of a target species whose enthalpy and entropy is calculated size_t k; //! index of a species whose coverage affects enthalpy and entropy of @@ -179,13 +203,69 @@ public: * piecewise-linear */ InterpolativeDependency(size_t k, size_t j, - std::map enthalpy_map={{0.0, 0.0}, - {1.0, 0.0}}, - std::map entropy_map={{0.0, 0.0}, - {1.0, 0.0}}, - bool isPiecewise=false): - k(k), j(j), enthalpy_map(enthalpy_map), - entropy_map(entropy_map), isPiecewise(isPiecewise) {} + const AnyMap& dep_map, const AnyBase& node): + k(k), + j(j), + enthalpy_map({{0.0, 0.0}, {1.0, 0.0}}), + entropy_map({{0.0, 0.0}, {1.0, 0.0}}), + isPiecewise(false) + { + // For piecewise-linear model + if (dep_map["model"] == "piecewise-linear") { + if (dep_map.hasKey("enthalpy-low") || + dep_map.hasKey("enthalpy-change") || + dep_map.hasKey("enthalpy-high")) { + auto cov_change = dep_map["enthalpy-change"].as(); + enthalpy_map[cov_change] = + dep_map.convert("enthalpy-low", "J/kmol") * cov_change; + enthalpy_map[1.0] = (1.0 - cov_change) + * dep_map.convert("enthalpy-high", "J/kmol") + + enthalpy_map[cov_change]; + } + if (dep_map.hasKey("entropy-low") || + dep_map.hasKey("entropy-change") || + dep_map.hasKey("entropy-high")) { + auto cov_change = dep_map["entropy-change"].as(); + entropy_map[cov_change] = + dep_map.convert("entropy-low", "J/kmol/K") * cov_change; + entropy_map[1.0] = (1.0 - cov_change) + * dep_map.convert("entropy-high", "J/kmol/K") + + entropy_map[cov_change]; + } + isPiecewise = true; + // For interpolative model + } else if (dep_map["model"] == "interpolative") { + if (dep_map.hasKey("enthalpy-coverages") || + dep_map.hasKey("enthalpies")) { + auto hcovs = dep_map["enthalpy-coverages"].as(); + vector_fp enthalpies = dep_map.convertVector("enthalpies", "J/kmol"); + if (hcovs.size() != enthalpies.size()) { + throw InputFileError("CoverageDependentSurfPhase::\ + addInterpolativeDependency", node, + "Sizes of coverages array and enthalpies array are \ + not equal."); + } + for (size_t i = 0; i < hcovs.size(); i++) { + enthalpy_map[hcovs[i]] = enthalpies[i]; + } + } + if (dep_map.hasKey("entropy-coverages") || + dep_map.hasKey("entropies")) { + auto scovs = dep_map["entropy-coverages"].as(); + vector_fp entropies = dep_map.convertVector("entropies", + "J/kmol/K"); + if (scovs.size() != entropies.size()) { + throw InputFileError("CoverageDependentSurfPhase::\ + addInterpolativeDependency", node, + "Sizes of coverages array and entropies array are \ + not equal."); + } + for (size_t i = 0; i < scovs.size(); i++) { + entropy_map[scovs[i]] = entropies[i]; + } + } + } + } //! index of a target species whose enthalpy and entropy are calculated size_t k; //! index of a species whose coverage affects enthalpy and entropy of @@ -210,9 +290,8 @@ public: * @param coeff_a coefficient a [J/kmol/K] * @param coeff_b coefficient b [J/kmol/K] */ - HeatCapacityDependency(size_t k, size_t j, - double coeff_a=0.0, double coeff_b=0.0): - k(k), j(j), coeff_a(coeff_a), coeff_b(coeff_b) {} + HeatCapacityDependency(size_t k, size_t j): + k(k), j(j), coeff_a(0.0), coeff_b(0.0) {} //! index of a target species whose heat capacity is calculated size_t k; //! index of a species whose coverage affects heat capacity of diff --git a/src/thermo/CoverageDependentSurfPhase.cpp b/src/thermo/CoverageDependentSurfPhase.cpp index 3de7ffe14..13d2adf35 100644 --- a/src/thermo/CoverageDependentSurfPhase.cpp +++ b/src/thermo/CoverageDependentSurfPhase.cpp @@ -83,98 +83,16 @@ void CoverageDependentSurfPhase::initThermo() throw InputFileError("CoverageDependentSurfPhase::initThermo", item.second->input, "Unknown species '{}'.", item2.first); } - auto& cov_map2 = item2.second.as(); - // For linear model - if (cov_map2["model"] == "linear") { - PolynomialDependency poly_deps(k, j); - if (cov_map2.hasKey("enthalpy")) { - poly_deps.enthalpy_coeffs[1] = cov_map2.convert("enthalpy", - "J/kmol"); - } - if (cov_map2.hasKey("entropy")) { - poly_deps.entropy_coeffs[1] = cov_map2.convert("entropy", - "J/kmol/K"); - } - - poly_deps.isLinear = true; + auto& dep_map = item2.second.as(); + // For linear model and polynomial model + if (dep_map["model"] == "linear" || dep_map["model"] == "polynomial") { + PolynomialDependency poly_deps(k, j, dep_map); m_PolynomialDependency.push_back(poly_deps); - // For polynomial(4th) model - } else if (cov_map2["model"] == "polynomial") { - PolynomialDependency poly_deps(k, j); - if (cov_map2.hasKey("enthalpy-coefficients")) { - poly_deps.enthalpy_coeffs = cov_map2.convertVector( - "enthalpy-coefficients", "J/kmol"); - poly_deps.enthalpy_coeffs.insert( - poly_deps.enthalpy_coeffs.begin(), 0.0); - } - if (cov_map2.hasKey("entropy-coefficients")) { - poly_deps.entropy_coeffs = cov_map2.convertVector( - "entropy-coefficients", "J/kmol/K"); - poly_deps.entropy_coeffs.insert( - poly_deps.entropy_coeffs.begin(), 0.0); - } - - m_PolynomialDependency.push_back(poly_deps); - // For piecewise-linear model - } else if (cov_map2["model"] == "piecewise-linear") { - 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") || - 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]; - } - - int_deps.isPiecewise = true; - addInterpolativeDependency(int_deps); - // For interpolative model - } else if (cov_map2["model"] == "interpolative") { - 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", - "J/kmol"); - if (hcovs.size() != enthalpies.size()) { - throw InputFileError("CoverageDependentSurfPhase::\ - addInterpolativeDependency", item.second->input, - "Sizes of coverages array and enthalpies array are \ - not equal."); - } - for (size_t i = 0; i < hcovs.size(); i++) { - int_deps.enthalpy_map[hcovs[i]] = enthalpies[i]; - } - } - if (cov_map2.hasKey("entropy-coverages") || - cov_map2.hasKey("entropies")) { - auto scovs = cov_map2["entropy-coverages"].as(); - vector_fp entropies = cov_map2.convertVector("entropies", - "J/kmol/K"); - if (scovs.size() != entropies.size()) { - throw InputFileError("CoverageDependentSurfPhase::\ - addInterpolativeDependency", item.second->input, - "Sizes of coverages array and entropies array are \ - not equal."); - } - for (size_t i = 0; i < scovs.size(); i++) { - int_deps.entropy_map[scovs[i]] = entropies[i]; - } - } - + // For piecewise-linear model and interpolative model + } else if (dep_map["model"] == "piecewise-linear" || + dep_map["model"] == "interpolative") { + InterpolativeDependency int_deps(k, j, dep_map, + item.second->input); addInterpolativeDependency(int_deps); } else { throw InputFileError("CoverageDependentSurfPhase::initThermo", @@ -183,10 +101,10 @@ void CoverageDependentSurfPhase::initThermo() or 'interpolative'."); } // For coverage-dependent heat capacity parameters, if present - if (cov_map2.hasKey("heat-capacity-a")) { + if (dep_map.hasKey("heat-capacity-a")) { HeatCapacityDependency cpcov_deps(k, j); - cpcov_deps.coeff_a = cov_map2.convert("heat-capacity-a", "J/kmol/K"); - cpcov_deps.coeff_b = cov_map2.convert("heat-capacity-b", "J/kmol/K"); + cpcov_deps.coeff_a = dep_map.convert("heat-capacity-a", "J/kmol/K"); + cpcov_deps.coeff_b = dep_map.convert("heat-capacity-b", "J/kmol/K"); m_HeatCapacityDependency.push_back(cpcov_deps); }