Skip to content

Commit

Permalink
Make use of make_unique
Browse files Browse the repository at this point in the history
Also use make_shared more consistently
  • Loading branch information
speth authored and ischoegl committed Mar 9, 2023
1 parent da26479 commit 7a69a67
Show file tree
Hide file tree
Showing 37 changed files with 111 additions and 115 deletions.
1 change: 1 addition & 0 deletions include/cantera/base/ct_defs.h
Expand Up @@ -37,6 +37,7 @@ namespace Cantera
using std::shared_ptr;
using std::make_shared;
using std::unique_ptr;
using std::make_unique;
using std::isnan; // workaround for bug in libstdc++ 4.8
using std::string;
using std::vector;
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/Arrhenius.h
Expand Up @@ -183,7 +183,7 @@ class ArrheniusRate : public ArrheniusBase
using ArrheniusBase::ArrheniusBase; // inherit constructors

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<ArrheniusRate, ArrheniusData>);
return make_unique<MultiRate<ArrheniusRate, ArrheniusData>>();
}

virtual const std::string type() const override {
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/BlowersMaselRate.h
Expand Up @@ -88,7 +88,7 @@ class BlowersMaselRate : public ArrheniusBase
const UnitStack& rate_units={});

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<BlowersMaselRate, BlowersMaselData>);
return make_unique<MultiRate<BlowersMaselRate, BlowersMaselData>>();
}

virtual const std::string type() const override {
Expand Down
3 changes: 1 addition & 2 deletions include/cantera/kinetics/ChebyshevRate.h
Expand Up @@ -108,8 +108,7 @@ class ChebyshevRate final : public ReactionRate
ChebyshevRate(const AnyMap& node, const UnitStack& rate_units={});

unique_ptr<MultiRateBase> newMultiRate() const {
return unique_ptr<MultiRateBase>(
new MultiRate<ChebyshevRate, ChebyshevData>);
return make_unique<MultiRate<ChebyshevRate, ChebyshevData>>();
}

const std::string type() const { return "Chebyshev"; }
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/Custom.h
Expand Up @@ -40,7 +40,7 @@ class CustomFunc1Rate final : public ReactionRate
CustomFunc1Rate(const AnyMap& node, const UnitStack& rate_units);

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<CustomFunc1Rate, ArrheniusData>);
return make_unique<MultiRate<CustomFunc1Rate, ArrheniusData>>();
}

const std::string type() const override { return "custom-rate-function"; }
Expand Down
9 changes: 4 additions & 5 deletions include/cantera/kinetics/Falloff.h
Expand Up @@ -286,8 +286,7 @@ class LindemannRate final : public FalloffRate
const vector_fp& c);

unique_ptr<MultiRateBase> newMultiRate() const override{
return unique_ptr<MultiRateBase>(
new MultiRate<LindemannRate, FalloffData>);
return make_unique<MultiRate<LindemannRate, FalloffData>>();
}

virtual const std::string subType() const override {
Expand Down Expand Up @@ -337,7 +336,7 @@ class TroeRate final : public FalloffRate
const vector_fp& c);

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<TroeRate, FalloffData>);
return make_unique<MultiRate<TroeRate, FalloffData>>();
}

//! Set coefficients used by parameterization
Expand Down Expand Up @@ -436,7 +435,7 @@ class SriRate final : public FalloffRate
}

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<SriRate, FalloffData>);
return make_unique<MultiRate<SriRate, FalloffData>>();
}

//! Set coefficients used by parameterization
Expand Down Expand Up @@ -543,7 +542,7 @@ class TsangRate final : public FalloffRate
}

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(new MultiRate<TsangRate, FalloffData>);
return make_unique<MultiRate<TsangRate, FalloffData>>();
}

//! Set coefficients used by parameterization
Expand Down
6 changes: 2 additions & 4 deletions include/cantera/kinetics/InterfaceRate.h
Expand Up @@ -372,8 +372,7 @@ class InterfaceRate : public RateType, public InterfaceRateBase
}

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(
new MultiRate<InterfaceRate<RateType, DataType>, DataType>);
return make_unique<MultiRate<InterfaceRate<RateType, DataType>, DataType>>();
}

//! Identifier of reaction rate type
Expand Down Expand Up @@ -461,8 +460,7 @@ class StickingRate : public RateType, public StickingCoverage
}

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(
new MultiRate<StickingRate<RateType, DataType>, DataType>);
return make_unique<MultiRate<StickingRate<RateType, DataType>, DataType>>();
}

//! Identifier of reaction rate type
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/PlogRate.h
Expand Up @@ -84,7 +84,7 @@ class PlogRate final : public ReactionRate
PlogRate(const AnyMap& node, const UnitStack& rate_units={});

unique_ptr<MultiRateBase> newMultiRate() const {
return unique_ptr<MultiRateBase>(new MultiRate<PlogRate, PlogData>);
return make_unique<MultiRate<PlogRate, PlogData>>();
}

//! Identifier of reaction rate type
Expand Down
2 changes: 1 addition & 1 deletion include/cantera/kinetics/ReactionRate.h
Expand Up @@ -72,7 +72,7 @@ class ReactionRate
//!
//! ```.cpp
//! unique_ptr<MultiRateBase> newMultiRate() const override {
//! return unique_ptr<MultiRateBase>(new MultiRate<RateType, DataType>);
//! return make_unique<MultiRate<RateType, DataType>>();
//! ```
//!
//! where `RateType` is the derived class name and `DataType` is the corresponding
Expand Down
3 changes: 1 addition & 2 deletions include/cantera/kinetics/TwoTempPlasmaRate.h
Expand Up @@ -78,8 +78,7 @@ class TwoTempPlasmaRate : public ArrheniusBase
TwoTempPlasmaRate(const AnyMap& node, const UnitStack& rate_units={});

unique_ptr<MultiRateBase> newMultiRate() const override {
return unique_ptr<MultiRateBase>(
new MultiRate<TwoTempPlasmaRate, TwoTempPlasmaData>);
return make_unique<MultiRate<TwoTempPlasmaRate, TwoTempPlasmaData>>();
}

virtual const std::string type() const override {
Expand Down
9 changes: 5 additions & 4 deletions src/base/AnyMap.cpp
Expand Up @@ -607,7 +607,7 @@ AnyValue& AnyValue::operator=(AnyValue const& other) {
}
AnyBase::operator=(other);
m_key = other.m_key;
m_value.reset(new boost::any{*other.m_value});
m_value = make_unique<boost::any>(*other.m_value);
m_equals = other.m_equals;
return *this;
}
Expand Down Expand Up @@ -1560,7 +1560,8 @@ AnyMap::OrderedProxy::OrderedProxy(const AnyMap& data)
{
// Units always come first
if (m_data->hasKey("__units__") && m_data->at("__units__").as<AnyMap>().size()) {
m_units.reset(new std::pair<const string, AnyValue>{"units", m_data->at("__units__")});
m_units = make_unique<pair<const string, AnyValue>>(
"units", m_data->at("__units__"));
m_units->second.setFlowStyle();
m_ordered.emplace_back(std::pair<int, int>{-2, 0}, m_units.get());
}
Expand Down Expand Up @@ -1672,7 +1673,7 @@ void AnyMap::applyUnits(shared_ptr<UnitSystem>& units) {
m_data.erase("units");
}
if (hasKey("__units__")) {
m_units.reset(new UnitSystem(*units));
m_units = make_shared<UnitSystem>(*units);
m_units->setDefaults(m_data["__units__"].asMap<std::string>());
} else {
m_units = units;
Expand All @@ -1691,7 +1692,7 @@ void AnyMap::setUnits(const UnitSystem& units)
} else {
m_data["__units__"] = units.getDelta(*m_units);
}
m_units.reset(new UnitSystem(units));
m_units = make_shared<UnitSystem>(units);
}

void AnyMap::setFlowStyle(bool flow) {
Expand Down
4 changes: 2 additions & 2 deletions src/base/Storage.cpp
Expand Up @@ -51,9 +51,9 @@ namespace Cantera
Storage::Storage(std::string fname, bool write) : m_write(write)
{
if (m_write) {
m_file.reset(new h5::File(fname, h5::File::OpenOrCreate));
m_file = make_unique<h5::File>(fname, h5::File::OpenOrCreate);
} else {
m_file.reset(new h5::File(fname, h5::File::ReadOnly));
m_file = make_unique<h5::File>(fname, h5::File::ReadOnly);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/base/application.cpp
Expand Up @@ -39,7 +39,7 @@ Application::Messages::Messages()
{
// install a default logwriter that writes to standard
// output / standard error
logwriter.reset(new Logger());
logwriter = make_unique<Logger>();
}

void Application::Messages::addError(const std::string& r, const std::string& msg)
Expand Down
2 changes: 1 addition & 1 deletion src/clib/ct.cpp
Expand Up @@ -1657,7 +1657,7 @@ extern "C" {
{
static unique_ptr<Logger> logwriter;
try {
logwriter.reset(new ExternalLogger(writer));
logwriter = make_unique<ExternalLogger>(writer);
setLogger(logwriter.get());
return 0;
} catch (...) {
Expand Down
4 changes: 2 additions & 2 deletions src/equil/vcs_solve.cpp
Expand Up @@ -53,7 +53,7 @@ VCS_SOLVE::VCS_SOLVE(MultiPhase* mphase, int printLvl) :
{
m_speciesThermoList.resize(m_nsp);
for (size_t kspec = 0; kspec < m_nsp; kspec++) {
m_speciesThermoList[kspec].reset(new VCS_SPECIES_THERMO());
m_speciesThermoList[kspec] = make_unique<VCS_SPECIES_THERMO>();
}

string ser = "VCS_SOLVE: ERROR:\n\t";
Expand Down Expand Up @@ -123,7 +123,7 @@ VCS_SOLVE::VCS_SOLVE(MultiPhase* mphase, int printLvl) :
// Phase Info
m_VolPhaseList.resize(m_numPhases);
for (size_t iph = 0; iph < m_numPhases; iph++) {
m_VolPhaseList[iph].reset(new vcs_VolPhase(this));
m_VolPhaseList[iph] = make_unique<vcs_VolPhase>(this);
}

// For Future expansion
Expand Down
2 changes: 1 addition & 1 deletion src/kinetics/ImplicitSurfChem.cpp
Expand Up @@ -189,7 +189,7 @@ void ImplicitSurfChem::solvePseudoSteadyStateProblem(int ifuncOverride,
// time scale - time over which to integrate equations
doublereal time_scale = timeScaleOverride;
if (!m_surfSolver) {
m_surfSolver.reset(new solveSP(this, bulkFunc));
m_surfSolver = make_unique<solveSP>(this, bulkFunc);
// set ifunc, which sets the algorithm.
ifunc = SFLUX_INITIALIZE;
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/kinetics/Reaction.cpp
Expand Up @@ -282,7 +282,7 @@ void Reaction::setRate(shared_ptr<ReactionRate> rate)
"Reaction equation for falloff reaction '{}'\n does not "
"contain valid pressure-dependent third body", equation());
}
m_third_body.reset(new ThirdBody("(+M)"));
m_third_body = make_shared<ThirdBody>("(+M)");
}
}
}
Expand Down Expand Up @@ -404,7 +404,7 @@ void Reaction::setEquation(const std::string& equation, const Kinetics* kin)
"Collision efficiencies need to specify single species", equation);
}
third_body = effs.begin()->first;
m_third_body.reset(new ThirdBody(third_body));
m_third_body = make_shared<ThirdBody>(third_body);
m_third_body->explicit_3rd = true;
} else if (input.hasKey("default-efficiency")) {
// insufficient disambiguation of third bodies
Expand Down Expand Up @@ -462,7 +462,7 @@ void Reaction::setEquation(const std::string& equation, const Kinetics* kin)
}
m_third_body->setName(third_body);
} else {
m_third_body.reset(new ThirdBody(third_body));
m_third_body = make_shared<ThirdBody>(third_body);
}

// adjust reactant coefficients
Expand Down Expand Up @@ -825,7 +825,7 @@ ThreeBodyReaction::ThreeBodyReaction()
{
warn_deprecated("ThreeBodyReaction",
"To be removed after Cantera 3.0. Replaceable with Reaction.");
m_third_body.reset(new ThirdBody);
m_third_body = make_shared<ThirdBody>();
setRate(newReactionRate(type()));
}

Expand Down Expand Up @@ -853,7 +853,7 @@ FalloffReaction::FalloffReaction()
{
warn_deprecated("FalloffReaction",
"To be removed after Cantera 3.0. Replaceable with Reaction.");
m_third_body.reset(new ThirdBody);
m_third_body = make_shared<ThirdBody>();
setRate(newReactionRate(type()));
}

Expand All @@ -880,19 +880,19 @@ FalloffReaction::FalloffReaction(const AnyMap& node, const Kinetics& kin)
warn_deprecated("FalloffReaction",
"To be removed after Cantera 3.0. Replaceable with Reaction.");
if (node.empty()) {
m_third_body.reset(new ThirdBody);
m_third_body = make_shared<ThirdBody>();
setRate(newReactionRate(type()));
}
}

unique_ptr<Reaction> newReaction(const std::string& type)
{
return unique_ptr<Reaction>(new Reaction());
return make_unique<Reaction>();
}

unique_ptr<Reaction> newReaction(const AnyMap& rxn_node, const Kinetics& kin)
{
return unique_ptr<Reaction>(new Reaction(rxn_node, kin));
return make_unique<Reaction>(rxn_node, kin);
}

void parseReactionEquation(Reaction& R, const std::string& equation,
Expand Down Expand Up @@ -970,7 +970,7 @@ std::vector<shared_ptr<Reaction>> getReactions(const AnyValue& items,
{
std::vector<shared_ptr<Reaction>> all_reactions;
for (const auto& node : items.asVector<AnyMap>()) {
shared_ptr<Reaction> R(new Reaction(node, kinetics));
auto R = make_shared<Reaction>(node, kinetics);
R->check();
R->validate(kinetics);
if (R->valid() && R->checkSpecies(kinetics)) {
Expand Down
4 changes: 2 additions & 2 deletions src/kinetics/ReactionRateDelegator.cpp
Expand Up @@ -55,8 +55,8 @@ ReactionRateDelegator::ReactionRateDelegator()

unique_ptr<MultiRateBase> ReactionRateDelegator::newMultiRate() const
{
auto multirate = std::make_unique<MultiRate<ReactionRateDelegator,
ReactionDataDelegator>>();
auto multirate = make_unique<MultiRate<ReactionRateDelegator,
ReactionDataDelegator>>();
multirate->sharedData().setType(m_rateType);
ExtensionManager::wrapReactionData(m_rateType, multirate->sharedData());
return multirate;
Expand Down
2 changes: 1 addition & 1 deletion src/numerics/IDA_Solver.cpp
Expand Up @@ -466,7 +466,7 @@ void IDA_Solver::init(doublereal t0)
}

// pass a pointer to func in m_data
m_fdata.reset(new ResidData(&m_resid, this, m_resid.nparams()));
m_fdata = make_unique<ResidData>(&m_resid, this, m_resid.nparams());
flag = IDASetUserData(m_ida_mem, m_fdata.get());
if (flag != IDA_SUCCESS) {
throw CanteraError("IDA_Solver::init", "IDASetUserData failed.");
Expand Down
2 changes: 1 addition & 1 deletion src/oneD/Domain1D.cpp
Expand Up @@ -29,7 +29,7 @@ void Domain1D::resize(size_t nv, size_t np)
// new grid refiner is required.
if (nv != m_nv || !m_refiner) {
m_nv = nv;
m_refiner.reset(new Refiner(*this));
m_refiner = make_unique<Refiner>(*this);
}
m_nv = nv;
m_name.resize(m_nv,"");
Expand Down
6 changes: 3 additions & 3 deletions src/oneD/OneDim.cpp
Expand Up @@ -18,13 +18,13 @@ namespace Cantera

OneDim::OneDim()
{
m_newt.reset(new MultiNewton(1));
m_newt = make_unique<MultiNewton>(1);
}

OneDim::OneDim(vector<Domain1D*> domains)
{
// create a Newton iterator, and add each domain.
m_newt.reset(new MultiNewton(1));
m_newt = make_unique<MultiNewton>(1);
for (size_t i = 0; i < domains.size(); i++) {
addDomain(domains[i]);
}
Expand Down Expand Up @@ -197,7 +197,7 @@ void OneDim::resize()
m_mask.resize(size());

// delete the current Jacobian evaluator and create a new one
m_jac.reset(new MultiJac(*this));
m_jac = make_unique<MultiJac>(*this);
m_jac_ok = false;

for (size_t i = 0; i < nDomains(); i++) {
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/DebyeHuckel.cpp
Expand Up @@ -396,7 +396,7 @@ void DebyeHuckel::initThermo()
// Initialize the water property calculator. It will share the internal
// eos water calculator.
if (m_form_A_Debye == A_DEBYE_WATER) {
m_waterProps.reset(new WaterProps(m_waterSS));
m_waterProps = make_unique<WaterProps>(m_waterSS);
}
} else if (dynamic_cast<PDSS_ConstVol*>(providePDSS(0)) == 0) {
throw CanteraError("DebyeHuckel::initThermo", "Solvent standard state"
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/HMWSoln.cpp
Expand Up @@ -668,7 +668,7 @@ void HMWSoln::initThermo()

// Initialize the water property calculator. It will share the internal eos
// water calculator.
m_waterProps.reset(new WaterProps(dynamic_cast<PDSS_Water*>(m_waterSS)));
m_waterProps = make_unique<WaterProps>(dynamic_cast<PDSS_Water*>(m_waterSS));

// Lastly calculate the charge balance and then add stuff until the charges
// compensate
Expand Down
2 changes: 1 addition & 1 deletion src/thermo/PDSS_HKFT.cpp
Expand Up @@ -271,7 +271,7 @@ void PDSS_HKFT::initThermo()
m_Z_pr_tr = -1.0 / relepsilon;
doublereal drelepsilondT = m_waterProps->relEpsilon(m_temp, m_pres, 1);
m_Y_pr_tr = drelepsilondT / (relepsilon * relepsilon);
m_waterProps.reset(new WaterProps(m_waterSS));
m_waterProps = make_unique<WaterProps>(m_waterSS);
m_presR_bar = OneAtm / 1.0E5;
m_presR_bar = 1.0;
convertDGFormation();
Expand Down
6 changes: 3 additions & 3 deletions src/thermo/Species.cpp
Expand Up @@ -104,13 +104,13 @@ AnyMap Species::parameters(const ThermoPhase* phase, bool withInput) const

unique_ptr<Species> newSpecies(const AnyMap& node)
{
unique_ptr<Species> s(new Species(node["name"].asString(),
node["composition"].asMap<double>()));
auto s = make_unique<Species>(node["name"].asString(),
node["composition"].asMap<double>());

if (node.hasKey("thermo")) {
s->thermo = newSpeciesThermo(node["thermo"].as<AnyMap>());
} else {
s->thermo.reset(new SpeciesThermoInterpType());
s->thermo = make_shared<SpeciesThermoInterpType>();
}

s->size = node.getDouble("sites", 1.0);
Expand Down

0 comments on commit 7a69a67

Please sign in to comment.