Remove unnecessary manual memory management from examples

This commit is contained in:
Ray Speth 2014-12-12 01:36:41 +00:00
parent 0ad587f50b
commit edac95d06d
4 changed files with 24 additions and 37 deletions

View file

@ -65,16 +65,16 @@ void demoprog()
// Reaction information
int irxns = gas.nReactions();
double* qf = new double[irxns];
double* qr = new double[irxns];
double* q = new double[irxns];
vector_fp qf(irxns);
vector_fp qr(irxns);
vector_fp q(irxns);
// since the gas has been set to an equilibrium state, the forward
// and reverse rates of progress should be equal for all
// reversible reactions, and the net rates should be zero.
gas.getFwdRatesOfProgress(qf);
gas.getRevRatesOfProgress(qr);
gas.getNetRatesOfProgress(q);
gas.getFwdRatesOfProgress(&qf[0]);
gas.getRevRatesOfProgress(&qr[0]);
gas.getNetRatesOfProgress(&q[0]);
printf("\n\n");
for (int i = 0; i < irxns; i++) {
@ -87,7 +87,7 @@ void demoprog()
// create a transport manager for the gas that computes
// mixture-averaged properties
Transport* tr = newTransportMgr("Mix", &gas, 1);
std::auto_ptr<Transport> tr(newTransportMgr("Mix", &gas, 1));
// print the viscosity, thermal conductivity, and diffusion
// coefficients
@ -95,20 +95,13 @@ void demoprog()
printf("Thermal conductivity: %14.5g W/m/K\n", tr->thermalConductivity());
int nsp = gas.nSpecies();
double* diff = new double[nsp];
tr->getMixDiffCoeffs(diff);
vector_fp diff(nsp);
tr->getMixDiffCoeffs(&diff[0]);
int k;
printf("\n\n%20s %26s\n", "Species","Diffusion Coefficient");
for (k = 0; k < nsp; k++) {
printf("%20s %14.5g m2/s \n", gas.speciesName(k).c_str(), diff[k]);
}
// clean up
delete qf;
delete qr;
delete q;
delete diff;
delete tr;
}

View file

@ -59,16 +59,16 @@ int flamespeed(int np, void* p)
gas.setState_TPX(temp,pressure,DATA_PTR(x));
doublereal rho_in=gas.density();
double* yin=new double[nsp];
gas.getMassFractions(yin);
vector_fp yin(nsp);
gas.getMassFractions(&yin[0]);
try {
gas.equilibrate("HP");
} catch (CanteraError& err) {
std::cout << err.what() << std::endl;
}
double* yout=new double[nsp];
gas.getMassFractions(yout);
vector_fp yout(nsp);
gas.getMassFractions(&yout[0]);
doublereal rho_out = gas.density();
doublereal Tad=gas.temperature();
cout << phi<<' '<<Tad<<endl;
@ -89,7 +89,7 @@ int flamespeed(int np, void* p)
// create an initial grid
int nz=5;
doublereal lz=0.02;
doublereal* z=new double[nz+1];
vector_fp z(nz+1);
doublereal dz=lz/((doublereal)(nz-1));
for (int iz=0; iz<nz; iz++) {
z[iz]=((doublereal)iz)*dz;
@ -98,13 +98,13 @@ int flamespeed(int np, void* p)
z[nz]=lz*1.05;
nz++;
flow.setupGrid(nz, z);
flow.setupGrid(nz, &z[0]);
// specify the objects to use to compute kinetic rates and
// transport properties
Transport* trmix = newTransportMgr("Mix", &gas);
Transport* trmulti = newTransportMgr("Multi", &gas);
std::auto_ptr<Transport> trmix(newTransportMgr("Mix", &gas));
std::auto_ptr<Transport> trmulti(newTransportMgr("Multi", &gas));
flow.setTransport(*trmix);
flow.setKinetics(gas);

View file

@ -43,8 +43,7 @@ int kinetics_example1(int job)
// create an ideal gas mixture that corresponds to GRI-Mech
// 3.0
IdealGasMix* gg = new IdealGasMix("gri30.xml", "gri30");
IdealGasMix& gas = *gg;
IdealGasMix gas("gri30.xml", "gri30");
// set the state
gas.setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
@ -74,9 +73,9 @@ int kinetics_example1(int job)
// create a container object to run the simulation
// and add the reactor to it
ReactorNet* sim_ptr = new ReactorNet();
sim_ptr->setVerbose(false);
sim_ptr->addReactor(r);
ReactorNet sim;
sim.setVerbose(false);
sim.addReactor(r);
double tm;
double dt = 1.e-5; // interval at which output is written
@ -90,7 +89,7 @@ int kinetics_example1(int job)
// main loop
for (int i = 1; i <= nsteps; i++) {
tm = i*dt;
sim_ptr->advance(tm);
sim.advance(tm);
saveSoln(tm, gas, soln);
}
@ -104,8 +103,6 @@ int kinetics_example1(int job)
cout << "Output files:" << endl
<< " kin1.csv (Excel CSV file)" << endl
<< " kin1.dat (Tecplot data file)" << endl;
delete gg;
} catch (CanteraError& err) {
// handle exceptions thrown by Cantera
std::cout << err.what() << std::endl;

View file

@ -44,8 +44,7 @@ int kinetics_example3(int job)
// create an ideal gas mixture that corresponds to GRI-Mech
// 3.0
IdealGasMix* gg = new IdealGasMix("gri30.xml", "gri30");
IdealGasMix& gas = *gg;
IdealGasMix gas("gri30.xml", "gri30");
// set the state
gas.setState_TPX(1001.0, OneAtm, "H2:2.0, O2:1.0, N2:4.0");
@ -71,7 +70,7 @@ int kinetics_example3(int job)
// create a container object to run the simulation
// and add the reactor to it
ReactorNet& sim = *(new ReactorNet());
ReactorNet sim;
sim.setVerbose(false);
sim.addReactor(r);
@ -102,8 +101,6 @@ int kinetics_example3(int job)
cout << "Output files:" << endl
<< " kin3.csv (Excel CSV file)" << endl
<< " kin3.dat (Tecplot data file)" << endl;
delete gg;
} catch (CanteraError& err) {
// handle exceptions thrown by Cantera
std::cout << err.what() << std::endl;