Skip to content
Closed
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
1 change: 0 additions & 1 deletion docs/source/api/parameters/parameter_sets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ For an example, see the `Marquis2019`_ parameter sets.
def get_parameter_values():
"""Doc string for cell-alpha"""
return {
"chemistry": "lithium_ion",
"citation": "@book{van1995python, title={Python reference manual}}",
# ...
}
Expand Down

Large diffs are not rendered by default.

4 changes: 1 addition & 3 deletions examples/scripts/print_model_parameter_combinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import pybamm

all_options = pybamm.BatteryModelOptions({}).possible_options
all_parameter_sets = [
k for k, v in pybamm.parameter_sets.items() if v["chemistry"] == "lithium_ion"
]
all_parameter_sets = [k for k, v in pybamm.parameter_sets.items()]

for option_name, option_list in all_options.items():
for parameter_set in all_parameter_sets:
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/ecm/example_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ def get_parameter_values():
cell_capacity = 100

values = {
"chemistry": "ecm",
"Initial SoC": 0.5,
"Initial temperature [K]": 25 + 273.15,
"Cell capacity [A.h]": cell_capacity,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lead_acid/Sulzer2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lead_acid",
# cell
"Negative current collector thickness [m]": 0.0,
"Negative electrode thickness [m]": 0.0009,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Ai2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Ratio of lithium moles to SEI moles": 2.0,
"SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Chen2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Ratio of lithium moles to SEI moles": 2.0,
"SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Primary: Ratio of lithium moles to SEI moles": 2.0,
"Primary: SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Ecker2015.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# lithium plating
"Lithium metal partial molar volume [m3.mol-1]": 1.3e-05,
"Lithium plating kinetic rate constant [m.s-1]": 1e-10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# lithium plating
"Lithium plating kinetic rate constant [m.s-1]": 1e-10,
"Exchange-current density for plating [A.m-2]"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def get_parameter_values():
experimental cycling data.
"""
return {
"chemistry": "lithium_ion",
# cell
"Negative electrode thickness [m]": 8.52e-05,
"Separator thickness [m]": 1.2e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Marquis2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Ratio of lithium moles to SEI moles": 2.0,
"SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Mohtat2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# lithium plating
"Lithium metal partial molar volume [m3.mol-1]": 1.3e-05,
"Exchange-current density for plating [A.m-2]": 0.001,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Ratio of lithium moles to SEI moles": 2.0,
"SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/OKane2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# lithium plating
"Lithium metal partial molar volume [m3.mol-1]": 1.3e-05,
"Lithium plating kinetic rate constant [m.s-1]": 1e-09,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# lithium plating
"Lithium metal partial molar volume [m3.mol-1]": 1.3e-05,
"Lithium plating kinetic rate constant [m.s-1]": 1e-09,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/ORegan2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# cell
"Negative current collector thickness [m]": 1.2e-05,
"Negative electrode thickness [m]": 8.52e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Prada2013.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# cell
"Negative electrode thickness [m]": 3.4e-05,
"Separator thickness [m]": 2.5e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Ramadass2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Ratio of lithium moles to SEI moles": 2.0,
"SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/lithium_ion/Xu2019.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def get_parameter_values():
"""

return {
"chemistry": "lithium_ion",
# sei
"Ratio of lithium moles to SEI moles": 2.0,
"SEI partial molar volume [m3.mol-1]": 9.585e-05,
Expand Down
1 change: 0 additions & 1 deletion src/pybamm/input/parameters/sodium_ion/Chayambuka2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ def get_parameter_values():
"""

return {
"chemistry": "sodium_ion",
# cell
"Negative electrode thickness [m]": 64e-6,
"Separator thickness [m]": 25e-6,
Expand Down
27 changes: 21 additions & 6 deletions src/pybamm/parameters/parameter_values.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class ParameterValues:
Explicit set of parameters, or reference to an inbuilt parameter set
If string and matches one of the inbuilt parameter sets, returns that parameter
set.
initial_state_function : function, optional
The function to use to set the initial state of the simulation. By default, set to
`pybamm.lithium_ion.set_initial_state`, except for the `ECM_Example` parameter set,
which is set to `pybamm.equivalent_circuit.set_initial_state`.

Examples
--------
Expand All @@ -38,7 +42,7 @@ class ParameterValues:

"""

def __init__(self, values):
def __init__(self, values, initial_state_function=None):
# add physical constants as default values
self._dict_items = pybamm.FuzzyDict(
{
Expand All @@ -52,10 +56,25 @@ def __init__(self, values):
if isinstance(values, dict | ParameterValues):
# remove the "chemistry" key if it exists
chemistry = values.pop("chemistry", None)
if chemistry == "ecm" and initial_state_function is None:
warn(
"The chemistry key is no longer supported. Please use the initial_state_function parameter.",
stacklevel=2,
)
initial_state_function = pybamm.equivalent_circuit.set_initial_state
elif initial_state_function is None:
initial_state_function = pybamm.lithium_ion.set_initial_state
self.update(values, check_already_exists=False)
else:
# Check if values is a named parameter set
if isinstance(values, str) and values in pybamm.parameter_sets.keys():
if initial_state_function is None:
if values == "ECM_Example":
initial_state_function = (
pybamm.equivalent_circuit.set_initial_state
)
else:
initial_state_function = pybamm.lithium_ion.set_initial_state
values = pybamm.parameter_sets[values]
chemistry = values.pop("chemistry", None)
self.update(values, check_already_exists=False)
Expand All @@ -64,11 +83,7 @@ def __init__(self, values):
raise ValueError(
f"'{values}' is not a valid parameter set. Parameter set must be one of:\n{valid_sets}"
)

if chemistry == "ecm":
self._set_initial_state = pybamm.equivalent_circuit.set_initial_state
else:
self._set_initial_state = pybamm.lithium_ion.set_initial_state
self._set_initial_state = initial_state_function

# Initialise empty _processed_symbols dict (for caching)
self._processed_symbols = {}
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/test_parameters/test_base_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ def test_getattr__(self):
assert param.n.cap_init == param.n.Q_init
assert param.p.prim.cap_init == param.p.prim.Q_init

def test_that_initial_state_function_is_assigned(self):
param_1 = pybamm.ParameterValues("Chen2020")
assert param_1._set_initial_state == pybamm.lithium_ion.set_initial_state

def my_func(x):
return x

param_1 = pybamm.ParameterValues(param_1, initial_state_function=my_func)
assert param_1._set_initial_state == my_func

param_2 = pybamm.ParameterValues("ECM_Example")
assert param_2._set_initial_state == pybamm.equivalent_circuit.set_initial_state

def my_error_func(*args, **kwargs):
raise NotImplementedError("this function should error")

param_1 = pybamm.ParameterValues(param_1, initial_state_function=my_error_func)
model = pybamm.lithium_ion.SPM()
sim = pybamm.Simulation(model, parameter_values=param_1)
with pytest.raises(NotImplementedError, match="this function should error"):
sim.solve([0, 1], initial_soc=0.5)

def test__setattr__(self):
# domain gets added as a subscript
param = pybamm.GeometricParameters()
Expand Down
Loading