Skip to content

Commit

Permalink
fix issue with proxy-indexers and phases
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Nov 21, 2024
1 parent 477b3a9 commit 197807c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
5 changes: 3 additions & 2 deletions thermosteam/_phase.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
'S': 'SOLID',
'L': 'LIQUID',
}
index = {j: i for i,j in enumerate(valid_phases)}
index = {j: i for i,j in enumerate(sorted(valid_phases))}

def check_phase(phase):
"""
Expand All @@ -38,7 +38,8 @@ def check_phase(phase):
raise RuntimeError(
f"invalid phase {repr(phase)} encountered; valid phases are "
"'s' (solid), 'l' (liquid), 'g' (gas), 'S' (SOLID), and 'L' (LIQUID)"
)
)
return phase

def phase_tuple(phases):
"""
Expand Down
14 changes: 8 additions & 6 deletions thermosteam/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1320,17 +1320,19 @@ def group_vol_composition(self):
def by_mass(self):
"""Return a ChemicalMassFlowIndexer that references this object's molar data."""
try:
mass = self._data_cache['mass']
mass = self._data_cache['mass', self._phase]
except:
chemicals = self.chemicals
self._data_cache['mass'] = mass = \
self._data_cache['mass', self._phase] = mass = \
ChemicalMassFlowIndexer.from_data(
SparseVector.from_dict(
MassFlowDict(self.data.dct, chemicals.MW),
chemicals.size
),
self._phase, chemicals,
False
self._phase,
chemicals,
False,
True,
)
return mass
ChemicalMolarFlowIndexer.by_mass = by_mass
Expand Down Expand Up @@ -1367,12 +1369,12 @@ def by_volume(self, TP):
"""
try:
vol = self._data_cache['vol', TP]
vol = self._data_cache['vol', TP, self._phase]
except:
chemicals = self._chemicals
V = [i.V for i in chemicals]
phase = self._phase
self._data_cache['vol', TP] = \
self._data_cache['vol', TP, self._phase] = \
vol = ChemicalVolumetricFlowIndexer.from_data(
SparseVector.from_dict(
VolumetricFlowDict(self.data.dct, TP, V, None, self, {}),
Expand Down

0 comments on commit 197807c

Please sign in to comment.