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 685 casadi interpolation #714

Merged
merged 18 commits into from
Nov 8, 2019
Merged

Conversation

valentinsulzer
Copy link
Member

@valentinsulzer valentinsulzer commented Nov 7, 2019

Description

  • Set up interpolants in casadi form
  • Changed defaults to using the casadi structure for jacobians etc
  • Added casadi-safe-solver as a fallback for when SUNDIALS solvers aren't installed.

Fixes #685

Should allow fixing #463 by testing examples both with and without the optional solvers (requires changing scikits dae solver example to casadi, or skipping).

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.

  • 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 7, 2019

Codecov Report

Merging #714 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #714      +/-   ##
==========================================
+ Coverage   98.17%   98.18%   +0.01%     
==========================================
  Files         176      175       -1     
  Lines        9135     9089      -46     
==========================================
- Hits         8968     8924      -44     
+ Misses        167      165       -2
Impacted Files Coverage Δ
pybamm/solvers/casadi_solver.py 98.7% <ø> (ø) ⬆️
...bamm/models/full_battery_models/lithium_ion/dfn.py 100% <ø> (ø) ⬆️
...m/models/full_battery_models/base_battery_model.py 99.62% <ø> (-0.01%) ⬇️
pybamm/models/submodels/electrode/ohm/full_ohm.py 100% <ø> (+1.78%) ⬆️
...ybamm/models/full_battery_models/lead_acid/loqs.py 100% <ø> (ø) ⬆️
...ybamm/models/full_battery_models/lead_acid/full.py 100% <ø> (ø) ⬆️
...models/submodels/electrode/ohm/surface_form_ohm.py 100% <ø> (+3.44%) ⬆️
...bamm/models/full_battery_models/lithium_ion/spm.py 100% <ø> (ø) ⬆️
...bamm/models/submodels/electrode/ohm/leading_ohm.py 100% <ø> (+3.03%) ⬆️
...l/conductivity/full_stefan_maxwell_conductivity.py 100% <ø> (+3.33%) ⬆️
... and 20 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 aba1aae...234e7e8. Read the comment docs.

Copy link
Contributor

@rtimms rtimms 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 @tinosulzer !

@@ -22,7 +22,7 @@
"\n",
"In this notebook we will use the SPM as the example model, and change the input current from the default option. If you are not familiar with running a model in PyBaMM, please see [this](./models/SPM.ipynb) notebook for more details.\n",
"\n",
"In PyBaMM, the current function is set using the parameter \"Current function\". By default this is set to be a constant current provided by the class [`pybamm.GetConstantCurrent`](https://pybamm.readthedocs.io/en/latest/source/parameters/standard_current_functions/get_constant_current.html). This class takes a single optional argument \"current\" which is the size of the current in Amperes. If no argument is passed, the value of the current is set by the parameter \"Typical current [A]\" (see [this](parameter-values.ipynb) notebook for more information about parameters).\n",
"In PyBaMM, the current function is set using the parameter \"Current function\". By default this is set to be a constant current provided by the class [`pybamm.ConstantCurrent`](https://pybamm.readthedocs.io/en/latest/source/parameters/standard_current_functions/get_constant_current.html). This class takes a single optional argument \"current\" which is the size of the current in Amperes. If no argument is passed, the value of the current is set by the parameter \"Typical current [A]\" (see [this](parameter-values.ipynb) notebook for more information about parameters).\n",
Copy link
Contributor

Choose a reason for hiding this comment

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

should the read the docs link now be constant_current instead of get_constant_current?

Copy link
Member Author

Choose a reason for hiding this comment

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

Just looking at it now I can't find the page this was supposed to link to anyway. Getting rid of it in #699 so just going to leave it for now. We should look into finding a way to test hyperlinks in markdown/notebooks to make sure they exist

@@ -240,14 +212,14 @@
"source": [
"## Adding your own current function <a name=\"function\"></a>\n",
"\n",
"A user defined current function can be passed to any model using the class [`pybamm.GetUserCurrent`](https://pybamm.readthedocs.io/en/latest/source/parameters/standard_current_functions/get_user_current). The class takes in a method, which returns the current as a function of time, followed by any keyword arguments required by the method. \n",
"A user defined current function can be passed to any model using the class [`pybamm.UserCurrent`](https://pybamm.readthedocs.io/en/latest/source/parameters/standard_current_functions/get_user_current). The class takes in a method, which returns the current as a function of time, followed by any keyword arguments required by the method. \n",
Copy link
Contributor

Choose a reason for hiding this comment

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

same re read the docs link here

@@ -479,3 +479,15 @@ def check_variables(self):
var
)
)

@property
Copy link
Contributor

Choose a reason for hiding this comment

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

nice!

@@ -34,8 +34,22 @@ def default_geometry(self):

@property
def default_var_pts(self):
# Choose points that give uniform grid for the standard parameter values
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense. is this the case for li-ion too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thought I needed this to make one of the tests work but it turned out to be an issue with the solver. I guess we could add functionality so that the user can pass in grid points for, say, x_n, and then "uniform" for the other two, and it automatically selects the right number of points to make the grid uniform?

@valentinsulzer valentinsulzer merged commit 7d31c68 into master Nov 8, 2019
@valentinsulzer valentinsulzer deleted the issue-685-casadi-interpolation branch November 8, 2019 13:56
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.

Casadi interpolator
2 participants