Skip to content

Commit

Permalink
#2793 ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Mar 21, 2023
1 parent e59bb51 commit 1b7959e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,23 @@ def set_variable_slices(self, variables):
# Add to slices
y_slices[variable].append(slice(start, end))
y_slices_explicit[variable].append(slice(start, end))

# Add to bounds
lower_bounds.extend([variable.bounds[0].evaluate()] * (end - start))
upper_bounds.extend([variable.bounds[1].evaluate()] * (end - start))
def evaluate_bound(bound, side):
if bound.has_symbol_of_classes(pybamm.InputParameter):
if side == "lower":
return -np.inf
elif side == "upper":
return np.inf
else:
return bound.evaluate()

lower_bounds.extend(
[evaluate_bound(variable.bounds[0], "lower")] * (end - start)
)
upper_bounds.extend(
[evaluate_bound(variable.bounds[1], "upper")] * (end - start)
)
# Increment start
start = end

Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_discretisations/test_discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def test_discretise_slicing(self):
with self.assertRaisesRegex(TypeError, "y_slices should be"):
disc.y_slices = 1

# bounds with an InputParameter
a = pybamm.InputParameter("a")
v = pybamm.Variable("v", domain=whole_cell, bounds=(0, a))
disc.set_variable_slices([v])
np.testing.assert_array_equal(disc.bounds[0], [0] * 100)
np.testing.assert_array_equal(disc.bounds[1], [np.inf] * 100)

def test_process_symbol_base(self):
# create discretisation
mesh = get_mesh_for_testing()
Expand Down

0 comments on commit 1b7959e

Please sign in to comment.