Make use of initializer lists where appropriate

This commit is contained in:
Ray Speth 2015-10-08 19:05:52 -04:00
parent f9375e1a09
commit a945ef2c23
18 changed files with 54 additions and 112 deletions

View file

@ -225,10 +225,7 @@ protected:
// Add dummy terminator domains on either side of this one. // Add dummy terminator domains on either side of this one.
m_left = new Cantera::Empty1D; m_left = new Cantera::Empty1D;
m_right = new Cantera::Empty1D; m_right = new Cantera::Empty1D;
std::vector<Cantera::Domain1D*> domains; std::vector<Cantera::Domain1D*> domains { m_left, this, m_right };
domains.push_back(m_left);
domains.push_back(this);
domains.push_back(m_right);
// create the Sim1D instance that will control the // create the Sim1D instance that will control the
// solution process // solution process

View file

@ -105,15 +105,16 @@ void runexample()
double tres; double tres;
std::ofstream f("combustor_cxx.csv"); std::ofstream f("combustor_cxx.csv");
std::vector<size_t> k_out; std::vector<size_t> k_out {
k_out.push_back(gas.speciesIndex("CH4")); gas.speciesIndex("CH4"),
k_out.push_back(gas.speciesIndex("O2")); gas.speciesIndex("O2"),
k_out.push_back(gas.speciesIndex("CO2")); gas.speciesIndex("CO2"),
k_out.push_back(gas.speciesIndex("H2O")); gas.speciesIndex("H2O"),
k_out.push_back(gas.speciesIndex("CO")); gas.speciesIndex("CO"),
k_out.push_back(gas.speciesIndex("OH")); gas.speciesIndex("OH"),
k_out.push_back(gas.speciesIndex("H")); gas.speciesIndex("H"),
k_out.push_back(gas.speciesIndex("C2H6")); gas.speciesIndex("C2H6")
};
while (tnow < tfinal) { while (tnow < tfinal) {
tnow += 0.005; tnow += 0.005;

View file

@ -107,11 +107,7 @@ int flamespeed(double phi)
//=================== create the container and insert the domains ===== //=================== create the container and insert the domains =====
std::vector<Domain1D*> domains; std::vector<Domain1D*> domains { &inlet, &flow, &outlet };
domains.push_back(&inlet);
domains.push_back(&flow);
domains.push_back(&outlet);
Sim1D flame(domains); Sim1D flame(domains);
//----------- Supply initial guess---------------------- //----------- Supply initial guess----------------------

View file

@ -225,7 +225,7 @@ XML_Node* Application::get_XML_File(const std::string& file, int debug)
} }
} }
x->lock(); x->lock();
xmlfiles[path] = std::make_pair(x, mtime); xmlfiles[path] = {x, mtime};
return x; return x;
} }

View file

@ -226,12 +226,12 @@ std::pair<size_t, size_t> Kinetics::checkDuplicates(bool throw_err) const
"Reaction {}: {}\nReaction {}: {}\n", "Reaction {}: {}\nReaction {}: {}\n",
i+1, other.equation(), m+1, R.equation()); i+1, other.equation(), m+1, R.equation());
} else { } else {
return make_pair(i,m); return {i,m};
} }
} }
participants[key].push_back(i); participants[key].push_back(i);
} }
return make_pair(npos, npos); return {npos, npos};
} }
double Kinetics::checkDuplicateStoich(std::map<int, double>& r1, double Kinetics::checkDuplicateStoich(std::map<int, double>& r1,

View file

@ -78,7 +78,7 @@ Plog::Plog(const std::multimap<double, Arrhenius>& rates)
double logp = std::log(rate.first); double logp = std::log(rate.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] = {j, j+1};
} else { } else {
// another rate expression at the same pressure // another rate expression at the same pressure
pressures_[logp].second = j+1; pressures_[logp].second = j+1;

View file

@ -28,10 +28,7 @@ Sim1D::Sim1D(vector<Domain1D*>& domains) :
// set some defaults // set some defaults
m_tstep = 1.0e-5; m_tstep = 1.0e-5;
m_steps.push_back(1); m_steps = { 1, 2, 5, 10 };
m_steps.push_back(2);
m_steps.push_back(5);
m_steps.push_back(10);
} }
void Sim1D::setInitialGuess(const std::string& component, vector_fp& locs, vector_fp& vals) void Sim1D::setInitialGuess(const std::string& component, vector_fp& locs, vector_fp& vals)

View file

@ -84,7 +84,7 @@ void GeneralSpeciesThermo::install_STIT(size_t index,
"GeneralSpeciesThermo::install_STIT", "GeneralSpeciesThermo::install_STIT",
"Index position isn't null, duplication of assignment: {}", index); "Index position isn't null, duplication of assignment: {}", index);
int type = stit_ptr->reportType(); int type = stit_ptr->reportType();
m_speciesLoc[index] = std::make_pair(type, m_sp[type].size()); m_speciesLoc[index] = {type, m_sp[type].size()};
m_sp[type].emplace_back(index, stit_ptr); m_sp[type].emplace_back(index, stit_ptr);
if (m_sp[type].size() == 1) { if (m_sp[type].size() == 1) {
m_tpoly[type].resize(stit_ptr->temperaturePolySize()); m_tpoly[type].resize(stit_ptr->temperaturePolySize());

View file

@ -200,7 +200,7 @@ void ReactorNet::registerSensitivityReaction(void* reactor,
"Sensitivity reactions cannot be added after the" "Sensitivity reactions cannot be added after the"
"integrator has been initialized."); "integrator has been initialized.");
} }
std::pair<void*, int> R = std::make_pair(reactor, leftright); std::pair<void*, int> R = {reactor, leftright};
if (m_sensOrder.count(R) && if (m_sensOrder.count(R) &&
m_sensOrder[R].count(reactionIndex)) { m_sensOrder[R].count(reactionIndex)) {
throw CanteraError("ReactorNet::registerSensitivityReaction", throw CanteraError("ReactorNet::registerSensitivityReaction",

View file

@ -26,10 +26,7 @@ TEST(parseCompString, extra_spaces)
TEST(parseCompString, default_values) TEST(parseCompString, default_values)
{ {
std::vector<std::string> x; std::vector<std::string> x = { "foo", "bar", "baz" };
x.push_back("foo");
x.push_back("bar");
x.push_back("baz");
compositionMap c = parseCompString("foo:1.0 baz:2", x); compositionMap c = parseCompString("foo:1.0 baz:2", x);
ASSERT_EQ((size_t) 3, c.size()); ASSERT_EQ((size_t) 3, c.size());
ASSERT_FALSE(c.find("bar") == c.end()); ASSERT_FALSE(c.find("bar") == c.end());
@ -48,9 +45,7 @@ TEST(parseCompString, delimiters)
TEST(parseCompString, missing_element) TEST(parseCompString, missing_element)
{ {
std::vector<std::string> x; std::vector<std::string> x = { "foo", "bar" };
x.push_back("foo");
x.push_back("bar");
ASSERT_THROW(parseCompString("foo:1.0 bar:2 baz:1e-4", x), ASSERT_THROW(parseCompString("foo:1.0 bar:2 baz:1e-4", x),
CanteraError); CanteraError);
} }

View file

@ -117,11 +117,7 @@ TEST_F(KineticsFromScratch, add_falloff_reaction)
Composition prod = parseCompString("H2O2:1"); Composition prod = parseCompString("H2O2:1");
Arrhenius high_rate(7.4e10, -0.37, 0.0); Arrhenius high_rate(7.4e10, -0.37, 0.0);
Arrhenius low_rate(2.3e12, -0.9, -1700.0 / GasConst_cal_mol_K); Arrhenius low_rate(2.3e12, -0.9, -1700.0 / GasConst_cal_mol_K);
vector_fp falloff_params; vector_fp falloff_params { 0.7346, 94.0, 1756.0, 5182.0 };
falloff_params.push_back(0.7346);
falloff_params.push_back(94.0);
falloff_params.push_back(1756.0);
falloff_params.push_back(5182.0);
ThirdBody tbody; ThirdBody tbody;
tbody.efficiencies = parseCompString("AR:0.7 H2:2.0 H2O:6.0"); tbody.efficiencies = parseCompString("AR:0.7 H2:2.0 H2O:6.0");
shared_ptr<FalloffReaction> R(new FalloffReaction(reac, prod, low_rate, shared_ptr<FalloffReaction> R(new FalloffReaction(reac, prod, low_rate,
@ -142,12 +138,12 @@ TEST_F(KineticsFromScratch, add_plog_reaction)
// [(100.0, 'atm'), 5.963200e+56, -11.529, 52599.6]) // [(100.0, 'atm'), 5.963200e+56, -11.529, 52599.6])
Composition reac = parseCompString("H2:1, O2:1"); Composition reac = parseCompString("H2:1, O2:1");
Composition prod = parseCompString("OH:2"); Composition prod = parseCompString("OH:2");
std::multimap<double, Arrhenius> rates; std::multimap<double, Arrhenius> rates {
typedef std::multimap<double, Arrhenius>::value_type item; { 0.01*101325, Arrhenius(1.212400e+16, -0.5779, 10872.7 / GasConst_cal_mol_K) },
rates.insert(item(0.01*101325, Arrhenius(1.212400e+16, -0.5779, 10872.7 / GasConst_cal_mol_K))); { 1.0*101325, Arrhenius(4.910800e+31, -4.8507, 24772.8 / GasConst_cal_mol_K) },
rates.insert(item(1.0*101325, Arrhenius(4.910800e+31, -4.8507, 24772.8 / GasConst_cal_mol_K))); { 10.0*101325, Arrhenius(1.286600e+47, -9.0246, 39796.5 / GasConst_cal_mol_K) },
rates.insert(item(10.0*101325, Arrhenius(1.286600e+47, -9.0246, 39796.5 / GasConst_cal_mol_K))); { 100.0*101325, Arrhenius(5.963200e+56, -11.529, 52599.6 / GasConst_cal_mol_K) }
rates.insert(item(100.0*101325, Arrhenius(5.963200e+56, -11.529, 52599.6 / GasConst_cal_mol_K))); };
shared_ptr<PlogReaction> R(new PlogReaction(reac, prod, Plog(rates))); shared_ptr<PlogReaction> R(new PlogReaction(reac, prod, Plog(rates)));
kin.addReaction(R); kin.addReaction(R);
@ -159,12 +155,12 @@ TEST_F(KineticsFromScratch, plog_invalid_rate)
{ {
Composition reac = parseCompString("H2:1, O2:1"); Composition reac = parseCompString("H2:1, O2:1");
Composition prod = parseCompString("OH:2"); Composition prod = parseCompString("OH:2");
std::multimap<double, Arrhenius> rates; std::multimap<double, Arrhenius> rates {
typedef std::multimap<double, Arrhenius>::value_type item; { 0.01*101325, Arrhenius(1.2124e+16, -0.5779, 10872.7 / GasConst_cal_mol_K) },
rates.insert(item(0.01*101325, Arrhenius(1.2124e+16, -0.5779, 10872.7 / GasConst_cal_mol_K))); { 10.0*101325, Arrhenius(1e15, -1, 10000 / GasConst_cal_mol_K) },
rates.insert(item(10.0*101325, Arrhenius(1e15, -1, 10000 / GasConst_cal_mol_K))); { 10.0*101325, Arrhenius(-2e20, -2.0, 20000 / GasConst_cal_mol_K) },
rates.insert(item(10.0*101325, Arrhenius(-2e20, -2.0, 20000 / GasConst_cal_mol_K))); { 100.0*101325, Arrhenius(5.9632e+56, -11.529, 52599.6 / GasConst_cal_mol_K) }
rates.insert(item(100.0*101325, Arrhenius(5.9632e+56, -11.529, 52599.6 / GasConst_cal_mol_K))); };
shared_ptr<PlogReaction> R(new PlogReaction(reac, prod, Plog(rates))); shared_ptr<PlogReaction> R(new PlogReaction(reac, prod, Plog(rates)));
ASSERT_THROW(kin.addReaction(R), CanteraError); ASSERT_THROW(kin.addReaction(R), CanteraError);
@ -324,9 +320,7 @@ public:
, surf("../data/sofc-test.xml", "metal_surface") , surf("../data/sofc-test.xml", "metal_surface")
, surf_ref("../data/sofc-test.xml", "metal_surface") , surf_ref("../data/sofc-test.xml", "metal_surface")
{ {
std::vector<ThermoPhase*> th; std::vector<ThermoPhase*> th = { &surf_ref, &gas_ref };
th.push_back(&surf_ref);
th.push_back(&gas_ref);
importKinetics(surf_ref.xml(), th, &kin_ref); importKinetics(surf_ref.xml(), th, &kin_ref);
kin.addPhase(surf); kin.addPhase(surf);
kin.addPhase(gas); kin.addPhase(gas);

View file

@ -9,14 +9,12 @@ namespace Cantera
TEST(FracCoeff, ConvertFracCoeff) TEST(FracCoeff, ConvertFracCoeff)
{ {
IdealGasPhase thermo1("../data/frac.cti", "gas"); IdealGasPhase thermo1("../data/frac.cti", "gas");
std::vector<ThermoPhase*> phases1; std::vector<ThermoPhase*> phases1 { &thermo1 };
phases1.push_back(&thermo1);
GasKinetics kinetics1; GasKinetics kinetics1;
importKinetics(thermo1.xml(), phases1, &kinetics1); importKinetics(thermo1.xml(), phases1, &kinetics1);
IdealGasPhase thermo2("../data/frac.xml", "gas"); IdealGasPhase thermo2("../data/frac.xml", "gas");
std::vector<ThermoPhase*> phases2; std::vector<ThermoPhase*> phases2 { &thermo2 };
phases2.push_back(&thermo2);
GasKinetics kinetics2; GasKinetics kinetics2;
importKinetics(thermo2.xml(), phases2, &kinetics2); importKinetics(thermo2.xml(), phases2, &kinetics2);
@ -40,8 +38,7 @@ public:
FracCoeffTest() : FracCoeffTest() :
therm("../data/frac.xml", "gas") therm("../data/frac.xml", "gas")
{ {
std::vector<ThermoPhase*> phases; std::vector<ThermoPhase*> phases { &therm };
phases.push_back(&therm);
importKinetics(therm.xml(), phases, &kin); importKinetics(therm.xml(), phases, &kin);
therm.setState_TPX(2000, 4*OneAtm, therm.setState_TPX(2000, 4*OneAtm,
"H2O:0.5, OH:.05, H:0.1, O2:0.15, H2:0.2"); "H2O:0.5, OH:.05, H:0.1, O2:0.15, H2:0.2");
@ -150,8 +147,7 @@ public:
NegativePreexponentialFactor() {} NegativePreexponentialFactor() {}
void setup(const std::string& infile) { void setup(const std::string& infile) {
therm.reset(newPhase(infile)); therm.reset(newPhase(infile));
std::vector<ThermoPhase*> phases; std::vector<ThermoPhase*> phases { therm.get() };
phases.push_back(therm.get());
importKinetics(therm->xml(), phases, &kin); importKinetics(therm->xml(), phases, &kin);
therm->setState_TPX(2000, OneAtm, therm->setState_TPX(2000, OneAtm,
"H2O:1.0, H:0.2, O2:0.3, NH:0.05, NO:0.05, N2O:0.05"); "H2O:1.0, H:0.2, O2:0.3, NH:0.05, NO:0.05, N2O:0.05");
@ -199,9 +195,7 @@ TEST_F(NegativePreexponentialFactor, fromXml)
TEST(InterfaceReaction, CoverageDependency) { TEST(InterfaceReaction, CoverageDependency) {
IdealGasPhase gas("ptcombust.cti", "gas"); IdealGasPhase gas("ptcombust.cti", "gas");
SurfPhase surf("ptcombust.cti", "Pt_surf"); SurfPhase surf("ptcombust.cti", "Pt_surf");
std::vector<ThermoPhase*> phases; std::vector<ThermoPhase*> phases { &gas, &surf };
phases.push_back(&gas);
phases.push_back(&surf);
shared_ptr<Kinetics> kin(newKineticsMgr(surf.xml(), phases)); shared_ptr<Kinetics> kin(newKineticsMgr(surf.xml(), phases));
ASSERT_EQ(kin->nReactions(), 25); ASSERT_EQ(kin->nReactions(), 25);

View file

@ -57,10 +57,7 @@ int main(int argc, char** argv)
size_t nsp_d100 = diamond100TP->nSpecies(); size_t nsp_d100 = diamond100TP->nSpecies();
cout << "Number of species in diamond_100 = " << nsp_d100 << endl; cout << "Number of species in diamond_100 = " << nsp_d100 << endl;
vector<ThermoPhase*> phaseList; vector<ThermoPhase*> phaseList { gasTP, diamondTP, diamond100TP };
phaseList.push_back(gasTP);
phaseList.push_back(diamondTP);
phaseList.push_back(diamond100TP);
InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); InterfaceKinetics* iKin_ptr = new InterfaceKinetics();
importKinetics(*xs, phaseList, iKin_ptr); importKinetics(*xs, phaseList, iKin_ptr);
size_t nr = iKin_ptr->nReactions(); size_t nr = iKin_ptr->nReactions();

View file

@ -49,10 +49,7 @@ int main(int argc, char** argv)
int nsp_d100 = diamond100TP->nSpecies(); int nsp_d100 = diamond100TP->nSpecies();
cout << "Number of species in diamond_100 = " << nsp_d100 << endl; cout << "Number of species in diamond_100 = " << nsp_d100 << endl;
vector<ThermoPhase*> phaseList; vector<ThermoPhase*> phaseList { gasTP, diamondTP, diamond100TP };
phaseList.push_back(gasTP);
phaseList.push_back(diamondTP);
phaseList.push_back(diamond100TP);
InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); InterfaceKinetics* iKin_ptr = new InterfaceKinetics();
importKinetics(*xs, phaseList, iKin_ptr); importKinetics(*xs, phaseList, iKin_ptr);
int nr = iKin_ptr->nReactions(); int nr = iKin_ptr->nReactions();
@ -142,11 +139,8 @@ int main(int argc, char** argv)
ThermoPhase* diamondTP_dupl = diamondTP->duplMyselfAsThermoPhase(); ThermoPhase* diamondTP_dupl = diamondTP->duplMyselfAsThermoPhase();
ThermoPhase* diamond100TP_dupl = diamond100TP->duplMyselfAsThermoPhase(); ThermoPhase* diamond100TP_dupl = diamond100TP->duplMyselfAsThermoPhase();
vector<ThermoPhase*> phaseList_dupl { gasTP_dupl, diamondTP_dupl,
vector<ThermoPhase*> phaseList_dupl; diamond100TP_dupl };
phaseList_dupl.push_back(gasTP_dupl);
phaseList_dupl.push_back(diamondTP_dupl);
phaseList_dupl.push_back(diamond100TP_dupl);
InterfaceKinetics* iKin_ptr_dupl = new InterfaceKinetics(); InterfaceKinetics* iKin_ptr_dupl = new InterfaceKinetics();
importKinetics(*xs, phaseList_dupl, iKin_ptr_dupl); importKinetics(*xs, phaseList_dupl, iKin_ptr_dupl);
int nr_dupl = iKin_ptr_dupl->nReactions(); int nr_dupl = iKin_ptr_dupl->nReactions();

View file

@ -57,16 +57,10 @@ void testProblem()
unique_ptr<ThermoPhase> feo_s(newPhase("solidPhases.xml", "FeO(S)")); unique_ptr<ThermoPhase> feo_s(newPhase("solidPhases.xml", "FeO(S)"));
unique_ptr<ThermoPhase> fe_s(newPhase("solidPhases.xml", "Fe(S)")); unique_ptr<ThermoPhase> fe_s(newPhase("solidPhases.xml", "Fe(S)"));
vector<ThermoPhase*> phaseList; vector<ThermoPhase*> phaseList {
phaseList.push_back(gasTP.get()); gasTP.get(), cao_s.get(), caco3_s.get(), c_s.get(), fe3o4_s.get(),
phaseList.push_back(cao_s.get()); feo_s.get(), fe_s.get(), surfTP.get()
phaseList.push_back(caco3_s.get()); };
phaseList.push_back(c_s.get());
phaseList.push_back(fe3o4_s.get());
phaseList.push_back(feo_s.get());
phaseList.push_back(fe_s.get());
phaseList.push_back(surfTP.get());
InterfaceKinetics iKin; InterfaceKinetics iKin;
importKinetics(*xg, phaseList, &iKin); importKinetics(*xg, phaseList, &iKin);

View file

@ -244,10 +244,7 @@ int main(int argc, char** argv)
cout << "Number of species in surface phase, " << surfParticlePhaseName cout << "Number of species in surface phase, " << surfParticlePhaseName
<< " = " << nsp_d100 << endl; << " = " << nsp_d100 << endl;
vector<ThermoPhase*> phaseList; vector<ThermoPhase*> phaseList { gasTP, bulkPhaseTP, surfPhaseTP };
phaseList.push_back(gasTP);
phaseList.push_back(bulkPhaseTP);
phaseList.push_back(surfPhaseTP);
InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); InterfaceKinetics* iKin_ptr = new InterfaceKinetics();
importKinetics(*xs, phaseList, iKin_ptr); importKinetics(*xs, phaseList, iKin_ptr);

View file

@ -242,13 +242,7 @@ int main(int argc, char** argv)
cout << "Number of species in surface phase, " << surfParticlePhaseName cout << "Number of species in surface phase, " << surfParticlePhaseName
<< " = " << nsp_d100 << endl; << " = " << nsp_d100 << endl;
vector<ThermoPhase*> phaseList; vector<ThermoPhase*> phaseList { gasTP, bulkPhaseTP, surfPhaseTP };
phaseList.push_back(gasTP);
phaseList.push_back(bulkPhaseTP);
phaseList.push_back(surfPhaseTP);
InterfaceKinetics* iKin_ptr = new InterfaceKinetics(); InterfaceKinetics* iKin_ptr = new InterfaceKinetics();
importKinetics(*xs, phaseList, iKin_ptr); importKinetics(*xs, phaseList, iKin_ptr);
size_t nr = iKin_ptr->nReactions(); size_t nr = iKin_ptr->nReactions();
@ -265,10 +259,7 @@ int main(int argc, char** argv)
cout << "Number of species in 2nd surface phase, " << pname cout << "Number of species in 2nd surface phase, " << pname
<< " = " << nsp2 << endl; << " = " << nsp2 << endl;
vector<ThermoPhase*> phaseList2; vector<ThermoPhase*> phaseList2 { gasTP, bulkPhaseTP, surfPhaseTP2 };
phaseList2.push_back(gasTP);
phaseList2.push_back(bulkPhaseTP);
phaseList2.push_back(surfPhaseTP2);
// create the second InterfaceKinetics object based on the // create the second InterfaceKinetics object based on the
// second surface phase. // second surface phase.
@ -329,9 +320,7 @@ int main(int argc, char** argv)
* Set-up the Surface Problem * Set-up the Surface Problem
* This problem will consist of 2 identical InterfaceKinetics objects * This problem will consist of 2 identical InterfaceKinetics objects
*/ */
vector<InterfaceKinetics*> vecKinPtrs; vector<InterfaceKinetics*> vecKinPtrs { iKin_ptr, iKin2_ptr };
vecKinPtrs.push_back(iKin_ptr);
vecKinPtrs.push_back(iKin2_ptr);
// Create the ImplicitSurfChem problem // Create the ImplicitSurfChem problem
// Initialize it and call the pseudo steadystate capability. // Initialize it and call the pseudo steadystate capability.

View file

@ -16,12 +16,9 @@ int main()
gas.setState_TPX(1200.0, OneAtm, gas.setState_TPX(1200.0, OneAtm,
"H2:2, O2:1, OH:0.01, H:0.01, O:0.01"); "H2:2, O2:1, OH:0.01, H:0.01, O:0.01");
vector<ThermoPhase*> phases; vector<ThermoPhase*> phases { &gas };
phases.push_back(&gas);
Interface surf("surface.xml", "surface", phases); Interface surf("surface.xml", "surface", phases);
vector_fp cov; vector_fp cov { 0.8, 0.2 };
cov.push_back(0.8);
cov.push_back(0.2);
cout.precision(4); cout.precision(4);
surf.setCoverages(DATA_PTR(cov)); surf.setCoverages(DATA_PTR(cov));
vector_fp wdot(gas.nSpecies() + surf.nSpecies()); vector_fp wdot(gas.nSpecies() + surf.nSpecies());