Skip to content

Commit c36c2bd

Browse files
authored
Merge pull request #2795 from pybamm-team/issue-2793-input-bounds
`InputParameter` in variable bounds
2 parents e59bb51 + fca4dea commit c36c2bd

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CHANGELOG.md

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

1111
## Bug fixes
1212

13+
- Fixed a bug where variable bounds could not contain `InputParameters` ([#2795](https://github.com/pybamm-team/PyBaMM/pull/2795))
1314
- Improved `model.latexify()` to have a cleaner and more readable output ([#2764](https://github.com/pybamm-team/PyBaMM/pull/2764))
1415
- Fixed electrolyte conservation in the case of concentration-dependent transference number ([#2758](https://github.com/pybamm-team/PyBaMM/pull/2758))
1516
- Fixed `plot_voltage_components` so that the sum of overpotentials is now equal to the voltage ([#2740](https://github.com/pybamm-team/PyBaMM/pull/2740))

pybamm/discretisations/discretisation.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,23 @@ def set_variable_slices(self, variables):
297297
# Add to slices
298298
y_slices[variable].append(slice(start, end))
299299
y_slices_explicit[variable].append(slice(start, end))
300+
300301
# Add to bounds
301-
lower_bounds.extend([variable.bounds[0].evaluate()] * (end - start))
302-
upper_bounds.extend([variable.bounds[1].evaluate()] * (end - start))
302+
def evaluate_bound(bound, side):
303+
if bound.has_symbol_of_classes(pybamm.InputParameter):
304+
if side == "lower":
305+
return -np.inf
306+
elif side == "upper":
307+
return np.inf
308+
else:
309+
return bound.evaluate()
310+
311+
lower_bounds.extend(
312+
[evaluate_bound(variable.bounds[0], "lower")] * (end - start)
313+
)
314+
upper_bounds.extend(
315+
[evaluate_bound(variable.bounds[1], "upper")] * (end - start)
316+
)
303317
# Increment start
304318
start = end
305319

tests/unit/test_discretisations/test_discretisation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ def test_discretise_slicing(self):
142142
with self.assertRaisesRegex(TypeError, "y_slices should be"):
143143
disc.y_slices = 1
144144

145+
# bounds with an InputParameter
146+
a = pybamm.InputParameter("a")
147+
b = pybamm.InputParameter("b")
148+
v = pybamm.Variable("v", domain=whole_cell, bounds=(a, b))
149+
disc.set_variable_slices([v])
150+
np.testing.assert_array_equal(disc.bounds[0], [-np.inf] * 100)
151+
np.testing.assert_array_equal(disc.bounds[1], [np.inf] * 100)
152+
145153
def test_process_symbol_base(self):
146154
# create discretisation
147155
mesh = get_mesh_for_testing()

0 commit comments

Comments
 (0)