diff --git a/samples/cxx/demo.cpp b/samples/cxx/demo.cpp index 2197eae96..44ca9fb3b 100644 --- a/samples/cxx/demo.cpp +++ b/samples/cxx/demo.cpp @@ -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 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; } diff --git a/samples/cxx/flamespeed/flamespeed.cpp b/samples/cxx/flamespeed/flamespeed.cpp index c086a6a5f..e9d106bf3 100644 --- a/samples/cxx/flamespeed/flamespeed.cpp +++ b/samples/cxx/flamespeed/flamespeed.cpp @@ -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<<' '< trmix(newTransportMgr("Mix", &gas)); + std::auto_ptr trmulti(newTransportMgr("Multi", &gas)); flow.setTransport(*trmix); flow.setKinetics(gas); diff --git a/test_problems/cxx_ex/kinetics_example1.cpp b/test_problems/cxx_ex/kinetics_example1.cpp index ee3d8d187..3229a4e3f 100644 --- a/test_problems/cxx_ex/kinetics_example1.cpp +++ b/test_problems/cxx_ex/kinetics_example1.cpp @@ -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; diff --git a/test_problems/cxx_ex/kinetics_example3.cpp b/test_problems/cxx_ex/kinetics_example3.cpp index b5510d91e..57210720c 100644 --- a/test_problems/cxx_ex/kinetics_example3.cpp +++ b/test_problems/cxx_ex/kinetics_example3.cpp @@ -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;