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 933 remove reactions dict #948

Merged
merged 23 commits into from
Apr 29, 2020

Conversation

valentinsulzer
Copy link
Member

Description

Remove the dictionary of reactions, and explicitly define reactions instead.

Fixes #933

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

@valentinsulzer valentinsulzer changed the base branch from develop to issue-546-convection April 7, 2020 21:32
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 good Tino, thanks! My only concern here (which I guess it is at the core of the whole PR) is how easy it is to add new reactions and how compatible it is with across different models. Won't we end up with a lot of reactions (and the subsequent variables) which in the standard DFN model they will all be zero?

Also, for modelling purposes and prototyping, do you think it would be useful to always have a "dummy or miscellaneous reaction" that can easily be defined to be whatever is needed, before hardcoding that as a new reaction in PyBAMM?

Finally, the pull request is to merge with issue-546-convection instead of develop. Is that intended?

"Positive": {"s": 1, "aj": "Positive electrode" + icd},
}
}
def set_other_reaction_submodels_to_zero(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of having set_other_reaction_submodels_to_zero could we have something like set_reaction_submodels(self,[list of reactions]): which then sets the appropriate models from the list (and sets NoReaction for things that aren't in the list)? I'm just thinking of how this extends in the future and works with model options. It would be nice to have an option "reactions" which takes a list of names of any reactions you want to include. Actually it looks like this already happens, and these are always zero for li-ion. Maybe there could be a comment or this method renamed, as seeing it in e.g. DFN was a little confusing -- it wasn't clear which reactions this referred to.

)
param = self.param
# All possible reactions. Some of these could be zero
j_av = variables["First-order x-averaged interfacial current density"]
Copy link
Contributor

Choose a reason for hiding this comment

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

it seems like there are a lot of places where you need to remember to add a new 'j'. Could we pass the list of reaction names in and then search for the side reactions that need to be added on? e.g. look for "First-order x-averaged" + "reaction_name" + "interfacial current density". Maybe there are some quirks that make this hard, but I'm worried people will forget to add the extra current densities

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess then you need things like s_plus values. And then we basically end up back at the reaction dictionary... I don't think I appreciated how often you needed to get each of the current densities in separate files

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 exactly ... I'm leaning towards having to do everything explicitly though. I'll resolve conflicts and fix tests for now, and we can discuss at next meeting

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe having "Total negative electrolyte reactions", "Total negative solid reactions", etc variables in the variables dictionary. The electrolyte one can include the s_plus values. When you add a new reaction, you then just do:

variables["Total electrolyte reactions"] += s_plus * j_new

If the reaction is set to NoReaction then we just don't update it. If the reaction only consumes a reactant from the electrolyte, then we only add it to the electrolyte and not the solid.

This would be a bit cleaner than the current reactions dictionary and also would make it clearer from just looking at a particular reaction submodel where that reaction fits into the wider model. Also good is that you only have to edit that one reaction submodel to control how that reaction is coupled to the full model. Downside is that it is less clear than the approach in this issue to see what reactions are taking place just by looking at the electrolyte submodel.

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, I think that's the cleanest way of doing it, then it just goes into BaseInterface and all happens automatically

@valentinsulzer
Copy link
Member Author

Also, for modelling purposes and prototyping, do you think it would be useful to always have a "dummy or miscellaneous reaction" that can easily be defined to be whatever is needed, before hardcoding that as a new reaction in PyBAMM?

@ferranbrosa can you explain what you mean by this?

@brosaplanella
Copy link
Sponsor Member

Also, for modelling purposes and prototyping, do you think it would be useful to always have a "dummy or miscellaneous reaction" that can easily be defined to be whatever is needed, before hardcoding that as a new reaction in PyBAMM?

@ferranbrosa can you explain what you mean by this?

If I understand correctly every single reaction that we want to add needs to be defined correctly across a few files, even though the final form (or submodel) for the reaction might change. For example, the SEI formation will be there as a reaction but we might have different submodels for it that we can change. However, the SEI reaction is always there as it is a commonly accepted term.

Now, it is likely that people will want to add a new reaction or experiment with it which would require the user to add the reaction in the right places. This could be quite messy, especially for new users. We could have a dummy or miscellaneous reaction, apart from all the commonly accepted reaction terms, which is normally off, but that can be switched on for prototyping. Once this reaction works, the issue of hardcoding it into PyBaMM can be posted.

If I haven't understood it correctly, then the two paragraphs above probably make no sense haha

@rtimms
Copy link
Contributor

rtimms commented Apr 8, 2020

Also, for modelling purposes and prototyping, do you think it would be useful to always have a "dummy or miscellaneous reaction" that can easily be defined to be whatever is needed, before hardcoding that as a new reaction in PyBAMM?

@ferranbrosa can you explain what you mean by this?

I think the point is that if want to add a new side reaction submodel it's no longer self contained. In the sense that you have to also make changes to the electrode and electrolyte submodels . Maybe we could sum all these up in the interface submodel? i.e. define sum_j and sum_s_times_j in base_interface so that users only need to add new reaction to one other file? As you say, we can discuss this at the next meeting.

@valentinsulzer valentinsulzer changed the base branch from issue-546-convection to develop April 9, 2020 21:45
@rtimms rtimms mentioned this pull request Apr 28, 2020
@codecov
Copy link

codecov bot commented Apr 29, 2020

Codecov Report

Merging #948 into develop will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #948      +/-   ##
===========================================
- Coverage    97.49%   97.48%   -0.02%     
===========================================
  Files          222      222              
  Lines        11773    11791      +18     
===========================================
+ Hits         11478    11494      +16     
- Misses         295      297       +2     
Impacted Files Coverage Δ
...l_battery_models/lead_acid/base_lead_acid_model.py 100.00% <ø> (ø)
...ybamm/models/full_battery_models/lead_acid/loqs.py 100.00% <ø> (ø)
pybamm/models/submodels/base_submodel.py 91.80% <ø> (-0.14%) ⬇️
pybamm/parameters/standard_parameters_lead_acid.py 99.32% <ø> (ø)
...m/models/full_battery_models/base_battery_model.py 99.59% <100.00%> (+<0.01%) ⬆️
...models/full_battery_models/lead_acid/basic_full.py 100.00% <100.00%> (ø)
...ybamm/models/full_battery_models/lead_acid/full.py 100.00% <100.00%> (ø)
...dels/full_battery_models/lead_acid/higher_order.py 98.05% <100.00%> (ø)
...ttery_models/lithium_ion/base_lithium_ion_model.py 100.00% <100.00%> (ø)
...bamm/models/full_battery_models/lithium_ion/dfn.py 100.00% <100.00%> (ø)
... and 25 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 0805104...6473727. Read the comment docs.

@valentinsulzer valentinsulzer merged commit 83fba98 into develop Apr 29, 2020
@valentinsulzer valentinsulzer deleted the issue-933-remove-reactions-dict branch April 29, 2020 18:09
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.

Remove reactions dictionary
4 participants