Skip to content

Commit 5a707af

Browse files
#709 fix some more examples
1 parent 05c7446 commit 5a707af

File tree

4 files changed

+136
-125
lines changed

4 files changed

+136
-125
lines changed

examples/notebooks/change-input-current.ipynb

+20-36
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"\n",
2323
"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",
2424
"\n",
25-
"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."
25+
"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."
2626
]
2727
},
2828
{
@@ -45,15 +45,18 @@
4545
"# set the default model parameters\n",
4646
"param = model.default_parameter_values\n",
4747
"\n",
48-
"# change the current function\n",
49-
"param[\"Current function [A]\"] = 16"
48+
"# change the current function to be an input parameter\n",
49+
"def current_function(t):\n",
50+
" return pybamm.InputParameter(\"current\")\n",
51+
"\n",
52+
"param[\"Current function [A]\"] = current_function"
5053
]
5154
},
5255
{
5356
"cell_type": "markdown",
5457
"metadata": {},
5558
"source": [
56-
"We can now solve the model in the ususal way"
59+
"We can now solve the model in the ususal way, with a 16A current"
5760
]
5861
},
5962
{
@@ -66,12 +69,12 @@
6669
{
6770
"data": {
6871
"application/vnd.jupyter.widget-view+json": {
69-
"model_id": "000da8e81b0b4e91984553ba15ba179c",
72+
"model_id": "839ef921550749ecaae748a2068ee9cc",
7073
"version_major": 2,
7174
"version_minor": 0
7275
},
7376
"text/plain": [
74-
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.0036363636363636364, step=0.005), Output()…"
77+
"interactive(children=(FloatSlider(value=0.0, description='t', max=0.003612040133779264, step=0.005), Output())…"
7578
]
7679
},
7780
"metadata": {},
@@ -92,9 +95,9 @@
9295
"\n",
9396
"# Solve the model at the given time points\n",
9497
"solver = model.default_solver\n",
95-
"n = 100\n",
98+
"n = 300\n",
9699
"t_eval = np.linspace(0, 0.02, n)\n",
97-
"solution = solver.solve(model, t_eval)\n",
100+
"solution = solver.solve(model, t_eval, inputs={\"current\": 16})\n",
98101
"\n",
99102
"# plot\n",
100103
"quick_plot = pybamm.QuickPlot(solution)\n",
@@ -114,27 +117,11 @@
114117
"cell_type": "code",
115118
"execution_count": 3,
116119
"metadata": {},
117-
"outputs": [],
118-
"source": [
119-
"param[\"Current function [A]\"] = 0"
120-
]
121-
},
122-
{
123-
"cell_type": "markdown",
124-
"metadata": {},
125-
"source": [
126-
"The model may then be updated and solved again in the usual way."
127-
]
128-
},
129-
{
130-
"cell_type": "code",
131-
"execution_count": 4,
132-
"metadata": {},
133120
"outputs": [
134121
{
135122
"data": {
136123
"application/vnd.jupyter.widget-view+json": {
137-
"model_id": "cc4fd2e7c9ea4129a7acf0e519fea268",
124+
"model_id": "cfb285a7877c4853ae7144891b38e4cd",
138125
"version_major": 2,
139126
"version_minor": 0
140127
},
@@ -147,11 +134,8 @@
147134
}
148135
],
149136
"source": [
150-
"# set the parameters for the model and the geometry\n",
151-
"param.update_model(model, disc)\n",
152-
"\n",
153137
"# Solve the model at the given time points\n",
154-
"solution = solver.solve(model, t_eval)\n",
138+
"solution = solver.solve(model, t_eval, inputs={\"current\": 0})\n",
155139
"\n",
156140
"# plot\n",
157141
"quick_plot = pybamm.QuickPlot(solution)\n",
@@ -171,13 +155,13 @@
171155
},
172156
{
173157
"cell_type": "code",
174-
"execution_count": 5,
158+
"execution_count": 4,
175159
"metadata": {},
176160
"outputs": [
177161
{
178162
"data": {
179163
"application/vnd.jupyter.widget-view+json": {
180-
"model_id": "84f6cac9b14f43a1907322e650f3c9f8",
164+
"model_id": "d31307d03a2b4082a5ad7b4d91f85823",
181165
"version_major": 2,
182166
"version_minor": 0
183167
},
@@ -242,7 +226,7 @@
242226
},
243227
{
244228
"cell_type": "code",
245-
"execution_count": 6,
229+
"execution_count": 5,
246230
"metadata": {},
247231
"outputs": [],
248232
"source": [
@@ -264,7 +248,7 @@
264248
},
265249
{
266250
"cell_type": "code",
267-
"execution_count": 7,
251+
"execution_count": 6,
268252
"metadata": {},
269253
"outputs": [],
270254
"source": [
@@ -295,13 +279,13 @@
295279
},
296280
{
297281
"cell_type": "code",
298-
"execution_count": 8,
282+
"execution_count": 7,
299283
"metadata": {},
300284
"outputs": [
301285
{
302286
"data": {
303287
"application/vnd.jupyter.widget-view+json": {
304-
"model_id": "09ced8a9e10b4e769a9b4cc8573b7fa2",
288+
"model_id": "bb1a66bff842443cb81abb44a4b4a6a1",
305289
"version_major": 2,
306290
"version_minor": 0
307291
},
@@ -366,4 +350,4 @@
366350
},
367351
"nbformat": 4,
368352
"nbformat_minor": 2
369-
}
353+
}

0 commit comments

Comments
 (0)