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

Improved option checking for tuples #4707

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# [Unreleased](https://github.com/pybamm-team/PyBaMM/)

# [v25.1.0](https://github.com/pybamm-team/PyBaMM/tree/v25.1.0) - 2025-01-14
## Optimizations

- Enhanced option checking by converting string-based options into tuples for consistent handling.([#4707](https://github.com/pybamm-team/PyBaMM/pull/4707)


# [v25.1.0](https://github.com/pybamm-team/PyBaMM/tree/v25.1.0) - 2025-0

## Features

Expand Down
26 changes: 16 additions & 10 deletions src/pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#
# Base battery model class
#

import pybamm
from functools import cached_property

Expand Down Expand Up @@ -445,8 +444,8 @@ def __init__(self, extra_options):
default_options["SEI"] = "none"
# The "SEI" option will still be overridden by extra_options if provided

options = pybamm.FuzzyDict(default_options)
# any extra options overwrite the default options
options = pybamm.FuzzyDict(default_options)
for name, opt in extra_options.items():
if name in default_options:
options[name] = opt
Expand All @@ -467,7 +466,7 @@ def __init__(self, extra_options):
# half-cells where you must pass a tuple of options to only set MSMR models in
# the working electrode
msmr_check_list = [
options[opt] == "MSMR"
"MSMR" in options[opt]
for opt in ["open-circuit potential", "particle", "intercalation kinetics"]
]
if (
Expand Down Expand Up @@ -524,7 +523,7 @@ def __init__(self, extra_options):
)

# Options not yet compatible with particle-size distributions
if options["particle size"] == "distribution":
if "distribution" in options["particle size"]:
if options["lithium plating porosity change"] != "false":
raise pybamm.OptionError(
"Lithium plating porosity change not yet supported for particle-size"
Expand All @@ -540,22 +539,29 @@ def __init__(self, extra_options):
"Heat of mixing submodels do not yet support particle-size "
"distributions."
)
if options["particle"] in ["quadratic profile", "quartic profile"]:
if (
"quadratic profile" in options["particle"]
or "quartic profile" in options["particle"]
):
raise NotImplementedError(
"'quadratic' and 'quartic' concentration profiles have not yet "
"been implemented for particle-size ditributions"
)
if options["particle mechanics"] != "none":
if "none" not in options["particle mechanics"]:
raise NotImplementedError(
"Particle mechanics submodels do not yet support particle-size"
" distributions."
)
if options["particle shape"] != "spherical":
if "spherical" not in options["particle shape"]:
raise NotImplementedError(
"Particle shape must be 'spherical' for particle-size distribution"
" submodels."
)
if options["stress-induced diffusion"] == "true":
if "none" not in options["SEI"]:
raise NotImplementedError(
"SEI submodels do not yet support particle-size distributions."
)
if "true" in options["stress-induced diffusion"]:
raise NotImplementedError(
"stress-induced diffusion cannot yet be included in "
"particle-size distributions."
Expand Down Expand Up @@ -624,7 +630,7 @@ def __init__(self, extra_options):
if options["particle phases"] not in ["1", ("1", "1")]:
if not (
options["surface form"] != "false"
and options["particle"] == "Fickian diffusion"
and "Fickian diffusion" in options["particle"]
):
raise pybamm.OptionError(
"If there are multiple particle phases: 'surface form' cannot be "
Expand All @@ -644,7 +650,7 @@ def __init__(self, extra_options):
if isinstance(p_mechanics, str) and isinstance(sei_on_cr, tuple):
p_mechanics = (p_mechanics, p_mechanics)
if any(
sei == "true" and mech != "swelling and cracking"
"true" in sei and "swelling and cracking" not in mech
for mech, sei in zip(p_mechanics, sei_on_cr)
):
raise pybamm.OptionError(
Expand Down