Make use of "make_shared" where possible

This commit is contained in:
Ray Speth 2015-10-16 20:25:32 -04:00
parent a945ef2c23
commit 91d3002df1
8 changed files with 43 additions and 43 deletions

View file

@ -38,6 +38,7 @@ namespace Cantera
#endif
using std::shared_ptr;
using std::make_shared;
/*!
* All physical constants are stored here.

View file

@ -590,39 +590,39 @@ shared_ptr<Reaction> newReaction(const XML_Node& rxn_node)
// Create a new Reaction object of the appropriate type
if (type == "elementary" || type == "arrhenius" || type == "") {
shared_ptr<ElementaryReaction> R(new ElementaryReaction());
auto R = make_shared<ElementaryReaction>();
setupElementaryReaction(*R, rxn_node);
return R;
} else if (type == "threebody" || type == "three_body") {
shared_ptr<ThreeBodyReaction> R(new ThreeBodyReaction());
auto R = make_shared<ThreeBodyReaction>();
setupThreeBodyReaction(*R, rxn_node);
return R;
} else if (type == "falloff") {
shared_ptr<FalloffReaction> R(new FalloffReaction());
auto R = make_shared<FalloffReaction>();
setupFalloffReaction(*R, rxn_node);
return R;
} else if (type == "chemact" || type == "chemically_activated") {
shared_ptr<ChemicallyActivatedReaction> R(new ChemicallyActivatedReaction());
auto R = make_shared<ChemicallyActivatedReaction>();
setupChemicallyActivatedReaction(*R, rxn_node);
return R;
} else if (type == "plog" || type == "pdep_arrhenius") {
shared_ptr<PlogReaction> R(new PlogReaction());
auto R = make_shared<PlogReaction>();
setupPlogReaction(*R, rxn_node);
return R;
} else if (type == "chebyshev") {
shared_ptr<ChebyshevReaction> R(new ChebyshevReaction());
auto R = make_shared<ChebyshevReaction>();
setupChebyshevReaction(*R, rxn_node);
return R;
} else if (type == "interface" || type == "surface" || type == "edge" ||
type == "global") {
shared_ptr<InterfaceReaction> R(new InterfaceReaction());
auto R = make_shared<InterfaceReaction>();
setupInterfaceReaction(*R, rxn_node);
return R;
} else if (type == "electrochemical" ||
type == "butlervolmer_noactivitycoeffs" ||
type == "butlervolmer" ||
type == "surfaceaffinity") {
shared_ptr<ElectrochemicalReaction> R(new ElectrochemicalReaction());
auto R = make_shared<ElectrochemicalReaction>();
setupElectrochemicalReaction(*R, rxn_node);
return R;
} else {

View file

@ -49,7 +49,7 @@ FixedChemPotSSTP::FixedChemPotSSTP(const std::string& Ename, doublereal val) :
setName(pname);
setNDim(3);
addElement(Ename);
shared_ptr<Species> sp(new Species(pname, parseCompString(Ename + ":1.0")));
auto sp = make_shared<Species>(pname, parseCompString(Ename + ":1.0"));
double c[4] = {298.15, val, 0.0, 0.0};
shared_ptr<SpeciesThermoInterpType> stit(
newSpeciesThermoInterpType("const_cp", 0.1, 1e30, OneAtm, c));

View file

@ -99,7 +99,7 @@ void GeneralSpeciesThermo::install_STIT(size_t index,
void GeneralSpeciesThermo::installPDSShandler(size_t k, PDSS* PDSS_ptr,
VPSSMgr* vpssmgr_ptr)
{
shared_ptr<SpeciesThermoInterpType> stit_ptr(new STITbyPDSS(vpssmgr_ptr, PDSS_ptr));
auto stit_ptr = make_shared<STITbyPDSS>(vpssmgr_ptr, PDSS_ptr);
install_STIT(k, stit_ptr);
}

View file

@ -61,7 +61,7 @@ shared_ptr<Species> newSpecies(const XML_Node& species_node)
{
std::string name = species_node["name"];
compositionMap comp = parseCompString(species_node.child("atomArray").value());
shared_ptr<Species> s(new Species(name, comp));
auto s = make_shared<Species>(name, comp);
if (species_node.hasChild("charge")) {
s->charge = getFloat(species_node, "charge");
}

View file

@ -129,12 +129,12 @@ shared_ptr<TransportData> newTransportData(const XML_Node& transport_node)
{
std::string model = transport_node["model"];
if (model == "gas_transport") {
shared_ptr<GasTransportData> tr(new GasTransportData());
auto tr = make_shared<GasTransportData>();
setupGasTransportData(*tr, transport_node);
return tr;
} else {
// Transport model not handled here
return shared_ptr<TransportData>(new TransportData());
return make_shared<TransportData>();
}
}

View file

@ -54,7 +54,7 @@ TEST_F(KineticsFromScratch, add_elementary_reaction)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
kin.addReaction(R);
kin.finalize();
@ -71,7 +71,7 @@ TEST_F(KineticsFromScratch, add_three_body_reaction)
Arrhenius rate(1.2e11, -1.0, 0.0);
ThirdBody tbody;
tbody.efficiencies = parseCompString("AR:0.83 H2:2.4 H2O:15.4");
shared_ptr<ThreeBodyReaction> R(new ThreeBodyReaction(reac, prod, rate, tbody));
auto R = make_shared<ThreeBodyReaction>(reac, prod, rate, tbody);
kin.addReaction(R);
kin.finalize();
@ -85,7 +85,7 @@ TEST_F(KineticsFromScratch, undefined_third_body)
Arrhenius rate(1.2e11, -1.0, 0.0);
ThirdBody tbody;
tbody.efficiencies = parseCompString("H2:0.1 CO2:0.83");
shared_ptr<ThreeBodyReaction> R(new ThreeBodyReaction(reac, prod, rate, tbody));
auto R = make_shared<ThreeBodyReaction>(reac, prod, rate, tbody);
ASSERT_THROW(kin.addReaction(R), CanteraError);
}
@ -97,7 +97,7 @@ TEST_F(KineticsFromScratch, skip_undefined_third_body)
Arrhenius rate(1.2e11, -1.0, 0.0);
ThirdBody tbody;
tbody.efficiencies = parseCompString("H2:0.1 CO2:0.83");
shared_ptr<ThreeBodyReaction> R(new ThreeBodyReaction(reac, prod, rate, tbody));
auto R = make_shared<ThreeBodyReaction>(reac, prod, rate, tbody);
kin.skipUndeclaredThirdBodies(true);
kin.addReaction(R);
@ -120,8 +120,7 @@ TEST_F(KineticsFromScratch, add_falloff_reaction)
vector_fp falloff_params { 0.7346, 94.0, 1756.0, 5182.0 };
ThirdBody tbody;
tbody.efficiencies = parseCompString("AR:0.7 H2:2.0 H2O:6.0");
shared_ptr<FalloffReaction> R(new FalloffReaction(reac, prod, low_rate,
high_rate, tbody));
auto R = make_shared<FalloffReaction>(reac, prod, low_rate, high_rate, tbody);
R->falloff = newFalloff(TROE_FALLOFF, falloff_params);
kin.addReaction(R);
kin.finalize();
@ -145,7 +144,7 @@ TEST_F(KineticsFromScratch, add_plog_reaction)
{ 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)));
auto R = make_shared<PlogReaction>(reac, prod, Plog(rates));
kin.addReaction(R);
kin.finalize();
check_rates(3);
@ -162,7 +161,7 @@ TEST_F(KineticsFromScratch, plog_invalid_rate)
{ 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)));
auto R = make_shared<PlogReaction>(reac, prod, Plog(rates));
ASSERT_THROW(kin.addReaction(R), CanteraError);
}
@ -193,7 +192,7 @@ TEST_F(KineticsFromScratch, add_chebyshev_reaction)
coeffs(2,3) = -7.6385e-03;
ChebyshevRate rate(290, 3000, 1000.0, 10000000.0, coeffs);
shared_ptr<ChebyshevReaction> R(new ChebyshevReaction(reac, prod, rate));
auto R = make_shared<ChebyshevReaction>(reac, prod, rate);
kin.addReaction(R);
kin.finalize();
check_rates(4);
@ -204,7 +203,7 @@ TEST_F(KineticsFromScratch, undeclared_species)
Composition reac = parseCompString("CO:1 OH:1");
Composition prod = parseCompString("CO2:1 H:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
ASSERT_THROW(kin.addReaction(R), CanteraError);
ASSERT_EQ(0, kin.nReactions());
@ -215,7 +214,7 @@ TEST_F(KineticsFromScratch, skip_undeclared_species)
Composition reac = parseCompString("CO:1 OH:1");
Composition prod = parseCompString("CO2:1 H:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
kin.skipUndeclaredSpecies(true);
kin.addReaction(R);
@ -227,7 +226,7 @@ TEST_F(KineticsFromScratch, negative_A_error)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(-3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
ASSERT_THROW(kin.addReaction(R), CanteraError);
ASSERT_EQ(0, kin.nReactions());
@ -238,7 +237,7 @@ TEST_F(KineticsFromScratch, allow_negative_A)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(-3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
R->allow_negative_pre_exponential_factor = true;
kin.addReaction(R);
@ -250,7 +249,7 @@ TEST_F(KineticsFromScratch, invalid_reversible_with_orders)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
R->orders["H2"] = 0.5;
ASSERT_THROW(kin.addReaction(R), CanteraError);
@ -262,7 +261,7 @@ TEST_F(KineticsFromScratch, negative_order_override)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
R->reversible = false;
R->allow_negative_orders = true;
R->orders["H2"] = - 0.5;
@ -276,7 +275,7 @@ TEST_F(KineticsFromScratch, invalid_negative_orders)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
R->reversible = false;
R->orders["H2"] = - 0.5;
@ -289,7 +288,7 @@ TEST_F(KineticsFromScratch, nonreactant_order_override)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
R->reversible = false;
R->allow_nonreactant_orders = true;
R->orders["OH"] = 0.5;
@ -303,7 +302,7 @@ TEST_F(KineticsFromScratch, invalid_nonreactant_order)
Composition reac = parseCompString("O:1 H2:1");
Composition prod = parseCompString("H:1 OH:1");
Arrhenius rate(3.87e1, 2.7, 6260.0 / GasConst_cal_mol_K);
shared_ptr<ElementaryReaction> R(new ElementaryReaction(reac, prod, rate));
auto R = make_shared<ElementaryReaction>(reac, prod, rate);
R->reversible = false;
R->orders["OH"] = 0.5;
@ -368,7 +367,7 @@ TEST_F(InterfaceKineticsFromScratch, add_surface_reaction)
Composition prod = parseCompString("OH(m):1 (m):1");
Arrhenius rate(5e21, 0, 100.0e6 / GasConstant); // kJ/mol -> J/kmol
shared_ptr<InterfaceReaction>R(new InterfaceReaction(reac, prod, rate));
auto R = make_shared<InterfaceReaction>(reac, prod, rate);
kin.addReaction(R);
kin.finalize();
check_rates(3);
@ -383,7 +382,7 @@ TEST_F(InterfaceKineticsFromScratch, add_sticking_reaction)
Composition prod = parseCompString("H(m):2");
Arrhenius rate(0.1, 0, 0.0);
shared_ptr<InterfaceReaction>R(new InterfaceReaction(reac, prod, rate, true));
auto R = make_shared<InterfaceReaction>(reac, prod, rate, true);
kin.addReaction(R);
kin.finalize();
check_rates(0);

View file

@ -32,9 +32,9 @@ TEST_F(SpeciesThermoInterpTypeTest, install_const_cp)
{
// Compare against instantiation from CTI file
IdealGasPhase p2("../data/simplephases.cti", "simple1");
shared_ptr<Species> sO2(new Species("O2", parseCompString("O:2")));
shared_ptr<Species> sH2(new Species("H2", parseCompString("H:2")));
shared_ptr<Species> sH2O(new Species("H2O", parseCompString("H:2 O:1")));
auto sO2 = make_shared<Species>("O2", parseCompString("O:2"));
auto sH2 = make_shared<Species>("H2", parseCompString("H:2"));
auto sH2O = make_shared<Species>("H2O", parseCompString("H:2 O:1"));
sO2->thermo.reset(new ConstCpPoly(200, 5000, 101325, c_o2));
sH2->thermo.reset(new ConstCpPoly(200, 5000, 101325, c_h2));
sH2O->thermo.reset(new ConstCpPoly(200, 5000, 101325, c_h2o));
@ -54,8 +54,8 @@ TEST_F(SpeciesThermoInterpTypeTest, DISABLED_install_bad_pref)
{
// Currently broken because GeneralSpeciesThermo does not enforce reference
// pressure consistency.
shared_ptr<Species> sO2(new Species("O2", parseCompString("O:2")));
shared_ptr<Species> sH2(new Species("H2", parseCompString("H:2")));
auto sO2 = make_shared<Species>("O2", parseCompString("O:2"));
auto sH2 = make_shared<Species>("H2", parseCompString("H:2"));
sO2->thermo.reset(new ConstCpPoly(200, 5000, 101325, c_o2));
sH2->thermo.reset(new ConstCpPoly(200, 5000, 100000, c_h2));
p.addSpecies(sO2);
@ -67,9 +67,9 @@ TEST_F(SpeciesThermoInterpTypeTest, install_nasa)
{
// Compare against instantiation from CTI file
IdealGasPhase p2("../data/simplephases.cti", "nasa1");
shared_ptr<Species> sO2(new Species("O2", parseCompString("O:2")));
shared_ptr<Species> sH2(new Species("H2", parseCompString("H:2")));
shared_ptr<Species> sH2O(new Species("H2O", parseCompString("H:2 O:1")));
auto sO2 = make_shared<Species>("O2", parseCompString("O:2"));
auto sH2 = make_shared<Species>("H2", parseCompString("H:2"));
auto sH2O = make_shared<Species>("H2O", parseCompString("H:2 O:1"));
sO2->thermo.reset(new NasaPoly2(200, 3500, 101325, o2_nasa_coeffs));
sH2->thermo.reset(new NasaPoly2(200, 3500, 101325, h2_nasa_coeffs));
sH2O->thermo.reset(new NasaPoly2(200, 3500, 101325, h2o_nasa_coeffs));
@ -89,8 +89,8 @@ TEST_F(SpeciesThermoInterpTypeTest, install_shomate)
{
// Compare against instantiation from CTI file
IdealGasPhase p2("../data/simplephases.cti", "shomate1");
shared_ptr<Species> sCO(new Species("CO", parseCompString("C:1 O:1")));
shared_ptr<Species> sCO2(new Species("CO2", parseCompString("C:1 O:2")));
auto sCO = make_shared<Species>("CO", parseCompString("C:1 O:1"));
auto sCO2 = make_shared<Species>("CO2", parseCompString("C:1 O:2"));
sCO->thermo.reset(new ShomatePoly2(200, 6000, 101325, co_shomate_coeffs));
sCO2->thermo.reset(new ShomatePoly2(200, 6000, 101325, co2_shomate_coeffs));
p.addSpecies(sCO);