-
-
Notifications
You must be signed in to change notification settings - Fork 564
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
764ff2e
#685 set up casadi interpolation
valentinsulzer 0f6fc95
Merge branch 'master' into issue-685-casadi-interpolation
valentinsulzer e0a4661
#685 reformat current data
valentinsulzer 57404c3
#685 change defaults to IDAKLU or casadi
valentinsulzer 53c0b56
#685 remove skips from tests as they should use casadi
valentinsulzer f632714
#685 move default solver to base model
valentinsulzer cc33c95
#685 update (remove) solver tests
valentinsulzer 52e09a8
#685 remove some slow tests
valentinsulzer 1175cbf
#685 get drive cycle example working
valentinsulzer 9911d41
#685 fix casadi tests
valentinsulzer bc31cd9
#685 fix interpolation example
valentinsulzer bbc9bce
#685 fix integration tests
valentinsulzer db4f643
Merge branch 'master' into issue-685-casadi-interpolation
valentinsulzer 0029b95
#715 update sundials to 4.1.0
valentinsulzer 6ffcf81
#685 update changelog
valentinsulzer edf18a4
Merge remote-tracking branch 'origin/issue-715-scikit-install' into i…
valentinsulzer 8829213
#685 update solver tests
valentinsulzer 234e7e8
#685 coverage
valentinsulzer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
"\n", | ||
"In general it is recommended to change the size of a constant current input by changing the parameter \"Typical current [A]\", since this value is used to non-dimensionlise the model. Below we load the SPM with the default parameters, and then change the the typical current 16A. We then explicilty set the current function to be a constant current." | ||
] | ||
|
@@ -49,14 +49,14 @@ | |
"\n", | ||
"# change the typical current and set a constant discharge using the typical current value\n", | ||
"param[\"Typical current [A]\"] = 16\n", | ||
"param[\"Current function\"] = pybamm.GetConstantCurrent()\n" | ||
"param[\"Current function\"] = pybamm.ConstantCurrent()\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"However, you may wish to change the value of the constant current without altering the typical current value used for non-dimensionlidation. For instance, the current function could be change to draw a current of 8A by updating the current function and passing the optional argument \"current\" to the class `GetConstantCurrent`" | ||
"However, you may wish to change the value of the constant current without altering the typical current value used for non-dimensionlidation. For instance, the current function could be change to draw a current of 8A by updating the current function and passing the optional argument \"current\" to the class `ConstantCurrent`" | ||
] | ||
}, | ||
{ | ||
|
@@ -66,7 +66,7 @@ | |
"outputs": [], | ||
"source": [ | ||
"# update the value of the current profile *without* changing the typical current used for non-dimensionlisation\n", | ||
"param[\"Current function\"] = pybamm.GetConstantCurrent(current=pybamm.Scalar(8))" | ||
"param[\"Current function\"] = pybamm.ConstantCurrent(current=pybamm.Scalar(8))" | ||
] | ||
}, | ||
{ | ||
|
@@ -84,7 +84,7 @@ | |
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "fc997d14787542f69f2cba123ce0b994", | ||
"model_id": "b900a39a72704c88927058510b7913b2", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
|
@@ -127,11 +127,7 @@ | |
"source": [ | ||
"## Loading in current data <a name=\"data\"></a>\n", | ||
"\n", | ||
"Data can be loaded in from a csv file using the class [`pybamm.GetCurrentData`](https://pybamm.readthedocs.io/en/latest/source/parameters/standard_current_functions/get_current_data). Data should be given as a function of time (in seconds) and may be dimensional (in Amperes) or non-diemsnional (e.g. C-rate). Optionally, voltage data (in Volts) may be loaded in for convinient plotting and comparison. \n", | ||
"\n", | ||
"The input csv files should be stored in PyBaMM/input/drive_cycles and have the headings: \"time [s]\"; either \"current [A]\" for dimensional data, or \"current []\" for dimensionless data; and, optionally, \"voltage [V]\". \n", | ||
"\n", | ||
"To load in dimensional data we simply provide the filename and set the units to \"[A]\", e.g." | ||
"Data can be loaded in from a csv file by specifying the path to that file and using the prefix \"[current data]\"." | ||
] | ||
}, | ||
{ | ||
|
@@ -140,54 +136,30 @@ | |
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"param[\"Current function\"] = pybamm.GetCurrentData(\"US06.csv\", units=\"[A]\")" | ||
"param[\"Current function\"] = \"[current data]US06\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"For non dimensional data, you also need to provide a current scale. For instance, if the data were C-rate then you would set the current scale to the 1C discharge current. If the 1C discharge current were 24 A and we had some C-rate data in the file car_current.csv, this would be loaded in as" | ||
"As an example, we show how to solve the SPM using the US06 drive cycle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"param[\"Current function\"] = pybamm.GetCurrentData(\"car_current.csv\", units=\"[]\", current_scale=24)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"As an example, we how to solve the SPM using the US06 drive cycle" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/home/user/Documents/PyBaMM/pybamm/parameters/standard_current_functions/get_current_data.py:88: ModelWarning: Requested time (2387.404004088835) is outside of the data range [0, 600]\n", | ||
" pybamm.ModelWarning,\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "3f4c99601ab8417ba2186987cb532600", | ||
"model_id": "26e7b28104b34991b3ebac266dab4934", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.03900922998674932, step=0.001), Output()),…" | ||
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.026526276390989537, step=0.001), Output())…" | ||
] | ||
}, | ||
"metadata": {}, | ||
|
@@ -202,7 +174,7 @@ | |
"\n", | ||
"# load parameter values and process model and geometry\n", | ||
"param = model.default_parameter_values\n", | ||
"param[\"Current function\"] = pybamm.GetCurrentData(\"US06.csv\", units=\"[A]\")\n", | ||
"param[\"Current function\"] = \"[current data]US06\"\n", | ||
"param.process_model(model)\n", | ||
"param.process_geometry(geometry)\n", | ||
"\n", | ||
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same re read the docs link here |
||
"\n", | ||
"For example, you may want to simulate a sinusoidal current with amplitude A and freqency omega. In order to do so you must first define the method" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
|
@@ -262,12 +234,12 @@ | |
"source": [ | ||
"Note that time *must* me the first arguemnt of the function. The parameters may either be provided as floats, or may be one of the standard parameters provided in PyBaMM (see [here](https://pybamm.readthedocs.io/en/latest/source/parameters)). \n", | ||
"\n", | ||
"The the model may be loaded and the \"Current function\" parameter updated to be a `GetUserCurrent` class which calls `my_fun`" | ||
"The the model may be loaded and the \"Current function\" parameter updated to be a `UserCurrent` class which calls `my_fun`" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
|
@@ -282,7 +254,7 @@ | |
"# set user defined current function\n", | ||
"A = pybamm.electrical_parameters.I_typ\n", | ||
"omega = 0.1\n", | ||
"param[\"Current function\"] = pybamm.GetUserCurrent(my_fun, A=A, omega=omega)\n", | ||
"param[\"Current function\"] = pybamm.UserCurrent(my_fun, A=A, omega=omega)\n", | ||
"\n", | ||
"# process model and geometry\n", | ||
"param.process_model(model)\n", | ||
|
@@ -293,31 +265,23 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"Note that the parameters in `my_fun` were passed as keyword arguments to the `GetUserCurrent` class. The model may then be solved in the usual way" | ||
"Note that the parameters in `my_fun` were passed as keyword arguments to the `UserCurrent` class. The model may then be solved in the usual way" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 9, | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/home/user/Documents/PyBaMM/venv/lib/python3.6/site-packages/ipykernel_launcher.py:12: DeprecationWarning: object of type <class 'float'> cannot be safely interpreted as an integer.\n", | ||
" if sys.path[0] == '':\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"application/vnd.jupyter.widget-view+json": { | ||
"model_id": "913efe4e3e9e4b37bad2ded9c71b975e", | ||
"model_id": "629672e99152464dad01e57ff152347a", | ||
"version_major": 2, | ||
"version_minor": 0 | ||
}, | ||
"text/plain": [ | ||
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.0019504614993374662, step=9.75230749668733…" | ||
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.0013263138195494769, step=6.63156909774738…" | ||
] | ||
}, | ||
"metadata": {}, | ||
|
@@ -372,7 +336,7 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.8" | ||
"version": "3.7.4" | ||
} | ||
}, | ||
"nbformat": 4, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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