Skip to content

Commit

Permalink
pybamm-team#3630 fix interpolant shape error (pybamm-team#3761)
Browse files Browse the repository at this point in the history
* pybamm-team#3630 fix interpolant shape error

* pybamm-team#3630 changelog
  • Loading branch information
rtimms authored and js1tr3 committed Aug 12, 2024
1 parent fd1983d commit 8530f49
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Added a `get_parameter_info` method for models and modified "print_parameter_info" functionality to extract all parameters and their type in a tabular and readable format ([#3361](https://github.com/pybamm-team/PyBaMM/pull/3584))
## Bug fixes

- 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))
- 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))
- Fixed a bug where the lumped thermal model conflates cell volume with electrode volume ([#3707](https://github.com/pybamm-team/PyBaMM/pull/3707))
- 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))
Expand Down
18 changes: 16 additions & 2 deletions pybamm/models/submodels/thermal/isothermal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ def get_fundamental_variables(self):
# specified as a function of space (y, z) only and time
y = pybamm.standard_spatial_vars.y
z = pybamm.standard_spatial_vars.z
T_x_av = self.param.T_amb(y, z, pybamm.t)
# Broadcast t to be the same size as y and z (to catch cases where the ambient
# temperature is a function of time only)
t_broadcast = pybamm.PrimaryBroadcast(pybamm.t, "current collector")
T_x_av = self.param.T_amb(y, z, t_broadcast)
T_vol_av = self._yz_average(T_x_av)

T_dict = {
"negative current collector": T_x_av,
"positive current collector": T_x_av,
"x-averaged cell": T_x_av,
"volume-averaged cell": T_x_av,
"volume-averaged cell": T_vol_av,
}
for domain in ["negative electrode", "separator", "positive electrode"]:
T_dict[domain] = pybamm.PrimaryBroadcast(T_x_av, domain)
Expand All @@ -50,15 +54,25 @@ def get_coupled_variables(self, variables):
"Ohmic heating [W.m-3]",
"X-averaged Ohmic heating [W.m-3]",
"Volume-averaged Ohmic heating [W.m-3]",
"Ohmic heating per unit electrode-pair area [W.m-2]",
"Ohmic heating [W]",
"Irreversible electrochemical heating [W.m-3]",
"X-averaged irreversible electrochemical heating [W.m-3]",
"Volume-averaged irreversible electrochemical heating [W.m-3]",
"Irreversible electrochemical heating per unit electrode-pair area [W.m-2]",
"Irreversible electrochemical heating [W]",
"Reversible heating [W.m-3]",
"X-averaged reversible heating [W.m-3]",
"Volume-averaged reversible heating [W.m-3]",
"Reversible heating per unit electrode-pair area [W.m-2]",
"Reversible heating [W]",
"Total heating [W.m-3]",
"X-averaged total heating [W.m-3]",
"Volume-averaged total heating [W.m-3]",
"Total heating per unit electrode-pair area [W.m-2]",
"Total heating [W]",
"Negative current collector Ohmic heating [W.m-3]",
"Positive current collector Ohmic heating [W.m-3]",
]:
# All variables are zero
variables.update({var: zero})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,25 @@ def test_basic_processing_msmr(self):
model = self.model(options)
modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
modeltest.test_all(skip_output_tests=True)

def test_basic_processing_temperature_interpolant(self):
times = np.arange(0, 4000, 10)
tmax = max(times)

def temp_drive_cycle(y, z, t):
return pybamm.Interpolant(
times,
298.15 + 20 * (times / tmax),
t,
)

parameter_values = pybamm.ParameterValues("Chen2020")
parameter_values.update(
{
"Initial temperature [K]": 298.15,
"Ambient temperature [K]": temp_drive_cycle,
}
)
model = self.model()
modeltest = tests.StandardModelTest(model, parameter_values=parameter_values)
modeltest.test_all(skip_output_tests=True)

0 comments on commit 8530f49

Please sign in to comment.