Additional uses for getValue with default value
This commit is contained in:
parent
a74fda8ad2
commit
5b1b08849c
8 changed files with 19 additions and 49 deletions
|
|
@ -7,6 +7,7 @@
|
|||
#define CT_REACTION_DATA_H
|
||||
|
||||
#include "cantera/kinetics/reaction_defs.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
namespace Cantera
|
||||
{
|
||||
|
|
@ -212,12 +213,7 @@ public:
|
|||
|
||||
//! Get the actual third-body efficiency for species *k*
|
||||
double efficiency(size_t k) const {
|
||||
std::map<size_t, doublereal>::const_iterator iter = thirdBodyEfficiencies.find(k);
|
||||
if (iter != thirdBodyEfficiencies.end()) {
|
||||
return iter->second;
|
||||
} else {
|
||||
return default_3b_eff;
|
||||
}
|
||||
return getValue(thirdBodyEfficiencies, k, default_3b_eff);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "cantera/base/ct_defs.h"
|
||||
#include "cantera/base/ctexceptions.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
|
@ -49,11 +50,7 @@ public:
|
|||
m_constrain[k] = flag;
|
||||
}
|
||||
int constraint(const int k) const {
|
||||
std::map<int,int>::const_iterator i = m_constrain.find(k);
|
||||
if (i != m_constrain.end()) {
|
||||
return i->second;
|
||||
}
|
||||
return c_NONE;
|
||||
return getValue(m_constrain, k, c_NONE);
|
||||
}
|
||||
|
||||
//! Initialization function
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "cantera/base/ctexceptions.h"
|
||||
#include "cantera/base/stringUtils.h"
|
||||
#include "SpeciesThermo.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
namespace Cantera
|
||||
{
|
||||
|
|
@ -190,11 +191,7 @@ template<class T1, class T2>
|
|||
int
|
||||
SpeciesThermoDuo<T1, T2>::reportType(size_t k) const
|
||||
{
|
||||
std::map<size_t, int>::const_iterator p = speciesToType.find(k);
|
||||
if (p != speciesToType.end()) {
|
||||
return p->second;
|
||||
}
|
||||
return -1;
|
||||
return getValue(speciesToType, k, -1);
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
#include "cantera/base/xml.h"
|
||||
#include "cantera/base/stringUtils.h"
|
||||
#include "cantera/base/global.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
|
@ -518,11 +519,7 @@ std::string XML_Node::operator[](const std::string& attr) const
|
|||
|
||||
std::string XML_Node::attrib(const std::string& attr) const
|
||||
{
|
||||
std::map<std::string,std::string>::const_iterator i = m_attribs.find(attr);
|
||||
if (i != m_attribs.end()) {
|
||||
return i->second;
|
||||
}
|
||||
return "";
|
||||
return getValue<string,string>(m_attribs, attr, "");
|
||||
}
|
||||
|
||||
std::map<std::string,std::string>& XML_Node::attribs()
|
||||
|
|
|
|||
|
|
@ -427,10 +427,7 @@ void MultiPhase::setMolesByName(const compositionMap& xMap)
|
|||
size_t kk = nSpecies();
|
||||
vector_fp moles(kk, 0.0);
|
||||
for (size_t k = 0; k < kk; k++) {
|
||||
compositionMap::const_iterator iter = xMap.find(speciesName(k));
|
||||
if (iter != xMap.end() && iter->second > 0.0) {
|
||||
moles[k] = iter->second;
|
||||
}
|
||||
moles[k] = std::max(getValue(xMap, speciesName(k), 0.0), 0.0);
|
||||
}
|
||||
setMoles(DATA_PTR(moles));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "cantera/thermo/MolalityVPSSTP.h"
|
||||
#include "cantera/base/stringUtils.h"
|
||||
#include "cantera/base/ctml.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
|
|
@ -190,9 +191,9 @@ void MolalityVPSSTP::setMolalitiesByName(const compositionMap& mMap)
|
|||
double xmolS = mf[m_indexSolvent];
|
||||
double xmolSmin = std::max(xmolS, m_xmolSolventMIN);
|
||||
for (size_t k = 0; k < kk; k++) {
|
||||
compositionMap::const_iterator iter = mMap.find(speciesName(k));
|
||||
if (iter != mMap.end() && iter->second > 0.0) {
|
||||
mf[k] = iter->second * m_Mnaught * xmolSmin;
|
||||
double mol_k = getValue(mMap, speciesName(k), 0.0);
|
||||
if (mol_k > 0) {
|
||||
mf[k] = mol_k * m_Mnaught * xmolSmin;
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -383,10 +383,7 @@ void Phase::setMoleFractionsByName(const compositionMap& xMap)
|
|||
size_t kk = nSpecies();
|
||||
vector_fp mf(kk, 0.0);
|
||||
for (size_t k = 0; k < kk; k++) {
|
||||
compositionMap::const_iterator iter = xMap.find(speciesName(k));
|
||||
if (iter != xMap.end() && iter->second > 0.0) {
|
||||
mf[k] = iter->second;
|
||||
}
|
||||
mf[k] = std::max(getValue(xMap, speciesName(k), 0.0), 0.0);
|
||||
}
|
||||
setMoleFractions(&mf[0]);
|
||||
}
|
||||
|
|
@ -427,10 +424,7 @@ void Phase::setMassFractionsByName(const compositionMap& yMap)
|
|||
size_t kk = nSpecies();
|
||||
vector_fp mf(kk, 0.0);
|
||||
for (size_t k = 0; k < kk; k++) {
|
||||
compositionMap::const_iterator iter = yMap.find(speciesName(k));
|
||||
if (iter != yMap.end() && iter->second > 0.0) {
|
||||
mf[k] = iter->second;
|
||||
}
|
||||
mf[k] = std::max(getValue(yMap, speciesName(k), 0.0), 0.0);
|
||||
}
|
||||
setMassFractions(&mf[0]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
|
||||
#include "cantera/base/ctml.h"
|
||||
#include "cantera/base/stringUtils.h"
|
||||
#include "cantera/base/utilities.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
|
|
@ -213,13 +214,7 @@ void TransportFactory::deleteFactory()
|
|||
|
||||
std::string TransportFactory::modelName(int model)
|
||||
{
|
||||
TransportFactory& f = *factory();
|
||||
map<int, string>::iterator iter = f.m_modelNames.find(model);
|
||||
if (iter != f.m_modelNames.end()) {
|
||||
return iter->second;
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
return getValue<int,string>(factory()->m_modelNames, model, "");
|
||||
}
|
||||
|
||||
LTPspecies* TransportFactory::newLTP(const XML_Node& trNode, const std::string& name,
|
||||
|
|
@ -699,12 +694,8 @@ void TransportFactory::getTransportData(const ThermoPhase& thermo, const std::ve
|
|||
const XML_Node& sp = *xspecies[i];
|
||||
|
||||
// Find the index for this species in 'names'
|
||||
std::map<std::string, size_t>::const_iterator iter =
|
||||
speciesIndices.find(sp["name"]);
|
||||
size_t j;
|
||||
if (iter != speciesIndices.end()) {
|
||||
j = iter->second;
|
||||
} else {
|
||||
size_t j = getValue(speciesIndices, sp["name"], npos);
|
||||
if (j == npos) {
|
||||
// Don't need transport data for this species
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue