Skip to content

Commit

Permalink
[Thermo] Add Phase::nativeMode / fix glitch
Browse files Browse the repository at this point in the history
Prevent automatic alphabetic ordering of states in
SolutionArray::componentNames
  • Loading branch information
ischoegl authored and speth committed Apr 9, 2023
1 parent 4560e44 commit 124048f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/cantera/thermo/Phase.h
Expand Up @@ -291,6 +291,11 @@ class Phase
//! and restoreState().
virtual std::map<std::string, size_t> nativeState() const;

//! Return string acronym representing native state
//! @see nativeState
//! @since New in Cantera 3.0
string nativeMode() const;

//! Return a vector containing full states defining a phase.
//! Full states list combinations of properties that allow for the
//! specification of a thermodynamic state based on user input.
Expand Down
4 changes: 2 additions & 2 deletions src/base/SolutionArray.cpp
Expand Up @@ -216,8 +216,8 @@ vector<string> SolutionArray::componentNames() const

// state information
auto phase = m_sol->thermo();
const auto& nativeState = phase->nativeState();
for (auto& [name, value] : nativeState) {
for (auto code : phase->nativeMode()) {
string name = string(1, code);
if (name == "X" || name == "Y") {
for (auto& spc : phase->speciesNames()) {
components.push_back(spc);
Expand Down
13 changes: 13 additions & 0 deletions src/thermo/Phase.cpp
Expand Up @@ -196,6 +196,19 @@ std::map<std::string, size_t> Phase::nativeState() const
}
}

string Phase::nativeMode() const
{
map<size_t, string> states; // reverse lookup
for (auto& [name, value] : nativeState()) {
states[value] = name;
}
string out;
for (auto& [value, name] : states) {
out += name;
}
return out;
}

vector<std::string> Phase::fullStates() const
{
if (isPure()) {
Expand Down

0 comments on commit 124048f

Please sign in to comment.