Skip to content

Commit bb4b654

Browse files
rtimmsBradyPlanden
andauthored
Use T_init in initial_state (#5189)
* use T_init in initial_state * changelog * Update src/pybamm/models/full_battery_models/lithium_ion/electrode_soh_composite.py Co-authored-by: Brady Planden <[email protected]> --------- Co-authored-by: Brady Planden <[email protected]>
1 parent e3830d6 commit bb4b654

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
## Bug fixes
1111

12+
- Fix a bug in setting initial stoichiometries where the reference temperature was used instead of the initial temperature. ([#5189](https://github.com/pybamm-team/PyBaMM/pull/5189))
1213
- Fix a bug in the calculation of "Bulk" OCP terms in hysteresis models ([#5169](https://github.com/pybamm-team/PyBaMM/pull/5169))
1314
- Fixed a bug where the final duration of a drive cycle would not be inferred correctly. ([#5153](https://github.com/pybamm-team/PyBaMM/pull/5153))
1415

src/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -711,21 +711,21 @@ def get_initial_stoichiometries(self, initial_value, tol=1e-6, inputs=None):
711711
soc = pybamm.Variable("soc")
712712
x = x_0 + soc * (x_100 - x_0)
713713
y = y_0 - soc * (y_0 - y_100)
714-
T_ref = parameter_values["Reference temperature [K]"]
714+
T_init = parameter_values["Initial temperature [K]"]
715715
if self.options["open-circuit potential"] == "MSMR":
716716
xn = self.param.n.prim.x
717717
xp = self.param.p.prim.x
718718
Up = pybamm.Variable("Up")
719719
Un = pybamm.Variable("Un")
720-
soc_model.algebraic[Up] = x - xn(Un, T_ref)
721-
soc_model.algebraic[Un] = y - xp(Up, T_ref)
720+
soc_model.algebraic[Up] = x - xn(Un, T_init)
721+
soc_model.algebraic[Un] = y - xp(Up, T_init)
722722
soc_model.initial_conditions[Un] = 0
723723
soc_model.initial_conditions[Up] = V_max
724724
soc_model.algebraic[soc] = Up - Un - V_init
725725
else:
726726
Up = self.param.p.prim.U
727727
Un = self.param.n.prim.U
728-
soc_model.algebraic[soc] = Up(y, T_ref) - Un(x, T_ref) - V_init
728+
soc_model.algebraic[soc] = Up(y, T_init) - Un(x, T_init) - V_init
729729
# initial guess for soc linearly interpolates between 0 and 1
730730
# based on V linearly interpolating between V_max and V_min
731731
soc_model.initial_conditions[soc] = (V_init - V_min) / (V_max - V_min)
@@ -821,9 +821,13 @@ def get_initial_ocps(self, initial_value, tol=1e-6, inputs=None):
821821
Un = sol["Un"].data[0]
822822
Up = sol["Up"].data[0]
823823
else:
824-
T_ref = parameter_values["Reference temperature [K]"]
825-
Un = parameter_values.evaluate(self.param.n.prim.U(x, T_ref), inputs=inputs)
826-
Up = parameter_values.evaluate(self.param.p.prim.U(y, T_ref), inputs=inputs)
824+
T_init = parameter_values["Initial temperature [K]"]
825+
Un = parameter_values.evaluate(
826+
self.param.n.prim.U(x, T_init), inputs=inputs
827+
)
828+
Up = parameter_values.evaluate(
829+
self.param.p.prim.U(y, T_init), inputs=inputs
830+
)
827831
return Un, Up
828832

829833
def get_min_max_ocps(self, inputs=None):

src/pybamm/models/full_battery_models/lithium_ion/electrode_soh_composite.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ def __init__(
130130
y_0_1 = variables["y_0_1"]
131131
V_max = param.voltage_high_cut
132132
V_min = param.voltage_low_cut
133+
# Here we use T_ref as the stoichiometry limits are defined using the reference
134+
# state
133135
if is_negative_composite:
134136
x_100_2 = variables["x_100_2"]
135137
x_0_2 = variables["x_0_2"]
@@ -167,10 +169,12 @@ def __init__(
167169
x_init_1 = variables["x_init_1"]
168170
y_init_1 = variables["y_init_1"]
169171
if initialization_method == "voltage":
172+
# Here we use T_init so that the initial voltage is correct, including the
173+
# contribution from the entropic change
170174
V_init = pybamm.InputParameter("V_init")
171175
self.algebraic[x_init_1] = (
172-
param.p.prim.U(y_init_1, param.T_ref)
173-
- param.n.prim.U(x_init_1, param.T_ref)
176+
param.p.prim.U(y_init_1, param.T_init)
177+
- param.n.prim.U(x_init_1, param.T_init)
174178
- V_init
175179
)
176180
self.algebraic[y_init_1] = (
@@ -198,17 +202,21 @@ def __init__(
198202
)
199203
else:
200204
raise ValueError("Invalid initialization method")
201-
# Add voltage equations for secondary phases (init)
205+
# Add voltage equations for secondary phases (init), we use T_ref if setting
206+
# based on SOC since the stoichiometry limits are defined using the reference
207+
# state, and T_init if setting based on voltage since the entropic change is
208+
# included in the voltage equation
209+
T = param.T_init if initialization_method == "voltage" else param.T_ref
202210
if is_positive_composite:
203211
y_init_2 = variables["y_init_2"]
204-
self.algebraic[y_init_2] = param.p.prim.U(
205-
y_init_1, param.T_ref
206-
) - param.p.sec.U(y_init_2, param.T_ref)
212+
self.algebraic[y_init_2] = param.p.prim.U(y_init_1, T) - param.p.sec.U(
213+
y_init_2, T
214+
)
207215
if is_negative_composite:
208216
x_init_2 = variables["x_init_2"]
209-
self.algebraic[x_init_2] = param.n.prim.U(
210-
x_init_1, param.T_ref
211-
) - param.n.sec.U(x_init_2, param.T_ref)
217+
self.algebraic[x_init_2] = param.n.prim.U(x_init_1, T) - param.n.sec.U(
218+
x_init_2, T
219+
)
212220

213221
self.variables.update(variables)
214222
if initialization_method == "SOC":

src/pybamm/models/full_battery_models/lithium_ion/electrode_soh_half_cell.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,17 @@ def get_initial_stoichiometry_half_cell(
145145
model = pybamm.BaseModel()
146146
x = pybamm.Variable("x")
147147
Up = param.p.prim.U
148-
T_ref = parameter_values["Reference temperature [K]"]
148+
T_init = parameter_values["Initial temperature [K]"]
149149
model.variables["x"] = x
150-
model.algebraic[x] = Up(x, T_ref) - V_init
150+
model.algebraic[x] = Up(x, T_init) - V_init
151151
# initial guess for x linearly interpolates between 0 and 1
152152
# based on V linearly interpolating between V_max and V_min
153153
soc_initial_guess = (V_init - V_min) / (V_max - V_min)
154154
model.initial_conditions[x] = 1 - soc_initial_guess
155155
if is_composite:
156156
Up_2 = param.p.sec.U
157157
x_2 = pybamm.Variable("x_2")
158-
model.algebraic[x_2] = Up_2(x_2, T_ref) - V_init
158+
model.algebraic[x_2] = Up_2(x_2, T_init) - V_init
159159
model.variables["x_2"] = x_2
160160
model.initial_conditions[x_2] = 1 - soc_initial_guess
161161

@@ -177,6 +177,7 @@ def get_initial_stoichiometry_half_cell(
177177
x_2 = pybamm.Variable("x_2")
178178
U_p = param.p.prim.U
179179
U_p_2 = param.p.sec.U
180+
# here we use T_ref and SOC 0 and 1 are defined using the reference state
180181
T_ref = parameter_values["Reference temperature [K]"]
181182
model.algebraic[x] = U_p(x, T_ref) - U_p_2(x_2, T_ref)
182183
model.initial_conditions[x] = x_0 + initial_value * (x_100 - x_0)

tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_electrode_soh.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ def _get_params_and_options(composite_electrode):
179179
"Secondary: Negative electrode OCP [V]": params[
180180
"Negative electrode OCP [V]"
181181
],
182+
"Primary: Negative electrode OCP entropic change [V.K-1]": params[
183+
"Negative electrode OCP entropic change [V.K-1]"
184+
],
185+
"Secondary: Negative electrode OCP entropic change [V.K-1]": params[
186+
"Negative electrode OCP entropic change [V.K-1]"
187+
],
182188
"Primary: Negative electrode active material volume fraction": 0.5,
183189
"Secondary: Negative electrode active material volume fraction": 0.5,
184190
"Primary: Maximum concentration in negative electrode [mol.m-3]": params[
@@ -206,6 +212,12 @@ def _get_params_and_options(composite_electrode):
206212
"Secondary: Positive electrode OCP [V]": params[
207213
"Positive electrode OCP [V]"
208214
],
215+
"Primary: Positive electrode OCP entropic change [V.K-1]": params[
216+
"Positive electrode OCP entropic change [V.K-1]"
217+
],
218+
"Secondary: Positive electrode OCP entropic change [V.K-1]": params[
219+
"Positive electrode OCP entropic change [V.K-1]"
220+
],
209221
"Primary: Positive electrode active material volume fraction": 0.5,
210222
"Secondary: Positive electrode active material volume fraction": 0.5,
211223
"Primary: Maximum concentration in positive electrode [mol.m-3]": params[

0 commit comments

Comments
 (0)