Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InputParameter in variable bounds #2795

Merged
merged 2 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

## Bug fixes

- Fixed a bug where variable bounds could not contain `InputParameters` ([#2795](https://github.com/pybamm-team/PyBaMM/pull/2795))
- Improved `model.latexify()` to have a cleaner and more readable output ([#2764](https://github.com/pybamm-team/PyBaMM/pull/2764))
- Fixed electrolyte conservation in the case of concentration-dependent transference number ([#2758](https://github.com/pybamm-team/PyBaMM/pull/2758))
- 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))
Expand Down
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
8 changes: 8 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,14 @@ 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")
b = pybamm.InputParameter("b")
v = pybamm.Variable("v", domain=whole_cell, bounds=(a, b))
disc.set_variable_slices([v])
np.testing.assert_array_equal(disc.bounds[0], [-np.inf] * 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