Use range-based for and auto to simplify some loops

This commit is contained in:
Ray Speth 2015-09-10 18:22:55 -04:00
parent c2ba24c0c2
commit 2589a27b6c
29 changed files with 220 additions and 373 deletions

View file

@ -226,9 +226,9 @@ public:
* *
*/ */
void axpy(doublereal a, const Array2D& x, const Array2D& y) { void axpy(doublereal a, const Array2D& x, const Array2D& y) {
iterator b = begin(); auto b = begin();
const_iterator xb = x.begin(); auto xb = x.begin();
const_iterator yb = y.begin(); auto yb = y.begin();
for (; b != end(); ++b, ++xb, ++yb) { for (; b != end(); ++b, ++xb, ++yb) {
*b = a*(*xb) + *yb; *b = a*(*xb) + *yb;
} }

View file

@ -26,11 +26,8 @@ public:
//! static function that deletes all factories //! static function that deletes all factories
//! in the internal registry maintained in a static variable //! in the internal registry maintained in a static variable
static void deleteFactories() { static void deleteFactories() {
std::vector< FactoryBase* >::iterator iter; for (const auto& f : s_vFactoryRegistry) {
for (iter = s_vFactoryRegistry.begin(); f->deleteFactory();
iter != s_vFactoryRegistry.end();
++iter) {
(*iter)->deleteFactory();
} }
s_vFactoryRegistry.clear(); s_vFactoryRegistry.clear();
} }

View file

@ -190,7 +190,7 @@ public:
return; return;
} }
pressureIter iter = pressures_.upper_bound(c[0]); auto iter = pressures_.upper_bound(c[0]);
AssertThrowMsg(iter != pressures_.end(), "Plog::update_C", AssertThrowMsg(iter != pressures_.end(), "Plog::update_C",
"Pressure out of range: " + fp2str(logP_)); "Pressure out of range: " + fp2str(logP_));
AssertThrowMsg(iter != pressures_.begin(), "Plog::update_C", AssertThrowMsg(iter != pressures_.begin(), "Plog::update_C",
@ -252,7 +252,6 @@ public:
protected: protected:
//! log(p) to (index range) in the rates_ vector //! log(p) to (index range) in the rates_ vector
std::map<double, std::pair<size_t, size_t> > pressures_; std::map<double, std::pair<size_t, size_t> > pressures_;
typedef std::map<double, std::pair<size_t, size_t> >::iterator pressureIter;
// Rate expressions which are referenced by the indices stored in pressures_ // Rate expressions which are referenced by the indices stored in pressures_
std::vector<Arrhenius> rates_; std::vector<Arrhenius> rates_;

View file

@ -23,13 +23,10 @@ public:
m_species.push_back(std::vector<size_t>()); m_species.push_back(std::vector<size_t>());
m_eff.push_back(vector_fp()); m_eff.push_back(vector_fp());
for (std::map<size_t, double>::const_iterator iter = enhanced.begin(); for (const auto& eff : enhanced) {
iter != enhanced.end(); assert(eff.first != npos);
++iter) m_species.back().push_back(eff.first);
{ m_eff.back().push_back(eff.second - dflt);
assert(iter->first != npos);
m_species.back().push_back(iter->first);
m_eff.back().push_back(iter->second - dflt);
} }
} }

View file

@ -142,7 +142,7 @@ Application::Messages* Application::ThreadMessages::operator ->()
{ {
ScopedLock msgLock(msg_mutex); ScopedLock msgLock(msg_mutex);
cthreadId_t curId = getThisThreadId(); cthreadId_t curId = getThisThreadId();
threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId); auto iter = m_threadMsgMap.find(curId);
if (iter != m_threadMsgMap.end()) { if (iter != m_threadMsgMap.end()) {
return iter->second.get(); return iter->second.get();
} }
@ -155,7 +155,7 @@ void Application::ThreadMessages::removeThreadMessages()
{ {
ScopedLock msgLock(msg_mutex); ScopedLock msgLock(msg_mutex);
cthreadId_t curId = getThisThreadId(); cthreadId_t curId = getThisThreadId();
threadMsgMap_t::iterator iter = m_threadMsgMap.find(curId); auto iter = m_threadMsgMap.find(curId);
if (iter != m_threadMsgMap.end()) { if (iter != m_threadMsgMap.end()) {
m_threadMsgMap.erase(iter); m_threadMsgMap.erase(iter);
} }
@ -188,11 +188,10 @@ Application* Application::Instance()
Application::~Application() Application::~Application()
{ {
std::map<std::string, std::pair<XML_Node*, int> >::iterator pos; for (auto& f : xmlfiles) {
for (pos = xmlfiles.begin(); pos != xmlfiles.end(); ++pos) { f.second.first->unlock();
pos->second.first->unlock(); delete f.second.first;
delete pos->second.first; f.second.first = 0;
pos->second.first = 0;
} }
} }
@ -293,12 +292,9 @@ void Application::close_XML_File(const std::string& file)
{ {
ScopedLock xmlLock(xml_mutex); ScopedLock xmlLock(xml_mutex);
if (file == "all") { if (file == "all") {
std::map<string, std::pair<XML_Node*, int> >::iterator for (const auto& f : xmlfiles) {
b = xmlfiles.begin(), f.second.first->unlock();
e = xmlfiles.end(); delete f.second.first;
for (; b != e; ++b) {
b->second.first->unlock();
delete b->second.first;
} }
xmlfiles.clear(); xmlfiles.clear();
} else if (xmlfiles.find(file) != xmlfiles.end()) { } else if (xmlfiles.find(file) != xmlfiles.end()) {
@ -469,8 +465,7 @@ void Application::addDataDirectory(const std::string& dir)
string d = stripnonprint(dir); string d = stripnonprint(dir);
// Remove any existing entry for this directory // Remove any existing entry for this directory
std::vector<string>::iterator iter = std::find(inputDirs.begin(), auto iter = std::find(inputDirs.begin(), inputDirs.end(), d);
inputDirs.end(), d);
if (iter != inputDirs.end()) { if (iter != inputDirs.end()) {
inputDirs.erase(iter); inputDirs.erase(iter);
} }

View file

@ -303,11 +303,8 @@ static std::string::size_type findFirstWS(const std::string& val)
{ {
std::string::size_type ibegin = std::string::npos; std::string::size_type ibegin = std::string::npos;
int j = 0; int j = 0;
std::string::const_iterator i = val.begin(); for (const auto& ch : val) {
for (; i != val.end(); i++) { if (isspace(static_cast<int>(ch))) {
char ch = *i;
int ll = (int) ch;
if (isspace(ll)) {
ibegin = (std::string::size_type) j; ibegin = (std::string::size_type) j;
break; break;
} }
@ -328,11 +325,8 @@ static std::string::size_type findFirstNotOfWS(const std::string& val)
{ {
std::string::size_type ibegin = std::string::npos; std::string::size_type ibegin = std::string::npos;
int j = 0; int j = 0;
std::string::const_iterator i = val.begin(); for (const auto& ch : val) {
for (; i != val.end(); i++) { if (!isspace(static_cast<int>(ch))) {
char ch = *i;
int ll = (int) ch;
if (!isspace(ll)) {
ibegin = (std::string::size_type) j; ibegin = (std::string::size_type) j;
break; break;
} }

View file

@ -429,8 +429,7 @@ XML_Node& XML_Node::addChild(const std::string& name, const doublereal value,
void XML_Node::removeChild(const XML_Node* const node) void XML_Node::removeChild(const XML_Node* const node)
{ {
vector<XML_Node*>::iterator i; auto i = find(m_children.begin(), m_children.end(), node);
i = find(m_children.begin(), m_children.end(), node);
m_children.erase(i); m_children.erase(i);
m_childindex.erase(node->name()); m_childindex.erase(node->name());
} }
@ -792,10 +791,9 @@ void XML_Node::copyUnion(XML_Node* const node_dest) const
if (m_name == "") { if (m_name == "") {
return; return;
} }
map<string,string>::const_iterator b = m_attribs.begin(); for (const auto& attr : m_attribs) {
for (; b != m_attribs.end(); ++b) { if (!node_dest->hasAttrib(attr.first)) {
if (! node_dest->hasAttrib(b->first)) { node_dest->addAttribute(attr.first, attr.second);
node_dest->addAttribute(b->first, b->second);
} }
} }
const vector<XML_Node*> &vsc = node_dest->children(); const vector<XML_Node*> &vsc = node_dest->children();
@ -840,9 +838,8 @@ void XML_Node::copy(XML_Node* const node_dest) const
if (m_name == "") { if (m_name == "") {
return; return;
} }
map<string,string>::const_iterator b = m_attribs.begin(); for (const auto& attr : m_attribs) {
for (; b != m_attribs.end(); ++b) { node_dest->addAttribute(attr.first, attr.second);
node_dest->addAttribute(b->first, b->second);
} }
const vector<XML_Node*> &vsc = node_dest->children(); const vector<XML_Node*> &vsc = node_dest->children();
@ -888,21 +885,19 @@ XML_Node& XML_Node::child(const std::string& aloc) const
string::size_type iloc; string::size_type iloc;
string cname; string cname;
string loc = aloc; string loc = aloc;
std::multimap<std::string,XML_Node*>::const_iterator i;
while (true) { while (true) {
iloc = loc.find('/'); iloc = loc.find('/');
if (iloc != string::npos) { if (iloc != string::npos) {
cname = loc.substr(0,iloc); cname = loc.substr(0,iloc);
loc = loc.substr(iloc+1, loc.size()); loc = loc.substr(iloc+1, loc.size());
i = m_childindex.find(cname); auto i = m_childindex.find(cname);
if (i != m_childindex.end()) { if (i != m_childindex.end()) {
return i->second->child(loc); return i->second->child(loc);
} else { } else {
throw XML_NoChild(this, m_name, cname, lineNumber()); throw XML_NoChild(this, m_name, cname, lineNumber());
} }
} else { } else {
i = m_childindex.find(loc); auto i = m_childindex.find(loc);
if (i != m_childindex.end()) { if (i != m_childindex.end()) {
return *(i->second); return *(i->second);
} else { } else {
@ -938,9 +933,8 @@ void XML_Node::write_int(std::ostream& s, int level, int numRecursivesAllowed) c
} }
s << indent << "<" << m_name; s << indent << "<" << m_name;
map<string,string>::const_iterator b = m_attribs.begin(); for (const auto& attr : m_attribs) {
for (; b != m_attribs.end(); ++b) { s << " " << attr.first << "=\"" << attr.second << "\"";
s << " " << b->first << "=\"" << b->second << "\"";
} }
if (m_value == "" && m_children.empty()) { if (m_value == "" && m_children.empty()) {
s << "/>"; s << "/>";

View file

@ -65,7 +65,6 @@ class Cabinet
{ {
public: public:
typedef std::vector<M*>& dataRef; typedef std::vector<M*>& dataRef;
typedef typename std::vector<M*>::iterator dataIterator;
/** /**
* Destructor. Delete all objects in the list. * Destructor. Delete all objects in the list.
*/ */
@ -165,7 +164,7 @@ public:
*/ */
static int index(const M& obj) { static int index(const M& obj) {
dataRef data = getData(); dataRef data = getData();
dataIterator loc = std::find(data.begin(), data.end(), &obj); auto loc = std::find(data.begin(), data.end(), &obj);
if (loc != data.end()) { if (loc != data.end()) {
return static_cast<int>(loc-data.begin()); return static_cast<int>(loc-data.begin());
} else { } else {

View file

@ -27,9 +27,8 @@ double vcs_l2norm(const vector_fp vec)
return 0.0; return 0.0;
} }
double sum = 0.0; double sum = 0.0;
vector_fp::const_iterator pos; for (const auto& val : vec) {
for (pos = vec.begin(); pos != vec.end(); ++pos) { sum += val * val;
sum += (*pos) * (*pos);
} }
return std::sqrt(sum / len); return std::sqrt(sum / len);
} }

View file

@ -113,15 +113,11 @@ bool BulkKinetics::addReaction(shared_ptr<Reaction> r)
return false; return false;
} }
double dn = 0.0; double dn = 0.0;
for (Composition::const_iterator iter = r->products.begin(); for (const auto& sp : r->products) {
iter != r->products.end(); dn += sp.second;
++iter) {
dn += iter->second;
} }
for (Composition::const_iterator iter = r->reactants.begin(); for (const auto& sp : r->reactants) {
iter != r->reactants.end(); dn -= sp.second;
++iter) {
dn -= iter->second;
} }
m_dn.push_back(dn); m_dn.push_back(dn);

View file

@ -285,15 +285,13 @@ void GasKinetics::addFalloffReaction(FalloffReaction& r)
// install the enhanced third-body concentration calculator // install the enhanced third-body concentration calculator
map<size_t, double> efficiencies; map<size_t, double> efficiencies;
for (Composition::const_iterator iter = r.third_body.efficiencies.begin(); for (const auto& eff : r.third_body.efficiencies) {
iter != r.third_body.efficiencies.end(); size_t k = kineticsSpeciesIndex(eff.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
if (k != npos) { if (k != npos) {
efficiencies[k] = iter->second; efficiencies[k] = eff.second;
} else if (!m_skipUndeclaredThirdBodies) { } else if (!m_skipUndeclaredThirdBodies) {
throw CanteraError("GasKinetics::addTFalloffReaction", "Found " throw CanteraError("GasKinetics::addTFalloffReaction", "Found "
"third-body efficiency for undefined species '" + iter->first + "third-body efficiency for undefined species '" + eff.first +
"' while adding reaction '" + r.equation() + "'"); "' while adding reaction '" + r.equation() + "'");
} }
} }
@ -311,15 +309,13 @@ void GasKinetics::addThreeBodyReaction(ThreeBodyReaction& r)
{ {
m_rates.install(nReactions()-1, r.rate); m_rates.install(nReactions()-1, r.rate);
map<size_t, double> efficiencies; map<size_t, double> efficiencies;
for (Composition::const_iterator iter = r.third_body.efficiencies.begin(); for (const auto& eff : r.third_body.efficiencies) {
iter != r.third_body.efficiencies.end(); size_t k = kineticsSpeciesIndex(eff.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
if (k != npos) { if (k != npos) {
efficiencies[k] = iter->second; efficiencies[k] = eff.second;
} else if (!m_skipUndeclaredThirdBodies) { } else if (!m_skipUndeclaredThirdBodies) {
throw CanteraError("GasKinetics::addThreeBodyReaction", "Found " throw CanteraError("GasKinetics::addThreeBodyReaction", "Found "
"third-body efficiency for undefined species '" + iter->first + "third-body efficiency for undefined species '" + eff.first +
"' while adding reaction '" + r.equation() + "'"); "' while adding reaction '" + r.equation() + "'");
} }
} }

View file

@ -718,10 +718,8 @@ bool InterfaceKinetics::addReaction(shared_ptr<Reaction> r_base)
} }
if (!r.orders.empty()) { if (!r.orders.empty()) {
vector_fp orders(nTotalSpecies(), 0.0); vector_fp orders(nTotalSpecies(), 0.0);
for (Composition::const_iterator iter = r.orders.begin(); for (const auto& order : r.orders) {
iter != r.orders.end(); orders[kineticsSpeciesIndex(order.first)] = order.second;
++iter) {
orders[kineticsSpeciesIndex(iter->first)] = iter->second;
} }
} }
} else { } else {
@ -744,17 +742,13 @@ bool InterfaceKinetics::addReaction(shared_ptr<Reaction> r_base)
m_rxnPhaseIsReactant.push_back(std::vector<bool>(nPhases(), false)); m_rxnPhaseIsReactant.push_back(std::vector<bool>(nPhases(), false));
m_rxnPhaseIsProduct.push_back(std::vector<bool>(nPhases(), false)); m_rxnPhaseIsProduct.push_back(std::vector<bool>(nPhases(), false));
for (Composition::const_iterator iter = r.reactants.begin(); for (const auto& sp : r.reactants) {
iter != r.reactants.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
size_t p = speciesPhaseIndex(k); size_t p = speciesPhaseIndex(k);
m_rxnPhaseIsReactant[i][p] = true; m_rxnPhaseIsReactant[i][p] = true;
} }
for (Composition::const_iterator iter = r.products.begin(); for (const auto& sp : r.products) {
iter != r.products.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
size_t p = speciesPhaseIndex(k); size_t p = speciesPhaseIndex(k);
m_rxnPhaseIsProduct[i][p] = true; m_rxnPhaseIsProduct[i][p] = true;
} }
@ -795,10 +789,8 @@ SurfaceArrhenius InterfaceKinetics::buildSurfaceArrhenius(
if (sticking_species == "") { if (sticking_species == "") {
// Identify the sticking species if not explicitly given // Identify the sticking species if not explicitly given
bool foundStick = false; bool foundStick = false;
for (Composition::const_iterator iter = r.reactants.begin(); for (const auto& sp : r.reactants) {
iter != r.reactants.end(); size_t iPhase = speciesPhaseIndex(kineticsSpeciesIndex(sp.first));
++iter) {
size_t iPhase = speciesPhaseIndex(kineticsSpeciesIndex(iter->first));
if (iPhase != iInterface) { if (iPhase != iInterface) {
// Non-interface species. There should be exactly one of these // Non-interface species. There should be exactly one of these
if (foundStick) { if (foundStick) {
@ -807,7 +799,7 @@ SurfaceArrhenius InterfaceKinetics::buildSurfaceArrhenius(
"in sticking reaction: '" + r.equation() + "'"); "in sticking reaction: '" + r.equation() + "'");
} }
foundStick = true; foundStick = true;
sticking_species = iter->first; sticking_species = sp.first;
} }
} }
if (!foundStick) { if (!foundStick) {
@ -819,14 +811,12 @@ SurfaceArrhenius InterfaceKinetics::buildSurfaceArrhenius(
double surface_order = 0.0; double surface_order = 0.0;
// Adjust the A-factor // Adjust the A-factor
for (Composition::const_iterator iter = r.reactants.begin(); for (const auto& sp : r.reactants) {
iter != r.reactants.end(); size_t iPhase = speciesPhaseIndex(kineticsSpeciesIndex(sp.first));
++iter) {
size_t iPhase = speciesPhaseIndex(kineticsSpeciesIndex(iter->first));
const ThermoPhase& p = thermo(iPhase); const ThermoPhase& p = thermo(iPhase);
const ThermoPhase& surf = thermo(surfacePhaseIndex()); const ThermoPhase& surf = thermo(surfacePhaseIndex());
size_t k = p.speciesIndex(iter->first); size_t k = p.speciesIndex(sp.first);
if (iter->first == sticking_species) { if (sp.first == sticking_species) {
A_rate *= sqrt(GasConstant/(2*Pi*p.molecularWeight(k))); A_rate *= sqrt(GasConstant/(2*Pi*p.molecularWeight(k)));
} else { } else {
// Non-sticking species. Convert from coverages used in the // Non-sticking species. Convert from coverages used in the
@ -835,7 +825,7 @@ SurfaceArrhenius InterfaceKinetics::buildSurfaceArrhenius(
// the dependence on the site density is incorporated when the // the dependence on the site density is incorporated when the
// rate constant is evaluated, since we don't assume that the // rate constant is evaluated, since we don't assume that the
// site density is known at this time. // site density is known at this time.
double order = getValue(r.orders, iter->first, iter->second); double order = getValue(r.orders, sp.first, sp.second);
if (&p == &surf) { if (&p == &surf) {
A_rate *= pow(p.size(k), order); A_rate *= pow(p.size(k), order);
surface_order += order; surface_order += order;
@ -852,11 +842,9 @@ SurfaceArrhenius InterfaceKinetics::buildSurfaceArrhenius(
SurfaceArrhenius rate(A_rate, b_rate, r.rate.activationEnergy_R()); SurfaceArrhenius rate(A_rate, b_rate, r.rate.activationEnergy_R());
// Set up coverage dependencies // Set up coverage dependencies
for (map<string, CoverageDependency>::const_iterator iter = r.coverage_deps.begin(); for (const auto& sp : r.coverage_deps) {
iter != r.coverage_deps.end(); size_t k = thermo(reactionPhaseIndex()).speciesIndex(sp.first);
++iter) { rate.addCoverageDependence(k, sp.second.a, sp.second.m, sp.second.E);
size_t k = thermo(reactionPhaseIndex()).speciesIndex(iter->first);
rate.addCoverageDependence(k, iter->second.a, iter->second.m, iter->second.E);
} }
return rate; return rate;
} }
@ -1028,10 +1016,8 @@ void InterfaceKinetics::determineFwdOrdersBV(ElectrochemicalReaction& r, vector_
// Start out with the full ROP orders vector. // Start out with the full ROP orders vector.
// This vector will have the BV exchange current density orders in it. // This vector will have the BV exchange current density orders in it.
fwdFullOrders.assign(nTotalSpecies(), 0.0); fwdFullOrders.assign(nTotalSpecies(), 0.0);
for (Composition::const_iterator iter = r.orders.begin(); for (const auto& order : r.orders) {
iter != r.orders.end(); fwdFullOrders[kineticsSpeciesIndex(order.first)] = order.second;
++iter) {
fwdFullOrders[kineticsSpeciesIndex(iter->first)] = iter->second;
} }
// forward and reverse beta values // forward and reverse beta values
@ -1039,11 +1025,9 @@ void InterfaceKinetics::determineFwdOrdersBV(ElectrochemicalReaction& r, vector_
// Loop over the reactants doing away with the BV terms. // Loop over the reactants doing away with the BV terms.
// This should leave the reactant terms only, even if they are non-mass action. // This should leave the reactant terms only, even if they are non-mass action.
for (Composition::const_iterator iter = r.reactants.begin(); for (const auto& sp : r.reactants) {
iter != r.reactants.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) { fwdFullOrders[k] += betaf * sp.second;
size_t k = kineticsSpeciesIndex(iter->first);
fwdFullOrders[k] += betaf * iter->second;
// just to make sure roundoff doesn't leave a term that should be zero (haven't checked this out yet) // just to make sure roundoff doesn't leave a term that should be zero (haven't checked this out yet)
if (abs(fwdFullOrders[k]) < 0.00001) { if (abs(fwdFullOrders[k]) < 0.00001) {
fwdFullOrders[k] = 0.0; fwdFullOrders[k] = 0.0;
@ -1052,11 +1036,9 @@ void InterfaceKinetics::determineFwdOrdersBV(ElectrochemicalReaction& r, vector_
// Loop over the products doing away with the BV terms. // Loop over the products doing away with the BV terms.
// This should leave the reactant terms only, even if they are non-mass action. // This should leave the reactant terms only, even if they are non-mass action.
for (Composition::const_iterator iter = r.products.begin(); for (const auto& sp : r.products) {
iter != r.products.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) { fwdFullOrders[k] -= betaf * sp.second;
size_t k = kineticsSpeciesIndex(iter->first);
fwdFullOrders[k] -= betaf * iter->second;
// just to make sure roundoff doesn't leave a term that should be zero (haven't checked this out yet) // just to make sure roundoff doesn't leave a term that should be zero (haven't checked this out yet)
if (abs(fwdFullOrders[k]) < 0.00001) { if (abs(fwdFullOrders[k]) < 0.00001) {
fwdFullOrders[k] = 0.0; fwdFullOrders[k] = 0.0;

View file

@ -161,19 +161,15 @@ std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
Reaction& R = *m_reactions[i]; Reaction& R = *m_reactions[i];
net_stoich.push_back(std::map<int, double>()); net_stoich.push_back(std::map<int, double>());
std::map<int, double>& net = net_stoich.back(); std::map<int, double>& net = net_stoich.back();
for (Composition::const_iterator iter = R.reactants.begin(); for (const auto& sp : R.reactants) {
iter != R.reactants.end(); int k = static_cast<int>(kineticsSpeciesIndex(sp.first));
++iter) {
int k = static_cast<int>(kineticsSpeciesIndex(iter->first));
key += k*(k+1); key += k*(k+1);
net[-1 -k] -= iter->second; net[-1 -k] -= sp.second;
} }
for (Composition::const_iterator iter = R.products.begin(); for (const auto& sp : R.products) {
iter != R.products.end(); int k = static_cast<int>(kineticsSpeciesIndex(sp.first));
++iter) {
int k = static_cast<int>(kineticsSpeciesIndex(iter->first));
key += k*(k+1); key += k*(k+1);
net[1+k] += iter->second; net[1+k] += sp.second;
} }
// Compare this reaction to others with similar participants // Compare this reaction to others with similar participants
@ -241,7 +237,7 @@ std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
double Kinetics::checkDuplicateStoich(std::map<int, double>& r1, double Kinetics::checkDuplicateStoich(std::map<int, double>& r1,
std::map<int, double>& r2) const std::map<int, double>& r2) const
{ {
map<int, doublereal>::const_iterator b = r1.begin(), e = r1.end(); auto b = r1.begin(), e = r1.end();
int k1 = b->first; int k1 = b->first;
// check for duplicate written in the same direction // check for duplicate written in the same direction
doublereal ratio = 0.0; doublereal ratio = 0.0;
@ -282,23 +278,19 @@ void Kinetics::checkReactionBalance(const Reaction& R)
{ {
Composition balr, balp; Composition balr, balp;
// iterate over the products // iterate over the products
for (Composition::const_iterator iter = R.products.begin(); for (const auto& sp : R.products) {
iter != R.products.end(); const ThermoPhase& ph = speciesPhase(sp.first);
++iter) { size_t k = ph.speciesIndex(sp.first);
const ThermoPhase& ph = speciesPhase(iter->first); double stoich = sp.second;
size_t k = ph.speciesIndex(iter->first);
double stoich = iter->second;
for (size_t m = 0; m < ph.nElements(); m++) { for (size_t m = 0; m < ph.nElements(); m++) {
balr[ph.elementName(m)] = 0.0; // so that balr contains all species balr[ph.elementName(m)] = 0.0; // so that balr contains all species
balp[ph.elementName(m)] += stoich*ph.nAtoms(k,m); balp[ph.elementName(m)] += stoich*ph.nAtoms(k,m);
} }
} }
for (Composition::const_iterator iter = R.reactants.begin(); for (const auto& sp : R.reactants) {
iter != R.reactants.end(); const ThermoPhase& ph = speciesPhase(sp.first);
++iter) { size_t k = ph.speciesIndex(sp.first);
const ThermoPhase& ph = speciesPhase(iter->first); double stoich = sp.second;
size_t k = ph.speciesIndex(iter->first);
double stoich = iter->second;
for (size_t m = 0; m < ph.nElements(); m++) { for (size_t m = 0; m < ph.nElements(); m++) {
balr[ph.elementName(m)] += stoich*ph.nAtoms(k,m); balr[ph.elementName(m)] += stoich*ph.nAtoms(k,m);
} }
@ -306,10 +298,8 @@ void Kinetics::checkReactionBalance(const Reaction& R)
string msg; string msg;
bool ok = true; bool ok = true;
for (Composition::iterator iter = balr.begin(); for (const auto& el : balr) {
iter != balr.end(); const string& elem = el.first;
++iter) {
const string& elem = iter->first;
double elemsum = balr[elem] + balp[elem]; double elemsum = balr[elem] + balp[elem];
double elemdiff = fabs(balp[elem] - balr[elem]); double elemdiff = fabs(balp[elem] - balr[elem]);
if (elemsum > 0.0 && elemdiff/elemsum > 1e-4) { if (elemsum > 0.0 && elemdiff/elemsum > 1e-4) {
@ -552,29 +542,25 @@ bool Kinetics::addReaction(shared_ptr<Reaction> r)
} }
// Check for undeclared species // Check for undeclared species
for (Composition::const_iterator iter = r->reactants.begin(); for (const auto& sp : r->reactants) {
iter != r->reactants.end(); if (kineticsSpeciesIndex(sp.first) == npos) {
++iter) {
if (kineticsSpeciesIndex(iter->first) == npos) {
if (m_skipUndeclaredSpecies) { if (m_skipUndeclaredSpecies) {
return false; return false;
} else { } else {
throw CanteraError("Kinetics::addReaction", "Reaction '" + throw CanteraError("Kinetics::addReaction", "Reaction '" +
r->equation() + "' contains the undeclared species '" + r->equation() + "' contains the undeclared species '" +
iter->first + "'"); sp.first + "'");
} }
} }
} }
for (Composition::const_iterator iter = r->products.begin(); for (const auto& sp : r->products) {
iter != r->products.end(); if (kineticsSpeciesIndex(sp.first) == npos) {
++iter) {
if (kineticsSpeciesIndex(iter->first) == npos) {
if (m_skipUndeclaredSpecies) { if (m_skipUndeclaredSpecies) {
return false; return false;
} else { } else {
throw CanteraError("Kinetics::addReaction", "Reaction '" + throw CanteraError("Kinetics::addReaction", "Reaction '" +
r->equation() + "' contains the undeclared species '" + r->equation() + "' contains the undeclared species '" +
iter->first + "'"); sp.first + "'");
} }
} }
} }
@ -589,34 +575,28 @@ bool Kinetics::addReaction(shared_ptr<Reaction> r)
// the coefficient for species rk[i] // the coefficient for species rk[i]
vector_fp rstoich, pstoich; vector_fp rstoich, pstoich;
for (Composition::const_iterator iter = r->reactants.begin(); for (const auto& sp : r->reactants) {
iter != r->reactants.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
rk.push_back(k); rk.push_back(k);
rstoich.push_back(iter->second); rstoich.push_back(sp.second);
} }
for (Composition::const_iterator iter = r->products.begin(); for (const auto& sp : r->products) {
iter != r->products.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
pk.push_back(k); pk.push_back(k);
pstoich.push_back(iter->second); pstoich.push_back(sp.second);
} }
// The default order for each reactant is its stoichiometric coefficient, // The default order for each reactant is its stoichiometric coefficient,
// which can be overridden by entries in the Reaction.orders map. rorder[i] // which can be overridden by entries in the Reaction.orders map. rorder[i]
// is the order for species rk[i]. // is the order for species rk[i].
vector_fp rorder = rstoich; vector_fp rorder = rstoich;
for (Composition::const_iterator iter = r->orders.begin(); for (const auto& sp : r->orders) {
iter != r->orders.end(); size_t k = kineticsSpeciesIndex(sp.first);
++iter) {
size_t k = kineticsSpeciesIndex(iter->first);
// Find the index of species k within rk // Find the index of species k within rk
vector<size_t>::iterator rloc = std::find(rk.begin(), rk.end(), k); auto rloc = std::find(rk.begin(), rk.end(), k);
if (rloc != rk.end()) { if (rloc != rk.end()) {
rorder[rloc - rk.begin()] = iter->second; rorder[rloc - rk.begin()] = sp.second;
} else { } else {
// If the reaction order involves a non-reactant species, add an // If the reaction order involves a non-reactant species, add an
// extra term to the reactants with zero stoichiometry so that the // extra term to the reactants with zero stoichiometry so that the
@ -624,7 +604,7 @@ bool Kinetics::addReaction(shared_ptr<Reaction> r)
// reaction rate. // reaction rate.
rk.push_back(k); rk.push_back(k);
rstoich.push_back(0.0); rstoich.push_back(0.0);
rorder.push_back(iter->second); rorder.push_back(sp.second);
} }
} }

View file

@ -35,23 +35,19 @@ Reaction::Reaction(int type, const Composition& reactants_,
void Reaction::validate() void Reaction::validate()
{ {
if (!allow_nonreactant_orders) { if (!allow_nonreactant_orders) {
for (Composition::iterator iter = orders.begin(); for (const auto& order : orders) {
iter != orders.end(); if (reactants.find(order.first) == reactants.end()) {
++iter) {
if (reactants.find(iter->first) == reactants.end()) {
throw CanteraError("Reaction::validate", "Reaction order " throw CanteraError("Reaction::validate", "Reaction order "
"specified for non-reactant species '" + iter->first + "'"); "specified for non-reactant species '" + order.first + "'");
} }
} }
} }
if (!allow_negative_orders) { if (!allow_negative_orders) {
for (Composition::iterator iter = orders.begin(); for (const auto& order : orders) {
iter != orders.end(); if (order.second < 0.0) {
++iter) {
if (iter->second < 0.0) {
throw CanteraError("Reaction::validate", "Negative reaction " throw CanteraError("Reaction::validate", "Negative reaction "
"order specified for species '" + iter->first + "'"); "order specified for species '" + order.first + "'");
} }
} }
} }
@ -60,9 +56,7 @@ void Reaction::validate()
std::string Reaction::reactantString() const std::string Reaction::reactantString() const
{ {
std::ostringstream result; std::ostringstream result;
for (Composition::const_iterator iter = reactants.begin(); for (auto iter = reactants.begin(); iter != reactants.end(); ++iter) {
iter != reactants.end();
++iter) {
if (iter != reactants.begin()) { if (iter != reactants.begin()) {
result << " + "; result << " + ";
} }
@ -77,9 +71,7 @@ std::string Reaction::reactantString() const
std::string Reaction::productString() const std::string Reaction::productString() const
{ {
std::ostringstream result; std::ostringstream result;
for (Composition::const_iterator iter = products.begin(); for (auto iter = products.begin(); iter != products.end(); ++iter) {
iter != products.end();
++iter) {
if (iter != products.begin()) { if (iter != products.begin()) {
result << " + "; result << " + ";
} }
@ -487,14 +479,11 @@ void setupInterfaceReaction(InterfaceReaction& R, const XML_Node& rxn_node)
R.sticking_species = arr["species"]; R.sticking_species = arr["species"];
} }
std::vector<XML_Node*> cov = arr.getChildren("coverage"); std::vector<XML_Node*> cov = arr.getChildren("coverage");
for (std::vector<XML_Node*>::iterator iter = cov.begin(); for (const auto& node : cov) {
iter != cov.end(); CoverageDependency& cdep = R.coverage_deps[node->attrib("species")];
++iter) cdep.a = getFloat(*node, "a", "toSI");
{ cdep.m = getFloat(*node, "m");
CoverageDependency& cdep = R.coverage_deps[(*iter)->attrib("species")]; cdep.E = getFloat(*node, "e", "actEnergy") / GasConstant;
cdep.a = getFloat(**iter, "a", "toSI");
cdep.m = getFloat(**iter, "m");
cdep.E = getFloat(**iter, "e", "actEnergy") / GasConstant;
} }
setupElementaryReaction(R, rxn_node); setupElementaryReaction(R, rxn_node);
} }
@ -544,15 +533,11 @@ void setupElectrochemicalReaction(ElectrochemicalReaction& R,
R.orders.clear(); R.orders.clear();
// Reaction orders based on species stoichiometric coefficients // Reaction orders based on species stoichiometric coefficients
R.allow_nonreactant_orders = true; R.allow_nonreactant_orders = true;
for (Composition::const_iterator iter = R.reactants.begin(); for (const auto& sp : R.reactants) {
iter != R.reactants.end(); R.orders[sp.first] += sp.second * (1.0 - R.beta);
++iter) {
R.orders[iter->first] += iter->second * (1.0 - R.beta);
} }
for (Composition::const_iterator iter = R.products.begin(); for (const auto& sp : R.products) {
iter != R.products.end(); R.orders[sp.first] += sp.second * R.beta;
++iter) {
R.orders[iter->first] += iter->second * R.beta;
} }
} }
@ -565,24 +550,18 @@ void setupElectrochemicalReaction(ElectrochemicalReaction& R,
if (lowercase(rof_node["model"]) == "reactantorders") { if (lowercase(rof_node["model"]) == "reactantorders") {
R.orders = initial_orders; R.orders = initial_orders;
} else if (lowercase(rof_node["model"]) == "zeroorders") { } else if (lowercase(rof_node["model"]) == "zeroorders") {
for (Composition::const_iterator iter = R.reactants.begin(); for (const auto& sp : R.reactants) {
iter != R.reactants.end(); R.orders[sp.first] = 0.0;
++iter) {
R.orders[iter->first] = 0.0;
} }
} else if (lowercase(rof_node["model"]) == "butlervolmerorders") { } else if (lowercase(rof_node["model"]) == "butlervolmerorders") {
// Reaction orders based on provided reaction orders // Reaction orders based on provided reaction orders
for (Composition::const_iterator iter = R.reactants.begin(); for (const auto& sp : R.reactants) {
iter != R.reactants.end(); double c = getValue(initial_orders, sp.first, sp.second);
++iter) { R.orders[sp.first] += c * (1.0 - R.beta);
double c = getValue(initial_orders, iter->first, iter->second);
R.orders[iter->first] += c * (1.0 - R.beta);
} }
for (Composition::const_iterator iter = R.products.begin(); for (const auto& sp : R.products) {
iter != R.products.end(); double c = getValue(initial_orders, sp.first, sp.second);
++iter) { R.orders[sp.first] += c * R.beta;
double c = getValue(initial_orders, iter->first, iter->second);
R.orders[iter->first] += c * R.beta;
} }
} else { } else {
throw CanteraError("setupElectrochemicalReaction", "unknown model " throw CanteraError("setupElectrochemicalReaction", "unknown model "
@ -594,10 +573,8 @@ void setupElectrochemicalReaction(ElectrochemicalReaction& R,
// Override orders based on the <orders> node // Override orders based on the <orders> node
if (rxn_node.hasChild("orders")) { if (rxn_node.hasChild("orders")) {
Composition orders = parseCompString(rxn_node.child("orders").value()); Composition orders = parseCompString(rxn_node.child("orders").value());
for (Composition::iterator iter = orders.begin(); for (const auto& order : orders) {
iter != orders.end(); R.orders[order.first] = order.second;
++iter) {
R.orders[iter->first] = iter->second;
} }
} }
} }
@ -658,13 +635,8 @@ shared_ptr<Reaction> newReaction(const XML_Node& rxn_node)
std::vector<shared_ptr<Reaction> > getReactions(const XML_Node& node) std::vector<shared_ptr<Reaction> > getReactions(const XML_Node& node)
{ {
std::vector<shared_ptr<Reaction> > all_reactions; std::vector<shared_ptr<Reaction> > all_reactions;
std::vector<XML_Node*> reaction_nodes = for (const auto& rxnnode : node.child("reactionData").getChildren("reaction")) {
node.child("reactionData").getChildren("reaction"); all_reactions.push_back(newReaction(*rxnnode));
for (std::vector<XML_Node*>::iterator iter = reaction_nodes.begin();
iter != reaction_nodes.end();
++iter)
{
all_reactions.push_back(newReaction(**iter));
} }
return all_reactions; return all_reactions;
} }

View file

@ -57,13 +57,12 @@ void Path::writeLabel(ostream& s, doublereal threshold)
return; return;
} }
doublereal v; doublereal v;
map<string, doublereal>::const_iterator i = m_label.begin(); for (const auto& label : m_label) {
for (; i != m_label.end(); ++i) { v = label.second/m_total;
v = i->second/m_total;
if (nn == 1) { if (nn == 1) {
s << i->first << "\\l"; s << label.first << "\\l";
} else if (v > threshold) { } else if (v > threshold) {
s << i->first; s << label.first;
int percent = int(100*v + 0.5); int percent = int(100*v + 0.5);
if (percent < 100) { if (percent < 100) {
s << " (" << percent << "%)\\l"; s << " (" << percent << "%)\\l";
@ -101,9 +100,8 @@ ReactionPathDiagram::ReactionPathDiagram()
ReactionPathDiagram::~ReactionPathDiagram() ReactionPathDiagram::~ReactionPathDiagram()
{ {
// delete the nodes // delete the nodes
map<size_t, SpeciesNode*>::const_iterator i = m_nodes.begin(); for (const auto& node : m_nodes) {
for (; i != m_nodes.end(); ++i) { delete node.second;
delete i->second;
} }
// delete the paths // delete the paths
@ -117,27 +115,22 @@ vector_int ReactionPathDiagram::reactions()
{ {
size_t i, npaths = nPaths(); size_t i, npaths = nPaths();
doublereal flmax = 0.0, flxratio; doublereal flmax = 0.0, flxratio;
Path* p;
for (i = 0; i < npaths; i++) { for (i = 0; i < npaths; i++) {
p = path(i); Path* p = path(i);
flmax = std::max(p->flow(), flmax); flmax = std::max(p->flow(), flmax);
} }
m_rxns.clear(); m_rxns.clear();
for (i = 0; i < npaths; i++) { for (i = 0; i < npaths; i++) {
p = path(i); for (const auto& rxn : path(i)->reactionMap()) {
const Path::rxn_path_map& rxns = p->reactionMap(); flxratio = rxn.second/flmax;
Path::rxn_path_map::const_iterator m = rxns.begin();
for (; m != rxns.end(); ++m) {
flxratio = m->second/flmax;
if (flxratio > threshold) { if (flxratio > threshold) {
m_rxns[m->first] = 1; m_rxns[rxn.first] = 1;
} }
} }
} }
vector_int r; vector_int r;
map<size_t, int>::const_iterator begin = m_rxns.begin(); for (const auto& rxn : m_rxns) {
for (; begin != m_rxns.end(); ++begin) { r.push_back(int(rxn.first));
r.push_back(int(begin->first));
} }
return r; return r;
} }
@ -375,10 +368,9 @@ void ReactionPathDiagram::exportToDot(ostream& s)
} }
} }
s.precision(2); s.precision(2);
map<size_t, SpeciesNode*>::const_iterator b = m_nodes.begin(); for (const auto& node : m_nodes) {
for (; b != m_nodes.end(); ++b) { if (node.second->visible) {
if (b->second->visible) { s << "s" << node.first << " [ fontname=\""+m_font+"\", label=\"" << node.second->name
s << "s" << b->first << " [ fontname=\""+m_font+"\", label=\"" << b->second->name
<< "\"];" << endl; << "\"];" << endl;
} }
} }

View file

@ -74,10 +74,8 @@ Plog::Plog(const std::multimap<double, Arrhenius>& rates)
size_t j = 0; size_t j = 0;
rates_.reserve(rates.size()); rates_.reserve(rates.size());
// Insert intermediate pressures // Insert intermediate pressures
for (std::multimap<double, Arrhenius>::const_iterator iter = rates.begin(); for (const auto& rate : rates) {
iter != rates.end(); double logp = std::log(rate.first);
iter++) {
double logp = std::log(iter->first);
if (pressures_.empty() || pressures_.rbegin()->first != logp) { if (pressures_.empty() || pressures_.rbegin()->first != logp) {
// starting a new group // starting a new group
pressures_[logp] = std::make_pair(j, j+1); pressures_[logp] = std::make_pair(j, j+1);
@ -87,7 +85,7 @@ Plog::Plog(const std::multimap<double, Arrhenius>& rates)
} }
j++; j++;
rates_.push_back(iter->second); rates_.push_back(rate.second);
} }
// Duplicate the first and last groups to handle P < P_0 and P > P_N // Duplicate the first and last groups to handle P < P_0 and P > P_N
@ -98,9 +96,7 @@ Plog::Plog(const std::multimap<double, Arrhenius>& rates)
void Plog::validate(const std::string& equation) void Plog::validate(const std::string& equation)
{ {
double T[] = {200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0}; double T[] = {200.0, 500.0, 1000.0, 2000.0, 5000.0, 10000.0};
for (pressureIter iter = pressures_.begin(); for (auto iter = pressures_.begin(); iter->first < 1000; iter++) {
iter->first < 1000;
iter++) {
update_C(&iter->first); update_C(&iter->first);
for (size_t i=0; i < 6; i++) { for (size_t i=0; i < 6; i++) {
double k = updateRC(log(T[i]), 1.0/T[i]); double k = updateRC(log(T[i]), 1.0/T[i]);
@ -121,7 +117,7 @@ std::vector<std::pair<double, Arrhenius> > Plog::rates() const
{ {
std::vector<std::pair<double, Arrhenius> > R; std::vector<std::pair<double, Arrhenius> > R;
// initial preincrement to skip rate for P --> 0 // initial preincrement to skip rate for P --> 0
for (std::map<double, std::pair<size_t, size_t> >::const_iterator iter = ++pressures_.begin(); for (auto iter = ++pressures_.begin();
iter->first < 1000; // skip rates for (P --> infinity) iter->first < 1000; // skip rates for (P --> infinity)
++iter) { ++iter) {
for (size_t i = iter->second.first; for (size_t i = iter->second.first;

View file

@ -23,8 +23,7 @@ doublereal linearInterp(doublereal x, const vector_fp& xpts,
if (x >= xpts.back()) { if (x >= xpts.back()) {
return fpts.back(); return fpts.back();
} }
vector_fp::const_iterator loc = auto loc = lower_bound(xpts.begin(), xpts.end(), x);
lower_bound(xpts.begin(), xpts.end(), x);
int iloc = int(loc - xpts.begin()) - 1; int iloc = int(loc - xpts.begin()) - 1;
doublereal ff = fpts[iloc] + doublereal ff = fpts[iloc] +
(x - xpts[iloc])*(fpts[iloc + 1] (x - xpts[iloc])*(fpts[iloc + 1]

View file

@ -236,16 +236,15 @@ void OneDim::eval(size_t j, double* x, double* r, doublereal rdt, int count)
if (rdt < 0.0) { if (rdt < 0.0) {
rdt = m_rdt; rdt = m_rdt;
} }
vector<Domain1D*>::iterator d;
// iterate over the bulk domains first // iterate over the bulk domains first
for (d = m_bulk.begin(); d != m_bulk.end(); ++d) { for (const auto& d : m_bulk) {
(*d)->eval(j, x, r, DATA_PTR(m_mask), rdt); d->eval(j, x, r, DATA_PTR(m_mask), rdt);
} }
// then over the connector domains // then over the connector domains
for (d = m_connect.begin(); d != m_connect.end(); ++d) { for (const auto& d : m_connect) {
(*d)->eval(j, x, r, DATA_PTR(m_mask), rdt); d->eval(j, x, r, DATA_PTR(m_mask), rdt);
} }
// increment counter and time // increment counter and time

View file

@ -213,15 +213,13 @@ void Refiner::show()
writelog(string("Refining grid in ") + writelog(string("Refining grid in ") +
m_domain->id()+".\n" m_domain->id()+".\n"
+" New points inserted after grid points "); +" New points inserted after grid points ");
map<size_t, int>::const_iterator b = m_loc.begin(); for (const auto& loc : m_loc) {
for (; b != m_loc.end(); ++b) { writelog(int2str(loc.first)+" ");
writelog(int2str(b->first)+" ");
} }
writelog("\n"); writelog("\n");
writelog(" to resolve "); writelog(" to resolve ");
map<string, int>::const_iterator bb = m_c.begin(); for (const auto& c : m_c) {
for (; bb != m_c.end(); ++bb) { writelog(string(c.first)+" ");
writelog(string(bb->first)+" ");
} }
writelog("\n"); writelog("\n");
writeline('#', 78); writeline('#', 78);

View file

@ -846,11 +846,9 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
* lack of agreement (HKM -> may be changed in the * lack of agreement (HKM -> may be changed in the
* future). * future).
*/ */
for (map<std::string,std::string>::const_iterator _b = m.begin(); for (const auto& b : m) {
_b != m.end(); size_t kk = speciesIndex(b.first);
++_b) { m_Aionic[kk] = fpValue(b.second) * Afactor;
size_t kk = speciesIndex(_b->first);
m_Aionic[kk] = fpValue(_b->second) * Afactor;
} }
} }
} }
@ -917,11 +915,9 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
XML_Node& sIsNode = acNodePtr->child("stoichIsMods"); XML_Node& sIsNode = acNodePtr->child("stoichIsMods");
map<std::string, std::string> msIs; map<std::string, std::string> msIs;
getMap(sIsNode, msIs); getMap(sIsNode, msIs);
for (map<std::string,std::string>::const_iterator _b = msIs.begin(); for (const auto& b : msIs) {
_b != msIs.end(); size_t kk = speciesIndex(b.first);
++_b) { double val = fpValue(b.second);
size_t kk = speciesIndex(_b->first);
double val = fpValue(_b->second);
m_speciesCharge_Stoich[kk] = val; m_speciesCharge_Stoich[kk] = val;
} }
} }
@ -971,11 +967,9 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
XML_Node& ESTNode = acNodePtr->child("electrolyteSpeciesType"); XML_Node& ESTNode = acNodePtr->child("electrolyteSpeciesType");
map<std::string, std::string> msEST; map<std::string, std::string> msEST;
getMap(ESTNode, msEST); getMap(ESTNode, msEST);
for (map<std::string,std::string>::const_iterator _b = msEST.begin(); for (const auto& b : msEST) {
_b != msEST.end(); size_t kk = speciesIndex(b.first);
++_b) { std::string est = b.second;
size_t kk = speciesIndex(_b->first);
std::string est = _b->second;
if ((m_electrolyteSpeciesType[kk] = interp_est(est)) == -1) { if ((m_electrolyteSpeciesType[kk] = interp_est(est)) == -1) {
throw CanteraError("DebyeHuckel:initThermoXML", throw CanteraError("DebyeHuckel:initThermoXML",
"Bad electrolyte type: " + est); "Bad electrolyte type: " + est);

View file

@ -31,14 +31,12 @@ GeneralSpeciesThermo::GeneralSpeciesThermo(const GeneralSpeciesThermo& b) :
{ {
m_sp.clear(); m_sp.clear();
// Copy SpeciesThermoInterpTypes from 'b' // Copy SpeciesThermoInterpTypes from 'b'
for (STIT_map::const_iterator iter = b.m_sp.begin(); for (const auto& sp : b.m_sp) {
iter != b.m_sp.end(); for (size_t k = 0; k < sp.second.size(); k++) {
iter++) { size_t i = sp.second[k].first;
for (size_t k = 0; k < iter->second.size(); k++) {
size_t i = iter->second[k].first;
shared_ptr<SpeciesThermoInterpType> spec( shared_ptr<SpeciesThermoInterpType> spec(
iter->second[k].second->duplMyselfAsSpeciesThermoInterpType()); sp.second[k].second->duplMyselfAsSpeciesThermoInterpType());
m_sp[iter->first].push_back(std::make_pair(i, spec)); m_sp[sp.first].push_back(std::make_pair(i, spec));
} }
} }
} }
@ -53,14 +51,12 @@ GeneralSpeciesThermo::operator=(const GeneralSpeciesThermo& b)
SpeciesThermo::operator=(b); SpeciesThermo::operator=(b);
m_sp.clear(); m_sp.clear();
// Copy SpeciesThermoInterpType objects from 'b' // Copy SpeciesThermoInterpType objects from 'b'
for (STIT_map::const_iterator iter = b.m_sp.begin(); for (const auto& sp : b.m_sp) {
iter != b.m_sp.end(); for (size_t k = 0; k < sp.second.size(); k++) {
iter++) { size_t i = sp.second[k].first;
for (size_t k = 0; k < iter->second.size(); k++) {
size_t i = iter->second[k].first;
shared_ptr<SpeciesThermoInterpType> spec( shared_ptr<SpeciesThermoInterpType> spec(
iter->second[k].second->duplMyselfAsSpeciesThermoInterpType()); sp.second[k].second->duplMyselfAsSpeciesThermoInterpType());
m_sp[iter->first].push_back(std::make_pair(i, spec)); m_sp[sp.first].push_back(std::make_pair(i, spec));
} }
} }
@ -118,8 +114,8 @@ void GeneralSpeciesThermo::update_one(size_t k, doublereal t, doublereal* cp_R,
void GeneralSpeciesThermo::update(doublereal t, doublereal* cp_R, void GeneralSpeciesThermo::update(doublereal t, doublereal* cp_R,
doublereal* h_RT, doublereal* s_R) const doublereal* h_RT, doublereal* s_R) const
{ {
STIT_map::const_iterator iter = m_sp.begin(); auto iter = m_sp.begin();
tpoly_map::iterator jter = m_tpoly.begin(); auto jter = m_tpoly.begin();
for (; iter != m_sp.end(); iter++, jter++) { for (; iter != m_sp.end(); iter++, jter++) {
const std::vector<index_STIT>& species = iter->second; const std::vector<index_STIT>& species = iter->second;
double* tpoly = &jter->second[0]; double* tpoly = &jter->second[0];

View file

@ -1418,12 +1418,10 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
XML_Node& sIsNode = acNodePtr->child("stoichIsMods"); XML_Node& sIsNode = acNodePtr->child("stoichIsMods");
map<string, string> msIs; map<string, string> msIs;
getMap(sIsNode, msIs); getMap(sIsNode, msIs);
for (map<string,string>::const_iterator _b = msIs.begin(); for (const auto& b : msIs) {
_b != msIs.end(); size_t kk = speciesIndex(b.first);
++_b) {
size_t kk = speciesIndex(_b->first);
if (kk != npos) { if (kk != npos) {
double val = fpValue(_b->second); double val = fpValue(b.second);
m_speciesCharge_Stoich[kk] = val; m_speciesCharge_Stoich[kk] = val;
} }
} }
@ -1508,12 +1506,10 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
XML_Node& ESTNode = acNodePtr->child("electrolyteSpeciesType"); XML_Node& ESTNode = acNodePtr->child("electrolyteSpeciesType");
map<string, string> msEST; map<string, string> msEST;
getMap(ESTNode, msEST); getMap(ESTNode, msEST);
for (map<string,string>::const_iterator _b = msEST.begin(); for (const auto& b : msEST) {
_b != msEST.end(); size_t kk = speciesIndex(b.first);
++_b) {
size_t kk = speciesIndex(_b->first);
if (kk != npos) { if (kk != npos) {
string est = _b->second; string est = b.second;
if ((m_electrolyteSpeciesType[kk] = interp_est(est)) == -1) { if ((m_electrolyteSpeciesType[kk] = interp_est(est)) == -1) {
throw CanteraError("HMWSoln::initThermoXML", throw CanteraError("HMWSoln::initThermoXML",
"Bad electrolyte type: " + est); "Bad electrolyte type: " + est);

View file

@ -371,14 +371,12 @@ void Phase::setMoleFractions_NoNorm(const doublereal* const x)
void Phase::setMoleFractionsByName(const compositionMap& xMap) void Phase::setMoleFractionsByName(const compositionMap& xMap)
{ {
vector_fp mf(m_kk, 0.0); vector_fp mf(m_kk, 0.0);
for (compositionMap::const_iterator iter = xMap.begin(); for (const auto& sp : xMap) {
iter != xMap.end();
++iter) {
try { try {
mf[getValue(m_speciesIndices, iter->first)] = iter->second; mf[getValue(m_speciesIndices, sp.first)] = sp.second;
} catch (std::out_of_range&) { } catch (std::out_of_range&) {
throw CanteraError("Phase::setMoleFractionsByName", throw CanteraError("Phase::setMoleFractionsByName",
"Unknown species '{}'", iter->first); "Unknown species '{}'", sp.first);
} }
} }
setMoleFractions(&mf[0]); setMoleFractions(&mf[0]);
@ -417,14 +415,12 @@ void Phase::setMassFractions_NoNorm(const doublereal* const y)
void Phase::setMassFractionsByName(const compositionMap& yMap) void Phase::setMassFractionsByName(const compositionMap& yMap)
{ {
vector_fp mf(m_kk, 0.0); vector_fp mf(m_kk, 0.0);
for (compositionMap::const_iterator iter = yMap.begin(); for (const auto& sp : yMap) {
iter != yMap.end();
++iter) {
try { try {
mf[getValue(m_speciesIndices, iter->first)] = iter->second; mf[getValue(m_speciesIndices, sp.first)] = sp.second;
} catch (std::out_of_range&) { } catch (std::out_of_range&) {
throw CanteraError("Phase::setMassFractionsByName", throw CanteraError("Phase::setMassFractionsByName",
"Unknown species '{}'", iter->first); "Unknown species '{}'", sp.first);
} }
} }
setMassFractions(&mf[0]); setMassFractions(&mf[0]);
@ -710,9 +706,7 @@ size_t Phase::addElement(const std::string& symbol, doublereal weight,
} }
// Check for duplicates // Check for duplicates
vector<string>::const_iterator iter = find(m_elementNames.begin(), auto iter = find(m_elementNames.begin(), m_elementNames.end(), symbol);
m_elementNames.end(),
symbol);
if (iter != m_elementNames.end()) { if (iter != m_elementNames.end()) {
size_t m = iter - m_elementNames.begin(); size_t m = iter - m_elementNames.begin();
if (m_atomicWeights[m] != weight) { if (m_atomicWeights[m] != weight) {
@ -755,29 +749,27 @@ size_t Phase::addElement(const std::string& symbol, doublereal weight,
bool Phase::addSpecies(shared_ptr<Species> spec) { bool Phase::addSpecies(shared_ptr<Species> spec) {
m_species[spec->name] = spec; m_species[spec->name] = spec;
vector_fp comp(nElements()); vector_fp comp(nElements());
for (map<string, double>::const_iterator iter = spec->composition.begin(); for (const auto& elem : spec->composition) {
iter != spec->composition.end(); size_t m = elementIndex(elem.first);
iter++) {
size_t m = elementIndex(iter->first);
if (m == npos) { // Element doesn't exist in this phase if (m == npos) { // Element doesn't exist in this phase
switch (m_undefinedElementBehavior) { switch (m_undefinedElementBehavior) {
case UndefElement::ignore: case UndefElement::ignore:
return false; return false;
case UndefElement::add: case UndefElement::add:
addElement(iter->first); addElement(elem.first);
comp.resize(nElements()); comp.resize(nElements());
m = elementIndex(iter->first); m = elementIndex(elem.first);
break; break;
case UndefElement::error: case UndefElement::error:
default: default:
throw CanteraError("Phase::addSpecies", throw CanteraError("Phase::addSpecies",
"Species '{}' contains an undefined element '{}'.", "Species '{}' contains an undefined element '{}'.",
spec->name, iter->first); spec->name, elem.first);
} }
} }
comp[m] = iter->second; comp[m] = elem.second;
} }
m_speciesNames.push_back(spec->name); m_speciesNames.push_back(spec->name);

View file

@ -82,14 +82,8 @@ shared_ptr<Species> newSpecies(const XML_Node& species_node)
std::vector<shared_ptr<Species> > getSpecies(const XML_Node& node) std::vector<shared_ptr<Species> > getSpecies(const XML_Node& node)
{ {
std::vector<shared_ptr<Species> > all_species; std::vector<shared_ptr<Species> > all_species;
std::vector<XML_Node*> species_nodes = for (const auto& spnode : node.child("speciesData").getChildren("species")) {
node.child("speciesData").getChildren("species"); all_species.push_back(newSpecies(*spnode));
for (std::vector<XML_Node*>::iterator iter = species_nodes.begin();
iter != species_nodes.end();
++iter)
{
all_species.push_back(newSpecies(**iter));
} }
return all_species; return all_species;
} }

View file

@ -292,7 +292,7 @@ static void formSpeciesXMLNodeList(std::vector<XML_Node*> &spDataNodeList,
if (!skip) { if (!skip) {
declared[stemp] = true; declared[stemp] = true;
// Find the species in the database by name. // Find the species in the database by name.
std::map<std::string, XML_Node*>::iterator iter = speciesNodes.find(stemp); auto iter = speciesNodes.find(stemp);
if (iter == speciesNodes.end()) { if (iter == speciesNodes.end()) {
throw CanteraError("importPhase","no data for species, \"" throw CanteraError("importPhase","no data for species, \""
+ stemp + "\""); + stemp + "\"");

View file

@ -538,7 +538,7 @@ void GasTransport::fitCollisionIntegrals(MMCollisionInt& integrals)
// the list of delta* values for which fits have been done. // the list of delta* values for which fits have been done.
// 'find' returns a pointer to end() if not found // 'find' returns a pointer to end() if not found
vector_fp::iterator dptr = find(fitlist.begin(), fitlist.end(), dstar); auto dptr = find(fitlist.begin(), fitlist.end(), dstar);
if (dptr == fitlist.end()) { if (dptr == fitlist.end()) {
vector_fp ca(degree+1), cb(degree+1), cc(degree+1); vector_fp ca(degree+1), cb(degree+1), cc(degree+1);
vector_fp co22(degree+1); vector_fp co22(degree+1);

View file

@ -49,10 +49,8 @@ void GasTransportData::setCustomaryUnits(
void GasTransportData::validate(const Species& sp) void GasTransportData::validate(const Species& sp)
{ {
double nAtoms = 0; double nAtoms = 0;
for (compositionMap::const_iterator iter = sp.composition.begin(); for (const auto& elem : sp.composition) {
iter != sp.composition.end(); nAtoms += elem.second;
++iter) {
nAtoms += iter->second;
} }
if (geometry == "atom") { if (geometry == "atom") {

View file

@ -56,10 +56,8 @@ TransportFactory::TransportFactory()
m_models["User"] = cUserTransport; m_models["User"] = cUserTransport;
m_models["HighP"] = cHighP; m_models["HighP"] = cHighP;
m_models["None"] = None; m_models["None"] = None;
for (map<string, int>::iterator iter = m_models.begin(); for (const auto& model : m_models) {
iter != m_models.end(); m_modelNames[model.second] = model.first;
iter++) {
m_modelNames[iter->second] = iter->first;
} }
m_tranPropMap["viscosity"] = TP_VISCOSITY; m_tranPropMap["viscosity"] = TP_VISCOSITY;
@ -360,7 +358,6 @@ void TransportFactory::getLiquidSpeciesTransportData(const std::vector<const XML
Create a map of species names versus liquid transport data parameters Create a map of species names versus liquid transport data parameters
*/ */
std::map<std::string, LiquidTransportData> datatable; std::map<std::string, LiquidTransportData> datatable;
std::map<std::string, LiquidTransportData>::iterator it;
// Store the number of species in the phase // Store the number of species in the phase
size_t nsp = trParam.nsp_; size_t nsp = trParam.nsp_;
@ -464,7 +461,7 @@ void TransportFactory::getLiquidSpeciesTransportData(const std::vector<const XML
Check to see that we have a LiquidTransportData object for all of the Check to see that we have a LiquidTransportData object for all of the
species in the phase. If not, throw an error. species in the phase. If not, throw an error.
*/ */
it = datatable.find(names[i]); auto it = datatable.find(names[i]);
if (it == datatable.end()) { if (it == datatable.end()) {
throw TransportDBError(0,"No transport data found for species " + names[i]); throw TransportDBError(0,"No transport data found for species " + names[i]);
} }
@ -505,7 +502,7 @@ void TransportFactory::getLiquidInteractionsTransportData(const XML_Node& transp
if (tranTypeNode.name() == "compositionDependence") { if (tranTypeNode.name() == "compositionDependence") {
std::string modelName = tranTypeNode.attrib("model"); std::string modelName = tranTypeNode.attrib("model");
std::map<string, LiquidTranMixingModel>::iterator it = m_LTImodelMap.find(modelName); auto it = m_LTImodelMap.find(modelName);
if (it == m_LTImodelMap.end()) { if (it == m_LTImodelMap.end()) {
throw CanteraError("TransportFactory::getLiquidInteractionsTransportData", throw CanteraError("TransportFactory::getLiquidInteractionsTransportData",
"Unknown compositionDependence string: " + modelName); "Unknown compositionDependence string: " + modelName);

View file

@ -47,14 +47,10 @@ void ReactorNet::initialize()
r.initialize(m_time); r.initialize(m_time);
nv = r.neq(); nv = r.neq();
m_nparams.push_back(r.nSensParams()); m_nparams.push_back(r.nSensParams());
std::vector<std::pair<void*, int> > sens_objs = r.getSensitivityOrder(); for (const auto& sens_obj : r.getSensitivityOrder()) {
for (size_t i = 0; i < sens_objs.size(); i++) { for (const auto& order : m_sensOrder[sens_obj]) {
std::map<size_t, size_t>& s = m_sensOrder[sens_objs[i]]; m_sensIndex.resize(std::max(order.second + 1, m_sensIndex.size()));
for (std::map<size_t, size_t>::iterator iter = s.begin(); m_sensIndex[order.second] = sensParamNumber++;
iter != s.end();
++iter) {
m_sensIndex.resize(std::max(iter->second + 1, m_sensIndex.size()));
m_sensIndex[iter->second] = sensParamNumber++;
} }
} }
m_nv += nv; m_nv += nv;