Repository: pybamm-team/PyBaMM
Pull request #4692 (2024-12-18 21:30:48)

Plating particle size distribution
# Description

enables plating for particle size distribution models.

pending #4687 

## Type of change

Please add a line in the relevant section of [CHANGELOG.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CHANGELOG.md) to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

- [x] New feature (non-breaking change which adds functionality)
- [ ] Optimization (back-end change that speeds up the code)
- [ ] Bug fix (non-breaking change which fixes an issue)

# Key checklist:

- [ ] No style issues: `$ pre-commit run` (or `$ nox -s pre-commit`) (see [CONTRIBUTING.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md#installing-and-using-pre-commit) for how to set this up to run automatically when committing locally, in just two lines of code)
- [ ] All tests pass: `$ python -m pytest` (or `$ nox -s tests`)
- [ ] The documentation builds: `$ python -m pytest --doctest-plus src` (or `$ nox -s doctests`)

You can run integration tests, unit tests, and doctests together at once, using `$ nox -s quick`.

## Further checks:

- [ ] Code is commented, particularly in hard-to-understand areas
- [ ] Tests added that prove fix is effective or that feature works


review-notebook-app[bot]: Check out this pull request on&nbsp; <a href="https://app.reviewnb.com/pybamm-team/PyBaMM/pull/4692"><img align="absmiddle"  alt="ReviewNB" height="28" class="BotMessageButtonImage" src="https://raw.githubusercontent.com/ReviewNB/support/master/images/button_reviewnb.png"/></a> 

 See visual diffs & provide feedback on Jupyter Notebooks. 

---

 <i>Powered by <a href='https://www.reviewnb.com/?utm_source=gh'>ReviewNB</a></i>
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4692?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.22%. Comparing base [(`a7253b8`)](https://app.codecov.io/gh/pybamm-team/PyBaMM/commit/a7253b8cb6338e46e1468be1769602771c25e0c7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team) to head [(`d7c9b62`)](https://app.codecov.io/gh/pybamm-team/PyBaMM/commit/d7c9b627a4f3ab62e579ecffba393d612e92d180?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).
> Report is 1 commits behind head on develop.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff            @@
##           develop    #4692   +/-   ##
========================================
  Coverage    99.22%   99.22%           
========================================
  Files          303      303           
  Lines        23070    23070           
========================================
  Hits         22891    22891           
  Misses         179      179           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/pybamm-team/PyBaMM/pull/4692?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pybamm-team).


Patch:
diff --git a/src/pybamm/models/full_battery_models/base_battery_model.py b/src/pybamm/models/full_battery_models/base_battery_model.py
index e47a6c05c..83d62df27 100644
--- a/src/pybamm/models/full_battery_models/base_battery_model.py
+++ b/src/pybamm/models/full_battery_models/base_battery_model.py
@@ -525,14 +525,14 @@ class BatteryModelOptions(pybamm.FuzzyDict):
 
         # Options not yet compatible with particle-size distributions
         if options["particle size"] == "distribution":
-            if options["heat of mixing"] != "false":
+            if options["lithium plating porosity change"] != "false":
                 raise NotImplementedError(
-                    "Heat of mixing submodels do not yet support particle-size "
-                    "distributions."
+                    "Lithium plating porosity change not yet supported for particle-size"
+                    " distributions."
                 )
-            if options["lithium plating"] != "none":
+            if options["heat of mixing"] != "false":
                 raise NotImplementedError(
-                    "Lithium plating submodels do not yet support particle-size "
+                    "Heat of mixing submodels do not yet support particle-size "
                     "distributions."
                 )
             if options["particle"] in ["quadratic profile", "quartic profile"]:


Test patch:
diff --git a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py
index ad0221284..5f693264d 100644
--- a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py
+++ b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py
@@ -123,6 +123,18 @@ class TestMPM:
         model = pybamm.lithium_ion.MPM(options)
         model.check_well_posedness()
 
+    def test_mpm_with_lithium_plating(self):
+        options = {
+            "lithium plating": "irreversible",
+        }
+        model = pybamm.lithium_ion.MPM(options)
+        model.check_well_posedness()
+        options = {
+            "lithium plating": "reversible",
+        }
+        model = pybamm.lithium_ion.MPM(options)
+        model.check_well_posedness()
+
 
 class TestMPMExternalCircuits:
     def test_well_posed_voltage(self):
@@ -196,15 +208,3 @@ class TestMPMWithMechanics:
         options = {"particle mechanics": "swelling only"}
         with pytest.raises(NotImplementedError):
             pybamm.lithium_ion.MPM(options)
-
-
-class TestMPMWithPlating:
-    def test_well_posed_reversible_plating_not_implemented(self):
-        options = {"lithium plating": "reversible"}
-        with pytest.raises(NotImplementedError):
-            pybamm.lithium_ion.MPM(options)
-
-    def test_well_posed_irreversible_plating_not_implemented(self):
-        options = {"lithium plating": "irreversible"}
-        with pytest.raises(NotImplementedError):
-            pybamm.lithium_ion.MPM(options)