Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculation of Full Cell Open Circuit Voltage (OCV) for cells with Composite Negative Electrode #160

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ PyProBE is fully open source. For more information about its license, see [LICEN
<br />
<sub><b>Tom Holland</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/mohammedasher">
<img src="https://avatars.githubusercontent.com/u/168521559?v=4" width="100;" alt="mohammedasher"/>
<br />
<sub><b>Mohammed Asheruddin (Asher)</b></sub>
</a>
</td></tr>
</table>
<!-- readme: contributors -end -->
90 changes: 90 additions & 0 deletions pyprobe/analysis/base/degradation_mode_analysis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import scipy.interpolate as interp
import scipy.optimize as opt
from numpy.typing import NDArray
from scipy.interpolate import interp1d


def ocv_curve_fit(
Expand Down Expand Up @@ -142,6 +143,95 @@ def calc_full_cell_OCV(
return OCV


def calc_full_cell_OCV_composite(
SOC: NDArray[np.float64],
z_pe_lo: float,
z_pe_hi: float,
z_ne_lo: float,
z_ne_hi: float,
x_pe: NDArray[np.float64],
ocp_pe: NDArray[np.float64],
x_c1: NDArray[np.float64],
ocp_c1: NDArray[np.float64],
x_c2: NDArray[np.float64],
ocp_c2: NDArray[np.float64],
comp1_frac: float,
) -> NDArray[np.float64]:
"""Calculate the full cell OCV.

Args:
SOC (NDArray[np.float64]): The full cell SOC.
z_pe_lo (float): The cathode stoichiometry at the lowest cell SOC.
z_pe_hi (float): The cathode stoichiometry at the highest cell SOC.
z_ne_lo (float): The anode stoichiometry at the lowest cell SOC.
z_ne_hi (float): The anode stoichiometry at the highest cell SOC.
x_pe (NDArray[np.float64]): The cathode stoichiometry data.
ocp_pe (NDArray[np.float64]): The cathode OCP data.
x_c1 (NDArray[np.float64]): The anode component 1 stoichiometry data.
ocp_c1 (NDArray[np.float64]): The anode component 1 OCP data.
x_c2 (NDArray[np.float64]): The anode component 2 stoichiometry data.
ocp_c2 (NDArray[np.float64]): The anode component 2 OCP data.
comp1_frac (float): The fraction of the first anode component.

Returns:
NDArray[np.float64]: The full cell OCV.
"""
n_points = 10001

# Determine common voltage range for anode components
V_upper = min(ocp_c1.max(), ocp_c2.max())
V_lower = max(ocp_c1.min(), ocp_c2.min())

# Create a linearly spaced voltage series
ocp_composite = np.linspace(V_lower, V_upper, n_points)

# Filter valid indices for both components
valid_indices_c1 = (ocp_c1 >= V_lower) & (ocp_c1 <= V_upper)
valid_indices_c2 = (ocp_c2 >= V_lower) & (ocp_c2 <= V_upper)

# Create interpolating functions for the anode components
interp_c1 = interp1d(
ocp_c1[valid_indices_c1],
x_c1[valid_indices_c1] * comp1_frac,
bounds_error=False,
fill_value="extrapolate",
)
interp_c2 = interp1d(
ocp_c2[valid_indices_c2],
x_c2[valid_indices_c2] * (1 - comp1_frac),
bounds_error=False,
fill_value="extrapolate",
)

# Interpolate values for anode stoichiometry
x_c1_interp = interp_c1(ocp_composite)
x_c2_interp = interp_c2(ocp_composite)
x_composite = x_c1_interp + x_c2_interp

# Create linearly spaced values for stoichiometry
z_pe = np.linspace(z_pe_lo, z_pe_hi, n_points)
z_ne = np.linspace(z_ne_lo, z_ne_hi, n_points)
z_ne_clipped = np.clip(
z_ne, x_composite.min(), x_composite.max()
) # Measured NE cap. is within the composite cap. range

# Interpolate the OCP data
OCP_pe = interp1d(x_pe, ocp_pe, fill_value="extrapolate")(z_pe)
OCP_ne = interp1d(x_composite, ocp_composite, fill_value="extrapolate")(
z_ne_clipped
)

# Calculate the full cell OCV
OCV = OCP_pe - OCP_ne

# Interpolate the final OCV with the original SOC vector
cell_ocv = interp1d(
np.linspace(0, 1, n_points), OCV, bounds_error=False, fill_value="extrapolate"
)(SOC)

return SOC, cell_ocv


def calculate_dma_parameters(
cell_capacity: NDArray[np.float64],
pe_capacity: NDArray[np.float64],
Expand Down
51 changes: 51 additions & 0 deletions tests/analysis/test_dma.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,57 @@ def test_average_ocvs(BreakinCycles_fixture):
DMA.average_ocvs(input_data=break_in.charge(0))



def test_calc_full_cell_ocv_composite():
"""Test the composite_full_cell_ocv method."""
# Sample data
n_points = 10
params = [0.05, 0.01, 0.95, 0.9, 0.85]

# Create data arrays
z = np.linspace(0, 1, n_points)
x_c1, ocp_c1 = z, np.linspace(1.5, 0.05, n_points)
x_c2, ocp_c2 = z, np.linspace(2.3, 0.15, n_points)
x_pe, ocp_pe = z, np.linspace(4, 2, n_points)
cell_SOC = np.linspace(0, 1, n_points)

# Run the function
soc, y_pred = dma_functions.calc_full_cell_OCV_composite(
SOC=cell_SOC,
z_pe_lo=params[0],
z_pe_hi=params[2],
z_ne_lo=params[1],
z_ne_hi=params[3],
x_pe=x_pe,
ocp_pe=ocp_pe,
x_c1=x_c1,
ocp_c1=ocp_c1,
x_c2=x_c2,
ocp_c2=ocp_c2,
comp1_frac=params[4],
)

# Expected outcomes
expected_soc = np.linspace(0, 1, n_points)
expected_y_pred = np.array(
[
2.4,
2.28091008,
2.23166123,
2.18241239,
2.13316354,
2.0839147,
2.03466585,
1.98541701,
1.93616816,
1.88691932,
]
)

# Assertions
np.testing.assert_array_almost_equal(soc, expected_soc, decimal=8)
np.testing.assert_array_almost_equal(y_pred, expected_y_pred, decimal=8)

def test_downsample_ocv():
"""Test the downsample_ocv method."""
times = np.linspace(0, 100, 101)
Expand Down