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

Issue 1778 - heat of mixing #2837

Merged
merged 55 commits into from
Jun 21, 2024
Merged

Conversation

aabills
Copy link
Contributor

@aabills aabills commented Mar 29, 2023

Description

implemented heat of mixing

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

Fixes #1778

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

pybamm/models/submodels/thermal/base_thermal.py Outdated Show resolved Hide resolved
a_n = variables["Negative electrode surface area to volume ratio [m-1]"]
R_n = variables["Negative particle radius [m]"]
N_n = a_n / (4 * pi * R_n**2)
if self.x_average:
Copy link
Member

Choose a reason for hiding this comment

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

There is a bug in the expression tree but it should be possible to treat x-averaged and non-x-averaged the same way. Happy to leave this workaround in for now until the bug is resolved

Copy link
Member

Choose a reason for hiding this comment

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

Let's leave it for now, as most submodels use this anyway. When fixing the bug, it should be caught with the Ctrl+F for if self.x_average.

Copy link
Member

Choose a reason for hiding this comment

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

Happy to leave it. Just a clarification about why this is different from most other submodels: In the other submodels, we are specifying whether the variable we are solving for is full or x-averaged (e.g. full or x-averaged particle concentration, if we used full concentration in SPM we'd just be solving the exact same equation 20 times instead of 1). Here, we're just evaluating an expression and returning an object of the same shape at the end, and the expression tree logic should be able to figure out how to deal with the full and x-averaged cases with the same syntax by doing things like rewrite 2 * broadcast(var) to broadcast(2 * var), but there is an edge case here that hadn't come up before

Copy link
Member

Choose a reason for hiding this comment

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

Right, I thought it was the same case. Then happy to fix it here. Is it a matter of removing the if statement and using c_n and T_n to be the non-averaged quantities?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should work just always using the x_average is False branch

Copy link
Member

Choose a reason for hiding this comment

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

Actually I just gave it a try and now there is an issue with dU/dsto returning 0 for the SPMe. Not sure if that's related to the other PR or not (need to dig more on it). I won't have time to take a look in the next few days, so happy to hold this until I have time or just merge it as is.

Copy link
Member

Choose a reason for hiding this comment

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

Ah damn ok. Let's just merge as is then. My guess is that U(broadcast(c)) becomes broadcast(U(c)) and then it doesn't find broadcast(c) in the children so it thinks the derivative is zero

@brosaplanella
Copy link
Member

@all-contributors
please add @ikorotkin for code
please add @smitasahu2 for code
please add @Afgr1087 for code
please add @geslina for code

Copy link
Contributor

@brosaplanella

I've put up a pull request to add @ikorotkin! 🎉

We had trouble processing your request. Please try again later.

@agriyakhetarpal
Copy link
Member

We'll need to request additions for each person in separate comments

@brosaplanella
Copy link
Member

Yes, according to the bot docs what I have done should have worked (https://allcontributors.org/docs/en/bot/usage) but for some reason it didn't.

@ikorotkin
Copy link
Contributor

ikorotkin commented Jun 17, 2024

Yes, according to the bot docs what I have done should have worked (https://allcontributors.org/docs/en/bot/usage) but for some reason it didn't.

Maybe it's because the full stops are missing after each line?

That's the only difference I can see. Anyway, silly bot :)

@kratman
Copy link
Contributor

kratman commented Jun 17, 2024

@all-contributors add @smitasahu2 for code

Copy link
Contributor

@kratman

@smitasahu2 already contributed before to code

@kratman
Copy link
Contributor

kratman commented Jun 17, 2024

@all-contributors add @Afgr1087 for code

Copy link
Contributor

@kratman

I've put up a pull request to add @Afgr1087! 🎉

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.

Thanks, looks good to me

@brosaplanella
Copy link
Member

@all-contributors add @smitasahu2 for code

Copy link
Contributor

@brosaplanella

@smitasahu2 already contributed before to code

@brosaplanella brosaplanella merged commit 241e4cc into pybamm-team:develop Jun 21, 2024
24 checks passed
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
* fix

* fix exception

* added a Newfile

* pseudo

* pybamm-team#1778 add heat of mixing option

* pybamm-team#1778 fixed indentation

* pybamm-team#1778 fixed test

* pybamm-team#1778 fixed test

* pybamm-team#1788 added heat of mixing tests

* First commit

* pybamm-team#1778 fixed test

* First iteration

* pybamm-team#1788 try to fix diff of U

* first push from mac

* Fixed full broadcast

* Fixed domain in the integral

* pybamm-team#1778 fix parameter values example

* Added children[0].children[0]

* Added half cell

* style: pre-commit fixes

* pybamm-team#1788 revert some unrelated changes

* change ocv hack

* Revert "change ocv hack"

This reverts commit 3ad0c75.

* pybamm-team#1778 fix heat of mixing

* pybamm-team#1839 fix thermal submodels to take x_average

* pybamm-team#1778 add example heat of mixing

* ruff

* style: pre-commit fixes

* pybamm-team#1778 fix lead acid models

* fix SPM with the right broadcast of temperature

* pybamm-team#1778 refactor heat of mixing

* style: pre-commit fixes

* Add Richardson2021 citation for heat of mixing

* Fixed heat of mixing sign

* Rewritten heat of mixing example, added comparison plot to compare with the paper

* Fixed ruff formatting errors in the heat of mixing example script

* pybamm-team#1778 fix x-full

* pybamm-team#1778 fix tests

* pybamm-team#1778 improve coverage

* style: pre-commit fixes

* pybamm-team#1778 Valentin's suggestion to remove the dUdsto function and compute the derivative in the model directly instead

* pybamm-team#1778 fix failing test

* pybamm-team#1778 add heat of mixing to CHANGELOG

---------

Co-authored-by: Alec Bills <[email protected]>
Co-authored-by: smitasahu2 <[email protected]>
Co-authored-by: Afgr1087 <[email protected]>
Co-authored-by: Ferran Brosa Planella <[email protected]>
Co-authored-by: Ivan Korotkin <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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.

Add option to include heat of mixing
8 participants