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

MSMR model #3116

Merged
merged 53 commits into from
Sep 14, 2023
Merged

MSMR model #3116

merged 53 commits into from
Sep 14, 2023

Conversation

rtimms
Copy link
Contributor

@rtimms rtimms commented Jul 6, 2023

Description

Implements the MSMR model from Baker & Verbrugge, 2018.

In particular, this PR adds a new "particle" model that solves for the potential within the particles. Then OCP is then this potential evaluated at the surface. In order to use this model, users must write down the OCV for each reaction (in the form of Eq 3), which are inverted to give the fraction of occupied sites (Eq 5). These are summed to give an explicit expression for the inverse of the OCV (Eq 6).

Also updates the electrode State of Health models to work with the MSMR formulation.

Fixes # (issue)

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • 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 (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all
  • The documentation builds: $ python run-tests.py --doctest

You can run unit and doctests together at once, using $ python run-tests.py --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
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@rtimms rtimms marked this pull request as draft July 6, 2023 18:04
@rtimms rtimms changed the title MSMR model [WIP] MSMR model Jul 6, 2023
@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Patch coverage: 95.46% and project coverage change: -0.16% ⚠️

Comparison is base (ec5383c) 99.70% compared to head (cb36b35) 99.55%.

❗ Current head cb36b35 differs from pull request most recent head 77a62c1. Consider uploading reports for the commit 77a62c1 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3116      +/-   ##
===========================================
- Coverage    99.70%   99.55%   -0.16%     
===========================================
  Files          248      253       +5     
  Lines        18899    19523     +624     
===========================================
+ Hits         18844    19436     +592     
- Misses          55       87      +32     
Files Changed Coverage Δ
pybamm/expression_tree/unary_operators.py 100.00% <ø> (ø)
pybamm/models/submodels/particle/base_particle.py 100.00% <ø> (ø)
...amm/models/full_battery_models/lithium_ion/msmr.py 72.22% <72.22%> (ø)
...odels/interface/open_circuit_potential/msmr_ocp.py 88.88% <88.88%> (ø)
pybamm/models/submodels/particle/msmr_diffusion.py 93.24% <93.24%> (ø)
...m/models/full_battery_models/base_battery_model.py 99.33% <94.73%> (-0.21%) ⬇️
...submodels/interface/kinetics/msmr_butler_volmer.py 96.49% <96.49%> (ø)
...s/full_battery_models/lithium_ion/electrode_soh.py 98.88% <97.66%> (-1.12%) ⬇️
pybamm/expression_tree/broadcasts.py 100.00% <100.00%> (ø)
...m/input/parameters/lithium_ion/MSMR_example_set.py 100.00% <100.00%> (ø)
... and 15 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@valentinsulzer valentinsulzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, will need some more testing for coverage. Let me know if you want me to review any equations in particular

"""
Override :meth:`pybamm.SpatialOperator.diff()` to reinstate behaviour of
:meth:`pybamm.Symbol.diff()`.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably cleaner to just get rid of the NotImplementedError for spatial operators

@rtimms
Copy link
Contributor Author

rtimms commented Jul 6, 2023

Thanks. Yep, tests and examples still to do but wanted another pair of eyes on the general implementation.

@rtimms
Copy link
Contributor Author

rtimms commented Jul 10, 2023

The model and example are implemented. Remaining tasks:

  • Clean up eSOH (lots of if statements now). Could be tackled as a separate issue. It all works correctly as it is now, but the code isn't as clean as it could be.
  • Add helper functions for adding individual reaction variables to models (or explicitly give the number of reactions as a model option)
  • Doc rst

@rtimms
Copy link
Contributor Author

rtimms commented Aug 11, 2023

To do:

  • Refomulate exchange current to use potential and lithiation extent (for numerical stability)
  • Make setting up options cleaner for half cells. At the moment the checks are set up such that you have to pass a tuple of options for the open circuit potential, particle and intercalation kinetics for a half cell even though the values in the li metal side are ignored (or don't make sense in the case of particle)

Copy link
Sponsor Member

@brosaplanella brosaplanella left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks Rob! Just a few comments, happy to merge once tests pass.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Picky comment, can you delete the empty cells at the end of the notebook?

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This notebook has an error, can you rerun it and check if the error is still there of it is legacy?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was old and is fixed by re-running

Comment on lines 255 to 265
"none",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably something for a future issue, but I wonder if we can have a way to not hard code when an option is an integer (similar issue occurs with the RC components in the ECM), as technically we could have as many as we wanted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, changed to check for positive integers

@@ -98,44 +98,63 @@ def _get_standard_concentration_variables(
c_s_av = pybamm.r_average(c_s_xav)

variables = {
f"{Domain} {phase_name}particle stoichiometry": c_s / c_scale,
f"{Domain} {phase_name}particle concentration": c_s / c_scale,
# Dimensional concentration
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have stoichiometry and dimensionless concentration?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a hangover from when we had dimensional and dimensionless concentration. now they are equivalent. maybe we should remove dimensionless concentration now?

Comment on lines +702 to +707
# j0_j = (
# j0_ref_j
# * xj ** (wj * aj)
# * (Xj - xj) ** (wj * (1 - aj))
# * (c_e / c_e_ref) ** (1 - aj)
# )
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the comment to explain this is what the original formulation is in the paper

@rtimms rtimms merged commit e094094 into develop Sep 14, 2023
31 of 32 checks passed
@kratman kratman mentioned this pull request Sep 14, 2023
5 tasks
@kratman kratman deleted the msmr branch March 19, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants