From 9a310a202a76ce99c2e1e4415cba2effecbde7ec Mon Sep 17 00:00:00 2001 From: Jongyoon Bae Date: Thu, 30 Jun 2022 16:21:40 -0400 Subject: [PATCH] combined PiecewiseDependency into Interpolative Dependency --- .../thermo/CoverageDependentSurfPhase.h | 69 ------------ src/thermo/CoverageDependentSurfPhase.cpp | 100 +++++++----------- 2 files changed, 41 insertions(+), 128 deletions(-) diff --git a/include/cantera/thermo/CoverageDependentSurfPhase.h b/include/cantera/thermo/CoverageDependentSurfPhase.h index e36eec2e54d..743a3b7c734 100644 --- a/include/cantera/thermo/CoverageDependentSurfPhase.h +++ b/include/cantera/thermo/CoverageDependentSurfPhase.h @@ -54,44 +54,6 @@ struct PolynomialDependency vector_fp entropy_coeffs; }; -//! Set of parameters modifying SurfPhase enthalpy and entropy based on -//! surface coverages using a piecewise linear model. -struct PiecewiseDependency -{ - //! Constructor - //! @param k_ index of a target species whose thermodynamics are calculated - //! @param j_ index of a species whose coverage affects thermodynamics of - //! a target species - //! @param enthalpy_params_ array of three parameters to calculate - //! coverage-dependent enthalpy [J/kmol]: slope of - //! enthalpy change in the first region, slope of enthalpy - //! change in the second region, and coverage - //! dividing first and second region - //! @param entropy_params_ array of three parameters to calculate - //! coverage-dependent entropy [J/kmol/K]: slope of - //! entropy change in the first region, slope of entropy - //! change in the second region, and coverage dividing - //! first and second region - PiecewiseDependency(size_t k_, size_t j_, - vector_fp enthalpy_params_, vector_fp entropy_params_): - k(k_), j(j_), - enthalpy_params(enthalpy_params_), - entropy_params(entropy_params_) {} - PiecewiseDependency() {} - //! index of a target species whose thermodynamics are calculated - size_t k; - //! index of a species whose coverage affects thermodynamics of a target species - size_t j; - //! array of three parameters to calculate coverage-dependent enthalpy [J/kmol]: - //! slope of enthalpy change in the first region, slope of enthalpy change in the - //! second region, and coverage dividing first and second region - vector_fp enthalpy_params; - //! array of three parameters to calculate coverage-dependent entropy [J/kmol/K]: - //! slope of entropy change in the first region, slope of entropy change in the - //! second region, and coverage dividing first and second region - vector_fp entropy_params; -}; - //! Set of parameters modifying SurfPhase enthalpy and entropy based on //! surface coverages using a interpolative model. //! Piecewise model is a subset of interpolative with three data points. @@ -182,33 +144,6 @@ class CoverageDependentSurfPhase : public SurfPhase */ void setPolynomialDependency(const PolynomialDependency& poly_deps); - //! Set the piecewise linear coverage dependece for species - /*! - * enthalpy and entropy are sum of ideal surface species enthalpy and entropy - * and coverage-dependent enthalpy and entropy which are calculated with - * a piecewise linear function of coverages: - * - * \f[ h^{cov}_k(\theta) = \sum_j h^{low}_{k,j} \theta_j - * \text{, for } \theta_j \leq \theta^{change}_{k,j} - * \f] - * \f[ h^{cov}_k(\theta) = \sum_j h^{high}_{k,j} - * (\theta_j - \theta^{change}_{k,j}) + - * (h^{low}_{k,j} \theta^{change}_{k,j}) \text{, for } - * \theta_j > \theta^{change}_{k,j} - * \f] - * - * \f[ s^{cov}_k(\theta) = \sum_j s^{low}_{k,j} \theta_j - * \text{, for } \theta_j \leq \theta^\text{change}_{k,j} - * \f] - * \f[ s^{cov}_k(\theta) = \sum_j s^{high}_{k,j} - * (\theta_j - \theta^{change}_{k,j}) + - * (s^{low}_{k,j} \theta^{change}_{k,j}) \text{, for } - * \theta_j > \theta^{change}_{k,j} - * \f] - * @param plin_deps list of parameters as a PiecewiseDependency object - */ - void setPiecewiseDependency(const PiecewiseDependency& plin_deps); - //! Set the interpolative coverage dependece for species /*! * enthalpy and entropy are sum of ideal surface species enthalpy and entropy @@ -449,10 +384,6 @@ class CoverageDependentSurfPhase : public SurfPhase //! the linear and polynomial models. std::vector m_PolynomialDependency; - //! Array of enthalpy and entropy coverage dependency parameters used in - //! the piecewise linear model. - std::vector m_PiecewiseDependency; - //! Array of enthalpy and entropy coverage dependency parameters used in //! the interpolative model. std::vector m_InterpolativeDependency; diff --git a/src/thermo/CoverageDependentSurfPhase.cpp b/src/thermo/CoverageDependentSurfPhase.cpp index f6567982aa1..1b6564aa2d4 100644 --- a/src/thermo/CoverageDependentSurfPhase.cpp +++ b/src/thermo/CoverageDependentSurfPhase.cpp @@ -14,7 +14,6 @@ #include "cantera/thermo/ThermoFactory.h" #include "cantera/base/stringUtils.h" #include "cantera/base/utilities.h" -#include "cantera/base/ctml.h" #include "cantera/thermo/Species.h" using namespace std; @@ -42,22 +41,6 @@ void CoverageDependentSurfPhase::setPolynomialDependency(const PolynomialDepende m_PolynomialDependency.push_back(poly_deps); } -void CoverageDependentSurfPhase::setPiecewiseDependency(const PiecewiseDependency& - plin_deps) -{ - double hcov_change = plin_deps.enthalpy_params[2]; - double scov_change = plin_deps.entropy_params[2]; - - if (hcov_change <= 0.0 || hcov_change > 1.0 || scov_change <= 0.0 - || scov_change > 1.0) { - throw CanteraError("CoverageDependentSurfPhase::setPiecewiseDependency", - "Coverage where slope changes must be greater than 0.0 and less" - + " than or equal to 1.0."); - } - - m_PiecewiseDependency.push_back(plin_deps); -} - void CoverageDependentSurfPhase::setInterpolativeDependency(const InterpolativeDependency& int_deps) @@ -119,8 +102,8 @@ void CoverageDependentSurfPhase::initThermo() m_theta_ref = m_input["reference-state-coverage"].as(); if (m_theta_ref <= 0.0 || m_theta_ref > 1.0) { throw CanteraError("CoverageDependentSurfPhase::initThermo", - "Reference state coverage must be greater than 0.0 and less" - + " than or equal to 1.0."); + "Reference state coverage must be greater than 0.0 and less\ + than or equal to 1.0."); } } for (auto& item : m_species) { @@ -175,21 +158,43 @@ void CoverageDependentSurfPhase::initThermo() setPolynomialDependency(poly_deps); // For piecewise linear model } else if (cov_map2["model"] == "piecewise-linear") { - vector_fp h_piecewise = {0.0, 0.0, 0.5}; - vector_fp s_piecewise = {0.0, 0.0, 0.5}; + 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")) { - h_piecewise[0] = cov_map2.convert("enthalpy-low", "J/kmol"); - h_piecewise[1] = cov_map2.convert("enthalpy-high", "J/kmol"); - h_piecewise[2] = cov_map2["enthalpy-change"].as(); + 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}); } + if (cov_map2.hasKey("entropy-low")) { - s_piecewise[0] = cov_map2.convert("entropy-low", "J/kmol/K"); - s_piecewise[1] = cov_map2.convert("entropy-high", "J/kmol/K"); - s_piecewise[2] = cov_map2["entropy-change"].as(); + 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}); } - PiecewiseDependency plin_deps(k, j, h_piecewise, s_piecewise); - setPiecewiseDependency(plin_deps); + InterpolativeDependency int_deps(k, j, hmap, smap); + setInterpolativeDependency(int_deps); // For interpolative model } else if (cov_map2["model"] == "interpolative") { std::map hmap, smap; @@ -199,9 +204,9 @@ void CoverageDependentSurfPhase::initThermo() vector_fp enthalpies = cov_map2.convertVector("enthalpies", "J/kmol"); if (hcovs.size() != enthalpies.size()) { - throw CanteraError("CoverageDependentSurfPhase::" - + "setInterpolativeDependency", "Sizes of coverages array" - + " and enthalpies array are not equal."); + throw CanteraError("CoverageDependentSurfPhase::\ + setInterpolativeDependency", "Sizes of coverages array\ + and enthalpies array are not equal."); } for (size_t i = 0; i < hcovs.size(); i++) { hmap.insert({hcovs[i], enthalpies[i]}); @@ -216,9 +221,9 @@ void CoverageDependentSurfPhase::initThermo() vector_fp entropies = cov_map2.convertVector("entropies", "J/kmol/K"); if (scovs.size() != entropies.size()) { - throw CanteraError("CoverageDependentSurfPhase::" - + "setInterpolativeDependency", "Sizes of coverages array" - + "and entropies array are not equal."); + throw CanteraError("CoverageDependentSurfPhase::\ + setInterpolativeDependency", "Sizes of coverages array\ + and entropies array are not equal."); } for (size_t i = 0; i < scovs.size(); i++) { smap.insert({scovs[i], entropies[i]}); @@ -426,30 +431,7 @@ void CoverageDependentSurfPhase::_updateCovDepThermo(bool force) const m_s_cov[item.k] += poly4(m_cov[item.j], item.entropy_coeffs.data()); } - // For piecewise linear model - for (auto& item : m_PiecewiseDependency) { - double h_slope_low = item.enthalpy_params[0]; - double h_slope_high = item.enthalpy_params[1]; - double h_cov_change = item.enthalpy_params[2]; - if (m_cov[item.j] <= h_cov_change) { - m_h_cov[item.k] += h_slope_low * m_cov[item.j]; - } else { - m_h_cov[item.k] += h_slope_low * h_cov_change; - m_h_cov[item.k] += h_slope_high * (m_cov[item.j] - h_cov_change); - } - - double s_slope_low = item.entropy_params[0]; - double s_slope_high = item.entropy_params[1]; - double s_cov_change = item.entropy_params[2]; - if (m_cov[item.j] <= s_cov_change) { - m_s_cov[item.k] += s_slope_low * m_cov[item.j]; - } else { - m_s_cov[item.k] += s_slope_low * s_cov_change; - m_s_cov[item.k] += s_slope_high * (m_cov[item.j] - s_cov_change); - } - } - - // For interpolative model + // For piecewise linear and interpolative model for (auto& item : m_InterpolativeDependency) { auto h_iter = item.enthalpy_map.upper_bound(m_cov[item.j]); auto s_iter = item.entropy_map.upper_bound(m_cov[item.j]);