Skip to content

Commit

Permalink
#709 fix some more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Feb 1, 2020
1 parent 05c7446 commit 5a707af
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 125 deletions.
56 changes: 20 additions & 36 deletions examples/notebooks/change-input-current.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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 [A]\". Below we load the SPM with the default parameters, and then change the the current function to 16A."
"In PyBaMM, the current function is set using the parameter \"Current function [A]\". Below we load the SPM with the default parameters, and then change the the current function to be an input parameter, so that we can change it easily later."
]
},
{
Expand All @@ -45,15 +45,18 @@
"# set the default model parameters\n",
"param = model.default_parameter_values\n",
"\n",
"# change the current function\n",
"param[\"Current function [A]\"] = 16"
"# change the current function to be an input parameter\n",
"def current_function(t):\n",
" return pybamm.InputParameter(\"current\")\n",
"\n",
"param[\"Current function [A]\"] = current_function"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now solve the model in the ususal way"
"We can now solve the model in the ususal way, with a 16A current"
]
},
{
Expand All @@ -66,12 +69,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "000da8e81b0b4e91984553ba15ba179c",
"model_id": "839ef921550749ecaae748a2068ee9cc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.0036363636363636364, step=0.005), Output()…"
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.003612040133779264, step=0.005), Output())…"
]
},
"metadata": {},
Expand All @@ -92,9 +95,9 @@
"\n",
"# Solve the model at the given time points\n",
"solver = model.default_solver\n",
"n = 100\n",
"n = 300\n",
"t_eval = np.linspace(0, 0.02, n)\n",
"solution = solver.solve(model, t_eval)\n",
"solution = solver.solve(model, t_eval, inputs={\"current\": 16})\n",
"\n",
"# plot\n",
"quick_plot = pybamm.QuickPlot(solution)\n",
Expand All @@ -114,27 +117,11 @@
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"param[\"Current function [A]\"] = 0"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The model may then be updated and solved again in the usual way."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "cc4fd2e7c9ea4129a7acf0e519fea268",
"model_id": "cfb285a7877c4853ae7144891b38e4cd",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -147,11 +134,8 @@
}
],
"source": [
"# set the parameters for the model and the geometry\n",
"param.update_model(model, disc)\n",
"\n",
"# Solve the model at the given time points\n",
"solution = solver.solve(model, t_eval)\n",
"solution = solver.solve(model, t_eval, inputs={\"current\": 0})\n",
"\n",
"# plot\n",
"quick_plot = pybamm.QuickPlot(solution)\n",
Expand All @@ -171,13 +155,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "84f6cac9b14f43a1907322e650f3c9f8",
"model_id": "d31307d03a2b4082a5ad7b4d91f85823",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -242,7 +226,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -264,7 +248,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -295,13 +279,13 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "09ced8a9e10b4e769a9b4cc8573b7fa2",
"model_id": "bb1a66bff842443cb81abb44a4b4a6a1",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -366,4 +350,4 @@
},
"nbformat": 4,
"nbformat_minor": 2
}
}
Loading

0 comments on commit 5a707af

Please sign in to comment.