Skip to content

Commit f9b4566

Browse files
committed
Add proper storage of phase
1 parent fd5ccd9 commit f9b4566

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

thermo/electrochem.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,7 +1376,7 @@ def ion_balance_adjust_wrapper(charges, zs, n_anions, n_cations,
13761376
charge = selected_ion.charge
13771377
positive = charge > 0
13781378
if charge == 0: # pragma: no cover
1379-
raise Exception('Cannot adjust selected compound as it has no charge!')
1379+
raise ValueError('Cannot adjust selected compound as it has no charge!')
13801380

13811381

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

14151415

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

14221422
z_water = 1. - sum(zs[0:-1])
14231423
anion_zs = zs[0:n_anions]
@@ -1448,7 +1448,7 @@ def ion_balance_dominant(impacts, balance_error, charges, zs, n_anions,
14481448
else:
14491449
adjust = impacts.index(min(impacts))
14501450
else:
1451-
raise Exception('Allowable methods are %s' %charge_balance_methods)
1451+
raise ValueError('Allowable methods are %s' %charge_balance_methods)
14521452
return ion_balance_adjust_one(charges, zs, n_anions, n_cations, adjust)
14531453

14541454

thermo/phases.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@
145145
'VirialCorrelationsPitzerCurl', # For testing - try to get rid of
146146
]
147147

148-
import sys
148+
import sys, os
149149
from math import isinf, isnan, sqrt
150150
from fluids.constants import R, R_inv
151151
import fluids.constants
@@ -6109,19 +6109,26 @@ def build_CEOSLiquid():
61096109
import marshal
61106110
loaded_data = False
61116111
# Cost is ~10 ms - must be pasted in the future!
6112-
if 1:
6113-
try:
6114-
f = open('/home/caleb/testCEOSLiquiddat', 'rb')
6112+
try: # pragma: no cover
6113+
from appdirs import user_data_dir, user_config_dir
6114+
data_dir = user_config_dir('thermo')
6115+
except ImportError: # pragma: no cover
6116+
data_dir = ''
6117+
if data_dir:
6118+
try:
6119+
f = open(os.path.join(data_dir, 'CEOSLiquid.dat'), 'rb')
61156120
compiled_CEOSLiquid = marshal.load(f)
61166121
f.close()
61176122
loaded_data = True
61186123
except:
61196124
pass
61206125
if not loaded_data:
61216126
compiled_CEOSLiquid = compile(build_CEOSLiquid(), '<string>', 'exec')
6122-
f = open('/home/caleb/testCEOSLiquiddat', 'wb')
6127+
f = open(os.path.join(data_dir, 'CEOSLiquid.dat'), 'wb')
61236128
marshal.dump(compiled_CEOSLiquid, f)
61246129
f.close()
6130+
else:
6131+
compiled_CEOSLiquid = compile(build_CEOSLiquid(), '<string>', 'exec')
61256132
exec(compiled_CEOSLiquid)
61266133
# exec(build_CEOSLiquid())
61276134

0 commit comments

Comments
 (0)