From 1de9c110798f18f75138a0df835f5d580acf5e38 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 9 Nov 2021 12:15:58 -0500 Subject: [PATCH] #1489 fix half-cell models --- .../scripts/compare_lithium_ion_half_cell.py | 12 +++++++++--- .../interface/sei/ec_reaction_limited.py | 16 +++++++--------- .../interface/sei/electron_migration_limited.py | 16 +++++++--------- .../sei/interstitial_diffusion_limited.py | 16 +++++++--------- .../submodels/interface/sei/reaction_limited.py | 16 +++++++--------- .../interface/sei/solvent_diffusion_limited.py | 16 +++++++--------- pybamm/util.py | 5 +---- 7 files changed, 45 insertions(+), 52 deletions(-) diff --git a/examples/scripts/compare_lithium_ion_half_cell.py b/examples/scripts/compare_lithium_ion_half_cell.py index 0686e53314..b6dcac3f3e 100644 --- a/examples/scripts/compare_lithium_ion_half_cell.py +++ b/examples/scripts/compare_lithium_ion_half_cell.py @@ -7,9 +7,15 @@ # load models models = [ - pybamm.lithium_ion.SPM({"working electrode": "positive"}), - pybamm.lithium_ion.SPMe({"working electrode": "positive"}), - pybamm.lithium_ion.DFN({"working electrode": "positive"}), + pybamm.lithium_ion.SPM( + {"working electrode": "positive", "SEI": "ec reaction limited"} + ), + pybamm.lithium_ion.SPMe( + {"working electrode": "positive", "SEI": "ec reaction limited"} + ), + pybamm.lithium_ion.DFN( + {"working electrode": "positive", "SEI": "ec reaction limited"} + ), ] chemistry = pybamm.parameter_sets.Xu2019 diff --git a/pybamm/models/submodels/interface/sei/ec_reaction_limited.py b/pybamm/models/submodels/interface/sei/ec_reaction_limited.py index c71fd41b19..be9bc1edc6 100644 --- a/pybamm/models/submodels/interface/sei/ec_reaction_limited.py +++ b/pybamm/models/submodels/interface/sei/ec_reaction_limited.py @@ -119,18 +119,16 @@ def set_rhs(self, variables): if self.reaction_loc == "x-average": L_sei = variables["X-averaged outer SEI thickness"] j_sei = variables["X-averaged outer SEI interfacial current density"] - if self.reaction_loc == "interface": - a = 1 - else: - # Note a is dimensionless (has a constant value of 1 if the surface - # area does not change) - a = variables[ - "X-averaged negative electrode surface area to volume ratio" - ] + # Note a is dimensionless (has a constant value of 1 if the surface + # area does not change) + a = variables["X-averaged negative electrode surface area to volume ratio"] else: L_sei = variables["Outer SEI thickness"] j_sei = variables["Outer SEI interfacial current density"] - a = variables["Negative electrode surface area to volume ratio"] + if self.reaction_loc == "interface": + a = 1 + else: + a = variables["Negative electrode surface area to volume ratio"] Gamma_SEI = self.param.Gamma_SEI diff --git a/pybamm/models/submodels/interface/sei/electron_migration_limited.py b/pybamm/models/submodels/interface/sei/electron_migration_limited.py index 4fb8b6ba07..b52200fcff 100644 --- a/pybamm/models/submodels/interface/sei/electron_migration_limited.py +++ b/pybamm/models/submodels/interface/sei/electron_migration_limited.py @@ -73,20 +73,18 @@ def set_rhs(self, variables): L_outer = variables["X-averaged outer SEI thickness"] j_inner = variables["X-averaged inner SEI interfacial current density"] j_outer = variables["X-averaged outer SEI interfacial current density"] - if self.reaction_loc == "interface": - a = 1 - else: - # Note a is dimensionless (has a constant value of 1 if the surface - # area does not change) - a = variables[ - "X-averaged negative electrode surface area to volume ratio" - ] + # Note a is dimensionless (has a constant value of 1 if the surface + # area does not change) + a = variables["X-averaged negative electrode surface area to volume ratio"] else: L_inner = variables["Inner SEI thickness"] L_outer = variables["Outer SEI thickness"] j_inner = variables["Inner SEI interfacial current density"] j_outer = variables["Outer SEI interfacial current density"] - a = variables["Negative electrode surface area to volume ratio"] + if self.reaction_loc == "interface": + a = 1 + else: + a = variables["Negative electrode surface area to volume ratio"] v_bar = self.param.v_bar Gamma_SEI = self.param.Gamma_SEI diff --git a/pybamm/models/submodels/interface/sei/interstitial_diffusion_limited.py b/pybamm/models/submodels/interface/sei/interstitial_diffusion_limited.py index 7a059c8e93..0c265fc13a 100644 --- a/pybamm/models/submodels/interface/sei/interstitial_diffusion_limited.py +++ b/pybamm/models/submodels/interface/sei/interstitial_diffusion_limited.py @@ -75,20 +75,18 @@ def set_rhs(self, variables): L_outer = variables["X-averaged outer SEI thickness"] j_inner = variables["X-averaged inner SEI interfacial current density"] j_outer = variables["X-averaged outer SEI interfacial current density"] - if self.reaction_loc == "interface": - a = 1 - else: - # Note a is dimensionless (has a constant value of 1 if the surface - # area does not change) - a = variables[ - "X-averaged negative electrode surface area to volume ratio" - ] + # Note a is dimensionless (has a constant value of 1 if the surface + # area does not change) + a = variables["X-averaged negative electrode surface area to volume ratio"] else: L_inner = variables["Inner SEI thickness"] L_outer = variables["Outer SEI thickness"] j_inner = variables["Inner SEI interfacial current density"] j_outer = variables["Outer SEI interfacial current density"] - a = variables["Negative electrode surface area to volume ratio"] + if self.reaction_loc == "interface": + a = 1 + else: + a = variables["Negative electrode surface area to volume ratio"] v_bar = self.param.v_bar Gamma_SEI = self.param.Gamma_SEI diff --git a/pybamm/models/submodels/interface/sei/reaction_limited.py b/pybamm/models/submodels/interface/sei/reaction_limited.py index 8d8d2d4be6..9de7438408 100644 --- a/pybamm/models/submodels/interface/sei/reaction_limited.py +++ b/pybamm/models/submodels/interface/sei/reaction_limited.py @@ -95,20 +95,18 @@ def set_rhs(self, variables): L_outer = variables["X-averaged outer SEI thickness"] j_inner = variables["X-averaged inner SEI interfacial current density"] j_outer = variables["X-averaged outer SEI interfacial current density"] - if self.reaction_loc == "interface": - a = 1 - else: - # Note a is dimensionless (has a constant value of 1 if the surface - # area does not change) - a = variables[ - "X-averaged negative electrode surface area to volume ratio" - ] + # Note a is dimensionless (has a constant value of 1 if the surface + # area does not change) + a = variables["X-averaged negative electrode surface area to volume ratio"] else: L_inner = variables["Inner SEI thickness"] L_outer = variables["Outer SEI thickness"] j_inner = variables["Inner SEI interfacial current density"] j_outer = variables["Outer SEI interfacial current density"] - a = variables["Negative electrode surface area to volume ratio"] + if self.reaction_loc == "interface": + a = 1 + else: + a = variables["Negative electrode surface area to volume ratio"] v_bar = self.param.v_bar Gamma_SEI = self.param.Gamma_SEI diff --git a/pybamm/models/submodels/interface/sei/solvent_diffusion_limited.py b/pybamm/models/submodels/interface/sei/solvent_diffusion_limited.py index 1091225f1f..5d4e235e0c 100644 --- a/pybamm/models/submodels/interface/sei/solvent_diffusion_limited.py +++ b/pybamm/models/submodels/interface/sei/solvent_diffusion_limited.py @@ -68,20 +68,18 @@ def set_rhs(self, variables): L_outer = variables["X-averaged outer SEI thickness"] j_inner = variables["X-averaged inner SEI interfacial current density"] j_outer = variables["X-averaged outer SEI interfacial current density"] - if self.reaction_loc == "interface": - a = 1 - else: - # Note a is dimensionless (has a constant value of 1 if the surface - # area does not change) - a = variables[ - "X-averaged negative electrode surface area to volume ratio" - ] + # Note a is dimensionless (has a constant value of 1 if the surface + # area does not change) + a = variables["X-averaged negative electrode surface area to volume ratio"] else: L_inner = variables["Inner SEI thickness"] L_outer = variables["Outer SEI thickness"] j_inner = variables["Inner SEI interfacial current density"] j_outer = variables["Outer SEI interfacial current density"] - a = variables["Negative electrode surface area to volume ratio"] + if self.reaction_loc == "interface": + a = 1 + else: + a = variables["Negative electrode surface area to volume ratio"] v_bar = self.param.v_bar Gamma_SEI = self.param.Gamma_SEI diff --git a/pybamm/util.py b/pybamm/util.py index 786dd0a3f7..cab5d995b3 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -285,10 +285,7 @@ def load_function(filename): path = root_path.replace("/", ".") path = path.replace("\\", ".") - try: - module_object = importlib.import_module(path) - except ModuleNotFoundError: - module_object = importlib.import_module("pybamm.input.parameters." + path) + module_object = importlib.import_module(path) return getattr(module_object, tail)