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 1219 smooth approximations #1223

Merged
merged 16 commits into from
Nov 4, 2020

Conversation

valentinsulzer
Copy link
Member

Description

Add smooth versions of the heaviside, minimum, and maximum operators, which can all have discontinuous values and/or derivatives. This clearly improves the performance of the solver, when applicable. A new setting min_max_heaviside_smoothing_parameter can be set to choose the degree of smoothing (or "exact" for no smoothing).

Fixes #1219

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 Nov 3, 2020

Codecov Report

Merging #1223 into develop will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1223      +/-   ##
===========================================
+ Coverage    97.92%   97.98%   +0.05%     
===========================================
  Files          249      250       +1     
  Lines        14184    14576     +392     
===========================================
+ Hits         13890    14282     +392     
  Misses         294      294              
Impacted Files Coverage Δ
pybamm/models/submodels/particle/base_particle.py 100.00% <ø> (ø)
pybamm/expression_tree/binary_operators.py 95.76% <100.00%> (+0.22%) ⬆️
pybamm/expression_tree/concatenations.py 97.57% <100.00%> (+0.09%) ⬆️
pybamm/expression_tree/functions.py 100.00% <100.00%> (ø)
pybamm/expression_tree/symbol.py 98.03% <100.00%> (+0.15%) ⬆️
pybamm/expression_tree/unary_operators.py 100.00% <100.00%> (ø)
...ernal_circuit/function_control_external_circuit.py 98.07% <100.00%> (ø)
pybamm/parameters/electrical_parameters.py 100.00% <100.00%> (ø)
pybamm/settings.py 100.00% <100.00%> (ø)
pybamm/solvers/algebraic_solver.py 100.00% <100.00%> (ø)
... and 18 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 33e2278...f0c9915. Read the comment docs.

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, only two minor comments (the one on the CHANGELOG might not require any action).

CHANGELOG.md Outdated
- Added parameter set for an A123 LFP cell ([#1209](https://github.com/pybamm-team/PyBaMM/pull/1209))
- Added variables related to equivalent circuit models ([#1204](https://github.com/pybamm-team/PyBaMM/pull/1204))
- Added an example script to check conservation of lithium ([#1186](https://github.com/pybamm-team/PyBaMM/pull/1186))
- Added `erf` and `erfc` functions ([#1184](https://github.com/pybamm-team/PyBaMM/pull/1184))

## Optimizations

- Add (optional) smooth approximations for the `minimum`, `maximum`, `Heaviside`, and `AbsoluteValue` operators ([#1223](https://github.com/pybamm-team/PyBaMM/pull/1223))
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Very minor thing: should minimum and maximum be capitalised or is it because the smooth approximation is for the method but not for the class?

@@ -9,7 +9,7 @@


# load model
model = pybamm.lithium_ion.DFN()
model = pybamm.lithium_ion.SPM()
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 should be DFN

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 Tino!

@brosaplanella brosaplanella merged commit d3b1cca into develop Nov 4, 2020
@brosaplanella brosaplanella deleted the issue-1219-smooth-approximations branch November 4, 2020 16:28
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.

Look into using smooth approximations for min, max, heaviside
2 participants