Skip to content

Commit

Permalink
pybamm-team#1056 added examples on how to pass custom drive cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
brosaplanella committed Jul 28, 2020
1 parent 58e379b commit c57f1bd
Show file tree
Hide file tree
Showing 2 changed files with 175 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@
" 'EC initial concentration in electrolyte [mol.m-3]': 4541.0,\n",
" 'Electrode height [m]': 0.065,\n",
" 'Electrode width [m]': 1.58,\n",
" 'Electrolyte conductivity [S.m-1]': <function electrolyte_conductivity_Nyman2008 at 0x7f234684e1e0>,\n",
" 'Electrolyte diffusivity [m2.s-1]': <function electrolyte_diffusivity_Nyman2008 at 0x7f2391b5a268>,\n",
" 'Electrolyte conductivity [S.m-1]': <function electrolyte_conductivity_Nyman2008 at 0x7f9afbc630d0>,\n",
" 'Electrolyte diffusivity [m2.s-1]': <function electrolyte_diffusivity_Nyman2008 at 0x7f9afbc63048>,\n",
" 'Initial concentration in electrolyte [mol.m-3]': 1000.0,\n",
" 'Initial concentration in negative electrode [mol.m-3]': 29866.0,\n",
" 'Initial concentration in positive electrode [mol.m-3]': 17038.0,\n",
Expand Down Expand Up @@ -407,7 +407,7 @@
" 'Negative electrode diffusivity [m2.s-1]': 3.3e-14,\n",
" 'Negative electrode double-layer capacity [F.m-2]': 0.2,\n",
" 'Negative electrode electrons in reaction': 1.0,\n",
" 'Negative electrode exchange-current density [A.m-2]': <function graphite_LGM50_electrolyte_exchange_current_density_Chen2020 at 0x7f23886d5ea0>,\n",
" 'Negative electrode exchange-current density [A.m-2]': <function graphite_LGM50_electrolyte_exchange_current_density_Chen2020 at 0x7f9afbc9bea0>,\n",
" 'Negative electrode porosity': 0.25,\n",
" 'Negative electrode specific heat capacity [J.kg-1.K-1]': 700.0,\n",
" 'Negative electrode surface area to volume ratio [m-1]': 383959.0,\n",
Expand Down Expand Up @@ -675,7 +675,7 @@
" 'Positive electrode diffusivity [m2.s-1]': 4e-15,\n",
" 'Positive electrode double-layer capacity [F.m-2]': 0.2,\n",
" 'Positive electrode electrons in reaction': 1.0,\n",
" 'Positive electrode exchange-current density [A.m-2]': <function nmc_LGM50_electrolyte_exchange_current_density_Chen2020 at 0x7f234684e0d0>,\n",
" 'Positive electrode exchange-current density [A.m-2]': <function nmc_LGM50_electrolyte_exchange_current_density_Chen2020 at 0x7f9afbc9bf28>,\n",
" 'Positive electrode porosity': 0.335,\n",
" 'Positive electrode specific heat capacity [J.kg-1.K-1]': 700.0,\n",
" 'Positive electrode surface area to volume ratio [m-1]': 382184.0,\n",
Expand Down Expand Up @@ -730,8 +730,8 @@
"output_type": "stream",
"text": [
"EC initial concentration in electrolyte [mol.m-3]\t4541.0\n",
"Electrolyte conductivity [S.m-1]\t<function electrolyte_conductivity_Nyman2008 at 0x7f234684e1e0>\n",
"Electrolyte diffusivity [m2.s-1]\t<function electrolyte_diffusivity_Nyman2008 at 0x7f2391b5a268>\n",
"Electrolyte conductivity [S.m-1]\t<function electrolyte_conductivity_Nyman2008 at 0x7f9afbc630d0>\n",
"Electrolyte diffusivity [m2.s-1]\t<function electrolyte_diffusivity_Nyman2008 at 0x7f9afbc63048>\n",
"Initial concentration in electrolyte [mol.m-3]\t1000.0\n",
"Negative electrode Bruggeman coefficient (electrolyte)\t1.5\n",
"Positive electrode Bruggeman coefficient (electrolyte)\t1.5\n",
Expand All @@ -753,13 +753,13 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "b5f87571fee74cbb90479e86401f1eb4",
"model_id": "972080a3919746689eafda23f53570fc",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -796,7 +796,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -813,7 +813,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -829,13 +829,13 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "947dc63e8bf449028214c950ff6f6844",
"model_id": "2429167130dd43038d4689be994e39f9",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -864,12 +864,19 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also simulate drive cycles by passing the data directly"
"### Drive cycle"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also simulate the PyBaMM default drive cycles by calling the dataset directly"
]
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -880,18 +887,18 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Then we can just define the model and solve it"
"Then we can just define the model and solve it. In this case we do not need to specify a time interval to solve as PyBaMM automatically picks it from data"
]
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "08ca39eec4544f6b86e227156d3937b2",
"model_id": "899c5194ed124a76a3cbc9ea8c372956",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -910,6 +917,74 @@
"sim.plot([\"Current [A]\", \"Terminal voltage [V]\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Alternatively, you can implement your own drive cycles importing the dataset and creating an interpolant to pass as the current function."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd # needed to read the csv data file\n",
"\n",
"# Import drive cycle from file\n",
"drive_cycle = pd.read_csv(\"../../../pybamm/input/drive_cycles/US06.csv\", comment=\"#\", header=None).to_numpy()\n",
"\n",
"# Create interpolant\n",
"timescale = parameter_values.evaluate(model.timescale)\n",
"current_interpolant = pybamm.Interpolant(drive_cycle, timescale * pybamm.t)\n",
"\n",
"# Set drive cycle\n",
"parameter_values[\"Current function [A]\"] = current_interpolant"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Then, again, the model can be solved as usual but notice that now we do need to pass `t_eval` to the solver."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "349094f0a1dc43ecbf1fa0b67931823d",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=600.0, step=6.0), Output()), _dom_classes=('…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"model = pybamm.lithium_ion.SPMe()\n",
"sim = pybamm.Simulation(model, parameter_values=parameter_values)\n",
"t_eval = drive_cycle[:, 0] # define t_eval from the dataset\n",
"sim.solve(t_eval)\n",
"sim.plot([\"Current [A]\", \"Terminal voltage [V]\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Custom current function"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -919,7 +994,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -940,13 +1015,13 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e166a9f922d14eaebe4be57072829277",
"model_id": "d382e196729d4354a4e8fd50d700c50e",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -976,9 +1051,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "PyBaMM development (env)",
"language": "python",
"name": "python3"
"name": "pybamm-dev"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -990,7 +1065,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
"version": "3.6.8"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit c57f1bd

Please sign in to comment.