Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standardize code #1565

Merged
merged 4 commits into from
Aug 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/cantera/base/AnyMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ class AnyMap : public AnyBase

//! Return an unordered set of keys
//! @since New in %Cantera 3.0.
std::set<std::string> keys() const;
set<string> keys() const;

//! Set a metadata value that applies to this AnyMap and its children.
//! Mainly for internal use in reading or writing from files.
Expand Down
6 changes: 1 addition & 5 deletions include/cantera/base/ct_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ const int VT = -100, PH = -101, PS = -102, VP = -103, PT = -104,
const double SmallNumber = 1.e-300;
//! largest number to compare to inf.
const double BigNumber = 1.e300;
//! largest x such that exp(x) is valid
const double MaxExp = 690.775527898;

//! Fairly random number to be used to initialize variables against
//! to see if they are subsequently defined.
Expand All @@ -177,6 +175,7 @@ const double Tiny = 1.e-20;
//! Map connecting a string name with a double.
/*!
* This is used mostly to assign concentrations and mole fractions to species.
* @deprecated To be removed after %Cantera 3.0
*/
typedef map<string, double> compositionMap;

Expand All @@ -190,9 +189,6 @@ typedef vector<double> vector_fp;
//! Vector of ints
typedef vector<int> vector_int;

//! A grouplist is a vector of groups of species
typedef vector<vector<size_t>> grouplist_t;

//! index returned by functions to indicate "no position"
const size_t npos = static_cast<size_t>(-1);

Expand Down
4 changes: 2 additions & 2 deletions include/cantera/base/stringUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ std::string stripnonprint(const std::string& s);
* empty or unspecified, all values are allowed.
* @return map of names to values
*/
compositionMap parseCompString(const std::string& ss,
const std::vector<std::string>& names=std::vector<std::string>());
Composition parseCompString(const string& ss,
const vector<string>& names=vector<string>());

//! Translate a string into one doublereal value
/*!
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/equil/MultiPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,11 @@ class MultiPhase

//! Set the number of moles of species in the mixture
/*!
* @param xMap CompositionMap of the species with nonzero mole numbers.
* @param xMap Composition of the species with nonzero mole numbers.
* Mole numbers that are less than or equal to zero will be
* set to zero. units = kmol.
*/
void setMolesByName(const compositionMap& xMap);
void setMolesByName(const Composition& xMap);

//! Set the moles via a string containing their names.
/*!
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/LatticeSolidPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class LatticeSolidPhase : public ThermoPhase
void addLattice(shared_ptr<ThermoPhase> lattice);

//! Set the lattice stoichiometric coefficients, @f$ \theta_i @f$
void setLatticeStoichiometry(const compositionMap& comp);
void setLatticeStoichiometry(const Composition& comp);

virtual void setParameters(const AnyMap& phaseNode,
const AnyMap& rootNode=AnyMap());
Expand Down
6 changes: 3 additions & 3 deletions include/cantera/thermo/MolalityVPSSTP.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ class MolalityVPSSTP : public VPStandardStateTP
*
* @param xMap Composition Map containing the molalities.
*/
void setMolalitiesByName(const compositionMap& xMap);
void setMolalitiesByName(const Composition& xMap);

//! Set the molalities of a phase
/*!
Expand Down Expand Up @@ -514,9 +514,9 @@ class MolalityVPSSTP : public VPStandardStateTP
/*!
* @param t Temperature (K)
* @param p Pressure (Pa)
* @param m compositionMap containing the molalities
* @param m Composition containing the molalities
*/
void setState_TPM(doublereal t, doublereal p, const compositionMap& m);
void setState_TPM(doublereal t, doublereal p, const Composition& m);

//! Set the temperature (K), pressure (Pa), and molalities.
/*!
Expand Down
22 changes: 11 additions & 11 deletions include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class Phase
//! 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(const compositionMap& xMap);
void setMoleFractionsByName(const Composition& 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.
Expand All @@ -368,7 +368,7 @@ class Phase
//! 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(const compositionMap& yMap);
void setMassFractionsByName(const Composition& yMap);

//! Set the species mass fractions by name.
//! Species not listed by name in \c x are set to zero.
Expand All @@ -391,7 +391,7 @@ class Phase
//! a zero mole fraction.
//! @deprecated To be removed after %Cantera 3.0; replaceable by calls to
//! setMoleFractionsByName() and setState_TD().
void setState_TRX(doublereal t, doublereal dens, const compositionMap& x);
void setState_TRX(doublereal t, doublereal dens, const Composition& x);

//! Set the internally stored temperature (K), density, and mass fractions.
//! @param t Temperature in kelvin
Expand All @@ -409,7 +409,7 @@ class Phase
//! a zero mass fraction.
//! @deprecated To be removed after %Cantera 3.0; replaceable by calls to
//! setMassFractionsByName() and setState_TD().
void setState_TRY(doublereal t, doublereal dens, const compositionMap& y);
void setState_TRY(doublereal t, doublereal dens, const Composition& y);

//! Set the internally stored temperature (K), molar density (kmol/m^3), and
//! mole fractions.
Expand Down Expand Up @@ -490,7 +490,7 @@ class Phase
//! @param threshold Exclude species with mole fractions less than or
//! equal to this threshold.
//! @return Map of species names to mole fractions
compositionMap getMoleFractionsByName(double threshold=0.0) const;
Composition getMoleFractionsByName(double threshold=0.0) const;

//! Return the mole fraction of a single species
//! @param k species index
Expand All @@ -506,7 +506,7 @@ class Phase
//! @param threshold Exclude species with mass fractions less than or
//! equal to this threshold.
//! @return Map of species names to mass fractions
compositionMap getMassFractionsByName(double threshold=0.0) const;
Composition getMassFractionsByName(double threshold=0.0) const;

//! Return the mass fraction of a single species
//! @param k species index
Expand Down Expand Up @@ -830,9 +830,9 @@ class Phase
void addSpeciesAlias(const std::string& name, const std::string& alias);

//! Return a vector with isomers names matching a given composition map
//! @param compMap compositionMap of the species.
//! @param compMap Composition of the species.
//! @return A vector of species names for matching species.
virtual std::vector<std::string> findIsomers(const compositionMap& compMap) const;
virtual vector<string> findIsomers(const Composition& compMap) const;

//! Return a vector with isomers names matching a given composition string
//! @param comp String containing a composition map
Expand Down Expand Up @@ -893,13 +893,13 @@ class Phase
m_caseSensitiveSpecies = cflag;
}

//! Converts a compositionMap to a vector with entries for each species
//! Converts a Composition to a vector with entries for each species
//! Species that are not specified are set to zero in the vector
/*!
* @param[in] comp compositionMap containing the mixture composition
* @param[in] comp Composition containing the mixture composition
* @return vector with length m_kk
*/
vector_fp getCompositionFromMap(const compositionMap& comp) const;
vector_fp getCompositionFromMap(const Composition& comp) const;

//! Converts a mixture composition from mole fractions to mass fractions
//! @param[in] Y mixture composition in mass fractions (length m_kk)
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/thermo/Species.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Species
Species() = default;

//! Constructor
Species(const std::string& name, const compositionMap& comp,
Species(const string& name, const Composition& comp,
double charge=0.0, double size=1.0);

//! Species objects are not copyable or assignable
Expand All @@ -42,7 +42,7 @@ class Species

//! The elemental composition of the species. Keys are element names; values
//! are the corresponding atomicities.
compositionMap composition;
Composition composition;

//! The electrical charge on the species, in units of the elementary charge.
double charge = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/SurfPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ class SurfPhase : public ThermoPhase
void setCoveragesByName(const std::string& cov);

//! Set the coverages from a map of name:value pairs
void setCoveragesByName(const compositionMap& cov);
void setCoveragesByName(const Composition& cov);

//! Return a vector of surface coverages
/*!
Expand Down
26 changes: 13 additions & 13 deletions include/cantera/thermo/ThermoPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ class ThermoPhase : public Phase
* @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, const compositionMap& x);
virtual void setState_TPX(doublereal t, doublereal p, const Composition& x);

//! Set the temperature (K), pressure (Pa), and mole fractions.
/*!
Expand Down Expand Up @@ -855,7 +855,7 @@ class ThermoPhase : public Phase
* @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, const compositionMap& y);
virtual void setState_TPY(doublereal t, doublereal p, const Composition& y);

//! Set the internally stored temperature (K), pressure (Pa), and mass
//! fractions of the phase
Expand Down Expand Up @@ -1130,7 +1130,7 @@ class ThermoPhase : public Phase
* @deprecated To be removed after %Cantera 3.0; replaceable by calls to
* setMoleFractionsByName() and setState_DP().
*/
virtual void setState_RPX(doublereal rho, doublereal p, const compositionMap& x);
virtual void setState_RPX(doublereal rho, doublereal p, const Composition& x);

//! Set the density (kg/m**3), pressure (Pa) and mole fractions
/*!
Expand Down Expand Up @@ -1176,7 +1176,7 @@ class ThermoPhase : public Phase
* @deprecated To be removed after %Cantera 3.0; replaceable by calls to
* setMassFractionsByName() and setState_DP().
*/
virtual void setState_RPY(doublereal rho, doublereal p, const compositionMap& y);
virtual void setState_RPY(doublereal rho, doublereal p, const Composition& y);

//! Set the density (kg/m**3), pressure (Pa) and mass fractions
/*!
Expand Down Expand Up @@ -1244,8 +1244,8 @@ class ThermoPhase : public Phase
void setMixtureFraction(double mixFrac, const std::string& fuelComp,
const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar);
//! @copydoc ThermoPhase::setMixtureFraction
void setMixtureFraction(double mixFrac, const compositionMap& fuelComp,
const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar);
void setMixtureFraction(double mixFrac, const Composition& fuelComp,
const Composition& oxComp, ThermoBasis basis=ThermoBasis::molar);
//! @}
//! @name Compute Mixture Fraction
//! @{
Expand Down Expand Up @@ -1290,7 +1290,7 @@ class ThermoPhase : public Phase
ThermoBasis basis=ThermoBasis::molar,
const std::string& element="Bilger") const;
//! @copydoc ThermoPhase::mixtureFraction
double mixtureFraction(const compositionMap& fuelComp, const compositionMap& oxComp,
double mixtureFraction(const Composition& fuelComp, const Composition& oxComp,
ThermoBasis basis=ThermoBasis::molar,
const std::string& element="Bilger") const;
//! @}
Expand All @@ -1317,8 +1317,8 @@ class ThermoPhase : public Phase
void setEquivalenceRatio(double phi, const std::string& fuelComp,
const std::string& oxComp, ThermoBasis basis=ThermoBasis::molar);
//! @copydoc ThermoPhase::setEquivalenceRatio
void setEquivalenceRatio(double phi, const compositionMap& fuelComp,
const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar);
void setEquivalenceRatio(double phi, const Composition& fuelComp,
const Composition& oxComp, ThermoBasis basis=ThermoBasis::molar);
//! @}

//! @name Compute Equivalence Ratio
Expand Down Expand Up @@ -1354,8 +1354,8 @@ class ThermoPhase : public Phase
double equivalenceRatio(const std::string& fuelComp, const std::string& oxComp,
ThermoBasis basis=ThermoBasis::molar) const;
//! @copydoc ThermoPhase::equivalenceRatio
double equivalenceRatio(const compositionMap& fuelComp,
const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar) const;
double equivalenceRatio(const Composition& fuelComp,
const Composition& oxComp, ThermoBasis basis=ThermoBasis::molar) const;
//! @}

//! Compute the equivalence ratio for the current mixture
Expand Down Expand Up @@ -1409,8 +1409,8 @@ class ThermoPhase : public Phase
double stoichAirFuelRatio(const std::string& fuelComp, const std::string& oxComp,
ThermoBasis basis=ThermoBasis::molar) const;
//! @copydoc ThermoPhase::stoichAirFuelRatio
double stoichAirFuelRatio(const compositionMap& fuelComp,
const compositionMap& oxComp, ThermoBasis basis=ThermoBasis::molar) const;
double stoichAirFuelRatio(const Composition& fuelComp,
const Composition& oxComp, ThermoBasis basis=ThermoBasis::molar) const;
//! @}

private:
Expand Down
3 changes: 1 addition & 2 deletions interfaces/cython/cantera/ctml2yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ def split_species_value_string(node: etree.Element) -> Dict[str, float]:
values are the number associated with each species. This is useful for things like
elemental composition, mole fraction mappings, coverage mappings, etc.

The algorithm is reimplemented from ``compositionMap::parseCompString`` in
``base/stringUtils.cpp``.
The algorithm is reimplemented from :ct:`parseCompString`.
"""
text = clean_node_text(node)
pairs = FlowMap({})
Expand Down
4 changes: 2 additions & 2 deletions src/base/AnyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1461,9 +1461,9 @@ std::string AnyMap::keys_str() const
return to_string(b);
}

std::set<std::string> AnyMap::keys() const
set<string> AnyMap::keys() const
{
std::set<std::string> out;
set<string> out;
auto iter = this->begin();
while (iter != this->end()) {
out.insert(iter->first);
Expand Down
2 changes: 1 addition & 1 deletion src/base/YamlWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ std::string YamlWriter::toYamlString() const
output["date"].setLoc(-2, 0);

// Add remaining header information, ignoring obsolete information
std::set<std::string> exclude = {
set<string> exclude = {
"description", "generator", "cantera-version", "git-commit", "date"};
for (const auto& [key, value] : m_header) {
if (!exclude.count(key)) {
Expand Down
7 changes: 3 additions & 4 deletions src/base/application.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,8 @@ class Application
//! Versions of Python to consider when attempting to load user extensions
vector<string> m_pythonSearchVersions = {"3.11", "3.10", "3.9", "3.8"};

//! Vector of deprecation warnings that have been emitted (to suppress
//! duplicates)
std::set<std::string> warnings;
//! Set of deprecation warnings that have been emitted (to suppress duplicates)
set<string> warnings;

bool m_suppress_deprecation_warnings = false;
bool m_fatal_deprecation_warnings = false;
Expand All @@ -448,7 +447,7 @@ class Application
bool m_fatal_warnings = false;
bool m_use_legacy_rate_constants = false;

std::set<std::pair<std::string, std::string>> m_loaded_extensions;
set<pair<string, string>> m_loaded_extensions;

ThreadMessages pMessenger;

Expand Down
5 changes: 2 additions & 3 deletions src/base/stringUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ std::string stripnonprint(const std::string& s)
return ss;
}

compositionMap parseCompString(const std::string& ss,
const std::vector<std::string>& names)
Composition parseCompString(const string& ss, const vector<string>& names)
{
compositionMap x;
Composition x;
for (size_t k = 0; k < names.size(); k++) {
x[names[k]] = 0.0;
}
Expand Down
4 changes: 2 additions & 2 deletions src/equil/MultiPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void MultiPhase::setPhaseMoleFractions(const size_t n, const doublereal* const x
}
}

void MultiPhase::setMolesByName(const compositionMap& xMap)
void MultiPhase::setMolesByName(const Composition& xMap)
{
size_t kk = nSpecies();
vector_fp moles(kk, 0.0);
Expand All @@ -353,7 +353,7 @@ void MultiPhase::setMolesByName(const compositionMap& xMap)
void MultiPhase::setMolesByName(const std::string& x)
{
// build the composition map from the string, and then set the moles.
compositionMap xx = parseCompString(x, m_snames);
Composition xx = parseCompString(x, m_snames);
setMolesByName(xx);
}

Expand Down
2 changes: 1 addition & 1 deletion src/oneD/Domain1D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ AnyMap Domain1D::getMeta() const
auto wrap_tols = [this](const vector_fp& tols) {
// If all tolerances are the same, just store the scalar value.
// Otherwise, store them by component name
std::set<double> unique_tols(tols.begin(), tols.end());
set<double> unique_tols(tols.begin(), tols.end());
if (unique_tols.size() == 1) {
return AnyValue(tols[0]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/oneD/StFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ AnyMap StFlow::getMeta() const
state["emissivity-right"] = m_epsilon_right;
}

std::set<bool> energy_flags(m_do_energy.begin(), m_do_energy.end());
set<bool> energy_flags(m_do_energy.begin(), m_do_energy.end());
if (energy_flags.size() == 1) {
state["energy-enabled"] = m_do_energy[0];
} else {
Expand All @@ -760,7 +760,7 @@ AnyMap StFlow::getMeta() const

state["Soret-enabled"] = m_do_soret;

std::set<bool> species_flags(m_do_species.begin(), m_do_species.end());
set<bool> species_flags(m_do_species.begin(), m_do_species.end());
if (species_flags.size() == 1) {
state["species-enabled"] = m_do_species[0];
} else {
Expand Down
Loading
Loading