Skip to content

Commit 5f3bd18

Browse files
#492 clean up setting external variables for potentials
1 parent f113293 commit 5f3bd18

File tree

5 files changed

+16
-91
lines changed

5 files changed

+16
-91
lines changed

pybamm/models/submodels/current_collector/base_current_collector.py

-45
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,6 @@ class BaseModel(pybamm.BaseSubModel):
1919
def __init__(self, param):
2020
super().__init__(param)
2121

22-
def get_coupled_variables(self, variables):
23-
24-
# 1D models determine phi_s_cp
25-
phi_s_cn = variables["Negative current collector potential"]
26-
phi_s_cp = variables["Positive current collector potential"]
27-
28-
variables = self._get_standard_potential_variables(phi_s_cn, phi_s_cp)
29-
return variables
30-
3122
def _get_standard_negative_potential_variables(self, phi_s_cn):
3223
"""
3324
A private function to obtain the standard variables which
@@ -54,42 +45,6 @@ def _get_standard_negative_potential_variables(self, phi_s_cn):
5445

5546
return variables
5647

57-
def _get_standard_potential_variables(self, phi_s_cn, phi_s_cp):
58-
"""
59-
A private function to obtain the standard variables which
60-
can be derived from the potentials in the current collector.
61-
62-
Parameters
63-
----------
64-
phi_s_cn : :class:`pybamm.Symbol`
65-
The potential in the negative current collector.
66-
phi_s_cp : :class:`pybamm.Symbol`
67-
The potential in the positive current collector.
68-
69-
Returns
70-
-------
71-
variables : dict
72-
The variables which can be derived from the potential in the
73-
current collector.
74-
"""
75-
76-
pot_scale = self.param.potential_scale
77-
U_ref = self.param.U_p_ref - self.param.U_n_ref
78-
79-
# Local potential difference
80-
V_cc = phi_s_cp - phi_s_cn
81-
82-
variables = {
83-
"Positive current collector potential": phi_s_cp,
84-
"Positive current collector potential [V]": U_ref + phi_s_cp * pot_scale,
85-
"Local current collector potential difference": V_cc,
86-
"Local current collector potential difference [V]": U_ref
87-
+ V_cc * pot_scale,
88-
}
89-
variables.update(self._get_standard_negative_potential_variables(phi_s_cn))
90-
91-
return variables
92-
9348
def _get_standard_current_variables(self, i_cc, i_boundary_cc):
9449
"""
9550
A private function to obtain the standard variables which

pybamm/models/submodels/current_collector/set_potential_single_particle.py

+2-8
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ def __init__(self, param):
3232
def get_fundamental_variables(self):
3333

3434
phi_s_cn = pybamm.standard_variables.phi_s_cn
35-
phi_s_cp = pybamm.standard_variables.phi_s_cp
3635

37-
variables = self._get_standard_potential_variables(phi_s_cn, phi_s_cp)
36+
variables = self._get_standard_negative_potential_variables(phi_s_cn)
3837

3938
# TO DO: grad not implemented for 2D yet
4039
i_cc = pybamm.Scalar(0)
@@ -53,11 +52,10 @@ def get_fundamental_variables(self):
5352

5453
def set_rhs(self, variables):
5554
phi_s_cn = variables["Negative current collector potential"]
56-
phi_s_cp = variables["Positive current collector potential"]
5755

5856
# Dummy equations so that PyBaMM doesn't change the potentials during solve
5957
# i.e. d_phi/d_t = 0. Potentials are set externally between steps.
60-
self.rhs = {phi_s_cn: pybamm.Scalar(0), phi_s_cp: pybamm.Scalar(0)}
58+
self.rhs = {phi_s_cn: pybamm.Scalar(0)}
6159

6260
def set_algebraic(self, variables):
6361
ocp_p_av = variables["X-averaged positive electrode open circuit potential"]
@@ -84,17 +82,13 @@ def set_algebraic(self, variables):
8482

8583
def set_initial_conditions(self, variables):
8684

87-
param = self.param
8885
applied_current = variables["Total current density"]
8986
cc_area = self._get_effective_current_collector_area()
9087
phi_s_cn = variables["Negative current collector potential"]
91-
phi_s_cp = variables["Positive current collector potential"]
9288
i_boundary_cc = variables["Current collector current density"]
9389

9490
self.initial_conditions = {
9591
phi_s_cn: pybamm.Scalar(0),
96-
phi_s_cp: param.U_p(param.c_p_init, param.T_init)
97-
- param.U_n(param.c_n_init, param.T_init),
9892
i_boundary_cc: applied_current / cc_area,
9993
}
10094

pybamm/models/submodels/electrode/base_electrode.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,18 @@ def _get_standard_current_collector_potential_variables(self, phi_s_cn, phi_s_cp
126126

127127
pot_scale = self.param.potential_scale
128128
U_ref = self.param.U_p_ref - self.param.U_n_ref
129+
phi_s_cp_dim = U_ref + phi_s_cp * pot_scale
129130

130131
# Local potential difference
131132
V_cc = phi_s_cp - phi_s_cn
132133

133-
# terminal voltage (Note: phi_s_cn is zero at the negative tab)
134+
# Terminal voltage
135+
# Note phi_s_cn is always zero at the negative tab
136+
V = pybamm.boundary_value(phi_s_cp, "positive tab")
137+
V_dim = pybamm.boundary_value(phi_s_cp_dim, "positive tab")
138+
134139
# Voltage is local current collector potential difference at the tabs, in 1D
135140
# this will be equal to the local current collector potential difference
136-
phi_s_cp_dim = U_ref + phi_s_cp * pot_scale
137141

138142
variables = {
139143
"Negative current collector potential": phi_s_cn,
@@ -142,6 +146,8 @@ def _get_standard_current_collector_potential_variables(self, phi_s_cn, phi_s_cp
142146
"Positive current collector potential [V]": phi_s_cp_dim,
143147
"Local voltage": V_cc,
144148
"Local voltage [V]": U_ref + V_cc * pot_scale,
149+
"Terminal voltage": V,
150+
"Terminal voltage [V]": V_dim,
145151
}
146152

147153
return variables
@@ -170,18 +176,13 @@ def _get_standard_whole_cell_variables(self, variables):
170176
i_s = pybamm.Concatenation(i_s_n, i_s_s, i_s_p)
171177

172178
variables.update({"Electrode current density": i_s})
179+
173180
if self.set_positive_potential:
174-
# don't overwrite current collector potentials
175-
try:
176-
phi_s_cn = variables["Negative current collector potential"]
177-
except KeyError:
178-
phi_s_n = variables["Negative electrode potential"]
179-
phi_s_cn = pybamm.boundary_value(phi_s_n, "left")
180-
try:
181-
phi_s_cp = variables["Positive current collector potential"]
182-
except KeyError:
183-
phi_s_p = variables["Positive electrode potential"]
184-
phi_s_cp = pybamm.boundary_value(phi_s_p, "right")
181+
# Get phi_s_cn from the current collector submodel and phi_s_p from the
182+
# electrode submodel
183+
phi_s_cn = variables["Negative current collector potential"]
184+
phi_s_p = variables["Positive electrode potential"]
185+
phi_s_cp = pybamm.boundary_value(phi_s_p, "right")
185186
variables.update(
186187
self._get_standard_current_collector_potential_variables(
187188
phi_s_cn, phi_s_cp

pybamm/models/submodels/external_circuit/current_control_external_circuit.py

-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#
22
# External circuit with current control
33
#
4-
import pybamm
54
from .base_external_circuit import BaseModel, LeadingOrderBaseModel
65

76

@@ -29,18 +28,6 @@ def get_fundamental_variables(self):
2928

3029
return variables
3130

32-
def get_coupled_variables(self, variables):
33-
# Update terminal voltage
34-
phi_s_cp_dim = variables["Positive current collector potential [V]"]
35-
phi_s_cp = variables["Positive current collector potential"]
36-
37-
V = pybamm.boundary_value(phi_s_cp, "positive tab")
38-
V_dim = pybamm.boundary_value(phi_s_cp_dim, "positive tab")
39-
variables["Terminal voltage"] = V
40-
variables["Terminal voltage [V]"] = V_dim
41-
42-
return variables
43-
4431

4532
class LeadingOrderCurrentControl(CurrentControl, LeadingOrderBaseModel):
4633
"""External circuit with current control, for leading order models. """

pybamm/models/submodels/external_circuit/function_control_external_circuit.py

-12
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,6 @@ def get_fundamental_variables(self):
3030

3131
return variables
3232

33-
def get_coupled_variables(self, variables):
34-
# Update terminal voltage
35-
phi_s_cp_dim = variables["Positive current collector potential [V]"]
36-
phi_s_cp = variables["Positive current collector potential"]
37-
38-
V = pybamm.boundary_value(phi_s_cp, "positive tab")
39-
V_dim = pybamm.boundary_value(phi_s_cp_dim, "positive tab")
40-
variables["Terminal voltage"] = V
41-
variables["Terminal voltage [V]"] = V_dim
42-
43-
return variables
44-
4533
def set_initial_conditions(self, variables):
4634
super().set_initial_conditions(variables)
4735
# Initial condition as a guess for consistent initial conditions

0 commit comments

Comments
 (0)