Use std::unique_ptr instead of raw pointers where appropriate

This commit is contained in:
Ray Speth 2015-10-07 15:03:43 -04:00
parent 0690626ab8
commit fb4eece9f8
30 changed files with 90 additions and 230 deletions

View file

@ -7,7 +7,7 @@ using namespace Cantera;
void simple_demo()
{
// Create a new phase
ThermoPhase* gas = newPhase("h2o2.cti","ohmech");
std::unique_ptr<ThermoPhase> gas(newPhase("h2o2.cti","ohmech"));
// Set its state by specifying T (500 K) P (2 atm) and the mole
// fractions. Note that the mole fractions do not need to sum to
@ -17,9 +17,6 @@ void simple_demo()
// Print a summary report of the state of the gas
std::cout << gas->report() << std::endl;
// Clean up
delete gas;
}
// the main program just calls function simple_demo within

View file

@ -11,10 +11,10 @@
#include "cantera/numerics/Integrator.h"
#include "cantera/kinetics/InterfaceKinetics.h"
#include "cantera/kinetics/solveSP.h"
namespace Cantera
{
class solveSP;
//! Advances the surface coverages of the associated set of SurfacePhase
//! objects in time
@ -63,10 +63,7 @@ public:
*/
ImplicitSurfChem(std::vector<InterfaceKinetics*> k);
/**
* Destructor. Deletes the integrator.
*/
virtual ~ImplicitSurfChem();
virtual ~ImplicitSurfChem() {};
/*!
* Must be called before calling method 'advance'
@ -245,7 +242,7 @@ protected:
std::vector<vector_int> pLocVec;
//! Pointer to the CVODE integrator
Integrator* m_integ;
std::unique_ptr<Integrator> m_integ;
doublereal m_atol, m_rtol; // tolerances
doublereal m_maxstep; //!< max step size
vector_fp m_work;
@ -279,7 +276,7 @@ protected:
* Pointer to the helper method, Placid, which solves the
* surface problem.
*/
solveSP* m_surfSolver;
std::unique_ptr<solveSP> m_surfSolver;
//! If true, a common temperature and pressure for all
//! surface and bulk phases associated with the surface problem

View file

@ -108,7 +108,7 @@ private:
double m_hmax, m_hmin;
int m_maxsteps;
int m_maxErrTestFails;
FuncData* m_fdata;
std::unique_ptr<FuncData> m_fdata;
N_Vector* m_yS;
size_t m_np;
int m_mupper, m_mlower;

View file

@ -296,7 +296,7 @@ protected:
//! If true, the algebraic variables don't contribute to error tolerances
int m_setSuppressAlg;
ResidData* m_fdata;
std::unique_ptr<ResidData> m_fdata;
int m_mupper;
int m_mlower;
};

View file

@ -56,13 +56,11 @@ public:
m_left(0),
m_right(0),
m_id(""), m_desc(""),
m_refiner(0), m_bw(-1) {
m_bw(-1) {
resize(nv, points);
}
virtual ~Domain1D() {
delete m_refiner;
}
virtual ~Domain1D() {}
//! Domain type flag.
int domainType() {
@ -137,8 +135,7 @@ public:
// new grid refiner is required.
if (nv != m_nv || !m_refiner) {
m_nv = nv;
delete m_refiner;
m_refiner = new Refiner(*this);
m_refiner.reset(new Refiner(*this));
}
m_nv = nv;
m_td.resize(m_nv, 1);
@ -596,7 +593,7 @@ protected:
//! Identity tag for the domain
std::string m_id;
std::string m_desc;
Refiner* m_refiner;
std::unique_ptr<Refiner> m_refiner;
vector_int m_td;
std::vector<std::string> m_name;
int m_bw;

View file

@ -6,12 +6,13 @@
#define CT_ONEDIM_H
#include "Domain1D.h"
#include "MultiJac.h"
namespace Cantera
{
class MultiNewton;
class Func1;
class MultiNewton;
/**
* Container class for multiple-domain 1D problems. Each domain is
@ -258,8 +259,8 @@ protected:
doublereal m_tfactor; // factor time step is multiplied by
// if time stepping fails ( < 1 )
MultiJac* m_jac; // Jacobian evaluator
MultiNewton* m_newt; // Newton iterator
std::unique_ptr<MultiJac> m_jac; // Jacobian evaluator
std::unique_ptr<MultiNewton> m_newt; // Newton iterator
doublereal m_rdt; // reciprocal of time step
bool m_jac_ok; // if true, Jacobian is current

View file

@ -1339,7 +1339,7 @@ protected:
double m_densWaterSS;
//! Pointer to the water property calculator
WaterProps* m_waterProps;
std::unique_ptr<WaterProps> m_waterProps;
//! Temporary array used in equilibrium calculations
mutable vector_fp m_pp;

View file

@ -2193,7 +2193,7 @@ private:
double m_densWaterSS;
//! Pointer to the water property calculator
WaterProps* m_waterProps;
std::unique_ptr<WaterProps> m_waterProps;
//! Temporary array used in equilibrium calculations
mutable vector_fp m_pp;

View file

@ -166,12 +166,8 @@ protected:
//! Lower boundaries of each temperature regions
vector_fp m_lowerTempBounds;
//! pointers to the objects
/*!
* This object will now own these pointers and delete
* them when the current object is deleted.
*/
std::vector<Nasa9Poly1*>m_regionPts;
//! Individual temperature region objects
std::vector<std::unique_ptr<Nasa9Poly1>> m_regionPts;
//! current region
mutable int m_currRegion;

View file

@ -347,7 +347,7 @@ private:
mutable doublereal m_densWaterSS;
//! Pointer to the water property calculator
WaterProps* m_waterProps;
std::unique_ptr<WaterProps> m_waterProps;
//! Born coefficient for the current ion or species
doublereal m_born_coeff_j;

View file

@ -46,9 +46,6 @@ public:
*/
PureFluidPhase& operator=(const PureFluidPhase& right);
//! Destructor
virtual ~PureFluidPhase();
//! Duplication function
/*!
* This virtual function is used to create a duplicate of the
@ -473,7 +470,7 @@ protected:
private:
//! Pointer to the underlying tpx object Substance that does the work
mutable tpx::Substance* m_sub;
mutable std::unique_ptr<tpx::Substance> m_sub;
//! Int indicating the type of the fluid
/*!

View file

@ -13,6 +13,7 @@
#include "SingleSpeciesTP.h"
#include "cantera/thermo/WaterPropsIAPWS.h"
#include "cantera/thermo/WaterProps.h"
namespace Cantera
{
@ -148,9 +149,6 @@ public:
*/
explicit WaterSSTP(XML_Node& phaseRef, const std::string& id = "");
//! Destructor
virtual ~WaterSSTP();
//! Duplicator from a ThermoPhase object
ThermoPhase* duplMyselfAsThermoPhase() const;
@ -423,7 +421,7 @@ public:
//! Get a pointer to a changeable WaterPropsIAPWS object
WaterProps* getWaterProps() {
return m_waterProps;
return m_waterProps.get();
}
protected:
@ -446,7 +444,7 @@ private:
* This object owns m_waterProps, and the WaterPropsIAPWS object used by
* WaterProps is m_sub, which is defined above.
*/
WaterProps* m_waterProps;
std::unique_ptr<WaterProps> m_waterProps;
//! Molecular weight of Water -> Cantera assumption
doublereal m_mw;

View file

@ -81,7 +81,6 @@ public:
*/
DustyGasTransport& operator=(const DustyGasTransport& right);
virtual ~DustyGasTransport();
virtual Transport* duplMyselfAsTransport() const;
//---------------------------------------------------------
@ -337,10 +336,7 @@ private:
doublereal m_perm;
//! Pointer to the transport object for the gas phase
/*!
* Note, this object owns the gastran object
*/
Transport* m_gastran;
std::unique_ptr<Transport> m_gastran;
};
}
#endif

View file

@ -66,22 +66,20 @@ static int get_modified_time(const std::string& path) {
#endif
}
Application::Messages::Messages() :
logwriter(0)
Application::Messages::Messages()
{
// install a default logwriter that writes to standard
// output / standard error
logwriter = new Logger();
logwriter.reset(new Logger());
}
Application::Messages::Messages(const Messages& r) :
errorMessage(r.errorMessage),
errorRoutine(r.errorRoutine),
logwriter(0)
errorRoutine(r.errorRoutine)
{
// install a default logwriter that writes to standard
// output / standard error
logwriter = new Logger(*(r.logwriter));
logwriter.reset(new Logger(*r.logwriter));
}
Application::Messages& Application::Messages::operator=(const Messages& r)
@ -91,15 +89,10 @@ Application::Messages& Application::Messages::operator=(const Messages& r)
}
errorMessage = r.errorMessage;
errorRoutine = r.errorRoutine;
logwriter = new Logger(*(r.logwriter));
logwriter.reset(new Logger(*r.logwriter));
return *this;
}
Application::Messages::~Messages()
{
delete logwriter;
}
void Application::Messages::addError(const std::string& r, const std::string& msg)
{
errorMessage.push_back(msg);
@ -113,14 +106,7 @@ int Application::Messages::getErrorCount()
void Application::Messages::setLogger(Logger* _logwriter)
{
if (logwriter == _logwriter) {
return;
}
if (logwriter != 0) {
delete logwriter;
logwriter = 0;
}
logwriter = _logwriter;
logwriter.reset(_logwriter);
}
void Application::Messages::writelog(const std::string& msg)

View file

@ -51,7 +51,6 @@ protected:
Messages(const Messages& r);
Messages& operator=(const Messages& r);
~Messages();
//! Set an error condition in the application class without
//! throwing an exception.
@ -152,7 +151,7 @@ protected:
std::vector<std::string> errorRoutine;
//! Current pointer to the logwriter
Logger* logwriter;
std::unique_ptr<Logger> logwriter;
};
#ifdef THREAD_SAFE_CANTERA

View file

@ -21,14 +21,12 @@ ImplicitSurfChem::ImplicitSurfChem(vector<InterfaceKinetics*> k) :
m_numBulkPhases(0),
m_numTotalBulkSpecies(0),
m_numTotalSpecies(0),
m_integ(0),
m_atol(1.e-14),
m_rtol(1.e-7),
m_maxstep(0.0),
m_mediumSpeciesStart(-1),
m_bulkSpeciesStart(-1),
m_surfSpeciesStart(-1),
m_surfSolver(0),
m_commonTempPressForPhases(true),
m_ioFlag(0)
{
@ -79,7 +77,7 @@ ImplicitSurfChem::ImplicitSurfChem(vector<InterfaceKinetics*> k) :
m_concSpecies.resize(m_numTotalSpecies, 0.0);
m_concSpeciesSave.resize(m_numTotalSpecies, 0.0);
m_integ = newIntegrator("CVODE");
m_integ.reset(newIntegrator("CVODE"));
// use backward differencing, with a full Jacobian computed
// numerically, and use a Newton linear iterator
@ -101,12 +99,6 @@ int ImplicitSurfChem::checkMatch(std::vector<ThermoPhase*> m_vec, ThermoPhase* t
return retn;
}
ImplicitSurfChem::~ImplicitSurfChem()
{
delete m_integ;
delete m_surfSolver;
}
void ImplicitSurfChem::getInitialConditions(doublereal t0, size_t lenc,
doublereal* c)
{
@ -181,7 +173,7 @@ void ImplicitSurfChem::solvePseudoSteadyStateProblem(int ifuncOverride,
*/
doublereal time_scale = timeScaleOverride;
if (!m_surfSolver) {
m_surfSolver = new solveSP(this, bulkFunc);
m_surfSolver.reset(new solveSP(this, bulkFunc));
/*
* set ifunc, which sets the algorithm.
*/

View file

@ -114,7 +114,6 @@ CVodesIntegrator::CVodesIntegrator() :
m_hmin(0.0),
m_maxsteps(20000),
m_maxErrTestFails(0),
m_fdata(0),
m_np(0),
m_mupper(0), m_mlower(0),
m_sens_ok(false)
@ -135,7 +134,6 @@ CVodesIntegrator::~CVodesIntegrator()
if (m_abstol) {
N_VDestroy_Serial(m_abstol);
}
delete m_fdata;
}
double& CVodesIntegrator::solution(size_t k)
@ -328,10 +326,9 @@ void CVodesIntegrator::initialize(double t0, FuncEval& func)
}
// pass a pointer to func in m_data
delete m_fdata;
m_fdata = new FuncData(&func, func.nparams());
m_fdata.reset(new FuncData(&func, func.nparams()));
flag = CVodeSetUserData(m_cvode_mem, (void*)m_fdata);
flag = CVodeSetUserData(m_cvode_mem, m_fdata.get());
if (flag != CV_SUCCESS) {
throw CVodesErr("CVodeSetUserData failed.");
}

View file

@ -145,7 +145,6 @@ IDA_Solver::IDA_Solver(ResidJacEval& f) :
m_maxNonlinIters(0),
m_maxNonlinConvFails(-1),
m_setSuppressAlg(0),
m_fdata(0),
m_mupper(0),
m_mlower(0)
{
@ -168,7 +167,6 @@ IDA_Solver::~IDA_Solver()
if (m_constraints) {
N_VDestroy_Serial(m_constraints);
}
delete m_fdata;
}
doublereal IDA_Solver::solution(int k) const
@ -400,8 +398,8 @@ void IDA_Solver::init(doublereal t0)
}
// pass a pointer to func in m_data
m_fdata = new ResidData(&m_resid, this, m_resid.nparams());
flag = IDASetUserData(m_ida_mem, (void*)m_fdata);
m_fdata.reset(new ResidData(&m_resid, this, m_resid.nparams()));
flag = IDASetUserData(m_ida_mem, m_fdata.get());
if (flag != IDA_SUCCESS) {
throw IDA_Err("IDASetUserData failed.");
}

View file

@ -1,8 +1,8 @@
//! @file OneDim.cpp
#include "cantera/oneD/MultiNewton.h"
#include "cantera/oneD/OneDim.h"
#include "cantera/numerics/Func1.h"
#include "cantera/base/ctml.h"
#include "cantera/oneD/MultiNewton.h"
#include <fstream>
#include <ctime>
@ -14,19 +14,17 @@ namespace Cantera
OneDim::OneDim()
: m_tmin(1.0e-16), m_tmax(10.0), m_tfactor(0.5),
m_jac(0), m_newt(0),
m_rdt(0.0), m_jac_ok(false),
m_nd(0), m_bw(0), m_size(0),
m_init(false), m_pts(0), m_solve_time(0.0),
m_ss_jac_age(10), m_ts_jac_age(20),
m_interrupt(0), m_nevals(0), m_evaltime(0.0)
{
m_newt = new MultiNewton(1);
m_newt.reset(new MultiNewton(1));
}
OneDim::OneDim(vector<Domain1D*> domains) :
m_tmin(1.0e-16), m_tmax(10.0), m_tfactor(0.5),
m_jac(0), m_newt(0),
m_rdt(0.0), m_jac_ok(false),
m_nd(0), m_bw(0), m_size(0),
m_init(false), m_solve_time(0.0),
@ -34,7 +32,7 @@ OneDim::OneDim(vector<Domain1D*> domains) :
m_interrupt(0), m_nevals(0), m_evaltime(0.0)
{
// create a Newton iterator, and add each domain.
m_newt = new MultiNewton(1);
m_newt.reset(new MultiNewton(1));
for (size_t i = 0; i < domains.size(); i++) {
addDomain(domains[i]);
}
@ -42,6 +40,10 @@ OneDim::OneDim(vector<Domain1D*> domains) :
resize();
}
OneDim::~OneDim()
{
}
size_t OneDim::domainIndex(const std::string& name)
{
for (size_t n = 0; n < m_nd; n++) {
@ -76,12 +78,6 @@ void OneDim::addDomain(Domain1D* d)
resize();
}
OneDim::~OneDim()
{
delete m_jac;
delete m_newt;
}
MultiJac& OneDim::jacobian()
{
return *m_jac;
@ -183,12 +179,11 @@ void OneDim::resize()
m_mask.resize(size());
// delete the current Jacobian evaluator and create a new one
delete m_jac;
m_jac = new MultiJac(*this);
m_jac.reset(new MultiJac(*this));
m_jac_ok = false;
for (size_t i = 0; i < m_nd; i++) {
m_dom[i]->setJac(m_jac);
m_dom[i]->setJac(m_jac.get());
}
}

View file

@ -38,8 +38,7 @@ DebyeHuckel::DebyeHuckel() :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_B_Debye(3.28640E9), // units = sqrt(kg/gmol) / m
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0)
m_densWaterSS(1000.)
{
}
@ -55,8 +54,7 @@ DebyeHuckel::DebyeHuckel(const std::string& inputFile,
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_B_Debye(3.28640E9), // units = sqrt(kg/gmol) / m
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0)
m_densWaterSS(1000.)
{
initThermoFile(inputFile, id_);
}
@ -72,8 +70,7 @@ DebyeHuckel::DebyeHuckel(XML_Node& phaseRoot, const std::string& id_) :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_B_Debye(3.28640E9), // units = sqrt(kg/gmol) / m
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0)
m_densWaterSS(1000.)
{
importPhase(phaseRoot, this);
}
@ -89,8 +86,7 @@ DebyeHuckel::DebyeHuckel(const DebyeHuckel& b) :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_B_Debye(3.28640E9), // units = sqrt(kg/gmol) / m
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0)
m_densWaterSS(1000.)
{
/*
* Use the assignment operator to do the brunt
@ -125,10 +121,8 @@ DebyeHuckel& DebyeHuckel::operator=(const DebyeHuckel& b)
m_densWaterSS = b.m_densWaterSS;
delete m_waterProps;
m_waterProps = 0;
if (b.m_waterProps) {
m_waterProps = new WaterProps(m_waterSS);
m_waterProps.reset(new WaterProps(m_waterSS));
}
m_pp = b.m_pp;
@ -143,8 +137,6 @@ DebyeHuckel& DebyeHuckel::operator=(const DebyeHuckel& b)
DebyeHuckel::~DebyeHuckel()
{
delete m_waterProps;
m_waterProps = 0;
}
ThermoPhase* DebyeHuckel::duplMyselfAsThermoPhase() const
@ -748,8 +740,7 @@ void DebyeHuckel::initThermoXML(XML_Node& phaseNode, const std::string& id_)
* the internal eos water calculator.
*/
if (m_form_A_Debye == A_DEBYE_WATER) {
delete m_waterProps;
m_waterProps = new WaterProps(m_waterSS);
m_waterProps.reset(new WaterProps(m_waterSS));
}
/*

View file

@ -39,7 +39,6 @@ HMWSoln::HMWSoln() :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0),
m_molalitiesAreCropped(false),
IMS_typeCutoff_(0),
IMS_X_o_cutoff_(0.2),
@ -85,7 +84,6 @@ HMWSoln::HMWSoln(const std::string& inputFile, const std::string& id_) :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0),
m_molalitiesAreCropped(false),
IMS_typeCutoff_(0),
IMS_X_o_cutoff_(0.2),
@ -132,7 +130,6 @@ HMWSoln::HMWSoln(XML_Node& phaseRoot, const std::string& id_) :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0),
m_molalitiesAreCropped(false),
IMS_typeCutoff_(0),
IMS_X_o_cutoff_(0.2),
@ -179,7 +176,6 @@ HMWSoln::HMWSoln(const HMWSoln& b) :
m_A_Debye(1.172576), // units = sqrt(kg/gmol)
m_waterSS(0),
m_densWaterSS(1000.),
m_waterProps(0),
m_molalitiesAreCropped(false),
IMS_typeCutoff_(0),
IMS_X_o_cutoff_(0.2),
@ -241,10 +237,9 @@ HMWSoln& HMWSoln::operator=(const HMWSoln& b)
m_densWaterSS = b.m_densWaterSS;
delete m_waterProps;
m_waterProps = 0;
if (b.m_waterProps) {
m_waterProps = new WaterProps(dynamic_cast<PDSS_Water*>(m_waterSS));
m_waterProps.reset(new WaterProps(dynamic_cast<PDSS_Water*>(m_waterSS)));
}
m_pp = b.m_pp;
@ -373,8 +368,6 @@ HMWSoln& HMWSoln::operator=(const HMWSoln& b)
HMWSoln::~HMWSoln()
{
delete m_waterProps;
m_waterProps = 0;
}
ThermoPhase* HMWSoln::duplMyselfAsThermoPhase() const

View file

@ -1321,7 +1321,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
* Initialize the water property calculator. It will share
* the internal eos water calculator.
*/
m_waterProps = new WaterProps(dynamic_cast<PDSS_Water*>(m_waterSS));
m_waterProps.reset(new WaterProps(dynamic_cast<PDSS_Water*>(m_waterSS)));
/*
* Fill in parameters for the calculation of the

View file

@ -30,9 +30,10 @@ Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(vector<Nasa9Poly1*>& regionPt
m_currRegion(0)
{
m_numTempRegions = regionPts.size();
// Do a shallow copy of the pointers. From now on, we will
// own these pointers and be responsible for deleting them.
m_regionPts = regionPts;
// From now on, we own these pointers
for (Nasa9Poly1* region : regionPts) {
m_regionPts.emplace_back(region);
}
m_lowerTempBounds.resize(m_numTempRegions);
m_lowT = m_regionPts[0]->minTemp();
m_highT = m_regionPts[m_numTempRegions-1]->maxTemp();
@ -64,8 +65,7 @@ Nasa9PolyMultiTempRegion::Nasa9PolyMultiTempRegion(const Nasa9PolyMultiTempRegio
{
m_regionPts.resize(m_numTempRegions);
for (size_t i = 0; i < m_numTempRegions; i++) {
Nasa9Poly1* dptr = b.m_regionPts[i];
m_regionPts[i] = new Nasa9Poly1(*dptr);
m_regionPts[i].reset(new Nasa9Poly1(*b.m_regionPts[i]));
}
}
@ -74,16 +74,12 @@ Nasa9PolyMultiTempRegion::operator=(const Nasa9PolyMultiTempRegion& b)
{
if (&b != this) {
SpeciesThermoInterpType::operator=(b);
for (size_t i = 0; i < m_numTempRegions; i++) {
delete m_regionPts[i];
m_regionPts[i] = 0;
}
m_numTempRegions = b.m_numTempRegions;
m_lowerTempBounds = b.m_lowerTempBounds;
m_currRegion = b.m_currRegion;
m_regionPts.resize(m_numTempRegions);
for (size_t i = 0; i < m_numTempRegions; i++) {
m_regionPts[i] = new Nasa9Poly1(*(b.m_regionPts[i]));
m_regionPts[i].reset(new Nasa9Poly1(*b.m_regionPts[i]));
}
}
return *this;
@ -91,10 +87,6 @@ Nasa9PolyMultiTempRegion::operator=(const Nasa9PolyMultiTempRegion& b)
Nasa9PolyMultiTempRegion::~Nasa9PolyMultiTempRegion()
{
for (size_t i = 0; i < m_numTempRegions; i++) {
delete m_regionPts[i];
m_regionPts[i] = 0;
}
}
SpeciesThermoInterpType*

View file

@ -32,7 +32,6 @@ PDSS_HKFT::PDSS_HKFT(VPStandardStateTP* tp, size_t spindex) :
PDSS(tp, spindex),
m_waterSS(0),
m_densWaterSS(-1.0),
m_waterProps(0),
m_born_coeff_j(-1.0),
m_r_e_j(-1.0),
m_deltaG_formation_tr_pr(0.0),
@ -63,7 +62,6 @@ PDSS_HKFT::PDSS_HKFT(VPStandardStateTP* tp, size_t spindex,
PDSS(tp, spindex),
m_waterSS(0),
m_densWaterSS(-1.0),
m_waterProps(0),
m_born_coeff_j(-1.0),
m_r_e_j(-1.0),
m_deltaG_formation_tr_pr(0.0),
@ -97,7 +95,6 @@ PDSS_HKFT::PDSS_HKFT(VPStandardStateTP* tp, size_t spindex, const XML_Node& spec
PDSS(tp, spindex),
m_waterSS(0),
m_densWaterSS(-1.0),
m_waterProps(0),
m_born_coeff_j(-1.0),
m_r_e_j(-1.0),
m_deltaG_formation_tr_pr(0.0),
@ -129,7 +126,6 @@ PDSS_HKFT::PDSS_HKFT(const PDSS_HKFT& b) :
PDSS(b),
m_waterSS(0),
m_densWaterSS(-1.0),
m_waterProps(0),
m_born_coeff_j(-1.0),
m_r_e_j(-1.0),
m_deltaG_formation_tr_pr(0.0),
@ -172,8 +168,6 @@ PDSS_HKFT& PDSS_HKFT::operator=(const PDSS_HKFT& b)
m_waterSS = 0;
m_densWaterSS = b.m_densWaterSS;
//! Need to call initAllPtrs AFTER, to get the correct m_waterProps
delete m_waterProps;
m_waterProps = 0;
m_born_coeff_j = b.m_born_coeff_j;
m_r_e_j = b.m_r_e_j;
m_deltaG_formation_tr_pr = b.m_deltaG_formation_tr_pr;
@ -195,14 +189,13 @@ PDSS_HKFT& PDSS_HKFT::operator=(const PDSS_HKFT& b)
// Here we just fill these in so that local copies within the VPSS object work.
m_waterSS = b.m_waterSS;
m_waterProps = new WaterProps(m_waterSS);
m_waterProps.reset(new WaterProps(m_waterSS));
return *this;
}
PDSS_HKFT::~PDSS_HKFT()
{
delete m_waterProps;
}
PDSS* PDSS_HKFT::duplMyselfAsPDSS() const
@ -414,7 +407,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 = new WaterProps(m_waterSS);
m_waterProps.reset(new WaterProps(m_waterSS));
m_presR_bar = OneAtm / 1.0E5;
m_presR_bar = 1.0;
m_charge_j = m_tp->charge(m_spindex);
@ -466,8 +459,7 @@ void PDSS_HKFT::initAllPtrs(VPStandardStateTP* vptp_ptr, VPSSMgr* vpssmgr_ptr,
{
PDSS::initAllPtrs(vptp_ptr, vpssmgr_ptr, spthermo_ptr);
m_waterSS = dynamic_cast<PDSS_Water*>(m_tp->providePDSS(0));
delete m_waterProps;
m_waterProps = new WaterProps(m_waterSS);
m_waterProps.reset(new WaterProps(m_waterSS));
}
void PDSS_HKFT::constructPDSSXML(VPStandardStateTP* tp, size_t spindex,

View file

@ -20,7 +20,6 @@ namespace Cantera
{
PureFluidPhase::PureFluidPhase() :
m_sub(0),
m_subflag(0),
m_mw(-1.0),
m_verbose(false)
@ -28,7 +27,6 @@ PureFluidPhase::PureFluidPhase() :
}
PureFluidPhase::PureFluidPhase(const PureFluidPhase& right) :
m_sub(0),
m_subflag(0),
m_mw(-1.0),
m_verbose(false)
@ -40,9 +38,8 @@ PureFluidPhase& PureFluidPhase::operator=(const PureFluidPhase& right)
{
if (&right != this) {
ThermoPhase::operator=(right);
delete m_sub;
m_subflag = right.m_subflag;
m_sub = tpx::GetSub(m_subflag);
m_sub.reset(tpx::GetSub(m_subflag));
m_mw = right.m_mw;
m_verbose = right.m_verbose;
}
@ -54,16 +51,10 @@ ThermoPhase* PureFluidPhase::duplMyselfAsThermoPhase() const
return new PureFluidPhase(*this);
}
PureFluidPhase::~PureFluidPhase()
{
delete m_sub;
}
void PureFluidPhase::initThermo()
{
delete m_sub;
m_sub = tpx::GetSub(m_subflag);
if (m_sub == 0) {
m_sub.reset(tpx::GetSub(m_subflag));
if (!m_sub) {
throw CanteraError("PureFluidPhase::initThermo",
"could not create new substance object.");
}

View file

@ -10,7 +10,6 @@
*/
#include "cantera/thermo/WaterSSTP.h"
#include "cantera/thermo/WaterProps.h"
#include "cantera/thermo/ThermoFactory.h"
#include "cantera/base/stringUtils.h"
@ -19,7 +18,6 @@ using namespace std;
namespace Cantera
{
WaterSSTP::WaterSSTP() :
m_waterProps(0),
m_mw(0.0),
EW_Offset(0.0),
SW_Offset(0.0),
@ -29,7 +27,6 @@ WaterSSTP::WaterSSTP() :
}
WaterSSTP::WaterSSTP(const std::string& inputFile, const std::string& id) :
m_waterProps(0),
m_mw(0.0),
EW_Offset(0.0),
SW_Offset(0.0),
@ -40,7 +37,6 @@ WaterSSTP::WaterSSTP(const std::string& inputFile, const std::string& id) :
}
WaterSSTP::WaterSSTP(XML_Node& phaseRoot, const std::string& id) :
m_waterProps(0),
m_mw(0.0),
EW_Offset(0.0),
SW_Offset(0.0),
@ -52,14 +48,13 @@ WaterSSTP::WaterSSTP(XML_Node& phaseRoot, const std::string& id) :
WaterSSTP::WaterSSTP(const WaterSSTP& b) :
SingleSpeciesTP(b),
m_waterProps(0),
m_mw(b.m_mw),
EW_Offset(b.EW_Offset),
SW_Offset(b.SW_Offset),
m_ready(false),
m_allowGasPhase(b.m_allowGasPhase)
{
m_waterProps = new WaterProps(&m_sub);
m_waterProps.reset(new WaterProps(&m_sub));
/*
* Use the assignment operator to do the brunt
@ -74,11 +69,7 @@ WaterSSTP& WaterSSTP::operator=(const WaterSSTP& b)
return *this;
}
m_sub = b.m_sub;
if (!m_waterProps) {
m_waterProps = new WaterProps(&m_sub);
}
*m_waterProps = *b.m_waterProps;
m_waterProps.reset(new WaterProps(&m_sub));
m_mw = b.m_mw;
m_ready = b.m_ready;
@ -91,11 +82,6 @@ ThermoPhase* WaterSSTP::duplMyselfAsThermoPhase() const
return new WaterSSTP(*this);
}
WaterSSTP::~WaterSSTP()
{
delete m_waterProps;
}
void WaterSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
{
/*
@ -162,7 +148,7 @@ void WaterSSTP::initThermoXML(XML_Node& phaseNode, const std::string& id)
double rho0 = m_sub.density(298.15, OneAtm, WATER_LIQUID);
setDensity(rho0);
m_waterProps = new WaterProps(&m_sub);
m_waterProps.reset(new WaterProps(&m_sub));
/*
* We have to do something with the thermo function here.

View file

@ -25,8 +25,7 @@ DustyGasTransport::DustyGasTransport(thermo_t* thermo) :
m_tortuosity(1.0),
m_pore_radius(0.0),
m_diam(0.0),
m_perm(-1.0),
m_gastran(0)
m_perm(-1.0)
{
}
@ -39,8 +38,7 @@ DustyGasTransport::DustyGasTransport(const DustyGasTransport& right) :
m_tortuosity(1.0),
m_pore_radius(0.0),
m_diam(0.0),
m_perm(-1.0),
m_gastran(0)
m_perm(-1.0)
{
*this = right;
}
@ -71,17 +69,11 @@ DustyGasTransport& DustyGasTransport::operator=(const DustyGasTransport& right)
// Warning -> gastran may not point to the correct object
// after this copy. The routine initialize() must be called
delete m_gastran;
m_gastran = right.duplMyselfAsTransport();
m_gastran.reset(right.m_gastran->duplMyselfAsTransport());
return *this;
}
DustyGasTransport::~DustyGasTransport()
{
delete m_gastran;
}
Transport* DustyGasTransport::duplMyselfAsTransport() const
{
DustyGasTransport* tr = new DustyGasTransport(*this);
@ -99,9 +91,8 @@ void DustyGasTransport::initialize(ThermoPhase* phase, Transport* gastr)
// constant mixture attributes
m_thermo = phase;
m_nsp = m_thermo->nSpecies();
if (m_gastran != gastr) {
delete m_gastran;
m_gastran = gastr;
if (m_gastran.get() != gastr) {
m_gastran.reset(gastr);
}
// make a local copy of the molecular weights

View file

@ -10,15 +10,11 @@ namespace Cantera
class MaskellSolidSolnPhase_Test : public testing::Test
{
protected:
ThermoPhase *test_phase;
std::unique_ptr<ThermoPhase> test_phase;
public:
MaskellSolidSolnPhase_Test() : test_phase(NULL) {}
~MaskellSolidSolnPhase_Test() { delete test_phase; }
void initializeTestPhaseWithXML(const std::string & filename)
{
test_phase = newPhase(filename);
test_phase.reset(newPhase(filename));
}
void set_r(const double r) {
@ -46,11 +42,10 @@ TEST_F(MaskellSolidSolnPhase_Test, construct_from_xml)
{
const std::string invalid_file("../data/MaskellSolidSolnPhase_nohmix.xml");
EXPECT_THROW(initializeTestPhaseWithXML(invalid_file), CanteraError);
delete test_phase;
const std::string valid_file("../data/MaskellSolidSolnPhase_valid.xml");
initializeTestPhaseWithXML(valid_file);
MaskellSolidSolnPhase * maskell_phase = dynamic_cast<MaskellSolidSolnPhase *>(test_phase);
MaskellSolidSolnPhase* maskell_phase = dynamic_cast<MaskellSolidSolnPhase*>(test_phase.get());
EXPECT_TRUE(maskell_phase != NULL);
}
@ -61,8 +56,7 @@ TEST_F(MaskellSolidSolnPhase_Test, chem_potentials)
test_phase->setState_TP(298., 1.);
set_r(0.5);
MaskellSolidSolnPhase * maskell_phase = dynamic_cast<MaskellSolidSolnPhase *>(test_phase);
ASSERT_TRUE(maskell_phase != NULL);
MaskellSolidSolnPhase* maskell_phase = dynamic_cast<MaskellSolidSolnPhase*>(test_phase.get());
maskell_phase->set_h_mix(0.);
const double expected_result_0[9] = {1.2338461168724738e7, 8.011774549216799e6, 4.990989640314685e6, 2.415973128783114e6, 0., -2.415973128783114e6, -4.99098964031469e6, -8.0117745492168e6, -1.2338461168724738e7};
@ -81,7 +75,6 @@ TEST_F(MaskellSolidSolnPhase_Test, partialMolarVolumes)
{
const std::string valid_file("../data/MaskellSolidSolnPhase_valid.xml");
initializeTestPhaseWithXML(valid_file);
ASSERT_TRUE(dynamic_cast<MaskellSolidSolnPhase *>(test_phase) != NULL);
vector_fp pmv(2);
test_phase->getPartialMolarVolumes(&pmv[0]);
@ -96,9 +89,6 @@ TEST_F(MaskellSolidSolnPhase_Test, activityCoeffs)
test_phase->setState_TP(298., 1.);
set_r(0.5);
MaskellSolidSolnPhase * maskell_phase = dynamic_cast<MaskellSolidSolnPhase *>(test_phase);
ASSERT_TRUE(maskell_phase != NULL);
// Test that mu0 + RT log(activityCoeff * MoleFrac) == mu
const double RT = GasConstant * 298.;
vector_fp mu0(2);
@ -120,7 +110,6 @@ TEST_F(MaskellSolidSolnPhase_Test, standardConcentrations)
{
const std::string valid_file("../data/MaskellSolidSolnPhase_valid.xml");
initializeTestPhaseWithXML(valid_file);
ASSERT_TRUE(dynamic_cast<MaskellSolidSolnPhase *>(test_phase) != NULL);
EXPECT_DOUBLE_EQ(1.0, test_phase->standardConcentration(0));
EXPECT_DOUBLE_EQ(1.0, test_phase->standardConcentration(1));
@ -130,7 +119,6 @@ TEST_F(MaskellSolidSolnPhase_Test, activityConcentrations)
{
const std::string valid_file("../data/MaskellSolidSolnPhase_valid.xml");
initializeTestPhaseWithXML(valid_file);
ASSERT_TRUE(dynamic_cast<MaskellSolidSolnPhase *>(test_phase) != NULL);
// Check to make sure activityConcentration_i == standardConcentration_i * gamma_i * X_i
vector_fp standardConcs(2);

View file

@ -49,13 +49,9 @@ TEST_F(ThermoPhase_Fixture, SetAndGetElementPotentials)
class TestThermoMethods : public testing::Test
{
public:
ThermoPhase* thermo;
std::unique_ptr<ThermoPhase> thermo;
TestThermoMethods() {
thermo = newPhase("h2o2.xml");
}
~TestThermoMethods() {
delete thermo;
thermo.reset(newPhase("h2o2.xml"));
}
};

View file

@ -17,12 +17,11 @@ class FixedChemPotSstpConstructorTest : public testing::Test
TEST_F(FixedChemPotSstpConstructorTest, fromXML)
{
ThermoPhase* p = newPhase("../data/LiFixed.xml");
std::unique_ptr<ThermoPhase> p(newPhase("../data/LiFixed.xml"));
ASSERT_EQ((int) p->nSpecies(), 1);
double mu;
p->getChemPotentials(&mu);
ASSERT_DOUBLE_EQ(-2.3e7, mu);
delete p;
}
TEST_F(FixedChemPotSstpConstructorTest, SimpleConstructor)
@ -38,16 +37,12 @@ TEST_F(FixedChemPotSstpConstructorTest, SimpleConstructor)
class CtiConversionTest : public testing::Test
{
public:
CtiConversionTest() : p1(0), p2(0) {
CtiConversionTest() {
appdelete();
}
~CtiConversionTest() {
delete p1;
delete p2;
}
ThermoPhase* p1;
ThermoPhase* p2;
std::unique_ptr<ThermoPhase> p1;
std::unique_ptr<ThermoPhase> p2;
void compare()
{
ASSERT_EQ(p1->nSpecies(), p2->nSpecies());
@ -59,15 +54,15 @@ public:
};
TEST_F(CtiConversionTest, ExplicitConversion) {
p1 = newPhase("../data/air-no-reactions.xml");
p1.reset(newPhase("../data/air-no-reactions.xml"));
ct2ctml("../data/air-no-reactions.cti");
p2 = newPhase("air-no-reactions.xml", "");
p2.reset(newPhase("air-no-reactions.xml", ""));
compare();
}
TEST_F(CtiConversionTest, ImplicitConversion) {
p1 = newPhase("../data/air-no-reactions.xml");
p2 = newPhase("../data/air-no-reactions.cti");
p1.reset(newPhase("../data/air-no-reactions.xml"));
p2.reset(newPhase("../data/air-no-reactions.cti"));
compare();
}
@ -84,9 +79,8 @@ public:
TEST_F(ChemkinConversionTest, ValidConversion) {
copyInputFile("pdep-test.inp");
ck2cti("pdep-test.inp");
ThermoPhase* p = newPhase("pdep-test.cti");
std::unique_ptr<ThermoPhase> p(newPhase("pdep-test.cti"));
ASSERT_GT(p->temperature(), 0.0);
delete p;
}
TEST_F(ChemkinConversionTest, MissingInputFile) {