diff --git a/include/cantera/equil/MultiPhase.h b/include/cantera/equil/MultiPhase.h index 91304a7ac..7569202fb 100644 --- a/include/cantera/equil/MultiPhase.h +++ b/include/cantera/equil/MultiPhase.h @@ -452,7 +452,7 @@ public: * Mole numbers that are less than or equal to zero will be * set to zero. units = kmol. */ - void setMolesByName(compositionMap& xMap); + void setMolesByName(const compositionMap& xMap); //! Set the moles via a string containing their names. /*! diff --git a/include/cantera/thermo/MolalityVPSSTP.h b/include/cantera/thermo/MolalityVPSSTP.h index 1406b994c..174d9db72 100644 --- a/include/cantera/thermo/MolalityVPSSTP.h +++ b/include/cantera/thermo/MolalityVPSSTP.h @@ -352,7 +352,7 @@ public: * * @param xMap Composition Map containing the molalities. */ - void setMolalitiesByName(compositionMap& xMap); + void setMolalitiesByName(const compositionMap& xMap); //! Set the molalities of a phase /*! @@ -660,7 +660,7 @@ public: * @param p Pressure (Pa) * @param m compositionMap containing the molalities */ - void setState_TPM(doublereal t, doublereal p, compositionMap& m); + void setState_TPM(doublereal t, doublereal p, const compositionMap& m); //! Set the temperature (K), pressure (Pa), and molalities. /*! diff --git a/include/cantera/thermo/Phase.h b/include/cantera/thermo/Phase.h index 736bb164b..9012a00cc 100644 --- a/include/cantera/thermo/Phase.h +++ b/include/cantera/thermo/Phase.h @@ -298,7 +298,7 @@ public: //! Set the species mole fractions by name. //! Species not listed by name in \c xMap are set to zero. //! @param xMap map from species names to mole fraction values. - void setMoleFractionsByName(compositionMap& xMap); + void setMoleFractionsByName(const compositionMap& xMap); //! Set the mole fractions of a group of species by name. Species which //! are not listed by name in the composition map are set to zero. @@ -308,7 +308,7 @@ public: //! Set the species mass fractions by name. //! Species not listed by name in \c yMap are set to zero. //! @param yMap map from species names to mass fraction values. - void setMassFractionsByName(compositionMap& yMap); + void setMassFractionsByName(const compositionMap& yMap); //! Set the species mass fractions by name. //! Species not listed by name in \c x are set to zero. @@ -327,7 +327,7 @@ public: //! @param x Composition Map containing the mole fractions. //! Species not included in the map are assumed to have //! a zero mole fraction. - void setState_TRX(doublereal t, doublereal dens, compositionMap& x); + void setState_TRX(doublereal t, doublereal dens, const compositionMap& x); //! Set the internally stored temperature (K), density, and mass fractions. //! @param t Temperature in kelvin @@ -341,7 +341,7 @@ public: //! @param y Composition Map containing the mass fractions. //! Species not included in the map are assumed to have //! a zero mass fraction. - void setState_TRY(doublereal t, doublereal dens, compositionMap& y); + void setState_TRY(doublereal t, doublereal dens, const compositionMap& y); //! Set the internally stored temperature (K), molar density (kmol/m^3), and mole fractions. //! @param t Temperature in kelvin diff --git a/include/cantera/thermo/SingleSpeciesTP.h b/include/cantera/thermo/SingleSpeciesTP.h index d497ca4c6..d36d0ff86 100644 --- a/include/cantera/thermo/SingleSpeciesTP.h +++ b/include/cantera/thermo/SingleSpeciesTP.h @@ -423,7 +423,7 @@ public: * @param x String containing a composition map of the mole fractions. Species not in * the composition map are assumed to have zero mole fraction */ - void setState_TPX(doublereal t, doublereal p, compositionMap& x); + void setState_TPX(doublereal t, doublereal p, const compositionMap& x); //! Set the temperature (K), pressure (Pa), and mole fractions. /*! @@ -459,7 +459,7 @@ public: * @param y Composition map of mass fractions. Species not in * the composition map are assumed to have zero mass fraction */ - void setState_TPY(doublereal t, doublereal p, compositionMap& y); + void setState_TPY(doublereal t, doublereal p, const compositionMap& y); //! Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase /*! diff --git a/include/cantera/thermo/ThermoPhase.h b/include/cantera/thermo/ThermoPhase.h index efd248c71..a38b59327 100644 --- a/include/cantera/thermo/ThermoPhase.h +++ b/include/cantera/thermo/ThermoPhase.h @@ -969,7 +969,7 @@ public: * @param x Composition map of mole fractions. Species not in * the composition map are assumed to have zero mole fraction */ - virtual void setState_TPX(doublereal t, doublereal p, compositionMap& x); + virtual void setState_TPX(doublereal t, doublereal p, const compositionMap& x); //! Set the temperature (K), pressure (Pa), and mole fractions. /*! @@ -1005,7 +1005,7 @@ public: * @param y Composition map of mass fractions. Species not in * the composition map are assumed to have zero mass fraction */ - virtual void setState_TPY(doublereal t, doublereal p, compositionMap& y); + virtual void setState_TPY(doublereal t, doublereal p, const compositionMap& y); //! Set the internally stored temperature (K), pressure (Pa), and mass fractions of the phase /*! diff --git a/src/equil/MultiPhase.cpp b/src/equil/MultiPhase.cpp index b42efc674..62ded410f 100644 --- a/src/equil/MultiPhase.cpp +++ b/src/equil/MultiPhase.cpp @@ -433,15 +433,14 @@ void MultiPhase::setPhaseMoleFractions(const size_t n, const doublereal* const x } } -void MultiPhase::setMolesByName(compositionMap& xMap) +void MultiPhase::setMolesByName(const compositionMap& xMap) { size_t kk = nSpecies(); - doublereal x; vector_fp moles(kk, 0.0); for (size_t k = 0; k < kk; k++) { - x = xMap[speciesName(k)]; - if (x > 0.0) { - moles[k] = x; + compositionMap::const_iterator iter = xMap.find(speciesName(k)); + if (iter != xMap.end() && iter->second > 0.0) { + moles[k] = iter->second; } } setMoles(DATA_PTR(moles)); diff --git a/src/thermo/MolalityVPSSTP.cpp b/src/thermo/MolalityVPSSTP.cpp index 11cfdaf63..e6d060626 100644 --- a/src/thermo/MolalityVPSSTP.cpp +++ b/src/thermo/MolalityVPSSTP.cpp @@ -178,7 +178,7 @@ void MolalityVPSSTP::setMolalities(const doublereal* const molal) calcMolalities(); } -void MolalityVPSSTP::setMolalitiesByName(compositionMap& mMap) +void MolalityVPSSTP::setMolalitiesByName(const compositionMap& mMap) { /* * HKM -> Might need to be more complicated here, setting @@ -186,7 +186,6 @@ void MolalityVPSSTP::setMolalitiesByName(compositionMap& mMap) * preserved. */ size_t kk = nSpecies(); - doublereal x; /* * Get a vector of mole fractions */ @@ -194,14 +193,10 @@ void MolalityVPSSTP::setMolalitiesByName(compositionMap& mMap) getMoleFractions(DATA_PTR(mf)); double xmolS = mf[m_indexSolvent]; double xmolSmin = std::max(xmolS, m_xmolSolventMIN); - compositionMap::iterator p; for (size_t k = 0; k < kk; k++) { - p = mMap.find(speciesName(k)); - if (p != mMap.end()) { - x = mMap[speciesName(k)]; - if (x > 0.0) { - mf[k] = x * m_Mnaught * xmolSmin; - } + compositionMap::const_iterator iter = mMap.find(speciesName(k)); + if (iter != mMap.end() && iter->second > 0.0) { + mf[k] = iter->second * m_Mnaught * xmolSmin; } } /* @@ -403,7 +398,7 @@ void MolalityVPSSTP::setState_TPM(doublereal t, doublereal p, setState_TP(t, p); } -void MolalityVPSSTP::setState_TPM(doublereal t, doublereal p, compositionMap& m) +void MolalityVPSSTP::setState_TPM(doublereal t, doublereal p, const compositionMap& m) { setMolalitiesByName(m); setState_TP(t, p); diff --git a/src/thermo/Phase.cpp b/src/thermo/Phase.cpp index ae77b5dbc..099aff0bf 100644 --- a/src/thermo/Phase.cpp +++ b/src/thermo/Phase.cpp @@ -344,15 +344,14 @@ void Phase::setMoleFractions_NoNorm(const doublereal* const x) m_stateNum++; } -void Phase::setMoleFractionsByName(compositionMap& xMap) +void Phase::setMoleFractionsByName(const compositionMap& xMap) { size_t kk = nSpecies(); - doublereal x; vector_fp mf(kk, 0.0); for (size_t k = 0; k < kk; k++) { - x = xMap[speciesName(k)]; - if (x > 0.0) { - mf[k] = x; + compositionMap::const_iterator iter = xMap.find(speciesName(k)); + if (iter != xMap.end() && iter->second > 0.0) { + mf[k] = iter->second; } } setMoleFractions(&mf[0]); @@ -389,15 +388,14 @@ void Phase::setMassFractions_NoNorm(const doublereal* const y) m_stateNum++; } -void Phase::setMassFractionsByName(compositionMap& yMap) +void Phase::setMassFractionsByName(const compositionMap& yMap) { size_t kk = nSpecies(); - doublereal y; vector_fp mf(kk, 0.0); for (size_t k = 0; k < kk; k++) { - y = yMap[speciesName(k)]; - if (y > 0.0) { - mf[k] = y; + compositionMap::const_iterator iter = yMap.find(speciesName(k)); + if (iter != yMap.end() && iter->second > 0.0) { + mf[k] = iter->second; } } setMassFractions(&mf[0]); @@ -423,7 +421,7 @@ void Phase::setState_TNX(doublereal t, doublereal n, const doublereal* x) setMolarDensity(n); } -void Phase::setState_TRX(doublereal t, doublereal dens, compositionMap& x) +void Phase::setState_TRX(doublereal t, doublereal dens, const compositionMap& x) { setMoleFractionsByName(x); setTemperature(t); @@ -437,7 +435,7 @@ void Phase::setState_TRY(doublereal t, doublereal dens, const doublereal* y) setDensity(dens); } -void Phase::setState_TRY(doublereal t, doublereal dens, compositionMap& y) +void Phase::setState_TRY(doublereal t, doublereal dens, const compositionMap& y) { setMassFractionsByName(y); setTemperature(t); diff --git a/src/thermo/SingleSpeciesTP.cpp b/src/thermo/SingleSpeciesTP.cpp index 869021b34..eac3fe666 100644 --- a/src/thermo/SingleSpeciesTP.cpp +++ b/src/thermo/SingleSpeciesTP.cpp @@ -247,7 +247,7 @@ void SingleSpeciesTP::setState_TPX(doublereal t, doublereal p, } void SingleSpeciesTP::setState_TPX(doublereal t, doublereal p, - compositionMap& x) + const compositionMap& x) { setTemperature(t); setPressure(p); @@ -268,7 +268,7 @@ void SingleSpeciesTP::setState_TPY(doublereal t, doublereal p, } void SingleSpeciesTP::setState_TPY(doublereal t, doublereal p, - compositionMap& y) + const compositionMap& y) { setTemperature(t); setPressure(p); diff --git a/src/thermo/ThermoPhase.cpp b/src/thermo/ThermoPhase.cpp index 390d191d7..b6dd71083 100644 --- a/src/thermo/ThermoPhase.cpp +++ b/src/thermo/ThermoPhase.cpp @@ -139,7 +139,7 @@ void ThermoPhase::setState_TPX(doublereal t, doublereal p, const doublereal* x) setState_TP(t,p); } -void ThermoPhase::setState_TPX(doublereal t, doublereal p, compositionMap& x) +void ThermoPhase::setState_TPX(doublereal t, doublereal p, const compositionMap& x) { setMoleFractionsByName(x); setState_TP(t,p); @@ -158,7 +158,7 @@ void ThermoPhase::setState_TPY(doublereal t, doublereal p, const doublereal* y) setState_TP(t,p); } -void ThermoPhase::setState_TPY(doublereal t, doublereal p, compositionMap& y) +void ThermoPhase::setState_TPY(doublereal t, doublereal p, const compositionMap& y) { setMassFractionsByName(y); setState_TP(t,p);