Skip to content

Commit 5957a80

Browse files
#933 remove reactions dict
1 parent 2181a54 commit 5957a80

34 files changed

+239
-240
lines changed

examples/scripts/compare_lead_acid.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
# load parameter values and process models and geometry
2727
param = models[0].default_parameter_values
28-
param.update({"Current function [A]": 85, "Initial State of Charge": 1})
28+
param.update({"Current function [A]": 17, "Initial State of Charge": 1})
2929
for model in models:
3030
param.process_model(model)
3131

pybamm/models/full_battery_models/base_battery_model.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,7 @@ def options(self, extra_options):
196196
):
197197
if len(options["side reactions"]) > 0:
198198
raise pybamm.OptionError(
199-
"""
200-
must use surface formulation to solve {!s} with side reactions
199+
"""must use surface formulation to solve {!s} with side reactions
201200
""".format(
202201
self
203202
)

pybamm/models/full_battery_models/lead_acid/base_lead_acid_model.py

-28
Original file line numberDiff line numberDiff line change
@@ -53,34 +53,6 @@ def default_solver(self):
5353
else:
5454
return pybamm.CasadiSolver(mode="safe")
5555

56-
def set_reactions(self):
57-
58-
# Should probably refactor as this is a bit clunky at the moment
59-
# Maybe each reaction as a Reaction class so we can just list names of classes
60-
param = self.param
61-
icd = " interfacial current density"
62-
self.reactions = {
63-
"main": {
64-
"Negative": {"s": -param.s_plus_n_S, "aj": "Negative electrode" + icd},
65-
"Positive": {"s": -param.s_plus_p_S, "aj": "Positive electrode" + icd},
66-
}
67-
}
68-
if "oxygen" in self.options["side reactions"]:
69-
self.reactions["oxygen"] = {
70-
"Negative": {
71-
"s": -param.s_plus_Ox,
72-
"s_ox": -param.s_ox_Ox,
73-
"aj": "Negative electrode oxygen" + icd,
74-
},
75-
"Positive": {
76-
"s": -param.s_plus_Ox,
77-
"s_ox": -param.s_ox_Ox,
78-
"aj": "Positive electrode oxygen" + icd,
79-
},
80-
}
81-
self.reactions["main"]["Negative"]["s_ox"] = 0
82-
self.reactions["main"]["Positive"]["s_ox"] = 0
83-
8456
def set_soc_variables(self):
8557
"Set variables relating to the state of charge."
8658
# State of Charge defined as function of dimensionless electrolyte concentration

pybamm/models/full_battery_models/lithium_ion/base_lithium_ion_model.py

+7-11
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,10 @@ def set_standard_output_variables(self):
3636
}
3737
)
3838

39-
def set_reactions(self):
40-
41-
# Should probably refactor as this is a bit clunky at the moment
42-
# Maybe each reaction as a Reaction class so we can just list names of classes
43-
icd = " interfacial current density"
44-
self.reactions = {
45-
"main": {
46-
"Negative": {"s": 1, "aj": "Negative electrode" + icd},
47-
"Positive": {"s": 1, "aj": "Positive electrode" + icd},
48-
}
49-
}
39+
def set_other_reaction_submodels_to_zero(self):
40+
self.submodels["negative oxygen interface"] = pybamm.interface.NoReaction(
41+
self.param, "Negative", "lithium-ion oxygen"
42+
)
43+
self.submodels["positive oxygen interface"] = pybamm.interface.NoReaction(
44+
self.param, "Positive", "lithium-ion oxygen"
45+
)

pybamm/models/full_battery_models/lithium_ion/dfn.py

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(self, options=None, name="Doyle-Fuller-Newman model", build=True):
3838
self.set_tortuosity_submodels()
3939
self.set_convection_submodel()
4040
self.set_interfacial_submodel()
41+
self.set_other_reaction_submodels_to_zero()
4142
self.set_particle_submodel()
4243
self.set_solid_submodel()
4344
self.set_electrolyte_submodel()

pybamm/models/full_battery_models/lithium_ion/spm.py

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ def __init__(self, options=None, name="Single Particle Model", build=True):
3737
self.set_tortuosity_submodels()
3838
self.set_convection_submodel()
3939
self.set_interfacial_submodel()
40+
self.set_other_reaction_submodels_to_zero()
4041
self.set_particle_submodel()
4142
self.set_negative_electrode_submodel()
4243
self.set_electrolyte_submodel()

pybamm/models/full_battery_models/lithium_ion/spme.py

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def __init__(
4040
self.set_tortuosity_submodels()
4141
self.set_convection_submodel()
4242
self.set_interfacial_submodel()
43+
self.set_other_reaction_submodels_to_zero()
4344
self.set_particle_submodel()
4445
self.set_negative_electrode_submodel()
4546
self.set_electrolyte_submodel()

pybamm/models/submodels/base_submodel.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,7 @@ class BaseSubModel:
4747
"""
4848

4949
def __init__(
50-
self,
51-
param,
52-
domain=None,
53-
reactions=None,
54-
name="Unnamed submodel",
55-
external=False,
50+
self, param, domain=None, name="Unnamed submodel", external=False,
5651
):
5752
super().__init__()
5853
self.param = param
@@ -67,7 +62,6 @@ def __init__(
6762

6863
self.domain = domain
6964
self.set_domain_for_broadcast()
70-
self.reactions = reactions
7165
self.name = name
7266

7367
self.external = external

pybamm/models/submodels/electrode/base_electrode.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class BaseElectrode(pybamm.BaseSubModel):
1919
**Extends:** :class:`pybamm.BaseSubModel`
2020
"""
2121

22-
def __init__(self, param, domain, reactions=None, set_positive_potential=True):
23-
super().__init__(param, domain, reactions)
22+
def __init__(self, param, domain, set_positive_potential=True):
23+
super().__init__(param, domain)
2424
self.set_positive_potential = set_positive_potential
2525

2626
def _get_standard_potential_variables(self, phi_s):
@@ -190,4 +190,3 @@ def _get_standard_whole_cell_variables(self, variables):
190190
)
191191

192192
return variables
193-

pybamm/models/submodels/electrode/ohm/base_ohm.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ class BaseModel(BaseElectrode):
2020
**Extends:** :class:`pybamm.electrode.BaseElectrode`
2121
"""
2222

23-
def __init__(self, param, domain, reactions=None, set_positive_potential=True):
24-
super().__init__(param, domain, reactions, set_positive_potential)
23+
def __init__(self, param, domain, set_positive_potential=True):
24+
super().__init__(param, domain, set_positive_potential)
2525

2626
def set_boundary_conditions(self, variables):
2727

pybamm/models/submodels/electrode/ohm/full_ohm.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class Full(BaseModel):
1919
**Extends:** :class:`pybamm.electrode.ohm.BaseModel`
2020
"""
2121

22-
def __init__(self, param, domain, reactions):
23-
super().__init__(param, domain, reactions)
22+
def __init__(self, param, domain):
23+
super().__init__(param, domain)
2424

2525
def get_fundamental_variables(self):
2626

@@ -59,10 +59,12 @@ def set_algebraic(self, variables):
5959

6060
phi_s = variables[self.domain + " electrode potential"]
6161
i_s = variables[self.domain + " electrode current density"]
62-
sum_j = sum(
63-
variables[reaction[self.domain]["aj"]]
64-
for reaction in self.reactions.values()
65-
)
62+
63+
# All possible reactions. Some of these could be zero
64+
j = variables[self.domain + " electrode interfacial current density"]
65+
j_ox = variables[self.domain + " electrode oxygen interfacial current density"]
66+
67+
sum_j = j + j_ox
6668

6769
self.algebraic[phi_s] = pybamm.div(i_s) + sum_j
6870

pybamm/models/submodels/electrolyte_conductivity/base_electrolyte_conductivity.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ class BaseElectrolyteConductivity(pybamm.BaseSubModel):
2020
**Extends:** :class:`pybamm.BaseSubModel`
2121
"""
2222

23-
def __init__(self, param, domain=None, reactions=None):
23+
def __init__(self, param, domain=None):
2424
super().__init__(param, domain)
25-
self.reactions = reactions
2625

2726
def _get_standard_potential_variables(self, phi_e_n, phi_e_s, phi_e_p):
2827
"""

pybamm/models/submodels/electrolyte_conductivity/full_conductivity.py

+8-10
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ class Full(BaseElectrolyteConductivity):
2121
**Extends:** :class:`pybamm.electrolyte_conductivity.BaseElectrolyteConductivity`
2222
"""
2323

24-
def __init__(self, param, reactions):
25-
super().__init__(param, reactions=reactions)
24+
def __init__(self, param):
25+
super().__init__(param)
2626

2727
def get_fundamental_variables(self):
2828
phi_e_n = pybamm.standard_variables.phi_e_n
@@ -51,14 +51,12 @@ def get_coupled_variables(self, variables):
5151
def set_algebraic(self, variables):
5252
phi_e = variables["Electrolyte potential"]
5353
i_e = variables["Electrolyte current density"]
54-
sum_j = sum(
55-
pybamm.Concatenation(
56-
variables[reaction["Negative"]["aj"]],
57-
pybamm.FullBroadcast(0, "separator", "current collector"),
58-
variables[reaction["Positive"]["aj"]],
59-
)
60-
for reaction in self.reactions.values()
61-
)
54+
55+
# All possible reactions. Some of these could be zero
56+
j = variables["Interfacial current density"]
57+
j_ox = variables["Oxygen interfacial current density"]
58+
59+
sum_j = j + j_ox
6260

6361
self.algebraic = {phi_e: pybamm.div(i_e) - sum_j}
6462

pybamm/models/submodels/electrolyte_conductivity/leading_order_conductivity.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class LeadingOrder(BaseElectrolyteConductivity):
2222
**Extends:** :class:`pybamm.electrolyte_conductivity.BaseElectrolyteConductivity`
2323
"""
2424

25-
def __init__(self, param, domain=None, reactions=None):
26-
super().__init__(param, domain, reactions)
25+
def __init__(self, param, domain=None):
26+
super().__init__(param, domain)
2727

2828
def get_coupled_variables(self, variables):
2929
ocp_n_av = variables["X-averaged negative electrode open circuit potential"]

pybamm/models/submodels/electrolyte_conductivity/surface_potential_form/full_surface_form_conductivity.py

+18-14
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class BaseModel(BaseElectrolyteConductivity):
2222
**Extends:** :class:`pybamm.electrolyte_conductivity.BaseElectrolyteConductivity`
2323
"""
2424

25-
def __init__(self, param, domain, reactions):
26-
super().__init__(param, domain, reactions)
25+
def __init__(self, param, domain):
26+
super().__init__(param, domain)
2727

2828
def get_fundamental_variables(self):
2929
if self.domain == "Negative":
@@ -222,19 +222,21 @@ class FullAlgebraic(BaseModel):
222222
**Extends:** :class:`pybamm.electrolyte_conductivity.surface_potential_form.BaseFull`
223223
""" # noqa: E501
224224

225-
def __init__(self, param, domain, reactions):
226-
super().__init__(param, domain, reactions)
225+
def __init__(self, param, domain):
226+
super().__init__(param, domain)
227227

228228
def set_algebraic(self, variables):
229229
if self.domain == "Separator":
230230
return
231231

232232
delta_phi = variables[self.domain + " electrode surface potential difference"]
233233
i_e = variables[self.domain + " electrolyte current density"]
234-
sum_j = sum(
235-
variables[reaction[self.domain]["aj"]]
236-
for reaction in self.reactions.values()
237-
)
234+
235+
# All possible reactions. Some of these could be zero
236+
j = variables[self.domain + " electrode interfacial current density"]
237+
j_ox = variables[self.domain + " electrode oxygen interfacial current density"]
238+
239+
sum_j = j + j_ox
238240
self.algebraic[delta_phi] = pybamm.div(i_e) - sum_j
239241

240242

@@ -253,8 +255,8 @@ class FullDifferential(BaseModel):
253255
254256
""" # noqa: E501
255257

256-
def __init__(self, param, domain, reactions):
257-
super().__init__(param, domain, reactions)
258+
def __init__(self, param, domain):
259+
super().__init__(param, domain)
258260

259261
def set_rhs(self, variables):
260262
if self.domain == "Separator":
@@ -267,9 +269,11 @@ def set_rhs(self, variables):
267269

268270
delta_phi = variables[self.domain + " electrode surface potential difference"]
269271
i_e = variables[self.domain + " electrolyte current density"]
270-
sum_j = sum(
271-
variables[reaction[self.domain]["aj"]]
272-
for reaction in self.reactions.values()
273-
)
272+
273+
# All possible reactions. Some of these could be zero
274+
j = variables[self.domain + " electrode interfacial current density"]
275+
j_ox = variables[self.domain + " electrode oxygen interfacial current density"]
276+
277+
sum_j = j + j_ox
274278

275279
self.rhs[delta_phi] = 1 / C_dl * (pybamm.div(i_e) - sum_j)

pybamm/models/submodels/electrolyte_conductivity/surface_potential_form/leading_surface_form_conductivity.py

+32-14
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ class BaseLeadingOrderSurfaceForm(LeadingOrder):
2323
**Extends:** :class:`pybamm.electrolyte_conductivity.LeadingOrder`
2424
"""
2525

26-
def __init__(self, param, domain, reactions):
27-
super().__init__(param, domain, reactions)
26+
def __init__(self, param, domain):
27+
super().__init__(param, domain)
2828

2929
def get_fundamental_variables(self):
3030

@@ -94,19 +94,28 @@ class LeadingOrderDifferential(BaseLeadingOrderSurfaceForm):
9494
9595
"""
9696

97-
def __init__(self, param, domain, reactions):
98-
super().__init__(param, domain, reactions)
97+
def __init__(self, param, domain):
98+
super().__init__(param, domain)
9999

100100
def set_rhs(self, variables):
101101
if self.domain == "Separator":
102102
return
103103

104104
param = self.param
105105

106-
sum_j = sum(
107-
variables["X-averaged " + reaction[self.domain]["aj"].lower()]
108-
for reaction in self.reactions.values()
109-
)
106+
# All possible reactions. Some of these could be zero
107+
j = variables[
108+
"X-averaged "
109+
+ self.domain.lower()
110+
+ " electrode interfacial current density"
111+
]
112+
j_ox = variables[
113+
"X-averaged "
114+
+ self.domain.lower()
115+
+ " electrode oxygen interfacial current density"
116+
]
117+
118+
sum_j = j + j_ox
110119

111120
sum_j_av = variables[
112121
"X-averaged "
@@ -141,17 +150,26 @@ class LeadingOrderAlgebraic(BaseLeadingOrderSurfaceForm):
141150
**Extends:** :class:`BaseLeadingOrderSurfaceForm`
142151
"""
143152

144-
def __init__(self, param, domain, reactions):
145-
super().__init__(param, domain, reactions)
153+
def __init__(self, param, domain):
154+
super().__init__(param, domain)
146155

147156
def set_algebraic(self, variables):
148157
if self.domain == "Separator":
149158
return
150159

151-
sum_j = sum(
152-
variables["X-averaged " + reaction[self.domain]["aj"].lower()]
153-
for reaction in self.reactions.values()
154-
)
160+
# All possible reactions. Some of these could be zero
161+
j = variables[
162+
"X-averaged "
163+
+ self.domain.lower()
164+
+ " electrode interfacial current density"
165+
]
166+
j_ox = variables[
167+
"X-averaged "
168+
+ self.domain.lower()
169+
+ " electrode oxygen interfacial current density"
170+
]
171+
172+
sum_j = j + j_ox
155173

156174
sum_j_av = variables[
157175
"X-averaged "

pybamm/models/submodels/electrolyte_diffusion/base_electrolyte_diffusion.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class BaseElectrolyteDiffusion(pybamm.BaseSubModel):
1717
**Extends:** :class:`pybamm.BaseSubModel`
1818
"""
1919

20-
def __init__(self, param, reactions=None):
21-
super().__init__(param, reactions=reactions)
20+
def __init__(self, param):
21+
super().__init__(param)
2222

2323
def _get_standard_concentration_variables(self, c_e_n, c_e_s, c_e_p):
2424
"""

0 commit comments

Comments
 (0)