Skip to content

Commit

Permalink
Using std::pair
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl authored and speth committed Aug 5, 2023
1 parent 3dae4d4 commit 8f320c2
Show file tree
Hide file tree
Showing 19 changed files with 35 additions and 35 deletions.
18 changes: 9 additions & 9 deletions include/cantera/base/AnyMap.h
Expand Up @@ -285,7 +285,7 @@ class AnyValue : public AnyBase
bool hasMapWhere(const std::string& key, const std::string& value) const;

//! Return values used to determine the sort order when outputting to YAML
std::pair <int, int> order() const;
pair <int, int> order() const;

//! See AnyMap::applyUnits()
void applyUnits(shared_ptr<UnitSystem>& units);
Expand Down Expand Up @@ -542,10 +542,10 @@ class AnyMap : public AnyBase
Iterator(const std::unordered_map<std::string, AnyValue>::const_iterator& start,
const std::unordered_map<std::string, AnyValue>::const_iterator& stop);

const std::pair<const std::string, AnyValue>& operator*() const {
const pair<const std::string, AnyValue>& operator*() const {
return *m_iter;
}
const std::pair<const std::string, AnyValue>* operator->() const {
const pair<const std::string, AnyValue>* operator->() const {
return &*m_iter;
}
bool operator!=(const Iterator& right) const {
Expand Down Expand Up @@ -579,13 +579,13 @@ class AnyMap : public AnyBase
OrderedIterator begin() const;
OrderedIterator end() const;

typedef vector<std::pair<
std::pair<int, int>,
const std::pair<const std::string, AnyValue>*>> OrderVector;
typedef vector<pair<
pair<int, int>,
const pair<const std::string, AnyValue>*>> OrderVector;
private:
const AnyMap* m_data;
OrderVector m_ordered;
unique_ptr<std::pair<const std::string, AnyValue>> m_units;
unique_ptr<pair<const std::string, AnyValue>> m_units;
};

//! Defined to allow the OrderedProxy class to be used with range-based
Expand All @@ -596,10 +596,10 @@ class AnyMap : public AnyBase
OrderedIterator(const AnyMap::OrderedProxy::OrderVector::const_iterator& start,
const AnyMap::OrderedProxy::OrderVector::const_iterator& stop);

const std::pair<const std::string, AnyValue>& operator*() const {
const pair<const std::string, AnyValue>& operator*() const {
return *m_iter->second;
}
const std::pair<const std::string, AnyValue>* operator->() const {
const pair<const std::string, AnyValue>* operator->() const {
return &(*m_iter->second);
}
bool operator!=(const OrderedIterator& right) const {
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/base/Units.h
Expand Up @@ -109,7 +109,7 @@ struct UnitStack
}

//! Alternative constructor allows for direct assignment of vector
UnitStack(std::initializer_list<std::pair<Units, double>> units)
UnitStack(std::initializer_list<pair<Units, double>> units)
: stack(units) {}

UnitStack() = default;
Expand Down Expand Up @@ -137,7 +137,7 @@ struct UnitStack
//! Calculate product of units-exponent stack
Units product() const;

vector<std::pair<Units, double>> stack; //!< Stack uses vector of pairs
vector<pair<Units, double>> stack; //!< Stack uses vector of pairs
};


Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/BlowersMaselRate.h
Expand Up @@ -177,7 +177,7 @@ class BlowersMaselRate : public ArrheniusBase

protected:
//! Pairs of species indices and multipliers to calculate enthalpy change
vector<std::pair<size_t, double>> m_stoich_coeffs;
vector<pair<size_t, double>> m_stoich_coeffs;

double m_deltaH_R = 0.0; //!< enthalpy change of reaction (in temperature units)
};
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/Kinetics.h
Expand Up @@ -1459,7 +1459,7 @@ class Kinetics
* both elements of the pair. If no unmarked duplicates or unmatched marked
* duplicate reactions are found, returns `(npos, npos)`.
*/
virtual std::pair<size_t, size_t> checkDuplicates(bool throw_err=true) const;
virtual pair<size_t, size_t> checkDuplicates(bool throw_err=true) const;

/**
* Takes as input an array of properties for all species in the mechanism
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/MultiRate.h
Expand Up @@ -209,7 +209,7 @@ class MultiRate final : public MultiRateBase
}

//! Vector of pairs of reaction rates indices and reaction rates
vector<std::pair<size_t, RateType>> m_rxn_rates;
vector<pair<size_t, RateType>> m_rxn_rates;
std::map<size_t, size_t> m_indices; //! Mapping of indices
DataType m_shared;
};
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/PlogRate.h
Expand Up @@ -182,7 +182,7 @@ class PlogRate final : public ReactionRate

protected:
//! log(p) to (index range) in the rates_ vector
std::map<double, std::pair<size_t, size_t>> pressures_;
std::map<double, pair<size_t, size_t>> pressures_;

// Rate expressions which are referenced by the indices stored in pressures_
vector<ArrheniusRate> rates_;
Expand Down
10 changes: 5 additions & 5 deletions include/cantera/kinetics/StoichManager.h
Expand Up @@ -156,7 +156,7 @@ class C1
R[m_rxn] -= S[m_ic0];
}

void resizeCoeffs(const std::map<std::pair<size_t, size_t>, size_t>& indices)
void resizeCoeffs(const std::map<pair<size_t, size_t>, size_t>& indices)
{
m_jc0 = indices.at({m_rxn, m_ic0});
}
Expand Down Expand Up @@ -218,7 +218,7 @@ class C2
R[m_rxn] -= (S[m_ic0] + S[m_ic1]);
}

void resizeCoeffs(const std::map<std::pair<size_t, size_t>, size_t>& indices)
void resizeCoeffs(const std::map<pair<size_t, size_t>, size_t>& indices)
{
m_jc0 = indices.at({m_rxn, m_ic0});
m_jc1 = indices.at({m_rxn, m_ic1});
Expand Down Expand Up @@ -289,7 +289,7 @@ class C3
R[m_rxn] -= (S[m_ic0] + S[m_ic1] + S[m_ic2]);
}

void resizeCoeffs(const std::map<std::pair<size_t, size_t>, size_t>& indices)
void resizeCoeffs(const std::map<pair<size_t, size_t>, size_t>& indices)
{
m_jc0 = indices.at({m_rxn, m_ic0});
m_jc1 = indices.at({m_rxn, m_ic1});
Expand Down Expand Up @@ -392,7 +392,7 @@ class C_AnyN
}
}

void resizeCoeffs(const std::map<std::pair<size_t, size_t>, size_t>& indices)
void resizeCoeffs(const std::map<pair<size_t, size_t>, size_t>& indices)
{
for (size_t i = 0; i < m_n; i++) {
m_jc[i] = indices.at({m_rxn, m_ic[i]});
Expand Down Expand Up @@ -622,7 +622,7 @@ class StoichManagerN
m_values.resize(nCoeffs, 0.);

// Set up index pairs for derivatives
std::map<std::pair<size_t, size_t>, size_t> indices;
std::map<pair<size_t, size_t>, size_t> indices;
size_t n = 0;
for (int i = 0; i < tmp.outerSize(); i++) {
for (Eigen::SparseMatrix<double>::InnerIterator it(tmp, i); it; ++it) {
Expand Down
4 changes: 2 additions & 2 deletions include/cantera/thermo/MultiSpeciesThermo.h
Expand Up @@ -203,7 +203,7 @@ class MultiSpeciesThermo
//! Mark species *k* as having its thermodynamic data installed
void markInstalled(size_t k);

typedef std::pair<size_t, shared_ptr<SpeciesThermoInterpType> > index_STIT;
typedef pair<size_t, shared_ptr<SpeciesThermoInterpType> > index_STIT;
typedef std::map<int, vector<index_STIT> > STIT_map;
typedef std::map<int, vector<double>> tpoly_map;

Expand All @@ -219,7 +219,7 @@ class MultiSpeciesThermo
//! Map from species index to location within #m_sp, such that
//! `m_sp[m_speciesLoc[k].first][m_speciesLoc[k].second]` is the
//! SpeciesThermoInterpType object for species `k`.
std::map<size_t, std::pair<int, size_t> > m_speciesLoc;
std::map<size_t, pair<int, size_t> > m_speciesLoc;

//! Maximum value of the lowest temperature
double m_tlow_max = 0.0;
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/thermo/RedlichKwongMFTP.h
Expand Up @@ -238,7 +238,7 @@ class RedlichKwongMFTP : public MixtureFugacityTP
Array2D a_coeff_vec;

//! Explicitly-specified binary interaction parameters
std::map<std::string, std::map<std::string, std::pair<double, double>>> m_binaryParameters;
std::map<std::string, std::map<std::string, pair<double, double>>> m_binaryParameters;

enum class CoeffSource { EoS, CritProps, Database };
//! For each species, specifies the source of the a and b coefficients
Expand Down
4 changes: 2 additions & 2 deletions src/base/AnyMap.cpp
Expand Up @@ -1106,7 +1106,7 @@ bool AnyValue::hasMapWhere(const std::string& key, const std::string& value) con
}
}

std::pair<int, int> AnyValue::order() const
pair<int, int> AnyValue::order() const
{
return {m_line, m_column};
}
Expand Down Expand Up @@ -1594,7 +1594,7 @@ AnyMap::OrderedProxy::OrderedProxy(const AnyMap& data)
m_units = make_unique<pair<const string, AnyValue>>(
"units", m_data->at("__units__"));
m_units->second.setFlowStyle();
m_ordered.emplace_back(std::pair<int, int>{-2, 0}, m_units.get());
m_ordered.emplace_back(pair<int, int>{-2, 0}, m_units.get());
}

int head = 0; // sort key of the first programmatically-added item
Expand Down
4 changes: 2 additions & 2 deletions src/base/Storage.cpp
Expand Up @@ -170,7 +170,7 @@ void Storage::deleteGroup(const string& id)
}
}

std::pair<size_t, set<string>> Storage::contents(const string& id) const
pair<size_t, set<string>> Storage::contents(const string& id) const
{
try {
checkGroupRead(id);
Expand Down Expand Up @@ -606,7 +606,7 @@ void Storage::deleteGroup(const string& id)
"Saving to HDF requires HighFive installation.");
}

std::pair<size_t, set<string>> Storage::contents(const string& id) const
pair<size_t, set<string>> Storage::contents(const string& id) const
{
throw CanteraError("Storage::contents",
"Saving to HDF requires HighFive installation.");
Expand Down
2 changes: 1 addition & 1 deletion src/base/Units.cpp
Expand Up @@ -584,7 +584,7 @@ double UnitSystem::convertFrom(double value, const Units& src) const
* pow(m_energy_factor, -src.m_energy_dim);
}

static std::pair<double, std::string> split_unit(const AnyValue& v) {
static pair<double, std::string> split_unit(const AnyValue& v) {
if (v.is<std::string>()) {
// Should be a value and units, separated by a space, for example '2e4 J/kmol'
std::string val_units = v.asString();
Expand Down
2 changes: 1 addition & 1 deletion src/equil/MultiPhaseEquil.cpp
Expand Up @@ -593,7 +593,7 @@ double MultiPhaseEquil::computeReactionSteps(vector<double>& dxi)
void MultiPhaseEquil::computeN()
{
// Sort the list of species by mole fraction (decreasing order)
vector<std::pair<double, size_t> > moleFractions(m_nsp);
vector<pair<double, size_t> > moleFractions(m_nsp);
for (size_t k = 0; k < m_nsp; k++) {
// use -Xk to generate reversed sort order
moleFractions[k] = {-m_mix->speciesMoles(m_species[k]), k};
Expand Down
2 changes: 1 addition & 1 deletion src/equil/vcs_solve.cpp
Expand Up @@ -1843,7 +1843,7 @@ int VCS_SOLVE::vcs_report(int iconv)
bool inertYes = false;

// SORT DEPENDENT SPECIES IN DECREASING ORDER OF MOLES
vector<std::pair<double, size_t>> x_order;
vector<pair<double, size_t>> x_order;
for (size_t i = 0; i < m_nsp; i++) {
x_order.push_back({-m_molNumSpecies_old[i], i});
}
Expand Down
2 changes: 1 addition & 1 deletion src/kinetics/Kinetics.cpp
Expand Up @@ -104,7 +104,7 @@ void Kinetics::checkSpeciesArraySize(size_t kk) const
}
}

std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
{
//! Map of (key indicating participating species) to reaction numbers
std::map<size_t, vector<size_t> > participants;
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/BinarySolutionTabulatedThermo.cpp
Expand Up @@ -110,7 +110,7 @@ void BinarySolutionTabulatedThermo::initThermo()
}

// Sort the x, h, s, vmol data in the order of increasing x
vector<std::pair<double,double>> x_h(N), x_s(N), x_vmol(N);
vector<pair<double,double>> x_h(N), x_s(N), x_vmol(N);
for(size_t i = 0; i < N; i++) {
x_h[i] = {x[i], h[i]};
x_s[i] = {x[i], s[i]};
Expand Down
2 changes: 1 addition & 1 deletion src/zeroD/MoleReactor.cpp
Expand Up @@ -196,7 +196,7 @@ void MoleReactor::updateState(double* y)
};
double T = m_thermo->temperature();
boost::uintmax_t maxiter = 100;
std::pair<double, double> TT;
pair<double, double> TT;
try {
TT = bmt::bracket_and_solve_root(
u_err, T, 1.2, true, bmt::eps_tolerance<double>(48), maxiter);
Expand Down
2 changes: 1 addition & 1 deletion src/zeroD/Reactor.cpp
Expand Up @@ -143,7 +143,7 @@ void Reactor::updateState(double* y)

double T = m_thermo->temperature();
boost::uintmax_t maxiter = 100;
std::pair<double, double> TT;
pair<double, double> TT;
try {
TT = bmt::bracket_and_solve_root(
u_err, T, 1.2, true, bmt::eps_tolerance<double>(48), maxiter);
Expand Down
2 changes: 1 addition & 1 deletion test/kinetics/kineticsFromYaml.cpp
Expand Up @@ -405,7 +405,7 @@ TEST(Reaction, PlogFromYaml)
auto R = newReaction(rxn, *(sol->kinetics()));
EXPECT_FALSE(R->usesThirdBody());
const auto& rateMap = std::dynamic_pointer_cast<PlogRate>(R->rate())->getRates();
vector<std::pair<double, ArrheniusRate>> rates(rateMap.begin(), rateMap.end());
vector<pair<double, ArrheniusRate>> rates(rateMap.begin(), rateMap.end());
EXPECT_EQ(rates.size(), (size_t) 4);
EXPECT_NEAR(rates[0].first, 0.039474 * OneAtm, 1e-6);
EXPECT_NEAR(rates[2].first, OneAtm, 1e-6);
Expand Down

0 comments on commit 8f320c2

Please sign in to comment.