Use std::sort to eliminate need for vcs_optMax
This commit is contained in:
parent
df6ecb101b
commit
07eed363fe
3 changed files with 7 additions and 53 deletions
|
|
@ -90,17 +90,6 @@ typedef double(*VCS_FUNC_PTR)(double xval, double Vtarget,
|
|||
*/
|
||||
double vcs_l2norm(const vector_fp& vec);
|
||||
|
||||
//! Finds the location of the maximum component in a double vector
|
||||
/*!
|
||||
* @param x pointer to a vector of doubles
|
||||
* @param xSize pointer to a vector of doubles used as a multiplier to x[]
|
||||
* before making the decision. Ignored if set to NULL.
|
||||
* @param j lowest index to search from
|
||||
* @param n highest index to search from
|
||||
* @returns index of the greatest value on X(i) searched, j <= i < n
|
||||
*/
|
||||
size_t vcs_optMax(const double* x, const double* xSize, size_t j, size_t n);
|
||||
|
||||
//! Returns a const char string representing the type of the species given by
|
||||
//! the first argument
|
||||
/*!
|
||||
|
|
|
|||
|
|
@ -12,24 +12,14 @@ namespace Cantera
|
|||
int VCS_SOLVE::vcs_report(int iconv)
|
||||
{
|
||||
bool inertYes = false;
|
||||
std::vector<size_t> sortindex(m_nsp, 0);
|
||||
vector_fp xy(m_nsp, 0.0);
|
||||
|
||||
// SORT DEPENDENT SPECIES IN DECREASING ORDER OF MOLES
|
||||
for (size_t i = 0; i < m_nsp; ++i) {
|
||||
sortindex[i] = i;
|
||||
xy[i] = m_molNumSpecies_old[i];
|
||||
}
|
||||
|
||||
// Sort the XY vector, the mole fraction vector, and the sort index vector,
|
||||
// sortindex, according to the magnitude of the mole fraction vector.
|
||||
for (size_t i = m_numComponents; i < m_numSpeciesRdc; ++i) {
|
||||
size_t k = vcs_optMax(&xy[0], 0, i, m_numSpeciesRdc);
|
||||
if (k != i) {
|
||||
std::swap(xy[k], xy[i]);
|
||||
std::swap(sortindex[k], sortindex[i]);
|
||||
}
|
||||
std::vector<std::pair<double, size_t>> x_order;
|
||||
for (size_t i = 0; i < m_nsp; i++) {
|
||||
x_order.push_back({-m_molNumSpecies_old[i], i});
|
||||
}
|
||||
std::sort(x_order.begin() + m_numComponents,
|
||||
x_order.begin() + m_numSpeciesRdc);
|
||||
|
||||
vcs_setFlagsVolPhases(false, VCS_STATECALC_OLD);
|
||||
vcs_dfe(VCS_STATECALC_OLD, 0, 0, m_nsp);
|
||||
|
|
@ -71,7 +61,7 @@ int VCS_SOLVE::vcs_report(int iconv)
|
|||
plogf("\n");
|
||||
}
|
||||
for (size_t i = m_numComponents; i < m_numSpeciesRdc; ++i) {
|
||||
size_t j = sortindex[i];
|
||||
size_t j = x_order[i].second;
|
||||
plogf(" %-12.12s", m_speciesName[j]);
|
||||
writeline(' ', 13, false);
|
||||
|
||||
|
|
@ -239,7 +229,7 @@ int VCS_SOLVE::vcs_report(int iconv)
|
|||
plogf("| (MolNum ChemPot)|");
|
||||
writeline('-', 147, true, true);
|
||||
for (size_t i = 0; i < m_nsp; ++i) {
|
||||
size_t j = sortindex[i];
|
||||
size_t j = x_order[i].second;
|
||||
size_t pid = m_phaseID[j];
|
||||
plogf(" %-12.12s", m_speciesName[j]);
|
||||
plogf(" %14.7E ", m_molNumSpecies_old[j]);
|
||||
|
|
|
|||
|
|
@ -30,31 +30,6 @@ double vcs_l2norm(const vector_fp& vec)
|
|||
return std::sqrt(sum / vec.size());
|
||||
}
|
||||
|
||||
size_t vcs_optMax(const double* x, const double* xSize, size_t j, size_t n)
|
||||
{
|
||||
size_t largest = j;
|
||||
double big = x[j];
|
||||
if (xSize) {
|
||||
assert(xSize[j] > 0.0);
|
||||
big *= xSize[j];
|
||||
for (size_t i = j + 1; i < n; ++i) {
|
||||
assert(xSize[i] > 0.0);
|
||||
if ((x[i] * xSize[i]) > big) {
|
||||
largest = i;
|
||||
big = x[i] * xSize[i];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (size_t i = j + 1; i < n; ++i) {
|
||||
if (x[i] > big) {
|
||||
largest = i;
|
||||
big = x[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return largest;
|
||||
}
|
||||
|
||||
const char* vcs_speciesType_string(int speciesStatus, int length)
|
||||
{
|
||||
switch (speciesStatus) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue