Skip to content

Commit

Permalink
fix phase expansion/replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
cortespea committed Dec 15, 2023
1 parent 574919d commit f4113bd
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions thermosteam/indexer.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,13 @@ def separate_out(self, other):

def to_material_indexer(self, phases):
material_array = self._MaterialIndexer.blank(phases, self._chemicals)
material_array[self.phase].copy_like(self.data)
phase = self.phase
if phase not in phases:
if phase.isupper():
phase = phase.lower()
else:
phase = phase.upper()
material_array[phase].copy_like(self.data)
return material_array

def copy_like(self, other):
Expand Down Expand Up @@ -797,12 +803,13 @@ def _expand_phases(self, other_phases):
if new_phases:
data = self.data
data_by_phase = {i: j for i, j in zip(phases, data.rows)}
all_phases = new_phases | phases
all_phases = new_phases.union(phases)
self._set_phases(all_phases)
size = self._chemicals.size
for i in new_phases: data_by_phase[i] = SparseVector.from_size(size)
phases = self._phases
data.rows = [data_by_phase[i] for i in phases]
self._set_cache()

def mix_from(self, others):
isa = isinstance
Expand Down Expand Up @@ -946,7 +953,13 @@ def to_chemical_indexer(self, phase=NoPhase):
def to_material_indexer(self, phases):
material_indexer = self.__class__.blank(phases, self._chemicals)
for phase, data in self:
if data.any(): material_indexer[phase] = data
if data.any():
if phase not in phases:
if phase.isupper():
phase = phase.lower()
else:
phase = phase.upper()
material_indexer[phase] += data
return material_indexer

def get_phase(self, phase):
Expand Down

0 comments on commit f4113bd

Please sign in to comment.