Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplication of string identifiers in Phase #724

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/cantera/equil/MultiPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,8 +670,8 @@ inline std::ostream& operator<<(std::ostream& s, MultiPhase& x)
{
x.updatePhases();
for (size_t ip = 0; ip < x.nPhases(); ip++) {
if (x.phase(ip).name() != "") {
s << "*************** " << x.phase(ip).name() << " *****************" << std::endl;
if (x.phase(ip).id() != "") {
s << "*************** " << x.phase(ip).id() << " *****************" << std::endl;
} else {
s << "*************** Phase " << ip << " *****************" << std::endl;
}
Expand Down
11 changes: 7 additions & 4 deletions include/cantera/equil/vcs_VolPhase.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ class vcs_VolPhase
/*!
* @param phaseNum index of the phase in the vcs problem
* @param numSpecies Number of species in the phase
* @param phaseName String name for the phase
* @param phaseID String identifier for the phase
* @param molesInert kmoles of inert in the phase (defaults to zero)
*/
void resize(const size_t phaseNum, const size_t numSpecies,
const size_t numElem, const char* const phaseName,
const size_t numElem, const char* const phaseID,
const double molesInert = 0.0);

void elemResize(const size_t numElemConstraints);
Expand Down Expand Up @@ -623,10 +623,13 @@ class vcs_VolPhase
size_t m_numSpecies;

public:
//! String name for the phase
std::string PhaseName;
//! String identifier for the phase
std::string PhaseID();

private:
//! String identifier of the phase
std::string m_phaseID;

//! Total moles of inert in the phase
double m_totalMolesInert;

Expand Down
4 changes: 2 additions & 2 deletions include/cantera/equil/vcs_solve.h
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ class VCS_SOLVE
* in the private data structure. All references to the species
* properties must employ the ind[] index vector.
* 4. Initialization of arrays to zero.
* 5. Check to see if the problem is well posed (If all the element
* 5. Check to see if the problem is well posed (If all the element
* abundances are zero, the algorithm will fail)
*
* @param printLvl Print level of the routine
Expand Down Expand Up @@ -1354,7 +1354,7 @@ class VCS_SOLVE
vector_int m_speciesStatus;

//! Mapping from the species number to the phase number
std::vector<size_t> m_phaseID;
std::vector<size_t> m_phaseNum;

//! Boolean indicating whether a species belongs to a single-species phase
// vector<bool> can't be used here because it doesn't work with std::swap
Expand Down
14 changes: 5 additions & 9 deletions include/cantera/thermo/Phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,11 @@ namespace Cantera
* operate on a state vector, which is in general of length (2 + nSpecies()).
* The first two entries of the state vector are temperature and density.
*
* A species name may be referred to via three methods:
*
* - "speciesName"
* - "PhaseId:speciesName"
* - "phaseName:speciesName"
* .
*
* The first two methods of naming may not yield a unique species within
* complicated assemblies of %Cantera Phases.
* A species name is referred to via "speciesName", which is unique within a
* given phase. Note that within multiphase mixtures ("MultiPhase"), both a
* phase name/index as well as species name are required to access information
* about a species in a particular phase. For surfaces, the species names are
* unique among the phases.
*
* @todo
* - Make the concept of saving state vectors more general, so that it can
Expand Down
2 changes: 1 addition & 1 deletion interfaces/cython/cantera/test/test_thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,14 @@ def test_name(self):

self.phase.name = 'something'
self.assertEqual(self.phase.name, 'something')
self.assertIn('something', self.phase.report())

def test_ID(self):
self.assertEqual(self.phase.ID, 'ohmech')

self.phase.ID = 'something'
self.assertEqual(self.phase.ID, 'something')
self.assertEqual(self.phase.name, 'ohmech')
self.assertIn('something', self.phase.report())

def test_badLength(self):
X = np.zeros(5)
Expand Down
4 changes: 2 additions & 2 deletions src/clib/ct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ extern "C" {
int thermo_getName(int n, size_t lennm, char* nm)
{
try {
return static_cast<int>(copyString(ThermoCabinet::item(n).name(), nm, lennm));
return static_cast<int>(copyString(ThermoCabinet::item(n).id(), nm, lennm));
} catch (...) {
return handleAllExceptions(-1, ERR);
}
Expand All @@ -296,7 +296,7 @@ extern "C" {
int thermo_setName(int n, const char* nm)
{
try {
ThermoCabinet::item(n).setName(nm);
ThermoCabinet::item(n).setID(nm);
return 0;
} catch (...) {
return handleAllExceptions(-1, ERR);
Expand Down
2 changes: 1 addition & 1 deletion src/equil/MultiPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void MultiPhase::addPhase(ThermoPhase* p, doublereal moles)

if (!p->compatibleWithMultiPhase()) {
throw CanteraError("MultiPhase::addPhase", "Phase '{}'' is not "
"compatible with MultiPhase equilibrium solver", p->name());
"compatible with MultiPhase equilibrium solver", p->id());
}

// save the pointer to the phase object
Expand Down
10 changes: 5 additions & 5 deletions src/equil/MultiPhaseEquil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ void MultiPhaseEquil::reportCSV(const std::string& reportFile)
ThermoPhase& tref = m_mix->phase(iphase);
ThermoPhase* tp = &tref;
tp->getMoleFractions(&mf[istart]);
string phaseName = tref.name();
string phaseID = tref.id();
double TMolesPhase = phaseMoles(iphase);
size_t nSpecies = tref.nSpecies();
activity.resize(nSpecies, 0.0);
Expand All @@ -733,7 +733,7 @@ void MultiPhaseEquil::reportCSV(const std::string& reportFile)
tp->getChemPotentials(mu.data());

if (iphase == 0) {
fprintf(FP," Name, Phase, PhaseMoles, Mole_Fract, "
fprintf(FP," Name, PhaseID, PhaseMoles, Mole_Fract, "
"Molalities, ActCoeff, Activity,"
"ChemPot_SS0, ChemPot, mole_num, PMVol, Phase_Volume\n");

Expand All @@ -746,15 +746,15 @@ void MultiPhaseEquil::reportCSV(const std::string& reportFile)
fprintf(FP,"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e,"
"%11.3e, %11.3e, %11.3e, %11.3e, %11.3e\n",
sName.c_str(),
phaseName.c_str(), TMolesPhase,
phaseID.c_str(), TMolesPhase,
mf[istart + k], molalities[k], ac[k], activity[k],
mu0[k]*1.0E-6, mu[k]*1.0E-6,
mf[istart + k] * TMolesPhase,
VolPM[k], VolPhaseVolumes);
}
} else {
if (iphase == 0) {
fprintf(FP," Name, Phase, PhaseMoles, Mole_Fract, "
fprintf(FP," Name, PhaseID, PhaseMoles, Mole_Fract, "
"Molalities, ActCoeff, Activity,"
" ChemPotSS0, ChemPot, mole_num, PMVol, Phase_Volume\n");

Expand All @@ -770,7 +770,7 @@ void MultiPhaseEquil::reportCSV(const std::string& reportFile)
fprintf(FP,"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e, "
"%11.3e, %11.3e,% 11.3e, %11.3e, %11.3e\n",
sName.c_str(),
phaseName.c_str(), TMolesPhase,
phaseID.c_str(), TMolesPhase,
mf[istart + k], molalities[k], ac[k],
activity[k], mu0[k]*1.0E-6, mu[k]*1.0E-6,
mf[istart + k] * TMolesPhase,
Expand Down
2 changes: 1 addition & 1 deletion src/equil/vcs_Gibbs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ double VCS_SOLVE::vcs_GibbsPhase(size_t iphase, const double* const w,
double g = 0.0;
double phaseMols = 0.0;
for (size_t kspec = 0; kspec < m_numSpeciesRdc; ++kspec) {
if (m_phaseID[kspec] == iphase && m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
if (m_phaseNum[kspec] == iphase && m_speciesUnknownType[kspec] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE) {
g += w[kspec] * fe[kspec];
phaseMols += w[kspec];
}
Expand Down
12 changes: 6 additions & 6 deletions src/equil/vcs_MultiPhaseEquil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ int vcs_MultiPhaseEquil::equilibrate_TP(int estimateEquil,
} else {
plogf(" %15.3e %15.3e ", m_mix->speciesMoles(i), m_mix->moleFraction(i));
if (m_mix->speciesMoles(i) <= 0.0) {
size_t iph = m_vsolve.m_phaseID[i];
size_t iph = m_vsolve.m_phaseNum[i];
vcs_VolPhase* VPhase = m_vsolve.m_VolPhaseList[iph].get();
if (VPhase->nSpecies() > 1) {
plogf(" -1.000e+300\n");
Expand Down Expand Up @@ -533,7 +533,7 @@ void vcs_MultiPhaseEquil::reportCSV(const std::string& reportFile)

for (size_t iphase = 0; iphase < nphase; iphase++) {
ThermoPhase& tref = m_mix->phase(iphase);
string phaseName = tref.name();
string phaseID = tref.id();
vcs_VolPhase* volP = m_vsolve.m_VolPhaseList[iphase].get();
double TMolesPhase = volP->totalMoles();
size_t nSpecies = tref.nSpecies();
Expand Down Expand Up @@ -562,7 +562,7 @@ void vcs_MultiPhaseEquil::reportCSV(const std::string& reportFile)
tref.getChemPotentials(&mu[0]);

if (iphase == 0) {
fprintf(FP," Name, Phase, PhaseMoles, Mole_Fract, "
fprintf(FP," Name, PhaseID, PhaseMoles, Mole_Fract, "
"Molalities, ActCoeff, Activity,"
"ChemPot_SS0, ChemPot, mole_num, PMVol, Phase_Volume\n");

Expand All @@ -575,15 +575,15 @@ void vcs_MultiPhaseEquil::reportCSV(const std::string& reportFile)
fprintf(FP,"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e,"
"%11.3e, %11.3e, %11.3e, %11.3e, %11.3e\n",
sName.c_str(),
phaseName.c_str(), TMolesPhase,
phaseID.c_str(), TMolesPhase,
tref.moleFraction(k), molalities[k], ac[k], activity[k],
mu0[k]*1.0E-6, mu[k]*1.0E-6,
tref.moleFraction(k) * TMolesPhase,
VolPM[k], VolPhaseVolumes);
}
} else {
if (iphase == 0) {
fprintf(FP," Name, Phase, PhaseMoles, Mole_Fract, "
fprintf(FP," Name, PhaseID, PhaseMoles, Mole_Fract, "
"Molalities, ActCoeff, Activity,"
" ChemPotSS0, ChemPot, mole_num, PMVol, Phase_Volume\n");

Expand All @@ -599,7 +599,7 @@ void vcs_MultiPhaseEquil::reportCSV(const std::string& reportFile)
fprintf(FP,"%12s, %11s, %11.3e, %11.3e, %11.3e, %11.3e, %11.3e, "
"%11.3e, %11.3e,% 11.3e, %11.3e, %11.3e\n",
sName.c_str(),
phaseName.c_str(), TMolesPhase,
phaseID.c_str(), TMolesPhase,
tref.moleFraction(k), molalities[k], ac[k],
activity[k], mu0[k]*1.0E-6, mu[k]*1.0E-6,
tref.moleFraction(k) * TMolesPhase,
Expand Down
22 changes: 14 additions & 8 deletions src/equil/vcs_VolPhase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ vcs_VolPhase::vcs_VolPhase(VCS_SOLVE* owningSolverObject) :
m_numElemConstraints(0),
m_elemGlobalIndex(0),
m_numSpecies(0),
m_phaseID("<phase-id>"),
m_totalMolesInert(0.0),
m_isIdealSoln(false),
m_existence(VCS_PHASE_EXIST_NO),
Expand Down Expand Up @@ -58,8 +59,13 @@ vcs_VolPhase::~vcs_VolPhase()
}
}

std::string vcs_VolPhase::PhaseID()
{
return m_phaseID;
}

void vcs_VolPhase::resize(const size_t phaseNum, const size_t nspecies,
const size_t numElem, const char* const phaseName,
const size_t numElem, const char* const phaseID,
const double molesInert)
{
AssertThrowMsg(nspecies > 0, "vcs_VolPhase::resize", "nspecies Error");
Expand All @@ -68,17 +74,17 @@ void vcs_VolPhase::resize(const size_t phaseNum, const size_t nspecies,
m_phiVarIndex = npos;

if (phaseNum == VP_ID_) {
if (strcmp(PhaseName.c_str(), phaseName)) {
if (strcmp(m_phaseID.c_str(), phaseID)) {
throw CanteraError("vcs_VolPhase::resize",
"Strings are different: " + PhaseName + " " +
phaseName + " :unknown situation");
"Strings are different: " + m_phaseID + " " +
phaseID + " :unknown situation");
}
} else {
VP_ID_ = phaseNum;
if (!phaseName) {
PhaseName = fmt::format("Phase_{}", VP_ID_);
if (!phaseID) {
m_phaseID = fmt::format("Phase_{}", VP_ID_);
} else {
PhaseName = phaseName;
m_phaseID = phaseID;
}
}
if (nspecies > 1) {
Expand Down Expand Up @@ -589,7 +595,7 @@ void vcs_VolPhase::setPtrThermoPhase(ThermoPhase* tp_ptr)
if (m_numSpecies != 0) {
plogf("Warning Nsp != NVolSpeces: %d %d \n", nsp, m_numSpecies);
}
resize(VP_ID_, nsp, nelem, PhaseName.c_str());
resize(VP_ID_, nsp, nelem, m_phaseID.c_str());
}
TP_ptr->getMoleFractions(&Xmol_[0]);
creationMoleNumbers_ = Xmol_;
Expand Down
2 changes: 1 addition & 1 deletion src/equil/vcs_elem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ void VCS_SOLVE::vcs_elabPhase(size_t iphase, double* const elemAbundPhase)
for (size_t j = 0; j < m_nelem; ++j) {
elemAbundPhase[j] = 0.0;
for (size_t i = 0; i < m_nsp; ++i) {
if (m_speciesUnknownType[i] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE && m_phaseID[i] == iphase) {
if (m_speciesUnknownType[i] != VCS_SPECIES_TYPE_INTERFACIALVOLTAGE && m_phaseNum[i] == iphase) {
elemAbundPhase[j] += m_formulaMatrix(i,j) * m_molNumSpecies_old[i];
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/equil/vcs_inest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
}
for (size_t kspec = 0; kspec < m_numComponents; ++kspec) {
if (m_speciesUnknownType[kspec] == VCS_SPECIES_TYPE_MOLNUM) {
m_tPhaseMoles_new[m_phaseID[kspec]] += m_molNumSpecies_old[kspec];
m_tPhaseMoles_new[m_phaseNum[kspec]] += m_molNumSpecies_old[kspec];
}
}
double TMolesMultiphase = 0.0;
Expand All @@ -103,7 +103,7 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
for (size_t kspec = 0; kspec < m_numComponents; ++kspec) {
if (m_speciesUnknownType[kspec] == VCS_SPECIES_TYPE_MOLNUM) {
if (! m_SSPhase[kspec]) {
size_t iph = m_phaseID[kspec];
size_t iph = m_phaseNum[kspec];
m_feSpecies_new[kspec] += log(m_molNumSpecies_new[kspec] / m_tPhaseMoles_old[iph]);
}
} else {
Expand Down Expand Up @@ -140,7 +140,7 @@ void VCS_SOLVE::vcs_inest(double* const aw, double* const sa, double* const sm,
// the phase exists, it stays. If it doesn't exist in the estimate, it
// doesn't come into existence here.
if (! m_SSPhase[kspec]) {
size_t iph = m_phaseID[kspec];
size_t iph = m_phaseNum[kspec];
if (m_deltaGRxn_new[irxn] > xtphMax[iph]) {
m_deltaGRxn_new[irxn] = 0.8 * xtphMax[iph];
}
Expand Down
12 changes: 6 additions & 6 deletions src/equil/vcs_phaseStability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ size_t VCS_SOLVE::vcs_popPhaseID(std::vector<size_t> & phasePopPhaseIDs)
if (existence > 0) {
if (m_debug_print_lvl >= 2) {
plogf(" --- %18s %5d NA %11.3e\n",
Vphase->PhaseName, existence, m_tPhaseMoles_old[iph]);
Vphase->PhaseID(), existence, m_tPhaseMoles_old[iph]);
}
} else {
if (Vphase->m_singleSpecies) {
Expand Down Expand Up @@ -154,7 +154,7 @@ size_t VCS_SOLVE::vcs_popPhaseID(std::vector<size_t> & phasePopPhaseIDs)

if (m_debug_print_lvl >= 2) {
plogf(" --- %18s %5d %10.3g %10.3g %s\n",
Vphase->PhaseName, existence, Fephase,
Vphase->PhaseID(), existence, Fephase,
m_tPhaseMoles_old[iph], anote);
}
} else {
Expand All @@ -171,13 +171,13 @@ size_t VCS_SOLVE::vcs_popPhaseID(std::vector<size_t> & phasePopPhaseIDs)
}
if (m_debug_print_lvl >= 2) {
plogf(" --- %18s %5d %11.3g %11.3g\n",
Vphase->PhaseName, existence, Fephase,
Vphase->PhaseID(), existence, Fephase,
m_tPhaseMoles_old[iph]);
}
} else {
if (m_debug_print_lvl >= 2) {
plogf(" --- %18s %5d blocked %11.3g\n",
Vphase->PhaseName,
Vphase->PhaseID(),
existence, m_tPhaseMoles_old[iph]);
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
"called for a phase that exists!");
if (m_debug_print_lvl >= 2) {
plogf(" --- vcs_popPhaseRxnStepSizes() called to pop phase %s %d into existence\n",
Vphase->PhaseName, iphasePop);
Vphase->PhaseID(), iphasePop);
}
// Section for a single-species phase
if (Vphase->m_singleSpecies) {
Expand Down Expand Up @@ -307,7 +307,7 @@ int VCS_SOLVE::vcs_popPhaseRxnStepSizes(const size_t iphasePop)
}
} else {
if (m_elType[j] == VCS_ELEM_TYPE_ABSPOS) {
size_t jph = m_phaseID[j];
size_t jph = m_phaseNum[j];
if ((jph != iphasePop) && (!m_SSPhase[j])) {
double fdeltaJ = fabs(deltaJ);
if (m_molNumSpecies_old[j] > 0.0) {
Expand Down
Loading