Eliminate do-while loops in favor of regular while loops
This commit is contained in:
parent
a6e390dfc5
commit
d086be8d3d
8 changed files with 52 additions and 76 deletions
|
|
@ -29,7 +29,6 @@ size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase,
|
||||||
vector_fp& formRxnMatrix)
|
vector_fp& formRxnMatrix)
|
||||||
{
|
{
|
||||||
size_t j, jj, k=0, kk, l, i, jl, ml;
|
size_t j, jj, k=0, kk, l, i, jl, ml;
|
||||||
bool lindep;
|
|
||||||
std::string ename;
|
std::string ename;
|
||||||
std::string sname;
|
std::string sname;
|
||||||
/*
|
/*
|
||||||
|
|
@ -139,16 +138,15 @@ size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase,
|
||||||
}
|
}
|
||||||
double molSave = 0.0;
|
double molSave = 0.0;
|
||||||
|
|
||||||
size_t jr = npos;
|
size_t jr = 0;
|
||||||
/*
|
/*
|
||||||
* Top of a loop of some sort based on the index JR. JR is the
|
* Top of a loop of some sort based on the index JR. JR is the
|
||||||
* current number of component species found.
|
* current number of component species found.
|
||||||
*/
|
*/
|
||||||
do {
|
while (jr < nComponents) {
|
||||||
++jr;
|
|
||||||
/* - Top of another loop point based on finding a linearly */
|
/* - Top of another loop point based on finding a linearly */
|
||||||
/* - independent species */
|
/* - independent species */
|
||||||
do {
|
while (true) {
|
||||||
/*
|
/*
|
||||||
* Search the remaining part of the mole number vector, molNum
|
* Search the remaining part of the mole number vector, molNum
|
||||||
* for the largest remaining species. Return its identity.
|
* for the largest remaining species. Return its identity.
|
||||||
|
|
@ -233,12 +231,10 @@ size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase,
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
/* **** IF NORM OF NEW ROW .LT. 1E-3 REJECT ********** */
|
/* **** IF NORM OF NEW ROW .LT. 1E-3 REJECT ********** */
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
if (sa[jr] < 1.0e-6) {
|
if (sa[jr] > 1.0e-6) {
|
||||||
lindep = true;
|
break;
|
||||||
} else {
|
|
||||||
lindep = false;
|
|
||||||
}
|
}
|
||||||
} while (lindep);
|
}
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
/* **** REARRANGE THE DATA ****************** */
|
/* **** REARRANGE THE DATA ****************** */
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
@ -255,13 +251,9 @@ size_t BasisOptimize(int* usedZeroedSpecies, bool doFormRxn, MultiPhase* mphase,
|
||||||
std::swap(orderVectorSpecies[jr], orderVectorSpecies[k]);
|
std::swap(orderVectorSpecies[jr], orderVectorSpecies[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// If we haven't found enough components, go back and find some more
|
||||||
* If we haven't found enough components, go back
|
jr++;
|
||||||
* and find some more. (nc -1 is used below, because
|
}
|
||||||
* jr is counted from 0, via the C convention.
|
|
||||||
*/
|
|
||||||
} while (jr < (nComponents-1));
|
|
||||||
|
|
||||||
|
|
||||||
if (! doFormRxn) {
|
if (! doFormRxn) {
|
||||||
return nComponents;
|
return nComponents;
|
||||||
|
|
@ -426,7 +418,6 @@ void ElemRearrange(size_t nComponents, const vector_fp& elementAbundances,
|
||||||
{
|
{
|
||||||
size_t j, k, l, i, jl, ml, jr, ielem, jj, kk=0;
|
size_t j, k, l, i, jl, ml, jr, ielem, jj, kk=0;
|
||||||
|
|
||||||
bool lindep = false;
|
|
||||||
size_t nelements = mphase->nElements();
|
size_t nelements = mphase->nElements();
|
||||||
std::string ename;
|
std::string ename;
|
||||||
/*
|
/*
|
||||||
|
|
@ -495,14 +486,13 @@ void ElemRearrange(size_t nComponents, const vector_fp& elementAbundances,
|
||||||
* Top of a loop of some sort based on the index JR. JR is the
|
* Top of a loop of some sort based on the index JR. JR is the
|
||||||
* current number independent elements found.
|
* current number independent elements found.
|
||||||
*/
|
*/
|
||||||
jr = npos;
|
jr = 0;
|
||||||
do {
|
while (jr < nComponents) {
|
||||||
++jr;
|
|
||||||
/*
|
/*
|
||||||
* Top of another loop point based on finding a linearly
|
* Top of another loop point based on finding a linearly
|
||||||
* independent element
|
* independent element
|
||||||
*/
|
*/
|
||||||
do {
|
while (true) {
|
||||||
/*
|
/*
|
||||||
* Search the element vector. We first locate elements that
|
* Search the element vector. We first locate elements that
|
||||||
* are present in any amount. Then, we locate elements that
|
* are present in any amount. Then, we locate elements that
|
||||||
|
|
@ -597,12 +587,10 @@ void ElemRearrange(size_t nComponents, const vector_fp& elementAbundances,
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
/* **** IF NORM OF NEW ROW .LT. 1E-6 REJECT ********** */
|
/* **** IF NORM OF NEW ROW .LT. 1E-6 REJECT ********** */
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
if (sa[jr] < 1.0e-6) {
|
if (sa[jr] > 1.0e-6) {
|
||||||
lindep = true;
|
break;
|
||||||
} else {
|
|
||||||
lindep = false;
|
|
||||||
}
|
}
|
||||||
} while (lindep);
|
}
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
/* **** REARRANGE THE DATA ****************** */
|
/* **** REARRANGE THE DATA ****************** */
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
@ -621,12 +609,9 @@ void ElemRearrange(size_t nComponents, const vector_fp& elementAbundances,
|
||||||
std::swap(orderVectorElements[jr], orderVectorElements[k]);
|
std::swap(orderVectorElements[jr], orderVectorElements[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// If we haven't found enough components, go back and find some more
|
||||||
* If we haven't found enough components, go back
|
jr++;
|
||||||
* and find some more. (nc -1 is used below, because
|
};
|
||||||
* jr is counted from 0, via the C convention.
|
|
||||||
*/
|
|
||||||
} while (jr < (nComponents-1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,9 +37,9 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
|
||||||
* Use a temporary work array for the element numbers
|
* Use a temporary work array for the element numbers
|
||||||
* Also make sure the value of test is unique.
|
* Also make sure the value of test is unique.
|
||||||
*/
|
*/
|
||||||
bool lindep = false;
|
bool lindep = true;
|
||||||
double test = -1.0E10;
|
double test = -1.0E10;
|
||||||
do {
|
while (lindep) {
|
||||||
lindep = false;
|
lindep = false;
|
||||||
for (size_t i = 0; i < m_numElemConstraints; ++i) {
|
for (size_t i = 0; i < m_numElemConstraints; ++i) {
|
||||||
test -= 1.0;
|
test -= 1.0;
|
||||||
|
|
@ -48,21 +48,20 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
|
||||||
lindep = true;
|
lindep = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (lindep);
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Top of a loop of some sort based on the index JR. JR is the
|
* Top of a loop of some sort based on the index JR. JR is the
|
||||||
* current number independent elements found.
|
* current number independent elements found.
|
||||||
*/
|
*/
|
||||||
size_t jr = npos;
|
size_t jr = 0;
|
||||||
do {
|
while (jr < ncomponents) {
|
||||||
++jr;
|
|
||||||
size_t k;
|
size_t k;
|
||||||
/*
|
/*
|
||||||
* Top of another loop point based on finding a linearly
|
* Top of another loop point based on finding a linearly
|
||||||
* independent species
|
* independent species
|
||||||
*/
|
*/
|
||||||
do {
|
while (true) {
|
||||||
/*
|
/*
|
||||||
* Search the remaining part of the mole fraction vector, AW,
|
* Search the remaining part of the mole fraction vector, AW,
|
||||||
* for the largest remaining species. Return its identity in K.
|
* for the largest remaining species. Return its identity in K.
|
||||||
|
|
@ -140,12 +139,10 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
/* **** IF NORM OF NEW ROW .LT. 1E-6 REJECT ********** */
|
/* **** IF NORM OF NEW ROW .LT. 1E-6 REJECT ********** */
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
if (sa[jr] < 1.0e-6) {
|
if (sa[jr] > 1.0e-6) {
|
||||||
lindep = true;
|
break;
|
||||||
} else {
|
|
||||||
lindep = false;
|
|
||||||
}
|
}
|
||||||
} while (lindep);
|
}
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
/* **** REARRANGE THE DATA ****************** */
|
/* **** REARRANGE THE DATA ****************** */
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
@ -162,12 +159,9 @@ int VCS_SOLVE::vcs_elem_rearrange(double* const aw, double* const sa,
|
||||||
std::swap(aw[jr], aw[k]);
|
std::swap(aw[jr], aw[k]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
// If we haven't found enough components, go back and find some more.
|
||||||
* If we haven't found enough components, go back
|
jr++;
|
||||||
* and find some more. (nc -1 is used below, because
|
}
|
||||||
* jr is counted from 0, via the C convention.
|
|
||||||
*/
|
|
||||||
} while (jr < (ncomponents-1));
|
|
||||||
return VCS_SUCCESS;
|
return VCS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2478,7 +2478,6 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
|
||||||
double ss[], double test, bool* const usedZeroedSpecies)
|
double ss[], double test, bool* const usedZeroedSpecies)
|
||||||
{
|
{
|
||||||
size_t k;
|
size_t k;
|
||||||
bool lindep;
|
|
||||||
size_t juse = npos;
|
size_t juse = npos;
|
||||||
size_t jlose = npos;
|
size_t jlose = npos;
|
||||||
double* scrxn_ptr;
|
double* scrxn_ptr;
|
||||||
|
|
@ -2547,16 +2546,15 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t jr = npos;
|
size_t jr = 0;
|
||||||
/*
|
/*
|
||||||
* Top of a loop of some sort based on the index JR. JR is the
|
* Top of a loop of some sort based on the index JR. JR is the
|
||||||
* current number of component species found.
|
* current number of component species found.
|
||||||
*/
|
*/
|
||||||
do {
|
while (jr < ncTrial) {
|
||||||
++jr;
|
|
||||||
/* - Top of another loop point based on finding a linearly */
|
/* - Top of another loop point based on finding a linearly */
|
||||||
/* - independent species */
|
/* - independent species */
|
||||||
do {
|
while (true) {
|
||||||
/*
|
/*
|
||||||
* Search the remaining part of the mole fraction vector, AW,
|
* Search the remaining part of the mole fraction vector, AW,
|
||||||
* for the largest remaining species. Return its identity in K.
|
* for the largest remaining species. Return its identity in K.
|
||||||
|
|
@ -2732,8 +2730,10 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
/* **** IF NORM OF NEW ROW .LT. 1E-3 REJECT ********** */
|
/* **** IF NORM OF NEW ROW .LT. 1E-3 REJECT ********** */
|
||||||
/* **************************************************** */
|
/* **************************************************** */
|
||||||
lindep = (sa[jr] < 1.0e-6);
|
if (sa[jr] > 1.0e-6) {
|
||||||
} while (lindep);
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
/* **** REARRANGE THE DATA ****************** */
|
/* **** REARRANGE THE DATA ****************** */
|
||||||
/* ****************************************** */
|
/* ****************************************** */
|
||||||
|
|
@ -2768,12 +2768,9 @@ int VCS_SOLVE::vcs_basopt(const bool doJustComponents, double aw[], double sa[],
|
||||||
/* - entry point from up above */
|
/* - entry point from up above */
|
||||||
L_END_LOOP:
|
L_END_LOOP:
|
||||||
;
|
;
|
||||||
/*
|
// If we haven't found enough components, go back and find some more.
|
||||||
* If we haven't found enough components, go back
|
jr++;
|
||||||
* and find some more. (nc -1 is used below, because
|
}
|
||||||
* jr is counted from 0, via the C convention.
|
|
||||||
*/
|
|
||||||
} while (jr < (ncTrial-1));
|
|
||||||
|
|
||||||
if (doJustComponents) {
|
if (doJustComponents) {
|
||||||
goto L_CLEANUP;
|
goto L_CLEANUP;
|
||||||
|
|
|
||||||
|
|
@ -528,13 +528,13 @@ void IDA_Solver::correctInitial_YaYp_given_Yd(doublereal* y, doublereal* yp, dou
|
||||||
|
|
||||||
int IDA_Solver::solve(double tout)
|
int IDA_Solver::solve(double tout)
|
||||||
{
|
{
|
||||||
double tretn;
|
double tretn = tout - 1000;
|
||||||
int flag;
|
int flag;
|
||||||
flag = IDASetStopTime(m_ida_mem, tout);
|
flag = IDASetStopTime(m_ida_mem, tout);
|
||||||
if (flag != IDA_SUCCESS) {
|
if (flag != IDA_SUCCESS) {
|
||||||
throw IDA_Err(" IDA error encountered.");
|
throw IDA_Err(" IDA error encountered.");
|
||||||
}
|
}
|
||||||
do {
|
while (tretn < tout) {
|
||||||
if (tout <= m_tcurrent) {
|
if (tout <= m_tcurrent) {
|
||||||
throw IDA_Err(" tout <= tcurrent");
|
throw IDA_Err(" tout <= tcurrent");
|
||||||
}
|
}
|
||||||
|
|
@ -552,7 +552,7 @@ int IDA_Solver::solve(double tout)
|
||||||
}
|
}
|
||||||
m_tcurrent = tretn;
|
m_tcurrent = tretn;
|
||||||
m_deltat = m_tcurrent - m_told;
|
m_deltat = m_tcurrent - m_told;
|
||||||
} while (tretn < tout);
|
};
|
||||||
|
|
||||||
if (flag != IDA_SUCCESS && flag != IDA_TSTOP_RETURN) {
|
if (flag != IDA_SUCCESS && flag != IDA_TSTOP_RETURN) {
|
||||||
throw IDA_Err(" IDA error encountered.");
|
throw IDA_Err(" IDA error encountered.");
|
||||||
|
|
|
||||||
|
|
@ -381,7 +381,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
// MAIN LOOP
|
// MAIN LOOP
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
do {
|
while (!converged && its < itmax) {
|
||||||
/*
|
/*
|
||||||
* Find an estimate of the next point, xnew, to try based on
|
* Find an estimate of the next point, xnew, to try based on
|
||||||
* a linear approximation from the last two points.
|
* a linear approximation from the last two points.
|
||||||
|
|
@ -910,7 +910,7 @@ int RootFind::solve(doublereal xmin, doublereal xmax, int itmax, doublereal& fun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (! converged && its < itmax);
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (converged) {
|
if (converged) {
|
||||||
|
|
|
||||||
|
|
@ -1567,7 +1567,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
|
||||||
getMoleFractions(DATA_PTR(mf));
|
getMoleFractions(DATA_PTR(mf));
|
||||||
bool notDone = true;
|
bool notDone = true;
|
||||||
|
|
||||||
do {
|
while (notDone) {
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
size_t kMaxC = npos;
|
size_t kMaxC = npos;
|
||||||
double MaxC = 0.0;
|
double MaxC = 0.0;
|
||||||
|
|
@ -1626,7 +1626,7 @@ void HMWSoln::initThermoXML(XML_Node& phaseNode, const std::string& id_)
|
||||||
} else {
|
} else {
|
||||||
notDone = false;
|
notDone = false;
|
||||||
}
|
}
|
||||||
} while (notDone);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HMWSoln::calcIMSCutoffParams_()
|
void HMWSoln::calcIMSCutoffParams_()
|
||||||
|
|
|
||||||
|
|
@ -956,7 +956,7 @@ doublereal RedlichKwongMFTP::liquidVolEst(doublereal TKelvin, doublereal& presGu
|
||||||
|
|
||||||
bool foundLiq = false;
|
bool foundLiq = false;
|
||||||
int m = 0;
|
int m = 0;
|
||||||
do {
|
while (m < 100 && !foundLiq) {
|
||||||
|
|
||||||
int nsol = NicholsSolve(TKelvin, pres, atmp, btmp, Vroot);
|
int nsol = NicholsSolve(TKelvin, pres, atmp, btmp, Vroot);
|
||||||
|
|
||||||
|
|
@ -970,7 +970,7 @@ doublereal RedlichKwongMFTP::liquidVolEst(doublereal TKelvin, doublereal& presGu
|
||||||
} else {
|
} else {
|
||||||
foundLiq = true;
|
foundLiq = true;
|
||||||
}
|
}
|
||||||
} while ((m < 100) && (!foundLiq));
|
}
|
||||||
|
|
||||||
if (foundLiq) {
|
if (foundLiq) {
|
||||||
v = Vroot[0];
|
v = Vroot[0];
|
||||||
|
|
|
||||||
|
|
@ -88,8 +88,8 @@ double Substance::Tsat(double p)
|
||||||
if (T >= Tcrit()) {
|
if (T >= Tcrit()) {
|
||||||
T = 0.5*(Tcrit() - Tmin());
|
T = 0.5*(Tcrit() - Tmin());
|
||||||
}
|
}
|
||||||
double dp;
|
double dp = 10*tol;
|
||||||
do {
|
while (fabs(dp) > tol) {
|
||||||
if (T > Tcrit()) {
|
if (T > Tcrit()) {
|
||||||
T = Tcrit() - 0.001;
|
T = Tcrit() - 0.001;
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ double Substance::Tsat(double p)
|
||||||
T = Tsave;
|
T = Tsave;
|
||||||
throw TPX_Error("Substance::Tsat", "No convergence");
|
throw TPX_Error("Substance::Tsat", "No convergence");
|
||||||
}
|
}
|
||||||
} while (fabs(dp) > tol);
|
}
|
||||||
double tsat = T;
|
double tsat = T;
|
||||||
T = Tsave;
|
T = Tsave;
|
||||||
return tsat;
|
return tsat;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue