Skip to content

Added "use lumped thermal capacity" option in lumped thermal model. - #4968

Merged
aabills merged 11 commits into
pybamm-team:developfrom
Rishab87:properly-lumped-thermal
Apr 14, 2025
Merged

Added "use lumped thermal capacity" option in lumped thermal model.#4968
aabills merged 11 commits into
pybamm-team:developfrom
Rishab87:properly-lumped-thermal

Conversation

@Rishab87

Copy link
Copy Markdown
Member

Description

Added "use lumped thermal capacity" option in lumped thermal model so that we can simulate properly for those who do not have detailed thermal characterization of each component of the cell.

Fixes #4612

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #)

Important checks:

Please confirm the following before marking the PR as ready for review:

  • No style issues: nox -s pre-commit
  • All tests pass: nox -s tests
  • The documentation builds: nox -s doctests
  • Code is commented for hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

@Rishab87
Rishab87 requested a review from a team as a code owner April 10, 2025 12:33
@codecov

codecov Bot commented Apr 10, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.64%. Comparing base (da9846f) to head (fbe028f).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4968   +/-   ##
========================================
  Coverage    98.64%   98.64%           
========================================
  Files          304      304           
  Lines        23742    23750    +8     
========================================
+ Hits         23421    23429    +8     
  Misses         321      321           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aabills aabills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @Rishab87 !

Overall it looks really great, there are just a few small issues.

I'd also like to see an integration test where we ensure that the equation is doing what it is supposed to be doing, maybe by back calculating the lumped capacity and comparing it with the standard thermal model.

"Initial concentration in negative electrode [mol.m-3]": 24108.0,
"Initial concentration in positive electrode [mol.m-3]": 21725.0,
"Initial temperature [K]": 298.15,
"Cell heat capacity [J.K-1.m-3]": 2.5e6,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In general, we try not to add parameters that were not in the original paper to the parameter sets, so could you delete this from all the parameter sets?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

alright

"voltage as a state": ["false", "true"],
"working electrode": ["both", "positive"],
"x-average side reactions": ["false", "true"],
"use lumped capacity": ["false", "true"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's rename this to "use lumped thermal capacity" for clarity, given that batteries also have an charge capacity.

y_eval = np.zeros((sim._built_model.len_rhs, 1))
heat_capacity_eval = var.evaluate(t_eval, y_eval)

assert abs(heat_capacity_eval - lumped_value) < lumped_value * 1e-10

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure that this is a great test. What is this trying to test exactly?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also you can use np.assert_almost_equal

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've changed this unit test a bit, it checks whether the heat capacity parameter is being used correctly when the option is enabled.

self.h_total = self.therm.h_total
self.rho_c_p_eff = self.therm.rho_c_p_eff
self.lambda_eff = self.therm.lambda_eff
self.cell_heat_capacity = self.therm.cell_heat_capacity

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is the same thing as rho_c_p_eff right? So why make a new parameter for it?

@Rishab87 Rishab87 Apr 11, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think rho_c_p_eff calculates the effective volumetric heat capacity of the entire battery cell by combining the heat capacities of each component but cell_heat_capacity is the lumped heat capacity of the whole cell, we can define this parameter directly in lumped.py too but I made it like this for consistency of the codebase

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah I think it makes sense to keep it separate after further consideration.

Comment thread src/pybamm/parameters/thermal_parameters.py
@Rishab87

Copy link
Copy Markdown
Member Author

@aabills thanks for the review!
I've added an integration test and made changes accordingly.

@Rishab87
Rishab87 requested a review from aabills April 11, 2025 14:02
@@ -224,6 +224,10 @@ class BatteryModelOptions(pybamm.FuzzyDict):
the respective porosity change) over the x-axis in Single Particle
Models, can be "false" or "true". Default is "false" for SPMe and
"true" for SPM.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add a check that raises an OptionError for incompatible options? There are some examples of this further down in this file.

@Rishab87 Rishab87 Apr 12, 2025

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

ohh right, missed that, adding

Q_cr_W = pybamm.Scalar(0)
Q_cr_vol_av = Q_cr_W

# Add lumped heat capacity if option is enabled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It might be cleaner to have this option check in the base class rather than overwriting the variable for the lumped model.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

right

@aabills

aabills commented Apr 12, 2025

Copy link
Copy Markdown
Contributor

Hey @Rishab87 I'll re-review once you've implemented Rob's changes

@Rishab87

Copy link
Copy Markdown
Member Author

@rtimms, thanks for the review
I've made those changes.

@aabills it's ready to be re-reviewed

@aabills aabills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok at this point it looks great substantively. The only thing is, the testing in unit/ doesn't really match what we did for the other models. Could you please add it to unit/test_models/test_full_battery_models/base_lithium_ion_tests.py and base_lithium_ion_half_cell_tests.py? You should be able to do both the option error and the check well posedness there. And then move the parameter test from unittests to test_thermal_parameters, which is in test_lithium_ion_parameters.py

Thanks so much!

self.h_total = self.therm.h_total
self.rho_c_p_eff = self.therm.rho_c_p_eff
self.lambda_eff = self.therm.lambda_eff
self.cell_heat_capacity = self.therm.cell_heat_capacity

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

yeah I think it makes sense to keep it separate after further consideration.

@Rishab87

Copy link
Copy Markdown
Member Author

@aabills, shifted those tests and changed them accordingly

@Rishab87
Rishab87 requested a review from aabills April 13, 2025 05:43

@aabills aabills left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks awesome, thanks a lot!!

@aabills
aabills merged commit 9989403 into pybamm-team:develop Apr 14, 2025
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.

Create "Properly Lumped" thermal model

3 participants