Skip to content

Commit 1b7959e

Browse files
committed
#2793 ruff
1 parent e59bb51 commit 1b7959e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,13 @@ 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+
v = pybamm.Variable("v", domain=whole_cell, bounds=(0, a))
148+
disc.set_variable_slices([v])
149+
np.testing.assert_array_equal(disc.bounds[0], [0] * 100)
150+
np.testing.assert_array_equal(disc.bounds[1], [np.inf] * 100)
151+
145152
def test_process_symbol_base(self):
146153
# create discretisation
147154
mesh = get_mesh_for_testing()

0 commit comments

Comments
 (0)