Skip to content

Commit

Permalink
Add proper storage of phase
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Jan 3, 2021
1 parent fd5ccd9 commit f9b4566
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
10 changes: 5 additions & 5 deletions thermo/electrochem.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ def ion_balance_adjust_wrapper(charges, zs, n_anions, n_cations,
charge = selected_ion.charge
positive = charge > 0
if charge == 0: # pragma: no cover
raise Exception('Cannot adjust selected compound as it has no charge!')
raise ValueError('Cannot adjust selected compound as it has no charge!')


if selected_ion not in anions and selected_ion not in cations:
Expand Down Expand Up @@ -1407,17 +1407,17 @@ def ion_balance_adjust_wrapper(charges, zs, n_anions, n_cations,
anion_zs, cation_zs, z_water = ion_balance_adjust_one(charges, zs, n_anions, n_cations, adjust=adjust)
new_zi = cation_zs[cation_index] if positive else anion_zs[anion_index]
if increase == True and new_zi < old_zi:
raise Exception('Adjusting specified ion %s resulted in a decrease of its quantity but an increase was specified' % selected_ion.formula)
raise ValueError('Adjusting specified ion %s resulted in a decrease of its quantity but an increase was specified' % selected_ion.formula)
elif increase == False and new_zi > old_zi:
raise Exception('Adjusting specified ion %s resulted in a increase of its quantity but an decrease was specified' % selected_ion.formula)
raise ValueError('Adjusting specified ion %s resulted in a increase of its quantity but an decrease was specified' % selected_ion.formula)
return anion_zs, cation_zs, z_water


def ion_balance_adjust_one(charges, zs, n_anions, n_cations, adjust):
main_tot = sum([zs[i]*charges[i] for i in range(len(charges)) if i != adjust])
zs[adjust] = -main_tot/charges[adjust]
if zs[adjust] < 0:
raise Exception('A negative value of %f ion mole fraction was required to balance the charge' %zs[adjust])
raise ValueError('A negative value of %f ion mole fraction was required to balance the charge' %zs[adjust])

z_water = 1. - sum(zs[0:-1])
anion_zs = zs[0:n_anions]
Expand Down Expand Up @@ -1448,7 +1448,7 @@ def ion_balance_dominant(impacts, balance_error, charges, zs, n_anions,
else:
adjust = impacts.index(min(impacts))
else:
raise Exception('Allowable methods are %s' %charge_balance_methods)
raise ValueError('Allowable methods are %s' %charge_balance_methods)
return ion_balance_adjust_one(charges, zs, n_anions, n_cations, adjust)


Expand Down
17 changes: 12 additions & 5 deletions thermo/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
'VirialCorrelationsPitzerCurl', # For testing - try to get rid of
]

import sys
import sys, os
from math import isinf, isnan, sqrt
from fluids.constants import R, R_inv
import fluids.constants
Expand Down Expand Up @@ -6109,19 +6109,26 @@ def build_CEOSLiquid():
import marshal
loaded_data = False
# Cost is ~10 ms - must be pasted in the future!
if 1:
try:
f = open('/home/caleb/testCEOSLiquiddat', 'rb')
try: # pragma: no cover
from appdirs import user_data_dir, user_config_dir
data_dir = user_config_dir('thermo')
except ImportError: # pragma: no cover
data_dir = ''
if data_dir:
try:
f = open(os.path.join(data_dir, 'CEOSLiquid.dat'), 'rb')
compiled_CEOSLiquid = marshal.load(f)
f.close()
loaded_data = True
except:
pass
if not loaded_data:
compiled_CEOSLiquid = compile(build_CEOSLiquid(), '<string>', 'exec')
f = open('/home/caleb/testCEOSLiquiddat', 'wb')
f = open(os.path.join(data_dir, 'CEOSLiquid.dat'), 'wb')
marshal.dump(compiled_CEOSLiquid, f)
f.close()
else:
compiled_CEOSLiquid = compile(build_CEOSLiquid(), '<string>', 'exec')
exec(compiled_CEOSLiquid)
# exec(build_CEOSLiquid())

Expand Down

0 comments on commit f9b4566

Please sign in to comment.