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 791 complete models #795

Merged
merged 8 commits into from
Jan 28, 2020
Merged

Issue 791 complete models #795

merged 8 commits into from
Jan 28, 2020

Conversation

valentinsulzer
Copy link
Member

Description

Create a basic SPM and basic DFN in order to help introduce the battery models in a more user-friendly way.

Fixes #791

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: $ flake8
  • All tests pass: $ python run-tests.py --unit
  • The documentation builds: $ cd docs and then $ make clean; make html

You can run all three 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

@codecov
Copy link

codecov bot commented Jan 24, 2020

Codecov Report

Merging #795 into master will increase coverage by 0.08%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #795      +/-   ##
==========================================
+ Coverage   98.45%   98.53%   +0.08%     
==========================================
  Files         179      181       +2     
  Lines       10009    10260     +251     
==========================================
+ Hits         9854    10110     +256     
+ Misses        155      150       -5
Impacted Files Coverage Δ
pybamm/expression_tree/functions.py 100% <ø> (ø) ⬆️
pybamm/models/submodels/particle/base_particle.py 97.29% <ø> (ø) ⬆️
.../models/submodels/thermal/isothermal/isothermal.py 100% <100%> (ø) ⬆️
...odels/full_battery_models/lithium_ion/basic_spm.py 100% <100%> (ø)
...models/full_battery_models/lithium_ion/__init__.py 100% <100%> (ø) ⬆️
...odels/full_battery_models/lithium_ion/basic_dfn.py 100% <100%> (ø)
pybamm/solvers/solution.py 99.09% <0%> (+1.28%) ⬆️
pybamm/simulation.py 92.92% <0%> (+1.91%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ae1e6ae...a0bec49. Read the comment docs.

The following models are implemented and can easily be used or [compared](./models/lead-acid.ipynb). We always welcome [new models](https://pybamm.readthedocs.io/en/latest/tutorials/add-model.html)!
Several battery models are implemented and can easily be used or [compared](./models/lead-acid.ipynb). The notebooks below show the solution of each individual model. We always welcome [new models](https://pybamm.readthedocs.io/en/latest/tutorials/add-model.html)!

Once you are comfortable with the expression tree structure, a good starting point to understand the models in PyBaMM is to take a look at the [basic SPM](https://github.com/pybamm-team/PyBaMM/blob/master/pybamm/models/full_battery_models/lithium_ion/basic_spm.py) and [basic DFN](https://github.com/pybamm-team/PyBaMM/blob/master/pybamm/models/full_battery_models/lithium_ion/basic_dfn.py), since these show the entire model in one place and so are easier to understand. However, we recommend that you subsequently use the full models as they offer much greater flexibility for coupling different physical effects and visualising a greater range of variables.
Copy link
Contributor

Choose a reason for hiding this comment

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

At first I didn't exactly understand what showing the entire model in one place means.
After looking at the implementation of models, I think that means that the model parameters, variables, equations.. are set within the class definition explicitly, instead of happening hidden in the various sub models. Is that correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

that's correct, I will update to say that

@@ -23,7 +23,7 @@ def __init__(self, param):

def get_fundamental_variables(self):

T_x_av = pybamm.PrimaryBroadcast(0, "current collector")
T_x_av = pybamm.PrimaryBroadcast(self.param.T_init, "current collector")
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this likely to affect other models other than the new basic ones?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, this was a bug fix

Copy link
Contributor

@tlestang tlestang left a comment

Choose a reason for hiding this comment

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

Examples like this that help understanding how models are actually implemented are welcome! Definitely really useful.
Am I right in understanding that the 2 models BasicSPM and BasicDFN are purely pedagogical?
If yes I think this could maybe be made more explicit in the README and the classes' docstrings.

Also, looking at the tests, I fail to understand why the basic models are expected to yield the same results as the default ones. I've been trying to understand the difference(s) between the basic SPM and the default SPM, and if I'm correct the .rhs dict is different between the two. How can then both models give the same results ?
The docstring of the BasicSPM class mentions that using this class comes at the cost of flexibility, but couldn't I create a BasicSPM model and modify its parameters afterwards?

@valentinsulzer
Copy link
Member Author

Thanks for the review Thibault, yes the 2 basic models are purely pedagogical: people can see all the bits that go into those models in one place, and make their own copy to easily edit if they want to make changes to the model.

The basic SPM should be (almost) exactly the same as the "full" SPM with default options, with the only difference being that the full SPM variables have the option of being discretised to become 3D variables, but the basic SPM ones don't. So after discretisation they should be exactly the same.

The flexibility here means being able to combine different submodels (e.g. different thermal models, mechanics, degradation) in any arbitrary combination, which isn't possible with the basic SPM. We could do this with lots of if statements too but decided it would get too messy

@valentinsulzer valentinsulzer merged commit 29683da into master Jan 28, 2020
@valentinsulzer valentinsulzer deleted the issue-791-complete-models branch January 28, 2020 13:35
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 "complete" SPM and DFN classes
2 participants