Skip to content

Commit cf43cfd

Browse files
rtimmsSaransh-cpp
authored andcommitted
#3630 fix interpolant shape error (#3761)
* #3630 fix interpolant shape error * #3630 changelog
1 parent b84f7ad commit cf43cfd

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

CHANGELOG.md

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

1919
## Bug fixes
2020

21+
- Fixed a bug that lead to a `ShapeError` when specifying "Ambient temperature [K]" as an `Interpolant` with an isothermal model ([#3761](https://github.com/pybamm-team/PyBaMM/pull/3761))
2122
- Fixed a bug where if the first step(s) in a cycle are skipped then the cycle solution started from the model's initial conditions instead of from the last state of the previous cycle ([#3708](https://github.com/pybamm-team/PyBaMM/pull/3708))
2223
- Fixed a bug where the lumped thermal model conflates cell volume with electrode volume ([#3707](https://github.com/pybamm-team/PyBaMM/pull/3707))
2324
- Reverted a change to the coupled degradation example notebook that caused it to be unstable for large numbers of cycles ([#3691](https://github.com/pybamm-team/PyBaMM/pull/3691))

pybamm/models/submodels/thermal/isothermal.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@ def get_fundamental_variables(self):
2626
# specified as a function of space (y, z) only and time
2727
y = pybamm.standard_spatial_vars.y
2828
z = pybamm.standard_spatial_vars.z
29-
T_x_av = self.param.T_amb(y, z, pybamm.t)
29+
# Broadcast t to be the same size as y and z (to catch cases where the ambient
30+
# temperature is a function of time only)
31+
t_broadcast = pybamm.PrimaryBroadcast(pybamm.t, "current collector")
32+
T_x_av = self.param.T_amb(y, z, t_broadcast)
33+
T_vol_av = self._yz_average(T_x_av)
3034

3135
T_dict = {
3236
"negative current collector": T_x_av,
3337
"positive current collector": T_x_av,
3438
"x-averaged cell": T_x_av,
35-
"volume-averaged cell": T_x_av,
39+
"volume-averaged cell": T_vol_av,
3640
}
3741
for domain in ["negative electrode", "separator", "positive electrode"]:
3842
T_dict[domain] = pybamm.PrimaryBroadcast(T_x_av, domain)
@@ -50,15 +54,25 @@ def get_coupled_variables(self, variables):
5054
"Ohmic heating [W.m-3]",
5155
"X-averaged Ohmic heating [W.m-3]",
5256
"Volume-averaged Ohmic heating [W.m-3]",
57+
"Ohmic heating per unit electrode-pair area [W.m-2]",
58+
"Ohmic heating [W]",
5359
"Irreversible electrochemical heating [W.m-3]",
5460
"X-averaged irreversible electrochemical heating [W.m-3]",
5561
"Volume-averaged irreversible electrochemical heating [W.m-3]",
62+
"Irreversible electrochemical heating per unit electrode-pair area [W.m-2]",
63+
"Irreversible electrochemical heating [W]",
5664
"Reversible heating [W.m-3]",
5765
"X-averaged reversible heating [W.m-3]",
5866
"Volume-averaged reversible heating [W.m-3]",
67+
"Reversible heating per unit electrode-pair area [W.m-2]",
68+
"Reversible heating [W]",
5969
"Total heating [W.m-3]",
6070
"X-averaged total heating [W.m-3]",
6171
"Volume-averaged total heating [W.m-3]",
72+
"Total heating per unit electrode-pair area [W.m-2]",
73+
"Total heating [W]",
74+
"Negative current collector Ohmic heating [W.m-3]",
75+
"Positive current collector Ohmic heating [W.m-3]",
6276
]:
6377
# All variables are zero
6478
variables.update({var: zero})

tests/integration/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,25 @@ def test_basic_processing_msmr(self):
347347
model = self.model(options)
348348
modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
349349
modeltest.test_all(skip_output_tests=True)
350+
351+
def test_basic_processing_temperature_interpolant(self):
352+
times = np.arange(0, 4000, 10)
353+
tmax = max(times)
354+
355+
def temp_drive_cycle(y, z, t):
356+
return pybamm.Interpolant(
357+
times,
358+
298.15 + 20 * (times / tmax),
359+
t,
360+
)
361+
362+
parameter_values = pybamm.ParameterValues("Chen2020")
363+
parameter_values.update(
364+
{
365+
"Initial temperature [K]": 298.15,
366+
"Ambient temperature [K]": temp_drive_cycle,
367+
}
368+
)
369+
model = self.model()
370+
modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
371+
modeltest.test_all(skip_output_tests=True)

0 commit comments

Comments
 (0)