Skip to content

Commit

Permalink
attempt to reduce rounding error
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxyz1994 committed Feb 21, 2024
1 parent 76da652 commit 235025f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion qsdsan/_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1192,7 +1192,10 @@ def stoichiometry(self):
stoichio_vals = []
for row in stoichio:
stoichio_vals.append([v.subs(v_params) if not isa(v, (float, int)) else v for v in row])
try: stoichio_vals = np.asarray(stoichio_vals, dtype=float)
try:
stoichio_vals = np.asarray(stoichio_vals, dtype=float)
#!!! round-off error
stoichio_vals[np.abs(stoichio_vals) < 2.22044604925e-16] = 0.0
except TypeError: pass
return pd.DataFrame(stoichio_vals, index=self.IDs, columns=self._components.IDs)
else: return pd.DataFrame(stoichio, index=self.IDs, columns=self._components.IDs)
Expand Down
16 changes: 8 additions & 8 deletions qsdsan/processes/_adm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,9 +569,9 @@ def __new__(cls, components=None, path=None, N_xc=2.686e-3, N_I=4.286e-3, N_aa=7
**kwargs):

cmps = _load_components(components)
cmps.X_c.i_N = N_xc * N_mw
cmps.X_I.i_N = cmps.S_I.i_N = N_I * N_mw
cmps.S_aa.i_N = cmps.X_pr.i_N = N_aa * N_mw
cmps.X_c.i_N = round(N_xc * N_mw, 4)
cmps.X_I.i_N = cmps.S_I.i_N = round(N_I * N_mw, 4)
cmps.S_aa.i_N = cmps.X_pr.i_N = round(N_aa * N_mw, 4)

if not path: path = _path
self = Processes.load_from_file(path,
Expand All @@ -591,11 +591,11 @@ def __new__(cls, components=None, path=None, N_xc=2.686e-3, N_I=4.286e-3, N_aa=7
self.extend(gas_transfer)
self.compile(to_class=cls)

stoichio_vals = (f_ch_xc, f_pr_xc, f_li_xc, f_xI_xc, 1-f_ch_xc-f_pr_xc-f_li_xc-f_xI_xc,
f_fa_li, f_bu_su, f_pro_su, f_ac_su, 1-f_bu_su-f_pro_su-f_ac_su,
f_va_aa, f_bu_aa, f_pro_aa, f_ac_aa, 1-f_va_aa-f_bu_aa-f_pro_aa-f_ac_aa,
f_ac_fa, 1-f_ac_fa, f_pro_va, f_ac_va, 1-f_pro_va-f_ac_va,
f_ac_bu, 1-f_ac_bu, f_ac_pro, 1-f_ac_pro,
stoichio_vals = (f_ch_xc, f_pr_xc, f_li_xc, f_xI_xc, 1.0-f_ch_xc-f_pr_xc-f_li_xc-f_xI_xc,
f_fa_li, f_bu_su, f_pro_su, f_ac_su, 1.0-f_bu_su-f_pro_su-f_ac_su,
f_va_aa, f_bu_aa, f_pro_aa, f_ac_aa, 1.0-f_va_aa-f_bu_aa-f_pro_aa-f_ac_aa,
f_ac_fa, 1.0-f_ac_fa, f_pro_va, f_ac_va, 1.0-f_pro_va-f_ac_va,
f_ac_bu, 1.0-f_ac_bu, f_ac_pro, 1.0-f_ac_pro,
Y_su, Y_aa, Y_fa, Y_c4, Y_pro, Y_ac, Y_h2)
pH_LLs = np.array([pH_limits_aa[0]]*6 + [pH_limits_ac[0], pH_limits_h2[0]])
pH_ULs = np.array([pH_limits_aa[1]]*6 + [pH_limits_ac[1], pH_limits_h2[1]])
Expand Down

0 comments on commit 235025f

Please sign in to comment.