Skip to content

Commit

Permalink
Add post-processing energy integration
Browse files Browse the repository at this point in the history
  • Loading branch information
edan-bainglass committed Dec 18, 2023
1 parent 7a8f47e commit 5587848
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion aiida_aurora/utils/analyzers.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def _truncate_snapshot(self) -> None:
index = self.snapshot["cycle-index"][-size]
truncated[key] = value[index:]

elif key in ("cycle-number", "Qc", "Qd"):
elif key in ("cycle-number", "Qc", "Qd", "Ec", "Ed"):
truncated[key] = value[-size:]

self.snapshot = truncated
21 changes: 14 additions & 7 deletions aiida_aurora/utils/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@ def post_process_data(t: np.ndarray, Ewe: np.ndarray, I: np.ndarray) -> dict:
"""docstring"""

mask = I != 0 # filter out zero current
t, Ewe, I = t[mask], Ewe[mask], I[mask]
t, Ewe, I = t[mask], Ewe[mask], I[mask] # [s], [V], [A]

Q = cumtrapz(I, t, axis=0, initial=0) # [As]

# mark half-cycles (including first and last values)
idx = np.where(np.diff(np.sign(I), prepend=0) != 0)[0]
idx = np.append(idx, len(I))

# integrate and store charge and discharge currents
Qc, Qd, cycle_idx = [], [], []
# integrate and store charge/discharge capacities/energies
cycle_idx, Qc, Qd, Ec, Ed = [], [], [], [], []

for ii in range(len(idx) - 1):

Expand All @@ -58,20 +60,25 @@ def post_process_data(t: np.ndarray, Ewe: np.ndarray, I: np.ndarray) -> dict:
if ie - i0 < 10:
continue

e = np.trapz(Ewe[i0:ie], Q[i0:ie]) # [Ws]

if (q := np.trapz(I[i0:ie], t[i0:ie])) > 0:
cycle_idx.append(i0)
Qc.append(q)
Ec.append(e)
else:
Qd.append(abs(q))
Ed.append(abs(e))

return {
"time": t,
"Ewe": Ewe,
"I": I,
"Q": Q / 3.6,
"cycle-number": np.arange(len(Qd)),
"cycle-index": np.array(cycle_idx),
"cn": np.arange(len(Qd)),
"Q": cumtrapz(I, t, axis=0, initial=0) / 3.6,
"Qd": np.array(Qd) / 3.6,
"Qc": np.array(Qc) / 3.6,
"Qc": np.array(Qc) / 3.6, # [mAh]
"Qd": np.array(Qd) / 3.6, # [mAh]
"Ec": np.array(Ec) / 3600, # [Wh]
"Ed": np.array(Ed) / 3600, # [Wh]
}

0 comments on commit 5587848

Please sign in to comment.