Skip to content

Commit

Permalink
minor optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
yoelcortes committed Jan 28, 2024
1 parent ce79be9 commit 960a865
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions thermosteam/mixture/mixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def xsolve_T_at_SP(self, phase_mol, S, T_guess, P):

def xCn(self, phase_mol, T, P=None):
"""Multi-phase mixture molar isobaric heat capacity [J/mol/K]."""
return sum([self.Cn(phase, mol, T) for phase, mol in phase_mol])
return sum([self.Cn(phase, mol, T, P) for phase, mol in phase_mol])

def xH(self, phase_mol, T, P):
"""Multi-phase mixture enthalpy [J/mol]."""
Expand Down Expand Up @@ -560,12 +560,14 @@ def _load_free_energy_args(self, phase, mol, T, P):

def _load_xfree_energy_args(self, phase_mol, T, P):
fea = self._free_energy_args
for phase, mol in phase_mol: fea[phase] = self.eos_args(phase, mol, T, P)
for phase, mol in phase_mol:
if mol.dct: fea[phase] = self.eos_args(phase, mol, T, P)

def Cn(self, phase, mol, T, P):
if mol.__class__ is not SparseVector: mol = SparseVector(mol)
if not mol.dct: return 0
Cn = self.Cn_ideal(phase, mol, T, P)
if phase != 's' and mol.dct:
if phase != 's':
if phase in self._free_energy_args:
eos, eos_mol, eos_kwargs = self._free_energy_args[phase]
else:
Expand All @@ -577,17 +579,20 @@ def Cn(self, phase, mol, T, P):
)
if phase == 'l':
try: Cn += eos.Cn_dep_l * eos_mol
except: Cn += eos.Cn_dep_g * eos_mol
except:
try: Cn += eos.Cn_dep_g * eos_mol
except: pass
else:
try: Cn += eos.Cn_dep_g * eos_mol
except: Cn += eos.Cn_dep_l * eos_mol
except: pass
return Cn

def H(self, phase, mol, T, P):
"""Return enthalpy [J/mol]."""
if mol.__class__ is not SparseVector: mol = SparseVector(mol)
if not mol.dct: return 0
H = self.H_ideal(phase, mol, T, P)
if phase != 's' and mol.dct:
if phase != 's':
if phase in self._free_energy_args:
eos, eos_mol, eos_kwargs = self._free_energy_args[phase]
else:
Expand All @@ -599,17 +604,20 @@ def H(self, phase, mol, T, P):
)
if phase == 'l':
try: H += eos.H_dep_l * eos_mol
except: H += eos.H_dep_g * eos_mol
except:
try: H += eos.H_dep_g * eos_mol
except: pass
else:
try: H += eos.H_dep_g * eos_mol
except: H += eos.H_dep_l * eos_mol
except: pass
return H

def S(self, phase, mol, T, P):
"""Return entropy [J/mol/K]."""
if mol.__class__ is not SparseVector: mol = SparseVector(mol)
if not mol.dct: return 0
S = self.S_ideal(phase, mol, T, P)
if phase != 's' and mol.dct:
if phase != 's':
if phase in self._free_energy_args:
eos, eos_mol, eos_kwargs = self._free_energy_args[phase]
else:
Expand All @@ -621,10 +629,12 @@ def S(self, phase, mol, T, P):
)
if phase == 'l':
try: S += eos.S_dep_l * eos_mol
except: S += eos.S_dep_g * eos_mol
except:
try: S += eos.S_dep_g * eos_mol
except: pass
else:
try: S += eos.S_dep_g * eos_mol
except: S += eos.S_dep_l * eos_mol
except: pass
return S

@classmethod
Expand Down

0 comments on commit 960a865

Please sign in to comment.