Removed unnecessary manual memory management from equilibrate driver
This commit is contained in:
parent
047f3611e1
commit
bb358e812f
1 changed files with 14 additions and 22 deletions
|
|
@ -12,7 +12,6 @@
|
||||||
namespace Cantera
|
namespace Cantera
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set a multiphase mixture to a state of chemical equilibrium.
|
* Set a multiphase mixture to a state of chemical equilibrium.
|
||||||
* This is the top-level driver for multiphase equilibrium. It
|
* This is the top-level driver for multiphase equilibrium. It
|
||||||
|
|
@ -26,7 +25,6 @@ doublereal equilibrate(MultiPhase& s, const char* XY,
|
||||||
doublereal tol, int maxsteps, int maxiter,
|
doublereal tol, int maxsteps, int maxiter,
|
||||||
int loglevel)
|
int loglevel)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
beginLogGroup("equilibrate",loglevel);
|
beginLogGroup("equilibrate",loglevel);
|
||||||
addLogEntry("multiphase equilibrate function");
|
addLogEntry("multiphase equilibrate function");
|
||||||
|
|
@ -130,25 +128,23 @@ int equilibrate(thermo_t& s, const char* XY, int solver,
|
||||||
#ifdef WITH_VCSNONIDEAL
|
#ifdef WITH_VCSNONIDEAL
|
||||||
int printLvlSub = 0;
|
int printLvlSub = 0;
|
||||||
int estimateEquil = 0;
|
int estimateEquil = 0;
|
||||||
m = new MultiPhase;
|
|
||||||
try {
|
try {
|
||||||
m->addPhase(&s, 1.0);
|
MultiPhase m;
|
||||||
m->init();
|
m.addPhase(&s, 1.0);
|
||||||
|
m.init();
|
||||||
nAttempts++;
|
nAttempts++;
|
||||||
vcs_equilibrate(*m, XY, estimateEquil, printLvlSub, solver,
|
vcs_equilibrate(m, XY, estimateEquil, printLvlSub, solver,
|
||||||
rtol, maxsteps, maxiter, loglevel-1);
|
rtol, maxsteps, maxiter, loglevel-1);
|
||||||
redo = false;
|
redo = false;
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("VCSnonideal solver succeeded.");
|
addLogEntry("VCSnonideal solver succeeded.");
|
||||||
}
|
}
|
||||||
delete m;
|
|
||||||
retn = nAttempts;
|
retn = nAttempts;
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
err.save();
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("VCSnonideal solver failed.");
|
addLogEntry("VCSnonideal solver failed.");
|
||||||
}
|
}
|
||||||
delete m;
|
|
||||||
if (nAttempts < 2) {
|
if (nAttempts < 2) {
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("Trying single phase ChemEquil solver.");
|
addLogEntry("Trying single phase ChemEquil solver.");
|
||||||
|
|
@ -166,24 +162,22 @@ int equilibrate(thermo_t& s, const char* XY, int solver,
|
||||||
"VCSNonIdeal solver called, but not compiled");
|
"VCSNonIdeal solver called, but not compiled");
|
||||||
#endif
|
#endif
|
||||||
} else if (solver == 1) {
|
} else if (solver == 1) {
|
||||||
m = new MultiPhase;
|
|
||||||
try {
|
try {
|
||||||
m->addPhase(&s, 1.0);
|
MultiPhase m;
|
||||||
m->init();
|
m.addPhase(&s, 1.0);
|
||||||
|
m.init();
|
||||||
nAttempts++;
|
nAttempts++;
|
||||||
(void) equilibrate(*m, XY, rtol, maxsteps, maxiter, loglevel-1);
|
equilibrate(m, XY, rtol, maxsteps, maxiter, loglevel-1);
|
||||||
redo = false;
|
redo = false;
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("MultiPhaseEquil solver succeeded.");
|
addLogEntry("MultiPhaseEquil solver succeeded.");
|
||||||
}
|
}
|
||||||
delete m;
|
|
||||||
retn = nAttempts;
|
retn = nAttempts;
|
||||||
} catch (CanteraError& err) {
|
} catch (CanteraError& err) {
|
||||||
err.save();
|
err.save();
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("MultiPhaseEquil solver failed.");
|
addLogEntry("MultiPhaseEquil solver failed.");
|
||||||
}
|
}
|
||||||
delete m;
|
|
||||||
if (nAttempts < 2) {
|
if (nAttempts < 2) {
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("Trying single phase ChemEquil solver.");
|
addLogEntry("Trying single phase ChemEquil solver.");
|
||||||
|
|
@ -200,14 +194,14 @@ int equilibrate(thermo_t& s, const char* XY, int solver,
|
||||||
/*
|
/*
|
||||||
* Call the element potential solver
|
* Call the element potential solver
|
||||||
*/
|
*/
|
||||||
e = new ChemEquil;
|
|
||||||
try {
|
try {
|
||||||
e->options.maxIterations = maxsteps;
|
ChemEquil e;
|
||||||
e->options.relTolerance = rtol;
|
e.options.maxIterations = maxsteps;
|
||||||
|
e.options.relTolerance = rtol;
|
||||||
nAttempts++;
|
nAttempts++;
|
||||||
bool useThermoPhaseElementPotentials = true;
|
bool useThermoPhaseElementPotentials = true;
|
||||||
retnSub = e->equilibrate(s,XY,
|
retnSub = e.equilibrate(s, XY, useThermoPhaseElementPotentials,
|
||||||
useThermoPhaseElementPotentials, loglevel-1);
|
loglevel-1);
|
||||||
if (retnSub < 0) {
|
if (retnSub < 0) {
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("ChemEquil solver failed.");
|
addLogEntry("ChemEquil solver failed.");
|
||||||
|
|
@ -223,9 +217,8 @@ int equilibrate(thermo_t& s, const char* XY, int solver,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
retn = nAttempts;
|
retn = nAttempts;
|
||||||
s.setElementPotentials(e->elementPotentials());
|
s.setElementPotentials(e.elementPotentials());
|
||||||
redo = false;
|
redo = false;
|
||||||
delete e;
|
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("ChemEquil solver succeeded.");
|
addLogEntry("ChemEquil solver succeeded.");
|
||||||
}
|
}
|
||||||
|
|
@ -233,7 +226,6 @@ int equilibrate(thermo_t& s, const char* XY, int solver,
|
||||||
|
|
||||||
catch (CanteraError& err) {
|
catch (CanteraError& err) {
|
||||||
err.save();
|
err.save();
|
||||||
delete e;
|
|
||||||
if (loglevel > 0) {
|
if (loglevel > 0) {
|
||||||
addLogEntry("ChemEquil solver failed.");
|
addLogEntry("ChemEquil solver failed.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue