Skip to content

Commit

Permalink
try something else to reduce rounding error
Browse files Browse the repository at this point in the history
  • Loading branch information
joyxyz1994 committed Feb 22, 2024
1 parent 235025f commit 754fbe3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
5 changes: 3 additions & 2 deletions qsdsan/_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,11 +1191,12 @@ def stoichiometry(self):
if isa(stoichio, list) and len(v_params) > 0:
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])
# stoichio_vals.append([v.subs(v_params) if not isa(v, (float, int)) else v for v in row])
stoichio_vals.append([v.evalf(subs=v_params) if not isa(v, (float, int)) else v for v in row])
try:
stoichio_vals = np.asarray(stoichio_vals, dtype=float)
#!!! round-off error
stoichio_vals[np.abs(stoichio_vals) < 2.22044604925e-16] = 0.0
# 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
3 changes: 3 additions & 0 deletions qsdsan/processes/_adm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@ def __new__(cls, components=None, path=None, N_xc=2.686e-3, N_I=4.286e-3, N_aa=7
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)
# 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

if not path: path = _path
self = Processes.load_from_file(path,
Expand Down

0 comments on commit 754fbe3

Please sign in to comment.