From 82e19ef95c84fbb0d9f29e9de4c0aa1d96dd4c8c Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Mon, 9 Jan 2023 15:25:52 +0000 Subject: [PATCH 01/11] Added new parameter 'Contact resistance [Ohm]' and new variable 'Contact voltage [V]' --- .../input/parameters/lead_acid/Sulzer2019.py | 1 + pybamm/input/parameters/lithium_ion/Ai2020.py | 1 + .../input/parameters/lithium_ion/Chen2020.py | 1 + .../lithium_ion/Chen2020_composite.py | 1 + .../input/parameters/lithium_ion/Ecker2015.py | 1 + .../parameters/lithium_ion/Marquis2019.py | 1 + .../parameters/lithium_ion/Mohtat2020.py | 1 + .../parameters/lithium_ion/NCA_Kim2011.py | 1 + .../input/parameters/lithium_ion/OKane2022.py | 1 + .../parameters/lithium_ion/ORegan2022.py | 1 + .../input/parameters/lithium_ion/Prada2013.py | 1 + .../parameters/lithium_ion/Ramadass2004.py | 1 + pybamm/input/parameters/lithium_ion/Xu2019.py | 1 + .../cells/Enertech_Ai2020/parameters.csv | 3 ++- .../submodels/electrode/base_electrode.py | 22 +++++++++++++++++++ pybamm/parameters/electrical_parameters.py | 1 + pybamm/parameters/lead_acid_parameters.py | 1 + pybamm/parameters/lithium_ion_parameters.py | 1 + 18 files changed, 40 insertions(+), 1 deletion(-) diff --git a/pybamm/input/parameters/lead_acid/Sulzer2019.py b/pybamm/input/parameters/lead_acid/Sulzer2019.py index 95c1635884..279414348f 100644 --- a/pybamm/input/parameters/lead_acid/Sulzer2019.py +++ b/pybamm/input/parameters/lead_acid/Sulzer2019.py @@ -259,6 +259,7 @@ def get_parameter_values(): "Positive current collector specific heat capacity [J.kg-1.K-1]": 256.0, "Negative current collector thermal conductivity [W.m-1.K-1]": 35.0, "Positive current collector thermal conductivity [W.m-1.K-1]": 35.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 4800000.0, "Negative electrode pore size [m]": 1e-07, diff --git a/pybamm/input/parameters/lithium_ion/Ai2020.py b/pybamm/input/parameters/lithium_ion/Ai2020.py index cf05c19108..82f1c9a10c 100644 --- a/pybamm/input/parameters/lithium_ion/Ai2020.py +++ b/pybamm/input/parameters/lithium_ion/Ai2020.py @@ -607,6 +607,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 2.28, "Typical current [A]": 2.28, "Current function [A]": 2.28, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 100.0, "Maximum concentration in negative electrode [mol.m-3]": 28700.0, diff --git a/pybamm/input/parameters/lithium_ion/Chen2020.py b/pybamm/input/parameters/lithium_ion/Chen2020.py index 973a6893c1..520e0aac68 100644 --- a/pybamm/input/parameters/lithium_ion/Chen2020.py +++ b/pybamm/input/parameters/lithium_ion/Chen2020.py @@ -295,6 +295,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 5.0, "Typical current [A]": 5.0, "Current function [A]": 5.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 215.0, "Maximum concentration in negative electrode [mol.m-3]": 33133.0, diff --git a/pybamm/input/parameters/lithium_ion/Chen2020_composite.py b/pybamm/input/parameters/lithium_ion/Chen2020_composite.py index 3ca393d270..98d82b2ef3 100644 --- a/pybamm/input/parameters/lithium_ion/Chen2020_composite.py +++ b/pybamm/input/parameters/lithium_ion/Chen2020_composite.py @@ -395,6 +395,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 5.0, "Typical current [A]": 5.0, "Current function [A]": 5.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 215.0, "Primary: Maximum concentration in negative electrode [mol.m-3]": 28700.0, diff --git a/pybamm/input/parameters/lithium_ion/Ecker2015.py b/pybamm/input/parameters/lithium_ion/Ecker2015.py index 8feee0dc95..0e8a9aa1a6 100644 --- a/pybamm/input/parameters/lithium_ion/Ecker2015.py +++ b/pybamm/input/parameters/lithium_ion/Ecker2015.py @@ -498,6 +498,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 0.15625, "Typical current [A]": 0.15652, "Current function [A]": 0.15652, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 14.0, "Maximum concentration in negative electrode [mol.m-3]": 31920.0, diff --git a/pybamm/input/parameters/lithium_ion/Marquis2019.py b/pybamm/input/parameters/lithium_ion/Marquis2019.py index f004ea545c..49265e7a51 100644 --- a/pybamm/input/parameters/lithium_ion/Marquis2019.py +++ b/pybamm/input/parameters/lithium_ion/Marquis2019.py @@ -425,6 +425,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 0.680616, "Typical current [A]": 0.680616, "Current function [A]": 0.680616, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 100.0, "Maximum concentration in negative electrode [mol.m-3]": 24983.2619938437, diff --git a/pybamm/input/parameters/lithium_ion/Mohtat2020.py b/pybamm/input/parameters/lithium_ion/Mohtat2020.py index ed8f223b89..078655d2ea 100644 --- a/pybamm/input/parameters/lithium_ion/Mohtat2020.py +++ b/pybamm/input/parameters/lithium_ion/Mohtat2020.py @@ -419,6 +419,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 5.0, "Typical current [A]": 5.0, "Current function [A]": 5.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 100.0, "Maximum concentration in negative electrode [mol.m-3]": 28746.0, diff --git a/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py b/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py index 56ed2ffa5a..f0286fc24e 100644 --- a/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py +++ b/pybamm/input/parameters/lithium_ion/NCA_Kim2011.py @@ -369,6 +369,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 0.43, "Typical current [A]": 0.43, "Current function [A]": 0.43, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 100.0, "Maximum concentration in negative electrode [mol.m-3]": 28700.0, diff --git a/pybamm/input/parameters/lithium_ion/OKane2022.py b/pybamm/input/parameters/lithium_ion/OKane2022.py index 0040fb564e..7c6fe6ebb4 100644 --- a/pybamm/input/parameters/lithium_ion/OKane2022.py +++ b/pybamm/input/parameters/lithium_ion/OKane2022.py @@ -583,6 +583,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 5.0, "Typical current [A]": 5.0, "Current function [A]": 5.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 215.0, "Maximum concentration in negative electrode [mol.m-3]": 33133.0, diff --git a/pybamm/input/parameters/lithium_ion/ORegan2022.py b/pybamm/input/parameters/lithium_ion/ORegan2022.py index 5dfc091246..d1716bc9e3 100644 --- a/pybamm/input/parameters/lithium_ion/ORegan2022.py +++ b/pybamm/input/parameters/lithium_ion/ORegan2022.py @@ -963,6 +963,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 5.0, "Typical current [A]": 5.0, "Current function [A]": 5.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 215.0, "Maximum concentration in negative electrode [mol.m-3]": 29583.0, diff --git a/pybamm/input/parameters/lithium_ion/Prada2013.py b/pybamm/input/parameters/lithium_ion/Prada2013.py index b334a358f5..dd103ea2d8 100644 --- a/pybamm/input/parameters/lithium_ion/Prada2013.py +++ b/pybamm/input/parameters/lithium_ion/Prada2013.py @@ -268,6 +268,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 1.1, "Current function [A]": 1.1, "Typical current [A]": 1.1, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 215.0, "Maximum concentration in negative electrode [mol.m-3]": 33133.0, diff --git a/pybamm/input/parameters/lithium_ion/Ramadass2004.py b/pybamm/input/parameters/lithium_ion/Ramadass2004.py index 76db1eba63..bf8eb69c0e 100644 --- a/pybamm/input/parameters/lithium_ion/Ramadass2004.py +++ b/pybamm/input/parameters/lithium_ion/Ramadass2004.py @@ -438,6 +438,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 1.0, "Typical current [A]": 1.0, "Current function [A]": 1.0, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode conductivity [S.m-1]": 100.0, "Maximum concentration in negative electrode [mol.m-3]": 30555.0, diff --git a/pybamm/input/parameters/lithium_ion/Xu2019.py b/pybamm/input/parameters/lithium_ion/Xu2019.py index b67b66d32a..88ed1bfb07 100644 --- a/pybamm/input/parameters/lithium_ion/Xu2019.py +++ b/pybamm/input/parameters/lithium_ion/Xu2019.py @@ -270,6 +270,7 @@ def get_parameter_values(): "Nominal cell capacity [A.h]": 0.0024, "Typical current [A]": 0.0024, "Current function [A]": 0.0024, + "Contact resistance [Ohm]": 0, # negative electrode "Negative electrode OCP [V]": 0.0, "Negative electrode conductivity [S.m-1]": 10776000.0, diff --git a/pybamm/input/parameters/lithium_ion/testing_only/cells/Enertech_Ai2020/parameters.csv b/pybamm/input/parameters/lithium_ion/testing_only/cells/Enertech_Ai2020/parameters.csv index 9c3ff672b1..4a8a3594b5 100644 --- a/pybamm/input/parameters/lithium_ion/testing_only/cells/Enertech_Ai2020/parameters.csv +++ b/pybamm/input/parameters/lithium_ion/testing_only/cells/Enertech_Ai2020/parameters.csv @@ -33,4 +33,5 @@ Positive current collector thermal conductivity [W.m-1.K-1],237,CRC Handbook,alu # Electrical,,, Nominal cell capacity [A.h], 2.28,Ai 2020,2.28/34 Typical current [A], 2.28,Ai 2020, -Current function [A], 2.28,default current function, \ No newline at end of file +Current function [A], 2.28,default current function, +Contact resistance [Ohm], 0,, \ No newline at end of file diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 43436c2286..761721cce4 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -186,6 +186,7 @@ def _get_standard_whole_cell_variables(self, variables): variables.update({"Electrode current density": i_s}) if self.set_positive_potential: + param = self.param # Get phi_s_cn from the current collector submodel and phi_s_p from the # electrode submodel phi_s_cn = variables["Negative current collector potential"] @@ -196,5 +197,26 @@ def _get_standard_whole_cell_variables(self, variables): phi_s_cn, phi_s_cp ) ) + V_dim = variables["Terminal voltage [V]"] + if "Current [A]" in variables: + I = variables["Current [A]"] + V_contact_dim = V_dim - I * param.R_contact + elif self.options["operating mode"] == "explicit power": + P = pybamm.FunctionParameter( + "Power function [W]", {"Time [s]": pybamm.t * self.param.timescale} + ) + discriminant = V_dim ** 2 - 4 * P * param.R_contact + V_contact_dim = (V_dim + pybamm.sqrt(discriminant)) / 2 + elif self.options["operating mode"] == "explicit resistance": + # Approximation: only valid if R_contact << R + R = pybamm.FunctionParameter( + "Resistance function [Ohm]", {"Time [s]": pybamm.t * self.param.timescale} + ) + V_contact_dim = V_dim * (1 - param.R_contact / R) + V_contact = V_contact_dim / param.potential_scale + variables.update({ + "Contact voltage": V_contact, + "Contact voltage [V]": V_contact_dim, + }) return variables diff --git a/pybamm/parameters/electrical_parameters.py b/pybamm/parameters/electrical_parameters.py index 7992cbf727..a2bf2f22d4 100644 --- a/pybamm/parameters/electrical_parameters.py +++ b/pybamm/parameters/electrical_parameters.py @@ -29,6 +29,7 @@ def _set_dimensional_parameters(self): self.I_typ = pybamm.Parameter("Typical current [A]") self.Q = pybamm.Parameter("Nominal cell capacity [A.h]") + self.R_contact = pybamm.Parameter("Contact resistance [Ohm]") self.C_rate = pybamm.AbsoluteValue(self.I_typ / self.Q) self.n_electrodes_parallel = pybamm.Parameter( "Number of electrodes connected in parallel to make a cell" diff --git a/pybamm/parameters/lead_acid_parameters.py b/pybamm/parameters/lead_acid_parameters.py index 6c9ff95c20..eb79e5851e 100644 --- a/pybamm/parameters/lead_acid_parameters.py +++ b/pybamm/parameters/lead_acid_parameters.py @@ -67,6 +67,7 @@ def _set_dimensional_parameters(self): # Electrical self.I_typ = self.elec.I_typ self.Q = self.elec.Q + self.R_contact = self.elec.R_contact self.C_rate = self.elec.C_rate self.n_electrodes_parallel = self.elec.n_electrodes_parallel self.n_cells = self.elec.n_cells diff --git a/pybamm/parameters/lithium_ion_parameters.py b/pybamm/parameters/lithium_ion_parameters.py index c2118edaab..f255aefe5e 100644 --- a/pybamm/parameters/lithium_ion_parameters.py +++ b/pybamm/parameters/lithium_ion_parameters.py @@ -87,6 +87,7 @@ def _set_dimensional_parameters(self): # Electrical self.I_typ = self.elec.I_typ self.Q = self.elec.Q + self.R_contact = self.elec.R_contact self.C_rate = self.elec.C_rate self.n_electrodes_parallel = self.elec.n_electrodes_parallel self.n_cells = self.elec.n_cells From 80c9afd16d3b8280c8f7b94af797c997c037ea25 Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Mon, 9 Jan 2023 15:27:39 +0000 Subject: [PATCH 02/11] flake8 --- pybamm/models/submodels/electrode/base_electrode.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 761721cce4..5ac4386c72 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -210,7 +210,9 @@ def _get_standard_whole_cell_variables(self, variables): elif self.options["operating mode"] == "explicit resistance": # Approximation: only valid if R_contact << R R = pybamm.FunctionParameter( - "Resistance function [Ohm]", {"Time [s]": pybamm.t * self.param.timescale} + "Resistance function [Ohm]", { + "Time [s]": pybamm.t * self.param.timescale + } ) V_contact_dim = V_dim * (1 - param.R_contact / R) V_contact = V_contact_dim / param.potential_scale From 7a657881c7bd0914634d837dbc63bea9f0d3f1e5 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 9 Jan 2023 15:31:03 +0000 Subject: [PATCH 03/11] style: pre-commit fixes --- .../submodels/electrode/base_electrode.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 5ac4386c72..55319093c2 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -205,20 +205,21 @@ def _get_standard_whole_cell_variables(self, variables): P = pybamm.FunctionParameter( "Power function [W]", {"Time [s]": pybamm.t * self.param.timescale} ) - discriminant = V_dim ** 2 - 4 * P * param.R_contact + discriminant = V_dim**2 - 4 * P * param.R_contact V_contact_dim = (V_dim + pybamm.sqrt(discriminant)) / 2 elif self.options["operating mode"] == "explicit resistance": # Approximation: only valid if R_contact << R R = pybamm.FunctionParameter( - "Resistance function [Ohm]", { - "Time [s]": pybamm.t * self.param.timescale - } + "Resistance function [Ohm]", + {"Time [s]": pybamm.t * self.param.timescale}, ) V_contact_dim = V_dim * (1 - param.R_contact / R) V_contact = V_contact_dim / param.potential_scale - variables.update({ - "Contact voltage": V_contact, - "Contact voltage [V]": V_contact_dim, - }) + variables.update( + { + "Contact voltage": V_contact, + "Contact voltage [V]": V_contact_dim, + } + ) return variables From 9dde91396f0747285461480d9149c3a7f7da134a Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Mon, 9 Jan 2023 15:34:36 +0000 Subject: [PATCH 04/11] changelog --- CHANGELOG.md | 1 + pybamm/models/submodels/electrode/base_electrode.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a38d5b8c76..8c512b2960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Features - Steps in `Experiment` can now be tagged and cycle numbers be searched based on those tags ([#2593](https://github.com/pybamm-team/PyBaMM/pull/2593)). +- New parameter `Contact resistance [Ohm]` and corresponding variable `Contact voltage [V]` ([#2598](https://github.com/pybamm-team/PyBaMM/pull/2598)). # [v22.12](https://github.com/pybamm-team/PyBaMM/tree/v22.12) - 2022-12-31 diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 5ac4386c72..6bfbc4693c 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -197,6 +197,9 @@ def _get_standard_whole_cell_variables(self, variables): phi_s_cn, phi_s_cp ) ) + # Contact resistance alters the voltage. To make sure it works for all + # operating modes, a new variable "Contact voltage [V]" is created instead + # of changing the existing "Terminal voltage [V]". V_dim = variables["Terminal voltage [V]"] if "Current [A]" in variables: I = variables["Current [A]"] From cf28b969d4f583be6fc33bded4732bfd2588e558 Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Mon, 9 Jan 2023 16:45:31 +0000 Subject: [PATCH 05/11] Added contact resistance to test_bpx --- tests/unit/test_parameters/test_bpx.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_parameters/test_bpx.py b/tests/unit/test_parameters/test_bpx.py index 5aeca8696d..1b3ae54714 100644 --- a/tests/unit/test_parameters/test_bpx.py +++ b/tests/unit/test_parameters/test_bpx.py @@ -34,6 +34,7 @@ def setUp(self): "in parallel to make a cell": 34, "External surface area [m2]": 3.79e-2, "Volume [m3]": 1.28e-4, + "Contact resistance [Ohm]": 0, }, "Electrolyte": { "Initial concentration [mol.m-3]": 1000, From 9fc00b2967fd3dbb47685e09b375fbce9b2447c9 Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Mon, 9 Jan 2023 17:33:17 +0000 Subject: [PATCH 06/11] Added contact resistance to bpx.py --- pybamm/parameters/bpx.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pybamm/parameters/bpx.py b/pybamm/parameters/bpx.py index 61f2445166..524e9a0863 100644 --- a/pybamm/parameters/bpx.py +++ b/pybamm/parameters/bpx.py @@ -75,6 +75,9 @@ def _bpx_to_param_dict(bpx: BPX) -> dict: pybamm_dict["Current function [A]"] = pybamm_dict["Nominal cell capacity [A.h]"] pybamm_dict["Typical current [A]"] = pybamm_dict["Nominal cell capacity [A.h]"] + # assume no contact resistance + pybamm_dict["Contact resistance [Ohm]"] = 0 + # number of electrons in reaction (1 for li-ion) for domain in [negative_electrode, positive_electrode]: pybamm_dict[domain.pre_name + "electrons in reaction"] = 1.0 From 8741db629c1778282d4c8e770f013de7ba446be3 Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Fri, 13 Jan 2023 13:14:47 +0000 Subject: [PATCH 07/11] Added 'contact resistance' option; removed separate variable 'Contact voltage [V]' --- .../full_battery_models/base_battery_model.py | 14 ++++- .../submodels/electrode/base_electrode.py | 51 +++++++------------ pybamm/parameters/bpx.py | 3 -- .../test_base_battery_model.py | 23 ++++++++- .../base_lithium_ion_tests.py | 4 ++ tests/unit/test_parameters/test_bpx.py | 1 - 6 files changed, 55 insertions(+), 41 deletions(-) diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index 681c173f8d..08e3999813 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -187,8 +187,9 @@ class BatteryModelOptions(pybamm.FuzzyDict): def __init__(self, extra_options): self.possible_options = { "calculate discharge energy": ["false", "true"], - "cell geometry": ["arbitrary", "pouch"], "calculate heat source for isothermal models": ["false", "true"], + "cell geometry": ["arbitrary", "pouch"], + "contact resistance": ["false", "true"], "convection": ["none", "uniform transverse", "full transverse"], "current collector": [ "uniform", @@ -405,6 +406,17 @@ def __init__(self, extra_options): "and there are multiple phases then 'total interfacial " "current density as a state' must be 'true'" ) + + # Options not yet compatible with contact resistance + if options["contact resistance"] == "true": + if options["operating mode"] == "explicit power": + raise NotImplementedError( + "Contact resistance not yet supported for explicit power." + ) + if options["operating mode"] == "explicit resistance": + raise NotImplementedError( + "Contact resistance not yet supported for explicit resistance." + ) # Options not yet compatible with particle-size distributions if options["particle size"] == "distribution": diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 160d26ea04..67909a0927 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -111,7 +111,9 @@ def _get_standard_current_variables(self, i_s): return variables - def _get_standard_current_collector_potential_variables(self, phi_s_cn, phi_s_cp): + def _get_standard_current_collector_potential_variables( + self, phi_s_cn, phi_s_cp, delta_phi_contact + ): """ A private function to obtain the standard variables which can be derived from the potentials in the current collector. @@ -122,6 +124,8 @@ def _get_standard_current_collector_potential_variables(self, phi_s_cn, phi_s_cp The potential in the negative current collector. phi_s_cp : :class:`pybamm.Symbol` The potential in the positive current collector. + delta_phi_contact : :class:`pybamm.Symbol` + The potential difference due to the contact resistance, if any. Returns ------- @@ -141,8 +145,9 @@ def _get_standard_current_collector_potential_variables(self, phi_s_cn, phi_s_cp V = pybamm.boundary_value(phi_s_cp, "positive tab") V_dim = pybamm.boundary_value(phi_s_cp_dim, "positive tab") - # Voltage is local current collector potential difference at the tabs, in 1D - # this will be equal to the local current collector potential difference + # Voltage is local current collector potential difference at the tabs. + # In 1D this will be equal to the local current collector potential difference. + # The potential drop due to contact resistance (if any) is subtracted. variables = { "Negative current collector potential": phi_s_cn, @@ -151,8 +156,8 @@ def _get_standard_current_collector_potential_variables(self, phi_s_cn, phi_s_cp "Positive current collector potential [V]": phi_s_cp_dim, "Local voltage": V_cc, "Local voltage [V]": self.param.ocv_ref + V_cc * pot_scale, - "Terminal voltage": V, - "Terminal voltage [V]": V_dim, + "Terminal voltage": V - delta_phi_contact, + "Terminal voltage [V]": V_dim - delta_phi_contact * pot_scale, } return variables @@ -186,43 +191,21 @@ def _get_standard_whole_cell_variables(self, variables): variables.update({"Electrode current density": i_s}) if self.set_positive_potential: - param = self.param # Get phi_s_cn from the current collector submodel and phi_s_p from the # electrode submodel phi_s_cn = variables["Negative current collector potential"] phi_s_p = variables["Positive electrode potential"] phi_s_cp = pybamm.boundary_value(phi_s_p, "right") + if self.options["contact resistance"] == "true": + param = self.param + I = variables["Current [A]"] + delta_phi_contact = I * param.R_contact / param.potential_scale + else: + delta_phi_contact = pybamm.Scalar(0) variables.update( self._get_standard_current_collector_potential_variables( - phi_s_cn, phi_s_cp - ) - ) - # Contact resistance alters the voltage. To make sure it works for all - # operating modes, a new variable "Contact voltage [V]" is created instead - # of changing the existing "Terminal voltage [V]". - V_dim = variables["Terminal voltage [V]"] - if "Current [A]" in variables: - I = variables["Current [A]"] - V_contact_dim = V_dim - I * param.R_contact - elif self.options["operating mode"] == "explicit power": - P = pybamm.FunctionParameter( - "Power function [W]", {"Time [s]": pybamm.t * self.param.timescale} + phi_s_cn, phi_s_cp, delta_phi_contact ) - discriminant = V_dim**2 - 4 * P * param.R_contact - V_contact_dim = (V_dim + pybamm.sqrt(discriminant)) / 2 - elif self.options["operating mode"] == "explicit resistance": - # Approximation: only valid if R_contact << R - R = pybamm.FunctionParameter( - "Resistance function [Ohm]", - {"Time [s]": pybamm.t * self.param.timescale}, - ) - V_contact_dim = V_dim * (1 - param.R_contact / R) - V_contact = V_contact_dim / param.potential_scale - variables.update( - { - "Contact voltage": V_contact, - "Contact voltage [V]": V_contact_dim, - } ) return variables diff --git a/pybamm/parameters/bpx.py b/pybamm/parameters/bpx.py index 524e9a0863..61f2445166 100644 --- a/pybamm/parameters/bpx.py +++ b/pybamm/parameters/bpx.py @@ -75,9 +75,6 @@ def _bpx_to_param_dict(bpx: BPX) -> dict: pybamm_dict["Current function [A]"] = pybamm_dict["Nominal cell capacity [A.h]"] pybamm_dict["Typical current [A]"] = pybamm_dict["Nominal cell capacity [A.h]"] - # assume no contact resistance - pybamm_dict["Contact resistance [Ohm]"] = 0 - # number of electrons in reaction (1 for li-ion) for domain in [negative_electrode, positive_electrode]: pybamm_dict[domain.pre_name + "electrons in reaction"] = 1.0 diff --git a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py index b24026f251..a48c6c5def 100644 --- a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py +++ b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py @@ -15,8 +15,9 @@ PRINT_OPTIONS_OUTPUT = """\ 'calculate discharge energy': 'false' (possible: ['false', 'true']) -'cell geometry': 'pouch' (possible: ['arbitrary', 'pouch']) 'calculate heat source for isothermal models': 'false' (possible: ['false', 'true']) +'cell geometry': 'pouch' (possible: ['arbitrary', 'pouch']) +'contact resistance': 'false' (possible: ['false', 'true']) 'convection': 'none' (possible: ['none', 'uniform transverse', 'full transverse']) 'current collector': 'uniform' (possible: ['uniform', 'potential pair', 'potential pair quite conductive']) 'dimensionality': 0 (possible: [0, 1, 2]) @@ -310,7 +311,6 @@ def test_options(self): # plating model with self.assertRaisesRegex(pybamm.OptionError, "lithium plating"): pybamm.BaseBatteryModel({"lithium plating": "bad plating"}) - with self.assertRaisesRegex( pybamm.OptionError, "lithium plating porosity change" ): @@ -320,6 +320,25 @@ def test_options(self): "plating porosity change" } ) + + # contact resistance + with self.assertRaisesRegex(pybamm.OptionError, "contact resistance"): + pybamm.BaseBatteryModel({"contact resistance": "bad contact resistance"}) + with self.assertRaisesRegex(NotImplementedError, "Contact resistance not yet"): + pybamm.BaseBatteryModel( + { + "contact resistance": "true", + "operating mode": "explicit power", + } + ) + with self.assertRaisesRegex(NotImplementedError, "Contact resistance not yet"): + pybamm.BaseBatteryModel( + { + "contact resistance": "true", + "operating mode": "explicit resistance", + } + ) + # stress-induced diffusion with self.assertRaisesRegex(pybamm.OptionError, "cannot have stress"): pybamm.BaseBatteryModel({"stress-induced diffusion": "true"}) diff --git a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py index 7dbe128221..75e797960b 100644 --- a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py +++ b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/base_lithium_ion_tests.py @@ -67,6 +67,10 @@ def test_well_posed_thermal_2plus1D(self): } self.check_well_posedness(options) + def test_well_posed_contact_resistance(self): + options = {"contact resistance": "true"} + self.check_well_posedness(options) + def test_well_posed_particle_uniform(self): options = {"particle": "uniform profile"} self.check_well_posedness(options) diff --git a/tests/unit/test_parameters/test_bpx.py b/tests/unit/test_parameters/test_bpx.py index 1b3ae54714..5aeca8696d 100644 --- a/tests/unit/test_parameters/test_bpx.py +++ b/tests/unit/test_parameters/test_bpx.py @@ -34,7 +34,6 @@ def setUp(self): "in parallel to make a cell": 34, "External surface area [m2]": 3.79e-2, "Volume [m3]": 1.28e-4, - "Contact resistance [Ohm]": 0, }, "Electrolyte": { "Initial concentration [mol.m-3]": 1000, From e853c0831f57c33b168e2f61e5cd5687753259ce Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 13 Jan 2023 13:16:18 +0000 Subject: [PATCH 08/11] style: pre-commit fixes --- pybamm/models/full_battery_models/base_battery_model.py | 2 +- pybamm/models/submodels/electrode/base_electrode.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index 08e3999813..e2a30f21a4 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -406,7 +406,7 @@ def __init__(self, extra_options): "and there are multiple phases then 'total interfacial " "current density as a state' must be 'true'" ) - + # Options not yet compatible with contact resistance if options["contact resistance"] == "true": if options["operating mode"] == "explicit power": diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 67909a0927..f2a8367060 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -112,8 +112,8 @@ def _get_standard_current_variables(self, i_s): return variables def _get_standard_current_collector_potential_variables( - self, phi_s_cn, phi_s_cp, delta_phi_contact - ): + self, phi_s_cn, phi_s_cp, delta_phi_contact + ): """ A private function to obtain the standard variables which can be derived from the potentials in the current collector. From c7f2407f942332afaf2b8e38cb781c41759b8c0a Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Fri, 13 Jan 2023 13:18:06 +0000 Subject: [PATCH 09/11] flake8 --- pybamm/models/full_battery_models/base_battery_model.py | 2 +- pybamm/models/submodels/electrode/base_electrode.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index 08e3999813..e2a30f21a4 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -406,7 +406,7 @@ def __init__(self, extra_options): "and there are multiple phases then 'total interfacial " "current density as a state' must be 'true'" ) - + # Options not yet compatible with contact resistance if options["contact resistance"] == "true": if options["operating mode"] == "explicit power": diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index 67909a0927..f2a8367060 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -112,8 +112,8 @@ def _get_standard_current_variables(self, i_s): return variables def _get_standard_current_collector_potential_variables( - self, phi_s_cn, phi_s_cp, delta_phi_contact - ): + self, phi_s_cn, phi_s_cp, delta_phi_contact + ): """ A private function to obtain the standard variables which can be derived from the potentials in the current collector. From c95911a8b23c59336dbb638442e4b8106421e4a5 Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Thu, 19 Jan 2023 14:21:43 +0000 Subject: [PATCH 10/11] changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c512b2960..c05a453e2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Features - Steps in `Experiment` can now be tagged and cycle numbers be searched based on those tags ([#2593](https://github.com/pybamm-team/PyBaMM/pull/2593)). -- New parameter `Contact resistance [Ohm]` and corresponding variable `Contact voltage [V]` ([#2598](https://github.com/pybamm-team/PyBaMM/pull/2598)). +- New `contact resistance` option and corresponding parameter `Contact resistance [Ohm]` ([#2598](https://github.com/pybamm-team/PyBaMM/pull/2598)). # [v22.12](https://github.com/pybamm-team/PyBaMM/tree/v22.12) - 2022-12-31 From 9f8d315a89d53ba46d5cb095147bab1ba3118e2f Mon Sep 17 00:00:00 2001 From: DrSOKane Date: Wed, 25 Jan 2023 10:39:46 +0000 Subject: [PATCH 11/11] Added new variable 'Contact overpotential [V]' --- CHANGELOG.md | 2 +- pybamm/models/submodels/electrode/base_electrode.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c05a453e2c..f8094564c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ## Features - Steps in `Experiment` can now be tagged and cycle numbers be searched based on those tags ([#2593](https://github.com/pybamm-team/PyBaMM/pull/2593)). -- New `contact resistance` option and corresponding parameter `Contact resistance [Ohm]` ([#2598](https://github.com/pybamm-team/PyBaMM/pull/2598)). +- New `contact resistance` option, new parameter `Contact resistance [Ohm]` and new variable `Contact overpotential [V]` ([#2598](https://github.com/pybamm-team/PyBaMM/pull/2598)). # [v22.12](https://github.com/pybamm-team/PyBaMM/tree/v22.12) - 2022-12-31 diff --git a/pybamm/models/submodels/electrode/base_electrode.py b/pybamm/models/submodels/electrode/base_electrode.py index f2a8367060..92394e99d9 100644 --- a/pybamm/models/submodels/electrode/base_electrode.py +++ b/pybamm/models/submodels/electrode/base_electrode.py @@ -156,6 +156,8 @@ def _get_standard_current_collector_potential_variables( "Positive current collector potential [V]": phi_s_cp_dim, "Local voltage": V_cc, "Local voltage [V]": self.param.ocv_ref + V_cc * pot_scale, + "Contact overpotential": delta_phi_contact, + "Contact overpotential [V]": delta_phi_contact * pot_scale, "Terminal voltage": V - delta_phi_contact, "Terminal voltage [V]": V_dim - delta_phi_contact * pot_scale, }