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

Crossover and degradation checks #21

Merged
merged 4 commits into from
Jan 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
8 changes: 7 additions & 1 deletion src/rfbzero/experiment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Classes to define electrochemical cycling protocols.
"""

import copy
from abc import ABC, abstractmethod
from enum import Enum
from typing import Callable, Optional
Expand Down Expand Up @@ -524,13 +524,19 @@ def _validate_protocol(
if cell_model.init_ocv > 0.0 > self.voltage_limit_discharge:
raise ValueError("Ensure that 'voltage_limit_discharge' >= 0.0 when 'init_ocv' > 0.0")

if crossover and cell_model.init_ocv > 0.0:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, and passes new tests

raise ValueError("Cannot use crossover mechanism for a full cell ('init_ocv' > 0.0)")

if degradation is not None and (cls_degradation is not None or ncls_degradation is not None):
raise ValueError("Cannot specify both 'degradation' and '(n)cls_degradation'")

if degradation is not None:
cls_degradation = degradation
ncls_degradation = degradation

cls_degradation = copy.deepcopy(cls_degradation)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, but do we want a small comment here explaining why we use a deepcopy?

ncls_degradation = copy.deepcopy(ncls_degradation)

if cell_model.negative_concentrations():
raise ValueError('Negative concentration detected')

Expand Down
56 changes: 47 additions & 9 deletions tests/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,54 @@ def test_cv1(self):

class TestConstantCurrentConstantVoltage:

def test_cccv(self):
# define the battery design parameters
def test_cccv_full_cell(self):
with pytest.raises(ValueError):
cell = ZeroDModel(cls_volume=0.005, # L
ncls_volume=0.03, # L
cls_start_c_ox=0.01, # M
cls_start_c_red=0.01, # M
ncls_start_c_ox=0.01, # M
ncls_start_c_red=0.01, # M
init_ocv=1.1, # V
resistance=0.8, # ohms
k_0_cls=1e-3, # cm/s
k_0_ncls=1e-3, # cm/s
n_cls=1, # electrons
n_ncls=1, # electrons
)

# define degradation mechanisms
deg1 = ChemicalDegradation(rate_order=2, rate_constant=5e-5, species='red')

deg2 = AutoOxidation(rate_constant=1e-4)

# define crossover mechanisms
cross = Crossover(membrane_thickness=183, permeability_ox=5e-6, permeability_red=2e-6)

# define cycling protocol
protocol = ConstantCurrentConstantVoltage(
voltage_limit_charge=1.45,
voltage_limit_discharge=0.8,
current_cutoff_charge=0.005,
current_cutoff_discharge=-0.005,
current=0.1
)

# putting it all together
all_results = protocol.run(cell_model=cell,
duration=1000, # cycle time to simulate (s)
degradation=MultiDegradationMechanism([deg1, deg2]),
crossover=cross,
)

def test_cccv_symmetric_cell(self):
cell = ZeroDModel(cls_volume=0.005, # L
ncls_volume=0.03, # L
cls_start_c_ox=0.01, # M
cls_start_c_red=0.01, # M
ncls_start_c_ox=0.01, # M
ncls_start_c_red=0.01, # M
init_ocv=1.1, # V
init_ocv=0.0, # V
resistance=0.8, # ohms
k_0_cls=1e-3, # cm/s
k_0_ncls=1e-3, # cm/s
Expand All @@ -133,11 +172,11 @@ def test_cccv(self):

# define cycling protocol
protocol = ConstantCurrentConstantVoltage(
voltage_limit_charge=1.45,
voltage_limit_discharge=0.8,
voltage_limit_charge=0.25,
voltage_limit_discharge=-0.2,
current_cutoff_charge=0.005,
current_cutoff_discharge=-0.005,
current=0.1
current=0.12
)

# putting it all together
Expand All @@ -146,10 +185,9 @@ def test_cccv(self):
degradation=MultiDegradationMechanism([deg1, deg2]),
crossover=cross,
)
expected = [4.898116190603088, 9.622472024194355, 9.719800105349496, 9.622272591351388, 9.725092303584894]

expected = [4.887409109362002, 9.616027334885318, 9.695579899478137, 9.614489292146322, 9.69754666694821]
vals = all_results.half_cycle_capacity[:5]
assert np.isclose(vals, expected).all()