Skip to content

Commit 41ded61

Browse files
#1100 merge
2 parents e70e057 + 8d8ae1e commit 41ded61

19 files changed

+367
-218
lines changed

examples/notebooks/Getting Started/Tutorial 4 - Setting parameter values.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@
887887
"\n",
888888
"# Create interpolant\n",
889889
"timescale = parameter_values.evaluate(model.timescale)\n",
890-
"current_interpolant = pybamm.Interpolant(drive_cycle, timescale * pybamm.t)\n",
890+
"current_interpolant = pybamm.Interpolant(drive_cycle[:, 0], drive_cycle[:, 1], timescale * pybamm.t)\n",
891891
"\n",
892892
"# Set drive cycle\n",
893893
"parameter_values[\"Current function [A]\"] = current_interpolant"

examples/notebooks/Getting Started/Tutorial 6 - Managing simulation outputs.ipynb

+59-42
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,23 @@
2222
"metadata": {},
2323
"outputs": [
2424
{
25-
"output_type": "stream",
2625
"name": "stdout",
26+
"output_type": "stream",
2727
"text": [
28-
"\u001b[33mWARNING: You are using pip version 20.2.1; however, version 20.2.4 is available.\n",
28+
"\u001b[33mWARNING: You are using pip version 20.2.4; however, version 20.3.3 is available.\n",
2929
"You should consider upgrading via the '/Users/vsulzer/Documents/Energy_storage/PyBaMM/.tox/dev/bin/python -m pip install --upgrade pip' command.\u001b[0m\n",
3030
"Note: you may need to restart the kernel to use updated packages.\n"
3131
]
3232
},
3333
{
34-
"output_type": "execute_result",
3534
"data": {
3635
"text/plain": [
37-
"<pybamm.solvers.solution.Solution at 0x1467c6820>"
36+
"<pybamm.solvers.solution.Solution at 0x1479dff10>"
3837
]
3938
},
39+
"execution_count": 1,
4040
"metadata": {},
41-
"execution_count": 1
41+
"output_type": "execute_result"
4242
}
4343
],
4444
"source": [
@@ -102,33 +102,33 @@
102102
"metadata": {},
103103
"outputs": [
104104
{
105-
"output_type": "execute_result",
106105
"data": {
107106
"text/plain": [
108-
"array([3.77047806, 3.75305163, 3.74567013, 3.74038819, 3.73581198,\n",
109-
" 3.73153388, 3.72742394, 3.72343938, 3.71956644, 3.71580196,\n",
110-
" 3.71214617, 3.70860034, 3.70516557, 3.70184247, 3.69863116,\n",
111-
" 3.69553115, 3.69254136, 3.6896602 , 3.68688564, 3.68421527,\n",
107+
"array([3.77047806, 3.75305182, 3.74567027, 3.74038822, 3.73581196,\n",
108+
" 3.73153391, 3.72742393, 3.72343929, 3.71956623, 3.71580184,\n",
109+
" 3.71214621, 3.7086004 , 3.70516561, 3.70184253, 3.69863121,\n",
110+
" 3.69553118, 3.69254137, 3.68966018, 3.68688562, 3.68421526,\n",
112111
" 3.68164637, 3.67917591, 3.6768006 , 3.67451688, 3.67232094,\n",
113-
" 3.6702087 , 3.66817572, 3.66621717, 3.66432763, 3.66250091,\n",
114-
" 3.66072975, 3.65900537, 3.65731692, 3.65565067, 3.65398896,\n",
115-
" 3.65230898, 3.65058136, 3.6487688 , 3.64682545, 3.64469796,\n",
116-
" 3.64232964, 3.63966968, 3.63668791, 3.63339298, 3.62984705,\n",
117-
" 3.62616685, 3.62250444, 3.61901236, 3.61580864, 3.61295718,\n",
118-
" 3.61046845, 3.60831404, 3.60644483, 3.60480596, 3.60334607,\n",
112+
" 3.67020869, 3.66817572, 3.66621717, 3.66432762, 3.6625009 ,\n",
113+
" 3.66072974, 3.65900536, 3.65731692, 3.65565066, 3.65398895,\n",
114+
" 3.65230898, 3.65058135, 3.6487688 , 3.64682546, 3.64469798,\n",
115+
" 3.64232968, 3.63966973, 3.63668796, 3.63339303, 3.62984711,\n",
116+
" 3.62616692, 3.6225045 , 3.61901241, 3.61580868, 3.6129572 ,\n",
117+
" 3.61046847, 3.60831405, 3.60644483, 3.60480596, 3.60334607,\n",
119118
" 3.60202167, 3.60079822, 3.5996495 , 3.59855637, 3.59750531,\n",
120119
" 3.59648723, 3.59549638, 3.59452954, 3.59358541, 3.59266405,\n",
121120
" 3.59176646, 3.59089417, 3.59004885, 3.58923192, 3.58844407,\n",
122121
" 3.58768477, 3.58695179, 3.58624057, 3.58554372, 3.58485045,\n",
123122
" 3.58414611, 3.58341187, 3.58262441, 3.58175587, 3.58077378,\n",
124123
" 3.57964098, 3.57831538, 3.5767492 , 3.57488745, 3.57266504,\n",
125-
" 3.5700019 , 3.56679523, 3.56290767, 3.5581495 , 3.55225276,\n",
126-
" 3.54483362, 3.53533853, 3.52296795, 3.50656968, 3.48449277,\n",
127-
" 3.45439366, 3.41299183, 3.35578872, 3.27680073, 3.16842637])"
124+
" 3.5700019 , 3.56679523, 3.56290766, 3.5581495 , 3.55225276,\n",
125+
" 3.54483361, 3.53533853, 3.52296795, 3.50656968, 3.48449277,\n",
126+
" 3.45439366, 3.41299182, 3.35578871, 3.27680072, 3.16842636])"
128127
]
129128
},
129+
"execution_count": 4,
130130
"metadata": {},
131-
"execution_count": 4
131+
"output_type": "execute_result"
132132
}
133133
],
134134
"source": [
@@ -148,7 +148,6 @@
148148
"metadata": {},
149149
"outputs": [
150150
{
151-
"output_type": "execute_result",
152151
"data": {
153152
"text/plain": [
154153
"array([ 0. , 36.36363636, 72.72727273, 109.09090909,\n",
@@ -178,8 +177,9 @@
178177
" 3490.90909091, 3527.27272727, 3563.63636364, 3600. ])"
179178
]
180179
},
180+
"execution_count": 5,
181181
"metadata": {},
182-
"execution_count": 5
182+
"output_type": "execute_result"
183183
}
184184
],
185185
"source": [
@@ -199,14 +199,14 @@
199199
"metadata": {},
200200
"outputs": [
201201
{
202-
"output_type": "execute_result",
203202
"data": {
204203
"text/plain": [
205-
"array([3.72947891, 3.70860034, 3.67810702, 3.65400558])"
204+
"array([3.72947892, 3.7086004 , 3.67810702, 3.65400557])"
206205
]
207206
},
207+
"execution_count": 6,
208208
"metadata": {},
209-
"execution_count": 6
209+
"output_type": "execute_result"
210210
}
211211
],
212212
"source": [
@@ -265,16 +265,18 @@
265265
"metadata": {},
266266
"outputs": [
267267
{
268-
"output_type": "display_data",
269268
"data": {
270-
"text/plain": "interactive(children=(FloatSlider(value=0.0, description='t', max=1.0, step=0.01), Output()), _dom_classes=('w…",
271269
"application/vnd.jupyter.widget-view+json": {
270+
"model_id": "8ceaea70446149079f0194450d7828dc",
272271
"version_major": 2,
273-
"version_minor": 0,
274-
"model_id": "0b4ebac3fdd947218f9444b2b381cf04"
275-
}
272+
"version_minor": 0
273+
},
274+
"text/plain": [
275+
"interactive(children=(FloatSlider(value=0.0, description='t', max=1.0, step=0.01), Output()), _dom_classes=('w…"
276+
]
276277
},
277-
"metadata": {}
278+
"metadata": {},
279+
"output_type": "display_data"
278280
}
279281
],
280282
"source": [
@@ -311,26 +313,28 @@
311313
"metadata": {},
312314
"outputs": [
313315
{
314-
"output_type": "display_data",
315316
"data": {
316-
"text/plain": "interactive(children=(FloatSlider(value=0.0, description='t', max=1.0, step=0.01), Output()), _dom_classes=('w…",
317317
"application/vnd.jupyter.widget-view+json": {
318+
"model_id": "9c9e516a7aef46688f03aaea77505636",
318319
"version_major": 2,
319-
"version_minor": 0,
320-
"model_id": "f4a1b65b2bf945099197135c5598084b"
321-
}
320+
"version_minor": 0
321+
},
322+
"text/plain": [
323+
"interactive(children=(FloatSlider(value=0.0, description='t', max=1.0, step=0.01), Output()), _dom_classes=('w…"
324+
]
322325
},
323-
"metadata": {}
326+
"metadata": {},
327+
"output_type": "display_data"
324328
},
325329
{
326-
"output_type": "execute_result",
327330
"data": {
328331
"text/plain": [
329-
"<pybamm.plotting.quick_plot.QuickPlot at 0x14be13b80>"
332+
"<pybamm.plotting.quick_plot.QuickPlot at 0x149685400>"
330333
]
331334
},
335+
"execution_count": 11,
332336
"metadata": {},
333-
"execution_count": 11
337+
"output_type": "execute_result"
334338
}
335339
],
336340
"source": [
@@ -425,9 +429,22 @@
425429
"name": "python",
426430
"nbconvert_exporter": "python",
427431
"pygments_lexer": "ipython3",
428-
"version": "3.8.5-final"
432+
"version": "3.8.6"
433+
},
434+
"toc": {
435+
"base_numbering": 1,
436+
"nav_menu": {},
437+
"number_sections": true,
438+
"sideBar": true,
439+
"skip_h1_title": false,
440+
"title_cell": "Table of Contents",
441+
"title_sidebar": "Contents",
442+
"toc_cell": false,
443+
"toc_position": {},
444+
"toc_section_display": true,
445+
"toc_window_display": true
429446
}
430447
},
431448
"nbformat": 4,
432449
"nbformat_minor": 2
433-
}
450+
}

examples/notebooks/change-input-current.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@
158158
"\n",
159159
"# create interpolant - must be a function of *dimensional* time\n",
160160
"timescale = param.evaluate(model.timescale)\n",
161-
"current_interpolant = pybamm.Interpolant(drive_cycle, timescale * pybamm.t)\n",
161+
"current_interpolant = pybamm.Interpolant(drive_cycle[:, 0], drive_cycle[:, 1], timescale * pybamm.t)\n",
162162
"\n",
163163
"# set drive cycle\n",
164164
"param[\"Current function [A]\"] = current_interpolant\n",

examples/notebooks/initialize-model-with-solution.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"# create interpolant\n",
8383
"param = model.default_parameter_values\n",
8484
"timescale = param.evaluate(model.timescale)\n",
85-
"current_interpolant = pybamm.Interpolant(drive_cycle, timescale * pybamm.t)\n",
85+
"current_interpolant = pybamm.Interpolant(drive_cycle[:, 0], drive_cycle[:, 1], timescale * pybamm.t)\n",
8686
"# set drive cycle\n",
8787
"param[\"Current function [A]\"] = current_interpolant"
8888
]

examples/notebooks/models/pouch-cell-model.ipynb

+87-59
Large diffs are not rendered by default.

examples/scripts/compare_comsol/compare_comsol_DFN.py

+9-25
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import pybamm
2-
import numpy as np
32
import os
43
import pickle
54
import scipy.interpolate as interp
@@ -78,29 +77,17 @@ def get_interp_fun(variable_name, domain):
7877
comsol_x = comsol_variables["x_p"]
7978
elif domain == whole_cell:
8079
comsol_x = comsol_variables["x"]
80+
8181
# Make sure to use dimensional space
8282
pybamm_x = mesh.combine_submeshes(*domain).nodes * L_x
8383
variable = interp.interp1d(comsol_x, variable, axis=0)(pybamm_x)
8484

85-
def myinterp(t):
86-
try:
87-
return interp.interp1d(
88-
comsol_t, variable, fill_value="extrapolate", bounds_error=False
89-
)(t)[:, np.newaxis]
90-
except ValueError as err:
91-
raise ValueError(
92-
(
93-
"Failed to interpolate '{}' with time range [{}, {}] at time {}."
94-
+ "Original error: {}"
95-
).format(variable_name, comsol_t[0], comsol_t[-1], t, err)
96-
)
97-
98-
# Make sure to use dimensional time
99-
fun = pybamm.Function(
100-
myinterp,
85+
fun = pybamm.Interpolant(
86+
comsol_t,
87+
variable.T,
10188
pybamm.t * pybamm_model.timescale.evaluate(),
102-
name=variable_name + "_comsol",
10389
)
90+
10491
fun.domain = domain
10592
fun.mesh = mesh.combine_submeshes(*domain)
10693
fun.secondary_mesh = None
@@ -113,15 +100,12 @@ def myinterp(t):
113100
comsol_phi_n = get_interp_fun("phi_n", ["negative electrode"])
114101
comsol_phi_e = get_interp_fun("phi_e", whole_cell)
115102
comsol_phi_p = get_interp_fun("phi_p", ["positive electrode"])
116-
comsol_voltage = pybamm.Function(
117-
interp.interp1d(
118-
comsol_t,
119-
comsol_variables["voltage"],
120-
fill_value="extrapolate",
121-
bounds_error=False,
122-
),
103+
comsol_voltage = pybamm.Interpolant(
104+
comsol_t,
105+
comsol_variables["voltage"],
123106
pybamm.t * pybamm_model.timescale.evaluate(),
124107
)
108+
125109
comsol_voltage.mesh = None
126110
comsol_voltage.secondary_mesh = None
127111

examples/scripts/drive_cycle.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121

2222
# create interpolant
2323
timescale = param.evaluate(model.timescale)
24-
current_interpolant = pybamm.Interpolant(drive_cycle, timescale * pybamm.t)
24+
current_interpolant = pybamm.Interpolant(
25+
drive_cycle[:, 0], drive_cycle[:, 1], timescale * pybamm.t
26+
)
2527

2628
# set drive cycle
2729
param["Current function [A]"] = current_interpolant

examples/scripts/experimental_protocols/cccv.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44
import pybamm
55
import matplotlib.pyplot as plt
66

7-
pybamm.set_logging_level("DEBUG")
7+
pybamm.set_logging_level("INFO")
88
experiment = pybamm.Experiment(
99
[
10-
"Discharge at C/1 for 1 hours or until 3.3 V",
10+
"Discharge at C/10 for 10 hours or until 3.3 V",
1111
"Rest for 1 hour",
1212
"Charge at 1 A until 4.1 V",
1313
"Hold at 4.1 V until 50 mA",
1414
"Rest for 1 hour",
1515
]
1616
* 3
1717
)
18-
model = pybamm.lithium_ion.SPM()
18+
model = pybamm.lithium_ion.DFN()
1919
sim = pybamm.Simulation(model, experiment=experiment, solver=pybamm.CasadiSolver())
2020
sim.solve()
2121

pybamm/discretisations/discretisation.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -792,8 +792,8 @@ def process_dict(self, var_eqn_dict):
792792
"""
793793
new_var_eqn_dict = {}
794794
for eqn_key, eqn in var_eqn_dict.items():
795-
# Broadcast if the equation evaluates to a number(e.g. Scalar)
796-
if eqn.evaluates_to_number() and not isinstance(eqn_key, str):
795+
# Broadcast if the equation evaluates to a number (e.g. Scalar)
796+
if np.prod(eqn.shape_for_testing) == 1 and not isinstance(eqn_key, str):
797797
eqn = pybamm.FullBroadcast(
798798
eqn, eqn_key.domain, eqn_key.auxiliary_domains
799799
)

0 commit comments

Comments
 (0)