From 3f2c3c25ffab43cfa5acae2f6e33ae6841488fba Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 12 Nov 2019 13:43:41 -0500 Subject: [PATCH 1/7] #579 add tortuosity submodels --- pybamm/models/submodels/base_submodel.py | 16 ++++++++-- .../submodels/electrode/ohm/base_ohm.py | 10 +++--- .../submodels/electrode/ohm/full_ohm.py | 6 ++-- ...urface_form_stefan_maxwell_conductivity.py | 15 ++++----- .../composite_oxygen_diffusion.py | 13 +++----- .../oxygen_diffusion/full_oxygen_diffusion.py | 11 ++----- .../submodels/porosity/base_porosity.py | 6 ++++ .../models/submodels/tortuosity/__init__.py | 2 ++ .../submodels/tortuosity/base_tortuosity.py | 32 +++++++++++++++++++ .../tortuosity/bruggeman_tortuosity.py | 28 ++++++++++++++++ 10 files changed, 100 insertions(+), 39 deletions(-) create mode 100644 pybamm/models/submodels/tortuosity/__init__.py create mode 100644 pybamm/models/submodels/tortuosity/base_tortuosity.py create mode 100644 pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py diff --git a/pybamm/models/submodels/base_submodel.py b/pybamm/models/submodels/base_submodel.py index 26f41a2af9..e91d5d6764 100644 --- a/pybamm/models/submodels/base_submodel.py +++ b/pybamm/models/submodels/base_submodel.py @@ -68,13 +68,25 @@ def domain(self): @domain.setter def domain(self, domain): - if domain in ["Negative", "Separator", "Positive"]: + ok_domain_list = [ + "Negative", + "Separator", + "Positive", + "Negative electrode", + "Negative electrolyte", + "Separator electrolyte", + "Positive electrode", + "Positive electrolyte", + ] + if domain in ok_domain_list: self._domain = domain elif domain is None: pass else: raise pybamm.DomainError( - "Domain must be either 'Negative' or 'Positive' not {}".format(domain) + "Domain '{}' not recognised (must be one of {})".format( + domain, ok_domain_list + ) ) def set_domain_for_broadcast(self): diff --git a/pybamm/models/submodels/electrode/ohm/base_ohm.py b/pybamm/models/submodels/electrode/ohm/base_ohm.py index b2bb673e5a..f9174f8946 100644 --- a/pybamm/models/submodels/electrode/ohm/base_ohm.py +++ b/pybamm/models/submodels/electrode/ohm/base_ohm.py @@ -25,21 +25,19 @@ def __init__(self, param, domain, reactions=None, set_positive_potential=True): def set_boundary_conditions(self, variables): - phi_s = variables[self.domain + " electrode potential"] - eps = variables[self.domain + " electrode porosity"] - i_boundary_cc = variables["Current collector current density"] - phi_s_cn = variables["Negative current collector potential"] - if self.domain == "Negative": + phi_s_cn = variables["Negative current collector potential"] lbc = (phi_s_cn, "Dirichlet") rbc = (pybamm.Scalar(0), "Neumann") elif self.domain == "Positive": lbc = (pybamm.Scalar(0), "Neumann") - sigma_eff = self.param.sigma_p * (1 - eps) ** self.param.b_p + i_boundary_cc = variables["Current collector current density"] + sigma_eff = self.param.sigma_p * variables["Positive electrode tortuosity"] rbc = ( i_boundary_cc / pybamm.boundary_value(-sigma_eff, "right"), "Neumann", ) + phi_s = variables[self.domain + " electrode potential"] self.boundary_conditions[phi_s] = {"left": lbc, "right": rbc} diff --git a/pybamm/models/submodels/electrode/ohm/full_ohm.py b/pybamm/models/submodels/electrode/ohm/full_ohm.py index fac16021bc..a5a3bebe61 100644 --- a/pybamm/models/submodels/electrode/ohm/full_ohm.py +++ b/pybamm/models/submodels/electrode/ohm/full_ohm.py @@ -36,16 +36,14 @@ def get_fundamental_variables(self): def get_coupled_variables(self, variables): phi_s = variables[self.domain + " electrode potential"] - eps = variables[self.domain + " electrode porosity"] + tor = variables[self.domain + " electrode tortuosity"] if self.domain == "Negative": sigma = self.param.sigma_n - b = self.param.b_n elif self.domain == "Positive": sigma = self.param.sigma_p - b = self.param.b_p - sigma_eff = sigma * (1 - eps) ** b + sigma_eff = sigma * tor i_s = -sigma_eff * pybamm.grad(phi_s) variables.update({self.domain + " electrode effective conductivity": sigma_eff}) diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py index 996f9fdfe3..8c0e58ca02 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py @@ -130,21 +130,18 @@ def set_boundary_conditions(self, variables): def _get_conductivities(self, variables): param = self.param - eps = variables[self.domain + " electrode porosity"] + tor_e = variables[self.domain + " electrolyte tortuosity"] + tor_s = variables[self.domain + " electrode tortuosity"] c_e = variables[self.domain + " electrolyte concentration"] T = variables[self.domain + " electrode temperature"] if self.domain == "Negative": sigma = param.sigma_n - b = param.b_n elif self.domain == "Positive": sigma = param.sigma_p - b = param.b_p - sigma_eff = sigma * (1 - eps) ** b - conductivity = ( - param.kappa_e(c_e, T) - * (eps ** b) - / (param.C_e / param.gamma_e + param.kappa_e(c_e, T) / sigma_eff) - ) + + kappa_eff = param.kappa_e(c_e, T) * tor_e + sigma_eff = sigma * tor_s + conductivity = kappa_eff / (param.C_e / param.gamma_e + kappa_eff / sigma_eff) return conductivity, sigma_eff diff --git a/pybamm/models/submodels/oxygen_diffusion/composite_oxygen_diffusion.py b/pybamm/models/submodels/oxygen_diffusion/composite_oxygen_diffusion.py index a9f1c84111..41c1f54d25 100644 --- a/pybamm/models/submodels/oxygen_diffusion/composite_oxygen_diffusion.py +++ b/pybamm/models/submodels/oxygen_diffusion/composite_oxygen_diffusion.py @@ -32,21 +32,16 @@ def __init__(self, param, reactions, extended=False): def get_coupled_variables(self, variables): - eps_0 = separator_and_positive_only(variables["Leading-order porosity"]) + tor_0 = separator_and_positive_only( + variables["Leading-order electrolyte tortuosity"] + ) c_ox = variables["Separator and positive electrode oxygen concentration"] # TODO: allow charge and convection? # v_box = pybamm.Scalar(0) param = self.param - b = pybamm.Concatenation( - pybamm.FullBroadcast(param.b_s, ["separator"], "current collector"), - pybamm.FullBroadcast( - param.b_p, ["positive electrode"], "current collector" - ), - ) - - N_ox_diffusion = -(eps_0 ** b) * param.curlyD_ox * pybamm.grad(c_ox) + N_ox_diffusion = -tor_0 * param.curlyD_ox * pybamm.grad(c_ox) N_ox = N_ox_diffusion # + c_ox * v_box # Flux in the negative electrode is zero diff --git a/pybamm/models/submodels/oxygen_diffusion/full_oxygen_diffusion.py b/pybamm/models/submodels/oxygen_diffusion/full_oxygen_diffusion.py index 77c1dd9088..515153a5cd 100644 --- a/pybamm/models/submodels/oxygen_diffusion/full_oxygen_diffusion.py +++ b/pybamm/models/submodels/oxygen_diffusion/full_oxygen_diffusion.py @@ -67,21 +67,14 @@ def get_fundamental_variables(self): def get_coupled_variables(self, variables): - eps = separator_and_positive_only(variables["Porosity"]) + tor = separator_and_positive_only(variables["Electrolyte tortuosity"]) c_ox = variables["Separator and positive electrode oxygen concentration"] # TODO: allow charge and convection? v_box = pybamm.Scalar(0) param = self.param - b = pybamm.Concatenation( - pybamm.FullBroadcast(param.b_s, ["separator"], "current collector"), - pybamm.FullBroadcast( - param.b_p, ["positive electrode"], "current collector" - ), - ) - - N_ox_diffusion = -(eps ** b) * param.curlyD_ox * pybamm.grad(c_ox) + N_ox_diffusion = -tor * param.curlyD_ox * pybamm.grad(c_ox) N_ox = N_ox_diffusion + c_ox * v_box # Flux in the negative electrode is zero diff --git a/pybamm/models/submodels/porosity/base_porosity.py b/pybamm/models/submodels/porosity/base_porosity.py index 158adb1d77..6b0dd958b0 100644 --- a/pybamm/models/submodels/porosity/base_porosity.py +++ b/pybamm/models/submodels/porosity/base_porosity.py @@ -83,3 +83,9 @@ def _get_standard_porosity_change_variables(self, deps_dt, set_leading_order=Fal ) return variables + + def set_events(self, variables): + eps = variables["Porosity"] + self.events["Zero porosity cut-off"] = pybamm.min(eps) + self.events["Max porosity cut-off"] = pybamm.max(eps) - 1 + diff --git a/pybamm/models/submodels/tortuosity/__init__.py b/pybamm/models/submodels/tortuosity/__init__.py new file mode 100644 index 0000000000..cf0411c9d4 --- /dev/null +++ b/pybamm/models/submodels/tortuosity/__init__.py @@ -0,0 +1,2 @@ +from .base_tortuosity import BaseModel +from .bruggeman_tortuosity import Bruggeman diff --git a/pybamm/models/submodels/tortuosity/base_tortuosity.py b/pybamm/models/submodels/tortuosity/base_tortuosity.py new file mode 100644 index 0000000000..73ce2f9159 --- /dev/null +++ b/pybamm/models/submodels/tortuosity/base_tortuosity.py @@ -0,0 +1,32 @@ +# +# Base class for tortuosity +# +import pybamm + + +class BaseModel(pybamm.BaseSubModel): + """Base class for tortuosity + + Parameters + ---------- + param : parameter class + The parameters to use for this submodel + domain : str + The subdomain for the model ('Negative electrode', 'Negative electrolyte', + 'Separator electrolyte', 'Positive electrode' or 'Positive electrolyte'). Note + that there is no 'Separator electrode' as the separator is insulating (no solid + problem there). + + **Extends:** :class:`pybamm.BaseSubModel` + """ + + def __init__(self, param, domain): + super().__init__(param, domain) + + def _get_standard_tortuosity_variables(self, tor): + variables = { + self.domain + " tortuosity": tor, + "X-averaged " + self.domain.lower() + " tortuosity": pybamm.x_average(tor), + } + + return variables diff --git a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py new file mode 100644 index 0000000000..54222e1da9 --- /dev/null +++ b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py @@ -0,0 +1,28 @@ +# +# Class for Bruggeman tortuosity +# +import pybamm + +from .base_tortuosity import BaseModel + + +class Bruggeman(BaseModel): + """Submodel for Bruggeman tortuosity + + **Extends:** :class:`pybamm.tortuosity.BaseModel` + """ + + def get_coupled_variables(self, variables): + eps = variables[self.domain + " porosity"] + + if "Negative" in self.domain: + brugg = self.param.b_n + elif self.domain == "Separator": + brugg = self.param.b_s + if "Positive" in self.domain: + brugg = self.param.b_p + + tor = eps ** brugg + variables.update(self._get_standard_tortuosity_variables(tor)) + + return variables From 376429ae82fcbe28ef09c1591ee8a99228e4caba Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 12 Nov 2019 18:36:47 -0500 Subject: [PATCH 2/7] #579 get models running, but with errors --- .../parameters.csv | 3 +- .../cathodes/lico2_Marquis2019/parameters.csv | 3 +- pybamm/__init__.py | 1 + .../full_battery_models/base_battery_model.py | 12 ++++++- .../full_battery_models/lead_acid/full.py | 1 + .../lead_acid/higher_order.py | 1 + .../full_battery_models/lead_acid/loqs.py | 9 ++++++ .../full_battery_models/lithium_ion/dfn.py | 1 + .../full_battery_models/lithium_ion/spm.py | 1 + .../full_battery_models/lithium_ion/spme.py | 1 + .../submodels/porosity/base_porosity.py | 32 +++++++++++++++++++ .../porosity/full_reaction_driven_porosity.py | 2 +- .../leading_reaction_driven_porosity.py | 6 ++-- .../submodels/tortuosity/base_tortuosity.py | 29 +++++++++++------ .../tortuosity/bruggeman_tortuosity.py | 17 +++++----- .../standard_parameters_lead_acid.py | 18 +++++++---- .../standard_parameters_lithium_ion.py | 5 +++ 17 files changed, 111 insertions(+), 31 deletions(-) diff --git a/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv b/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv index 28a1733cb4..9bab3092f9 100644 --- a/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv +++ b/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv @@ -8,7 +8,8 @@ Negative electrode diffusivity [m2.s-1],[function]graphite_mcmb2528_diffusivity_ Negative electrode OCP [V],[function]graphite_mcmb2528_ocp_Dualfoil1998, ,,, # Microstructure,,, -Negative electrode porosity,0.3,Scott Moura FastDFN, +Negative electrode porosity,0.3,Scott Moura FastDFN,electrolyte volume fraction +Negative electrode active material volume fraction,0.7,,assuming zero binder volume fraction Negative particle radius [m],1E-05,Scott Moura FastDFN, Negative electrode surface area density [m-1],180000,Scott Moura FastDFN, Negative electrode Bruggeman coefficient,1.5,Scott Moura FastDFN, diff --git a/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv b/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv index 99f2b3840b..5e3c1c4db1 100644 --- a/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv +++ b/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv @@ -8,7 +8,8 @@ Positive electrode diffusivity [m2.s-1],[function]lico2_diffusivity_Dualfoil1998 Positive electrode OCP [V],[function]lico2_ocp_Dualfoil1998, ,,, # Microstructure,,, -Positive electrode porosity,0.3,Scott Moura FastDFN, +Positive electrode porosity,0.3,Scott Moura FastDFN,electrolyte volume fraction +Positive electrode active material volume fraction,0.7,,assuming zero binder volume fraction Positive particle radius [m],1E-05,Scott Moura FastDFN, Positive electrode surface area density [m-1],150000,Scott Moura FastDFN, Positive electrode Bruggeman coefficient,1.5,Scott Moura FastDFN, diff --git a/pybamm/__init__.py b/pybamm/__init__.py index ced6de35e3..4e3d07864c 100644 --- a/pybamm/__init__.py +++ b/pybamm/__init__.py @@ -164,6 +164,7 @@ def version(formatted=False): particle, porosity, thermal, + tortuosity, ) # diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index a50592bcac..90a3814470 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -415,7 +415,9 @@ def build_model(self): # return to it later and try again. If setting coupled variables fails and # there are no more submodels to try, raise an error. submodels = list(self.submodels.keys()) + count = 0 while len(submodels) > 0: + count += 1 for submodel_name, submodel in self.submodels.items(): if submodel_name in submodels: pybamm.logger.debug( @@ -429,7 +431,7 @@ def build_model(self): ) submodels.remove(submodel_name) except KeyError as key: - if len(submodels) == 1: + if len(submodels) == 1 or count == 100: # no more submodels to try raise pybamm.ModelError( """Submodel "{}" requires the variable {}, but it cannot be found. @@ -491,6 +493,14 @@ def build_model(self): self._built = True + def set_tortuosity_submodels(self): + self.submodels["electrolyte tortuosity"] = pybamm.tortuosity.Bruggeman( + self.param, "Electrolyte" + ) + self.submodels["electrode tortuosity"] = pybamm.tortuosity.Bruggeman( + self.param, "Electrode" + ) + def set_thermal_submodel(self): if self.options["thermal"] == "isothermal": diff --git a/pybamm/models/full_battery_models/lead_acid/full.py b/pybamm/models/full_battery_models/lead_acid/full.py index 056a3efc31..a93339cb46 100644 --- a/pybamm/models/full_battery_models/lead_acid/full.py +++ b/pybamm/models/full_battery_models/lead_acid/full.py @@ -37,6 +37,7 @@ def __init__(self, options=None, name="Full model", build=True): self.set_reactions() self.set_interfacial_submodel() self.set_porosity_submodel() + self.set_tortuosity_submodels() self.set_convection_submodel() self.set_electrolyte_submodel() self.set_solid_submodel() diff --git a/pybamm/models/full_battery_models/lead_acid/higher_order.py b/pybamm/models/full_battery_models/lead_acid/higher_order.py index a03afdc51b..8151cfe031 100644 --- a/pybamm/models/full_battery_models/lead_acid/higher_order.py +++ b/pybamm/models/full_battery_models/lead_acid/higher_order.py @@ -49,6 +49,7 @@ def __init__(self, options=None, name="Composite model", build=True): self.set_full_interface_submodel() self.set_full_convection_submodel() self.set_full_porosity_submodel() + self.set_tortuosity_submodels() self.set_thermal_submodel() self.set_current_collector_submodel() diff --git a/pybamm/models/full_battery_models/lead_acid/loqs.py b/pybamm/models/full_battery_models/lead_acid/loqs.py index cf6bea3ed1..14f6bf591c 100644 --- a/pybamm/models/full_battery_models/lead_acid/loqs.py +++ b/pybamm/models/full_battery_models/lead_acid/loqs.py @@ -37,6 +37,7 @@ def __init__(self, options=None, name="LOQS model", build=True): self.set_interfacial_submodel() self.set_convection_submodel() self.set_porosity_submodel() + self.set_tortuosity_submodels() self.set_negative_electrode_submodel() self.set_electrolyte_submodel() self.set_positive_electrode_submodel() @@ -70,6 +71,14 @@ def set_porosity_submodel(self): self.param ) + def set_tortuosity_submodels(self): + self.submodels[ + "leading-order electrolyte tortuosity" + ] = pybamm.tortuosity.Bruggeman(self.param, "Electrolyte") + self.submodels[ + "leading-order electrode tortuosity" + ] = pybamm.tortuosity.Bruggeman(self.param, "Electrode") + def set_convection_submodel(self): if self.options["convection"] is False: diff --git a/pybamm/models/full_battery_models/lithium_ion/dfn.py b/pybamm/models/full_battery_models/lithium_ion/dfn.py index 6268229624..b3acfb85ae 100644 --- a/pybamm/models/full_battery_models/lithium_ion/dfn.py +++ b/pybamm/models/full_battery_models/lithium_ion/dfn.py @@ -35,6 +35,7 @@ def __init__(self, options=None, name="Doyle-Fuller-Newman model", build=True): self.set_reactions() self.set_porosity_submodel() + self.set_tortuosity_submodels() self.set_convection_submodel() self.set_interfacial_submodel() self.set_particle_submodel() diff --git a/pybamm/models/full_battery_models/lithium_ion/spm.py b/pybamm/models/full_battery_models/lithium_ion/spm.py index d11f38abe1..fb1e405389 100644 --- a/pybamm/models/full_battery_models/lithium_ion/spm.py +++ b/pybamm/models/full_battery_models/lithium_ion/spm.py @@ -33,6 +33,7 @@ def __init__(self, options=None, name="Single Particle Model", build=True): super().__init__(options, name) self.set_porosity_submodel() + self.set_tortuosity_submodels() self.set_convection_submodel() self.set_interfacial_submodel() self.set_particle_submodel() diff --git a/pybamm/models/full_battery_models/lithium_ion/spme.py b/pybamm/models/full_battery_models/lithium_ion/spme.py index 974b60759d..afe023d6f5 100644 --- a/pybamm/models/full_battery_models/lithium_ion/spme.py +++ b/pybamm/models/full_battery_models/lithium_ion/spme.py @@ -37,6 +37,7 @@ def __init__( self.set_reactions() self.set_porosity_submodel() + self.set_tortuosity_submodels() self.set_convection_submodel() self.set_interfacial_submodel() self.set_particle_submodel() diff --git a/pybamm/models/submodels/porosity/base_porosity.py b/pybamm/models/submodels/porosity/base_porosity.py index 6b0dd958b0..d6946d8bb6 100644 --- a/pybamm/models/submodels/porosity/base_porosity.py +++ b/pybamm/models/submodels/porosity/base_porosity.py @@ -33,9 +33,29 @@ def _get_standard_porosity_variables(self, eps, set_leading_order=False): "X-averaged positive electrode porosity": pybamm.x_average(eps_p), } + # activate material volume fractions + eps_solid_n = eps_n - self.param.epsilon_binder_n + eps_solid_s = eps_s - self.param.epsilon_binder_s + eps_solid_p = eps_p - self.param.epsilon_binder_p + eps_solid = pybamm.Concatenation(eps_solid_n, eps_solid_s, eps_solid_p) + + am = "active material volume fraction" + variables.update( + { + am.capitalize(): eps_solid, + "Negative electrode " + am: eps_solid_n, + "Separator " + am: eps_solid, + "Positive electrode " + am: eps_solid_p, + "X-averaged negative electrode " + am: pybamm.x_average(eps_solid_n), + "X-averaged separator " + am: pybamm.x_average(eps_solid), + "X-averaged positive electrode " + am: pybamm.x_average(eps_solid_p), + } + ) + if set_leading_order is True: variables.update( { + "Leading-order porosity": eps, "Leading-order negative electrode porosity": eps_n, "Leading-order separator porosity": eps_s, "Leading-order positive electrode porosity": eps_p, @@ -46,6 +66,18 @@ def _get_standard_porosity_variables(self, eps, set_leading_order=False): ), "Leading-order x-averaged " + "positive electrode porosity": pybamm.x_average(eps_p), + "Leading-order " + am: eps_solid, + "Leading-order negative electrode " + am: eps_solid_n, + "Leading-order separator " + am: eps_solid_s, + "Leading-order positive electrode " + am: eps_solid_p, + "Leading-order x-averaged " + + "negative electrode " + + am: pybamm.x_average(eps_solid_n), + "Leading-order x-averaged separator " + + am: pybamm.x_average(eps_solid_s), + "Leading-order x-averaged " + + "positive electrode " + + am: pybamm.x_average(eps_solid_p), } ) diff --git a/pybamm/models/submodels/porosity/full_reaction_driven_porosity.py b/pybamm/models/submodels/porosity/full_reaction_driven_porosity.py index 3f65460cee..7f911abed6 100644 --- a/pybamm/models/submodels/porosity/full_reaction_driven_porosity.py +++ b/pybamm/models/submodels/porosity/full_reaction_driven_porosity.py @@ -52,4 +52,4 @@ def set_rhs(self, variables): def set_initial_conditions(self, variables): eps = variables["Porosity"] - self.initial_conditions = {eps: self.param.eps_init} + self.initial_conditions = {eps: self.param.epsilon_init} diff --git a/pybamm/models/submodels/porosity/leading_reaction_driven_porosity.py b/pybamm/models/submodels/porosity/leading_reaction_driven_porosity.py index 137746edff..e2eb57e691 100644 --- a/pybamm/models/submodels/porosity/leading_reaction_driven_porosity.py +++ b/pybamm/models/submodels/porosity/leading_reaction_driven_porosity.py @@ -60,6 +60,6 @@ def set_initial_conditions(self, variables): eps_s_av = variables["X-averaged separator porosity"] eps_p_av = variables["X-averaged positive electrode porosity"] - self.initial_conditions = {eps_n_av: self.param.eps_n_init} - self.initial_conditions.update({eps_s_av: self.param.eps_s_init}) - self.initial_conditions.update({eps_p_av: self.param.eps_p_init}) + self.initial_conditions = {eps_n_av: self.param.epsilon_n_init} + self.initial_conditions.update({eps_s_av: self.param.epsilon_s_init}) + self.initial_conditions.update({eps_p_av: self.param.epsilon_p_init}) diff --git a/pybamm/models/submodels/tortuosity/base_tortuosity.py b/pybamm/models/submodels/tortuosity/base_tortuosity.py index 73ce2f9159..aee27f4eee 100644 --- a/pybamm/models/submodels/tortuosity/base_tortuosity.py +++ b/pybamm/models/submodels/tortuosity/base_tortuosity.py @@ -11,22 +11,33 @@ class BaseModel(pybamm.BaseSubModel): ---------- param : parameter class The parameters to use for this submodel - domain : str - The subdomain for the model ('Negative electrode', 'Negative electrolyte', - 'Separator electrolyte', 'Positive electrode' or 'Positive electrolyte'). Note - that there is no 'Separator electrode' as the separator is insulating (no solid - problem there). + phase : str + The material for the model ('electrolyte' or 'electrode'). **Extends:** :class:`pybamm.BaseSubModel` """ - def __init__(self, param, domain): - super().__init__(param, domain) + def __init__(self, param, phase): + super().__init__(param) + self.phase = phase def _get_standard_tortuosity_variables(self, tor): + tor_n, tor_s, tor_p = tor.orphans + variables = { - self.domain + " tortuosity": tor, - "X-averaged " + self.domain.lower() + " tortuosity": pybamm.x_average(tor), + self.phase + " tortuosity": tor, + "Negative " + self.phase.lower() + " tortuosity": tor_n, + "Separator " + self.phase.lower() + " tortuosity": tor_s, + "Positive " + self.phase.lower() + " tortuosity": tor_p, + "X-averaged negative " + + self.phase.lower() + + " tortuosity": pybamm.x_average(tor_n), + "X-averaged separator " + + self.phase.lower() + + " tortuosity": pybamm.x_average(tor_s), + "X-averaged positive " + + self.phase.lower() + + " tortuosity": pybamm.x_average(tor_p), } return variables diff --git a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py index 54222e1da9..027643f785 100644 --- a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py +++ b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py @@ -13,16 +13,17 @@ class Bruggeman(BaseModel): """ def get_coupled_variables(self, variables): - eps = variables[self.domain + " porosity"] + param = self.param - if "Negative" in self.domain: - brugg = self.param.b_n - elif self.domain == "Separator": - brugg = self.param.b_s - if "Positive" in self.domain: - brugg = self.param.b_p + if self.phase == "Electrolyte": + eps = variables["Porosity"] + elif self.phase == "Electrode": + eps = variables["Active material volume fraction"] - tor = eps ** brugg + eps_n, eps_s, eps_p = eps.orphans + tor = pybamm.Concatenation( + eps_n ** param.b_n, eps_s ** param.b_s, eps_p ** param.b_p + ) variables.update(self._get_standard_tortuosity_variables(tor)) return variables diff --git a/pybamm/parameters/standard_parameters_lead_acid.py b/pybamm/parameters/standard_parameters_lead_acid.py index 496d5fb85e..0d89d92baa 100644 --- a/pybamm/parameters/standard_parameters_lead_acid.py +++ b/pybamm/parameters/standard_parameters_lead_acid.py @@ -78,6 +78,10 @@ b = pybamm.geometric_parameters.b xi_n = pybamm.Parameter("Negative electrode morphological parameter") xi_p = pybamm.Parameter("Positive electrode morphological parameter") +# no binder +epsilon_binder_n = pybamm.Scalar(0) +epsilon_binder_s = pybamm.Scalar(0) +epsilon_binder_p = pybamm.Scalar(0) # Electrochemical reactions # Main @@ -399,13 +403,13 @@ def U_p_dimensional(c_e, T): q_init = pybamm.Parameter("Initial State of Charge") c_e_init = q_init c_ox_init = c_ox_init_dim / c_ox_typ -eps_n_init = eps_n_max - beta_surf_n * Q_e_max / l_n * (1 - q_init) -eps_s_init = eps_s_max -eps_p_init = eps_p_max + beta_surf_p * Q_e_max / l_p * (1 - q_init) -eps_init = pybamm.Concatenation( - pybamm.FullBroadcast(eps_n_init, ["negative electrode"], "current collector"), - pybamm.FullBroadcast(eps_s_init, ["separator"], "current collector"), - pybamm.FullBroadcast(eps_p_init, ["positive electrode"], "current collector"), +epsilon_n_init = eps_n_max - beta_surf_n * Q_e_max / l_n * (1 - q_init) +epsilon_s_init = eps_s_max +epsilon_p_init = eps_p_max + beta_surf_p * Q_e_max / l_p * (1 - q_init) +epsilon_init = pybamm.Concatenation( + pybamm.FullBroadcast(epsilon_n_init, ["negative electrode"], "current collector"), + pybamm.FullBroadcast(epsilon_s_init, ["separator"], "current collector"), + pybamm.FullBroadcast(epsilon_p_init, ["positive electrode"], "current collector"), ) curlyU_n_init = Q_e_max * (1.2 - q_init) / (Q_n_max * l_n) curlyU_p_init = Q_e_max * (1.2 - q_init) / (Q_p_max * l_p) diff --git a/pybamm/parameters/standard_parameters_lithium_ion.py b/pybamm/parameters/standard_parameters_lithium_ion.py index 73a9f4b793..5e52bdacda 100644 --- a/pybamm/parameters/standard_parameters_lithium_ion.py +++ b/pybamm/parameters/standard_parameters_lithium_ion.py @@ -277,6 +277,11 @@ def U_p_dimensional(sto, T): pybamm.FullBroadcast(epsilon_s, ["separator"], "current collector"), pybamm.FullBroadcast(epsilon_p, ["positive electrode"], "current collector"), ) +epsilon_s_n = pybamm.Parameter("Negative electrode active material volume fraction") +epsilon_s_p = pybamm.Parameter("Positive electrode active material volume fraction") +epsilon_binder_n = 1 - epsilon_n - epsilon_s_n +epsilon_binder_s = 1 - epsilon_s +epsilon_binder_p = 1 - epsilon_p - epsilon_s_p a_n = a_n_dim * R_n a_p = a_p_dim * R_p From 09a3e777e6b95c188be52b3df98da87971a5d292 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 12 Nov 2019 19:00:05 -0500 Subject: [PATCH 3/7] #579 add tests and replace submodel in more places --- .../submodels/electrode/ohm/composite_ohm.py | 14 +++---- .../submodels/electrode/ohm/full_ohm.py | 4 +- .../electrode/ohm/surface_form_ohm.py | 6 +-- ...igher_order_stefan_maxwell_conductivity.py | 12 +++--- ...urface_form_stefan_maxwell_conductivity.py | 10 ++--- .../first_order_stefan_maxwell_diffusion.py | 9 +++-- .../full_diffusion_limited.py | 4 +- .../first_order_oxygen_diffusion.py | 8 ++-- .../submodels/porosity/base_porosity.py | 37 ++++--------------- .../submodels/tortuosity/base_tortuosity.py | 8 +++- .../test_tortuosity/__init__.py | 0 .../test_tortuosity/test_base_tortuosity.py | 28 ++++++++++++++ .../test_bruggeman_tortuosity.py | 35 ++++++++++++++++++ 13 files changed, 112 insertions(+), 63 deletions(-) create mode 100644 tests/unit/test_models/test_submodels/test_tortuosity/__init__.py create mode 100644 tests/unit/test_models/test_submodels/test_tortuosity/test_base_tortuosity.py create mode 100644 tests/unit/test_models/test_submodels/test_tortuosity/test_bruggeman_tortuosity.py diff --git a/pybamm/models/submodels/electrode/ohm/composite_ohm.py b/pybamm/models/submodels/electrode/ohm/composite_ohm.py index 696179856c..201cbcc8df 100644 --- a/pybamm/models/submodels/electrode/ohm/composite_ohm.py +++ b/pybamm/models/submodels/electrode/ohm/composite_ohm.py @@ -34,13 +34,13 @@ def get_coupled_variables(self, variables): x_n = pybamm.standard_spatial_vars.x_n x_p = pybamm.standard_spatial_vars.x_p - eps_0 = variables[ - "Leading-order x-averaged " + self.domain.lower() + " electrode porosity" + tor_0 = variables[ + "Leading-order x-averaged " + self.domain.lower() + " electrode tortuosity" ] phi_s_cn = variables["Negative current collector potential"] if self._domain == "Negative": - sigma_eff_0 = self.param.sigma_n * (1 - eps_0) ** self.param.b_n + sigma_eff_0 = self.param.sigma_n * tor_0 phi_s = pybamm.PrimaryBroadcast( phi_s_cn, "negative electrode" ) + pybamm.outer( @@ -54,7 +54,7 @@ def get_coupled_variables(self, variables): ] phi_e_p_av = variables["X-averaged positive electrolyte potential"] - sigma_eff_0 = self.param.sigma_p * (1 - eps_0) ** self.param.b_p + sigma_eff_0 = self.param.sigma_p * tor_0 const = ( delta_phi_p_av @@ -80,8 +80,8 @@ def get_coupled_variables(self, variables): def set_boundary_conditions(self, variables): phi_s = variables[self.domain + " electrode potential"] - eps_0 = variables[ - "Leading-order x-averaged " + self.domain.lower() + " electrode porosity" + tor_0 = variables[ + "Leading-order x-averaged " + self.domain.lower() + " electrode tortuosity" ] i_boundary_cc_0 = variables["Leading-order current collector current density"] @@ -91,7 +91,7 @@ def set_boundary_conditions(self, variables): elif self.domain == "Positive": lbc = (pybamm.Scalar(0), "Neumann") - sigma_eff_0 = self.param.sigma_p * (1 - eps_0) ** self.param.b_p + sigma_eff_0 = self.param.sigma_p * tor_0 rbc = (-i_boundary_cc_0 / sigma_eff_0, "Neumann") self.boundary_conditions[phi_s] = {"left": lbc, "right": rbc} diff --git a/pybamm/models/submodels/electrode/ohm/full_ohm.py b/pybamm/models/submodels/electrode/ohm/full_ohm.py index a5a3bebe61..c2e64a00fe 100644 --- a/pybamm/models/submodels/electrode/ohm/full_ohm.py +++ b/pybamm/models/submodels/electrode/ohm/full_ohm.py @@ -70,7 +70,7 @@ def set_boundary_conditions(self, variables): phi_s = variables[self.domain + " electrode potential"] phi_s_cn = variables["Negative current collector potential"] - eps = variables[self.domain + " electrode porosity"] + tor = variables[self.domain + " electrode tortuosity"] i_boundary_cc = variables["Current collector current density"] if self.domain == "Negative": @@ -79,7 +79,7 @@ def set_boundary_conditions(self, variables): elif self.domain == "Positive": lbc = (pybamm.Scalar(0), "Neumann") - sigma_eff = self.param.sigma_p * (1 - eps) ** self.param.b_p + sigma_eff = self.param.sigma_p * tor rbc = ( i_boundary_cc / pybamm.boundary_value(-sigma_eff, "right"), "Neumann", diff --git a/pybamm/models/submodels/electrode/ohm/surface_form_ohm.py b/pybamm/models/submodels/electrode/ohm/surface_form_ohm.py index f78453e495..143a1ee878 100644 --- a/pybamm/models/submodels/electrode/ohm/surface_form_ohm.py +++ b/pybamm/models/submodels/electrode/ohm/surface_form_ohm.py @@ -31,13 +31,13 @@ def get_coupled_variables(self, variables): x_p = pybamm.standard_spatial_vars.x_p i_boundary_cc = variables["Current collector current density"] i_e = variables[self.domain + " electrolyte current density"] - eps = variables[self.domain + " electrode porosity"] + tor = variables[self.domain + " electrode tortuosity"] phi_s_cn = variables["Negative current collector potential"] i_s = pybamm.PrimaryBroadcast(i_boundary_cc, self.domain_for_broadcast) - i_e if self.domain == "Negative": - conductivity = param.sigma_n * (1 - eps) ** param.b_n + conductivity = param.sigma_n * tor phi_s = pybamm.PrimaryBroadcast( phi_s_cn, "negative electrode" ) - pybamm.IndefiniteIntegral(i_s / conductivity, x_n) @@ -47,7 +47,7 @@ def get_coupled_variables(self, variables): phi_e_s = variables["Separator electrolyte potential"] delta_phi_p = variables["Positive electrode surface potential difference"] - conductivity = param.sigma_p * (1 - eps) ** param.b_p + conductivity = param.sigma_p * tor phi_s = -pybamm.IndefiniteIntegral( i_s / conductivity, x_p ) + pybamm.PrimaryBroadcast( diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py index b6c5bf756c..576de9cfb3 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py @@ -44,9 +44,9 @@ def get_coupled_variables(self, variables): "X-averaged negative electrode surface potential difference" ] phi_s_n_av = variables["X-averaged negative electrode potential"] - eps_n_av = variables["Leading-order x-averaged negative electrode porosity"] - eps_s_av = variables["Leading-order x-averaged separator porosity"] - eps_p_av = variables["Leading-order x-averaged positive electrode porosity"] + tor_n_av = variables["Leading-order x-averaged negative electrode tortuosity"] + tor_s_av = variables["Leading-order x-averaged separator tortuosity"] + tor_p_av = variables["Leading-order x-averaged positive electrode tortuosity"] T_av = variables["X-averaged cell temperature"] T_av_n = pybamm.PrimaryBroadcast(T_av, "negative electrode") @@ -63,9 +63,9 @@ def get_coupled_variables(self, variables): x_p = pybamm.standard_spatial_vars.x_p # bulk conductivities - kappa_n_av = param.kappa_e(c_e_av, T_av) * eps_n_av ** param.b_n - kappa_s_av = param.kappa_e(c_e_av, T_av) * eps_s_av ** param.b_s - kappa_p_av = param.kappa_e(c_e_av, T_av) * eps_p_av ** param.b_p + kappa_n_av = param.kappa_e(c_e_av, T_av) * tor_n_av + kappa_s_av = param.kappa_e(c_e_av, T_av) * tor_s_av + kappa_p_av = param.kappa_e(c_e_av, T_av) * tor_p_av chi_av = param.chi(c_e_av) if chi_av.domain == ["current collector"]: diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py index 8c0e58ca02..4cde01babd 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/surface_potential_form/full_surface_form_stefan_maxwell_conductivity.py @@ -187,11 +187,11 @@ def _get_sep_coupled_variables(self, variables): i_boundary_cc = variables["Current collector current density"] c_e_s = variables["Separator electrolyte concentration"] phi_e_n = variables["Negative electrolyte potential"] - eps_s = variables["Separator porosity"] + tor_s = variables["Separator porosity"] T = variables["Separator temperature"] chi_e_s = param.chi(c_e_s) - kappa_s_eff = param.kappa_e(c_e_s, T) * (eps_s ** param.b_s) + kappa_s_eff = param.kappa_e(c_e_s, T) * tor_s phi_e_s = pybamm.PrimaryBroadcast( pybamm.boundary_value(phi_e_n, "right"), "separator" @@ -223,14 +223,14 @@ def nasty_hack_to_get_phi_s(self, variables): x_n = pybamm.standard_spatial_vars.x_n x_p = pybamm.standard_spatial_vars.x_p - eps = variables[self.domain + " electrode porosity"] + tor = variables[self.domain + " electrode tortuosity"] i_boundary_cc = variables["Current collector current density"] i_e = variables[self.domain + " electrolyte current density"] i_s = pybamm.PrimaryBroadcast(i_boundary_cc, self.domain_for_broadcast) - i_e if self.domain == "Negative": - conductivity = param.sigma_n * (1 - eps) ** param.b_n + conductivity = param.sigma_n * tor phi_s = -pybamm.IndefiniteIntegral(i_s / conductivity, x_n) elif self.domain == "Positive": @@ -238,7 +238,7 @@ def nasty_hack_to_get_phi_s(self, variables): phi_e_s = variables["Separator electrolyte potential"] delta_phi_p = variables["Positive electrode surface potential difference"] - conductivity = param.sigma_p * (1 - eps) ** param.b_p + conductivity = param.sigma_p * tor phi_s = -pybamm.IndefiniteIntegral( i_s / conductivity, x_p diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py index f0914b4177..d973f19ab3 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py @@ -40,6 +40,9 @@ def get_coupled_variables(self, variables): eps_n_0 = variables["Leading-order x-averaged negative electrode porosity"] eps_s_0 = variables["Leading-order x-averaged separator porosity"] eps_p_0 = variables["Leading-order x-averaged positive electrode porosity"] + tor_n_0 = variables["Leading-order x-averaged negative electrode tortuosity"] + tor_s_0 = variables["Leading-order x-averaged separator tortuosity"] + tor_p_0 = variables["Leading-order x-averaged positive electrode tortuosity"] deps_n_0_dt = variables[ "Leading-order x-averaged negative electrode porosity change" ] @@ -70,9 +73,9 @@ def get_coupled_variables(self, variables): ) # Diffusivities - D_e_n = (eps_n_0 ** param.b_n) * param.D_e(c_e_0, T_0) - D_e_s = (eps_s_0 ** param.b_s) * param.D_e(c_e_0, T_0) - D_e_p = (eps_p_0 ** param.b_p) * param.D_e(c_e_0, T_0) + D_e_n = tor_n_0 * param.D_e(c_e_0, T_0) + D_e_s = tor_s_0 * param.D_e(c_e_0, T_0) + D_e_p = tor_p_0 * param.D_e(c_e_0, T_0) # Fluxes N_e_n_1 = -pybamm.outer(rhs_n, x_n) diff --git a/pybamm/models/submodels/interface/diffusion_limited/full_diffusion_limited.py b/pybamm/models/submodels/interface/diffusion_limited/full_diffusion_limited.py index e085ded460..a9f4bfc9f2 100644 --- a/pybamm/models/submodels/interface/diffusion_limited/full_diffusion_limited.py +++ b/pybamm/models/submodels/interface/diffusion_limited/full_diffusion_limited.py @@ -26,10 +26,10 @@ def __init__(self, param, domain): def _get_diffusion_limited_current_density(self, variables): param = self.param if self.domain == "Negative": - eps_s = variables["Separator porosity"] + tor_s = variables["Separator tortuosity"] c_ox_s = variables["Separator oxygen concentration"] N_ox_neg_sep_interface = ( - -pybamm.boundary_value(eps_s ** param.b_s, "left") + -pybamm.boundary_value(tor_s, "left") * param.curlyD_ox * pybamm.BoundaryGradient(c_ox_s, "left") ) diff --git a/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py b/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py index f3d5d17998..b407d8adbb 100644 --- a/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py +++ b/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py @@ -37,12 +37,12 @@ def get_coupled_variables(self, variables): x_p = pybamm.standard_spatial_vars.x_p # Unpack - eps_s_0_av = variables["Leading-order x-averaged separator porosity"] - eps_p_0_av = variables["Leading-order x-averaged positive electrode porosity"] + tor_s_0_av = variables["Leading-order x-averaged separator tortuosity"] + tor_p_0_av = variables["Leading-order x-averaged positive electrode tortuosity"] # Diffusivities - D_ox_s = (eps_s_0_av ** param.b_s) * param.curlyD_ox - D_ox_p = (eps_p_0_av ** param.b_p) * param.curlyD_ox + D_ox_s = tor_s_0_av * param.curlyD_ox + D_ox_p = tor_p_0_av * param.curlyD_ox # Reactions sj_ox_p = sum( diff --git a/pybamm/models/submodels/porosity/base_porosity.py b/pybamm/models/submodels/porosity/base_porosity.py index d6946d8bb6..3d52569d6f 100644 --- a/pybamm/models/submodels/porosity/base_porosity.py +++ b/pybamm/models/submodels/porosity/base_porosity.py @@ -34,9 +34,9 @@ def _get_standard_porosity_variables(self, eps, set_leading_order=False): } # activate material volume fractions - eps_solid_n = eps_n - self.param.epsilon_binder_n - eps_solid_s = eps_s - self.param.epsilon_binder_s - eps_solid_p = eps_p - self.param.epsilon_binder_p + eps_solid_n = 1 - eps_n - self.param.epsilon_binder_n + eps_solid_s = 1 - eps_s - self.param.epsilon_binder_s + eps_solid_p = 1 - eps_p - self.param.epsilon_binder_p eps_solid = pybamm.Concatenation(eps_solid_n, eps_solid_s, eps_solid_p) am = "active material volume fraction" @@ -53,33 +53,10 @@ def _get_standard_porosity_variables(self, eps, set_leading_order=False): ) if set_leading_order is True: - variables.update( - { - "Leading-order porosity": eps, - "Leading-order negative electrode porosity": eps_n, - "Leading-order separator porosity": eps_s, - "Leading-order positive electrode porosity": eps_p, - "Leading-order x-averaged " - + "negative electrode porosity": pybamm.x_average(eps_n), - "Leading-order x-averaged separator porosity": pybamm.x_average( - eps_s - ), - "Leading-order x-averaged " - + "positive electrode porosity": pybamm.x_average(eps_p), - "Leading-order " + am: eps_solid, - "Leading-order negative electrode " + am: eps_solid_n, - "Leading-order separator " + am: eps_solid_s, - "Leading-order positive electrode " + am: eps_solid_p, - "Leading-order x-averaged " - + "negative electrode " - + am: pybamm.x_average(eps_solid_n), - "Leading-order x-averaged separator " - + am: pybamm.x_average(eps_solid_s), - "Leading-order x-averaged " - + "positive electrode " - + am: pybamm.x_average(eps_solid_p), - } - ) + leading_order_variables = { + "Leading-order " + name.lower(): var for name, var in variables.items() + } + variables.update(leading_order_variables) return variables diff --git a/pybamm/models/submodels/tortuosity/base_tortuosity.py b/pybamm/models/submodels/tortuosity/base_tortuosity.py index aee27f4eee..d4b01718f9 100644 --- a/pybamm/models/submodels/tortuosity/base_tortuosity.py +++ b/pybamm/models/submodels/tortuosity/base_tortuosity.py @@ -21,7 +21,7 @@ def __init__(self, param, phase): super().__init__(param) self.phase = phase - def _get_standard_tortuosity_variables(self, tor): + def _get_standard_tortuosity_variables(self, tor, set_leading_order=False): tor_n, tor_s, tor_p = tor.orphans variables = { @@ -40,4 +40,10 @@ def _get_standard_tortuosity_variables(self, tor): + " tortuosity": pybamm.x_average(tor_p), } + if set_leading_order is True: + leading_order_variables = { + "Leading-order " + name.lower(): var for name, var in variables.items() + } + variables.update(leading_order_variables) + return variables diff --git a/tests/unit/test_models/test_submodels/test_tortuosity/__init__.py b/tests/unit/test_models/test_submodels/test_tortuosity/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/test_models/test_submodels/test_tortuosity/test_base_tortuosity.py b/tests/unit/test_models/test_submodels/test_tortuosity/test_base_tortuosity.py new file mode 100644 index 0000000000..6ab3879112 --- /dev/null +++ b/tests/unit/test_models/test_submodels/test_tortuosity/test_base_tortuosity.py @@ -0,0 +1,28 @@ +# +# Test base tortuosity submodel +# + +import pybamm +import tests +import unittest + + +class TestBaseModel(unittest.TestCase): + def test_public_functions(self): + submodel = pybamm.tortuosity.BaseModel(None, "Electrode") + std_tests = tests.StandardSubModelTests(submodel) + std_tests.test_all() + + submodel = pybamm.tortuosity.BaseModel(None, "Electrolyte") + std_tests = tests.StandardSubModelTests(submodel) + std_tests.test_all() + + +if __name__ == "__main__": + print("Add -v for more debug output") + import sys + + if "-v" in sys.argv: + debug = True + pybamm.settings.debug_mode = True + unittest.main() diff --git a/tests/unit/test_models/test_submodels/test_tortuosity/test_bruggeman_tortuosity.py b/tests/unit/test_models/test_submodels/test_tortuosity/test_bruggeman_tortuosity.py new file mode 100644 index 0000000000..eed98a060b --- /dev/null +++ b/tests/unit/test_models/test_submodels/test_tortuosity/test_bruggeman_tortuosity.py @@ -0,0 +1,35 @@ +# +# Test Bruggeman tortuosity submodel +# + +import pybamm +import tests +import unittest + + +class TestBruggeman(unittest.TestCase): + def test_public_functions(self): + param = pybamm.standard_parameters_lithium_ion + a = pybamm.Concatenation( + pybamm.FullBroadcast(0, ["negative electrode"], "current collector"), + pybamm.FullBroadcast(0, ["separator"], "current collector"), + pybamm.FullBroadcast(0, ["positive electrode"], "current collector"), + ) + variables = {"Porosity": a, "Active material volume fraction": a} + submodel = pybamm.tortuosity.Bruggeman(param, "Electrolyte") + std_tests = tests.StandardSubModelTests(submodel, variables) + std_tests.test_all() + + submodel = pybamm.tortuosity.Bruggeman(param, "Electrode") + std_tests = tests.StandardSubModelTests(submodel, variables) + std_tests.test_all() + + +if __name__ == "__main__": + print("Add -v for more debug output") + import sys + + if "-v" in sys.argv: + debug = True + pybamm.settings.debug_mode = True + unittest.main() From da30127eef455e16e4c300561f751c6d349497e0 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 12 Nov 2019 19:24:45 -0500 Subject: [PATCH 4/7] #579 get all models running --- pybamm/models/full_battery_models/lithium_ion/spme.py | 8 ++++++++ pybamm/models/submodels/porosity/base_porosity.py | 9 ++++++--- pybamm/models/submodels/tortuosity/base_tortuosity.py | 11 +++++++---- .../submodels/tortuosity/bruggeman_tortuosity.py | 8 +++++++- pybamm/parameters/standard_parameters_lead_acid.py | 2 +- 5 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pybamm/models/full_battery_models/lithium_ion/spme.py b/pybamm/models/full_battery_models/lithium_ion/spme.py index afe023d6f5..13084f91ae 100644 --- a/pybamm/models/full_battery_models/lithium_ion/spme.py +++ b/pybamm/models/full_battery_models/lithium_ion/spme.py @@ -54,6 +54,14 @@ def set_porosity_submodel(self): self.submodels["porosity"] = pybamm.porosity.Constant(self.param) + def set_tortuosity_submodels(self): + self.submodels["electrolyte tortuosity"] = pybamm.tortuosity.Bruggeman( + self.param, "Electrolyte", True + ) + self.submodels["electrode tortuosity"] = pybamm.tortuosity.Bruggeman( + self.param, "Electrode", True + ) + def set_convection_submodel(self): self.submodels["convection"] = pybamm.convection.NoConvection(self.param) diff --git a/pybamm/models/submodels/porosity/base_porosity.py b/pybamm/models/submodels/porosity/base_porosity.py index 3d52569d6f..ec7d873970 100644 --- a/pybamm/models/submodels/porosity/base_porosity.py +++ b/pybamm/models/submodels/porosity/base_porosity.py @@ -94,7 +94,10 @@ def _get_standard_porosity_change_variables(self, deps_dt, set_leading_order=Fal return variables def set_events(self, variables): - eps = variables["Porosity"] - self.events["Zero porosity cut-off"] = pybamm.min(eps) - self.events["Max porosity cut-off"] = pybamm.max(eps) - 1 + eps_n = variables["Negative electrode porosity"] + eps_p = variables["Positive electrode porosity"] + self.events["Zero negative electrode porosity cut-off"] = pybamm.min(eps_n) + self.events["Max negative electrode porosity cut-off"] = pybamm.max(eps_n) - 1 + self.events["Zero positive electrode porosity cut-off"] = pybamm.min(eps_p) + self.events["Max positive electrode porosity cut-off"] = pybamm.max(eps_p) - 1 diff --git a/pybamm/models/submodels/tortuosity/base_tortuosity.py b/pybamm/models/submodels/tortuosity/base_tortuosity.py index d4b01718f9..7c67705d73 100644 --- a/pybamm/models/submodels/tortuosity/base_tortuosity.py +++ b/pybamm/models/submodels/tortuosity/base_tortuosity.py @@ -27,18 +27,21 @@ def _get_standard_tortuosity_variables(self, tor, set_leading_order=False): variables = { self.phase + " tortuosity": tor, "Negative " + self.phase.lower() + " tortuosity": tor_n, - "Separator " + self.phase.lower() + " tortuosity": tor_s, "Positive " + self.phase.lower() + " tortuosity": tor_p, "X-averaged negative " + self.phase.lower() + " tortuosity": pybamm.x_average(tor_n), - "X-averaged separator " - + self.phase.lower() - + " tortuosity": pybamm.x_average(tor_s), "X-averaged positive " + self.phase.lower() + " tortuosity": pybamm.x_average(tor_p), } + if self.phase == "Electrolyte": + variables.update( + { + "Separator tortuosity": tor_s, + "X-averaged separator tortuosity": pybamm.x_average(tor_s), + } + ) if set_leading_order is True: leading_order_variables = { diff --git a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py index 027643f785..b4387e3862 100644 --- a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py +++ b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py @@ -12,6 +12,10 @@ class Bruggeman(BaseModel): **Extends:** :class:`pybamm.tortuosity.BaseModel` """ + def __init__(self, param, phase, set_leading_order=False): + super().__init__(param, phase) + self.set_leading_order = set_leading_order + def get_coupled_variables(self, variables): param = self.param @@ -24,6 +28,8 @@ def get_coupled_variables(self, variables): tor = pybamm.Concatenation( eps_n ** param.b_n, eps_s ** param.b_s, eps_p ** param.b_p ) - variables.update(self._get_standard_tortuosity_variables(tor)) + variables.update( + self._get_standard_tortuosity_variables(tor, self.set_leading_order) + ) return variables diff --git a/pybamm/parameters/standard_parameters_lead_acid.py b/pybamm/parameters/standard_parameters_lead_acid.py index 0d89d92baa..0025378e25 100644 --- a/pybamm/parameters/standard_parameters_lead_acid.py +++ b/pybamm/parameters/standard_parameters_lead_acid.py @@ -397,7 +397,7 @@ def U_p_dimensional(c_e, T): # Electrolyte volumetric capacity Q_e_max = (l_n * eps_n_max + l_s * eps_s_max + l_p * eps_p_max) / (s_p - s_n) Q_e_max_dimensional = Q_e_max * c_e_typ * F -capacity = Q_e_max_dimensional * 8 * A_cs * L_x +capacity = Q_e_max_dimensional * n_electrodes_parallel * A_cs * L_x # Initial conditions q_init = pybamm.Parameter("Initial State of Charge") From 99032495090f2913feebe651ccf2b54a2c84fc23 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 12 Nov 2019 19:49:24 -0500 Subject: [PATCH 5/7] #579 add docs and fix tests --- docs/source/models/submodels/index.rst | 1 + .../models/submodels/tortuosity/base_tortuosity.rst | 6 ++++++ .../submodels/tortuosity/bruggeman_tortuosity.rst | 8 ++++++++ docs/source/models/submodels/tortuosity/index.rst | 9 +++++++++ .../base_higher_order_stefan_maxwell_conductivity.py | 4 ++-- .../first_order_stefan_maxwell_diffusion.py | 4 ++-- .../oxygen_diffusion/first_order_oxygen_diffusion.py | 4 +++- .../test_composite_stefan_maxwell_conductivity.py | 3 +++ ..._full_surface_form_stefan_maxwell_conductivity.py | 4 ++++ .../test_full_oxygen_diffusion.py | 5 +++++ .../test_porosity/test_base_porosity.py | 4 +++- .../test_standard_parameters_lead_acid.py | 12 +++++++++--- 12 files changed, 55 insertions(+), 9 deletions(-) create mode 100644 docs/source/models/submodels/tortuosity/base_tortuosity.rst create mode 100644 docs/source/models/submodels/tortuosity/bruggeman_tortuosity.rst create mode 100644 docs/source/models/submodels/tortuosity/index.rst diff --git a/docs/source/models/submodels/index.rst b/docs/source/models/submodels/index.rst index ff2cc824d1..5377dcd868 100644 --- a/docs/source/models/submodels/index.rst +++ b/docs/source/models/submodels/index.rst @@ -14,3 +14,4 @@ Submodels particle/index porosity/index thermal/index + tortuosity/index diff --git a/docs/source/models/submodels/tortuosity/base_tortuosity.rst b/docs/source/models/submodels/tortuosity/base_tortuosity.rst new file mode 100644 index 0000000000..0d3a2261f7 --- /dev/null +++ b/docs/source/models/submodels/tortuosity/base_tortuosity.rst @@ -0,0 +1,6 @@ +Base Model +=========== + +.. autoclass:: pybamm.tortuosity.BaseModel + :members: + diff --git a/docs/source/models/submodels/tortuosity/bruggeman_tortuosity.rst b/docs/source/models/submodels/tortuosity/bruggeman_tortuosity.rst new file mode 100644 index 0000000000..0e72973772 --- /dev/null +++ b/docs/source/models/submodels/tortuosity/bruggeman_tortuosity.rst @@ -0,0 +1,8 @@ +Bruggeman Model +=============== + +.. autoclass:: pybamm.tortuosity.Bruggeman + :members: + + + diff --git a/docs/source/models/submodels/tortuosity/index.rst b/docs/source/models/submodels/tortuosity/index.rst new file mode 100644 index 0000000000..595a9bb303 --- /dev/null +++ b/docs/source/models/submodels/tortuosity/index.rst @@ -0,0 +1,9 @@ +Tortuosity +========== + +.. toctree:: + :maxdepth: 1 + + base_tortuosity + bruggeman_tortuosity + diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py index 576de9cfb3..88f97a86a8 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/base_higher_order_stefan_maxwell_conductivity.py @@ -44,9 +44,9 @@ def get_coupled_variables(self, variables): "X-averaged negative electrode surface potential difference" ] phi_s_n_av = variables["X-averaged negative electrode potential"] - tor_n_av = variables["Leading-order x-averaged negative electrode tortuosity"] + tor_n_av = variables["Leading-order x-averaged negative electrolyte tortuosity"] tor_s_av = variables["Leading-order x-averaged separator tortuosity"] - tor_p_av = variables["Leading-order x-averaged positive electrode tortuosity"] + tor_p_av = variables["Leading-order x-averaged positive electrolyte tortuosity"] T_av = variables["X-averaged cell temperature"] T_av_n = pybamm.PrimaryBroadcast(T_av, "negative electrode") diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py index d973f19ab3..a4c773cd00 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/first_order_stefan_maxwell_diffusion.py @@ -40,9 +40,9 @@ def get_coupled_variables(self, variables): eps_n_0 = variables["Leading-order x-averaged negative electrode porosity"] eps_s_0 = variables["Leading-order x-averaged separator porosity"] eps_p_0 = variables["Leading-order x-averaged positive electrode porosity"] - tor_n_0 = variables["Leading-order x-averaged negative electrode tortuosity"] + tor_n_0 = variables["Leading-order x-averaged negative electrolyte tortuosity"] tor_s_0 = variables["Leading-order x-averaged separator tortuosity"] - tor_p_0 = variables["Leading-order x-averaged positive electrode tortuosity"] + tor_p_0 = variables["Leading-order x-averaged positive electrolyte tortuosity"] deps_n_0_dt = variables[ "Leading-order x-averaged negative electrode porosity change" ] diff --git a/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py b/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py index b407d8adbb..9422c2d1d5 100644 --- a/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py +++ b/pybamm/models/submodels/oxygen_diffusion/first_order_oxygen_diffusion.py @@ -38,7 +38,9 @@ def get_coupled_variables(self, variables): # Unpack tor_s_0_av = variables["Leading-order x-averaged separator tortuosity"] - tor_p_0_av = variables["Leading-order x-averaged positive electrode tortuosity"] + tor_p_0_av = variables[ + "Leading-order x-averaged positive electrolyte tortuosity" + ] # Diffusivities D_ox_s = tor_s_0_av * param.curlyD_ox diff --git a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_composite_stefan_maxwell_conductivity.py b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_composite_stefan_maxwell_conductivity.py index c3e55d659f..bfe620ec2b 100644 --- a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_composite_stefan_maxwell_conductivity.py +++ b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_composite_stefan_maxwell_conductivity.py @@ -22,6 +22,9 @@ def test_public_functions(self): "Leading-order x-averaged negative electrode porosity": a, "Leading-order x-averaged separator porosity": a, "Leading-order x-averaged positive electrode porosity": a, + "Leading-order x-averaged negative electrolyte tortuosity": a, + "Leading-order x-averaged separator tortuosity": a, + "Leading-order x-averaged positive electrolyte tortuosity": a, "X-averaged cell temperature": a, } submodel = pybamm.electrolyte.stefan_maxwell.conductivity.Composite(param) diff --git a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_surface_form/test_full_surface_form_stefan_maxwell_conductivity.py b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_surface_form/test_full_surface_form_stefan_maxwell_conductivity.py index bc4bc47d73..530ee7206d 100644 --- a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_surface_form/test_full_surface_form_stefan_maxwell_conductivity.py +++ b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_surface_form/test_full_surface_form_stefan_maxwell_conductivity.py @@ -23,6 +23,8 @@ def test_public_functions(self): a, "current collector" ), "Negative electrode porosity": a_n, + "Negative electrolyte tortuosity": a_n, + "Negative electrode tortuosity": a_n, "Negative electrolyte concentration": a_n, "Negative electrode interfacial current density": a_n, "Electrolyte potential": pybamm.Concatenation(a_n, a_s, a_p), @@ -55,6 +57,8 @@ def test_public_functions(self): "Separator electrolyte potential": a_s, "Separator electrolyte current density": a_s, "Positive electrode porosity": a_p, + "Positive electrolyte tortuosity": a_p, + "Positive electrode tortuosity": a_p, "Positive electrolyte concentration": a_p, "Positive electrode interfacial current density": a_p, "Positive electrode temperature": a_p, diff --git a/tests/unit/test_models/test_submodels/test_oxygen_diffusion/test_full_oxygen_diffusion.py b/tests/unit/test_models/test_submodels/test_oxygen_diffusion/test_full_oxygen_diffusion.py index 5618f0200d..cf11d742aa 100644 --- a/tests/unit/test_models/test_submodels/test_oxygen_diffusion/test_full_oxygen_diffusion.py +++ b/tests/unit/test_models/test_submodels/test_oxygen_diffusion/test_full_oxygen_diffusion.py @@ -17,6 +17,11 @@ def test_public_functions(self): pybamm.FullBroadcast(a, "separator", "current collector"), pybamm.FullBroadcast(a, "positive electrode", "current collector"), ), + "Electrolyte tortuosity": pybamm.Concatenation( + pybamm.FullBroadcast(a, "negative electrode", "current collector"), + pybamm.FullBroadcast(a, "separator", "current collector"), + pybamm.FullBroadcast(a, "positive electrode", "current collector"), + ), "Porosity change": pybamm.Concatenation( pybamm.FullBroadcast(a, "negative electrode", "current collector"), pybamm.FullBroadcast(a, "separator", "current collector"), diff --git a/tests/unit/test_models/test_submodels/test_porosity/test_base_porosity.py b/tests/unit/test_models/test_submodels/test_porosity/test_base_porosity.py index eba6e0d35e..4025bde773 100644 --- a/tests/unit/test_models/test_submodels/test_porosity/test_base_porosity.py +++ b/tests/unit/test_models/test_submodels/test_porosity/test_base_porosity.py @@ -9,8 +9,10 @@ class TestBaseModel(unittest.TestCase): def test_public_functions(self): + a = pybamm.Scalar(0) + variables = {"Negative electrode porosity": a, "Positive electrode porosity": a} submodel = pybamm.porosity.BaseModel(None) - std_tests = tests.StandardSubModelTests(submodel) + std_tests = tests.StandardSubModelTests(submodel, variables) std_tests.test_all() diff --git a/tests/unit/test_parameters/test_standard_parameters_lead_acid.py b/tests/unit/test_parameters/test_standard_parameters_lead_acid.py index e5f7a6193f..0521776d59 100644 --- a/tests/unit/test_parameters/test_standard_parameters_lead_acid.py +++ b/tests/unit/test_parameters/test_standard_parameters_lead_acid.py @@ -157,9 +157,15 @@ def test_update_initial_state_of_charge(self): # Test that relevant parameters have changed as expected self.assertLess(param_eval_update["q_init"], param_eval["q_init"]) self.assertLess(param_eval_update["c_e_init"], param_eval["c_e_init"]) - self.assertLess(param_eval_update["eps_n_init"], param_eval["eps_n_init"]) - self.assertEqual(param_eval_update["eps_s_init"], param_eval["eps_s_init"]) - self.assertLess(param_eval_update["eps_p_init"], param_eval["eps_p_init"]) + self.assertLess( + param_eval_update["epsilon_n_init"], param_eval["epsilon_n_init"] + ) + self.assertEqual( + param_eval_update["epsilon_s_init"], param_eval["epsilon_s_init"] + ) + self.assertLess( + param_eval_update["epsilon_p_init"], param_eval["epsilon_p_init"] + ) self.assertGreater( param_eval_update["curlyU_n_init"], param_eval["curlyU_n_init"] ) From a988a1458c96fd80fcf5f72ce2fc5c04309a2fa3 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 12 Nov 2019 19:52:20 -0500 Subject: [PATCH 6/7] #579 changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e21824ce4a..cc7c5fa89d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Features +- Separated active and inactive material volume fractions ([#726](https://github.com/pybamm-team/PyBaMM/pull/726)) +- Added submodels for tortuosity ([#726](https://github.com/pybamm-team/PyBaMM/pull/726)) - Simplified the interface for setting current functions ([#723](https://github.com/pybamm-team/PyBaMM/pull/723)) - Added Heaviside operator ([#723](https://github.com/pybamm-team/PyBaMM/pull/723)) - Added Simulation class ([#693](https://github.com/pybamm-team/PyBaMM/pull/693)) From c200a412dd2f1ae72ae9ded6422d47fcb72cdf38 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Wed, 13 Nov 2019 10:21:04 -0500 Subject: [PATCH 7/7] #579 Ferran comments --- .../anodes/lead_Sulzer2019/parameters.csv | 3 ++- .../lead_dioxide_Sulzer2019/parameters.csv | 3 ++- .../separators/agm_Sulzer2019/parameters.csv | 3 ++- .../graphite_mcmb2528_Marquis2019/parameters.csv | 3 ++- .../cathodes/lico2_Marquis2019/parameters.csv | 3 ++- .../separator_Marquis2019/parameters.csv | 3 ++- .../full_stefan_maxwell_conductivity.py | 4 ++-- .../composite_stefan_maxwell_diffusion.py | 4 ++-- .../diffusion/full_stefan_maxwell_diffusion.py | 4 ++-- .../models/submodels/porosity/base_porosity.py | 6 +++--- .../submodels/tortuosity/bruggeman_tortuosity.py | 14 ++++++++------ pybamm/parameters/geometric_parameters.py | 14 ++++++-------- .../parameters/standard_parameters_lead_acid.py | 16 +++++++++------- .../standard_parameters_lithium_ion.py | 16 +++++++++------- tests/unit/test_expression_tree/test_symbol.py | 1 + .../test_full_stefan_maxwell_conductivity.py | 2 +- .../test_full_stefan_maxwell_diffusion.py | 1 + 17 files changed, 56 insertions(+), 44 deletions(-) diff --git a/input/parameters/lead-acid/anodes/lead_Sulzer2019/parameters.csv b/input/parameters/lead-acid/anodes/lead_Sulzer2019/parameters.csv index 82b3a81251..56fc70558f 100644 --- a/input/parameters/lead-acid/anodes/lead_Sulzer2019/parameters.csv +++ b/input/parameters/lead-acid/anodes/lead_Sulzer2019/parameters.csv @@ -12,7 +12,8 @@ Negative electrode open-circuit potential [V],[function]lead_ocp_Bode1977,, ,,, # Microstructure,,, Negative electrode surface area density [m-1],2300000,, -Negative electrode Bruggeman coefficient,1.5,, +Negative electrode Bruggeman coefficient (electrolyte),1.5,, +Negative electrode Bruggeman coefficient (electrode),1.5,, Negative electrode morphological parameter,0.6,srinivasan2003mathematical, Negative electrode capacity [C.m-3],3473000000,, ,,, diff --git a/input/parameters/lead-acid/cathodes/lead_dioxide_Sulzer2019/parameters.csv b/input/parameters/lead-acid/cathodes/lead_dioxide_Sulzer2019/parameters.csv index ca1c454989..cd38f78b40 100644 --- a/input/parameters/lead-acid/cathodes/lead_dioxide_Sulzer2019/parameters.csv +++ b/input/parameters/lead-acid/cathodes/lead_dioxide_Sulzer2019/parameters.csv @@ -12,7 +12,8 @@ Positive electrode open-circuit potential [V],[function]lead_dioxide_ocp_Bode197 ,,, # Microstructure,,, Positive electrode surface area density [m-1],23000000,, -Positive electrode Bruggeman coefficient,1.5,, +Positive electrode Bruggeman coefficient (electrolyte),1.5,, +Positive electrode Bruggeman coefficient (electrode),1.5,, Positive electrode morphological parameter,0.6,srinivasan2003mathematical, Positive electrode capacity [C.m-3],2745000000,, ,,, diff --git a/input/parameters/lead-acid/separators/agm_Sulzer2019/parameters.csv b/input/parameters/lead-acid/separators/agm_Sulzer2019/parameters.csv index 8625bf67d4..539bddd464 100644 --- a/input/parameters/lead-acid/separators/agm_Sulzer2019/parameters.csv +++ b/input/parameters/lead-acid/separators/agm_Sulzer2019/parameters.csv @@ -2,4 +2,5 @@ Name [units],Value,Reference,Notes # Empty rows and rows starting with ‘#’ will be ignored,,, ,,, Maximum porosity of separator,0.92,, -Separator Bruggeman coefficient,1.5,, +Separator Bruggeman coefficient (electrolyte),1.5,, +Separator Bruggeman coefficient (electrode),1.5,, diff --git a/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv b/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv index 9bab3092f9..3d1469d95c 100644 --- a/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv +++ b/input/parameters/lithium-ion/anodes/graphite_mcmb2528_Marquis2019/parameters.csv @@ -12,7 +12,8 @@ Negative electrode porosity,0.3,Scott Moura FastDFN,electrolyte volume fraction Negative electrode active material volume fraction,0.7,,assuming zero binder volume fraction Negative particle radius [m],1E-05,Scott Moura FastDFN, Negative electrode surface area density [m-1],180000,Scott Moura FastDFN, -Negative electrode Bruggeman coefficient,1.5,Scott Moura FastDFN, +Negative electrode Bruggeman coefficient (electrolyte),1.5,Scott Moura FastDFN, +Negative electrode Bruggeman coefficient (electrode),1.5,Scott Moura FastDFN, ,,, # Interfacial reactions,,, Negative electrode cation signed stoichiometry,-1,, diff --git a/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv b/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv index 5e3c1c4db1..d1fabddca7 100644 --- a/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv +++ b/input/parameters/lithium-ion/cathodes/lico2_Marquis2019/parameters.csv @@ -12,7 +12,8 @@ Positive electrode porosity,0.3,Scott Moura FastDFN,electrolyte volume fraction Positive electrode active material volume fraction,0.7,,assuming zero binder volume fraction Positive particle radius [m],1E-05,Scott Moura FastDFN, Positive electrode surface area density [m-1],150000,Scott Moura FastDFN, -Positive electrode Bruggeman coefficient,1.5,Scott Moura FastDFN, +Positive electrode Bruggeman coefficient (electrolyte),1.5,Scott Moura FastDFN, +Positive electrode Bruggeman coefficient (electrode),1.5,Scott Moura FastDFN, ,,, # Interfacial reactions,,, Positive electrode cation signed stoichiometry,-1,, diff --git a/input/parameters/lithium-ion/separators/separator_Marquis2019/parameters.csv b/input/parameters/lithium-ion/separators/separator_Marquis2019/parameters.csv index c07313986c..d1af7d5bda 100644 --- a/input/parameters/lithium-ion/separators/separator_Marquis2019/parameters.csv +++ b/input/parameters/lithium-ion/separators/separator_Marquis2019/parameters.csv @@ -2,7 +2,8 @@ Name [units],Value,Reference,Notes # Empty rows and rows starting with ‘#’ will be ignored,,, ,,, Separator porosity,1,Scott Moura FastDFN, -Separator Bruggeman coefficient,1.5,Scott Moura FastDFN, +Separator Bruggeman coefficient (electrolyte),1.5,Scott Moura FastDFN, +Separator Bruggeman coefficient (electrode),1.5,Scott Moura FastDFN, Separator density [kg.m-3],397,, Separator specific heat capacity [J.kg-1.K-1],700,, Separator thermal conductivity [W.m-1.K-1],0.16,, diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/full_stefan_maxwell_conductivity.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/full_stefan_maxwell_conductivity.py index 89272892c8..2f28574512 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/full_stefan_maxwell_conductivity.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/conductivity/full_stefan_maxwell_conductivity.py @@ -34,11 +34,11 @@ def get_fundamental_variables(self): def get_coupled_variables(self, variables): param = self.param T = variables["Cell temperature"] - eps = variables["Porosity"] + tor = variables["Electrolyte tortuosity"] c_e = variables["Electrolyte concentration"] phi_e = variables["Electrolyte potential"] - i_e = (param.kappa_e(c_e, T) * (eps ** param.b) * param.gamma_e / param.C_e) * ( + i_e = (param.kappa_e(c_e, T) * tor * param.gamma_e / param.C_e) * ( param.chi(c_e) * (1 + param.Theta * T) * pybamm.grad(c_e) / c_e - pybamm.grad(phi_e) ) diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/composite_stefan_maxwell_diffusion.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/composite_stefan_maxwell_diffusion.py index dc7cd379d6..574a655015 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/composite_stefan_maxwell_diffusion.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/composite_stefan_maxwell_diffusion.py @@ -29,7 +29,7 @@ def __init__(self, param, reactions, extended=False): def get_coupled_variables(self, variables): - eps_0 = variables["Leading-order porosity"] + tor_0 = variables["Leading-order electrolyte tortuosity"] c_e_0_av = variables["Leading-order x-averaged electrolyte concentration"] c_e = variables["Electrolyte concentration"] # i_e = variables["Electrolyte current density"] @@ -40,7 +40,7 @@ def get_coupled_variables(self, variables): whole_cell = ["negative electrode", "separator", "positive electrode"] N_e_diffusion = ( - -(eps_0 ** param.b) + -tor_0 * pybamm.PrimaryBroadcast(param.D_e(c_e_0_av, T_0), whole_cell) * pybamm.grad(c_e) ) diff --git a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/full_stefan_maxwell_diffusion.py b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/full_stefan_maxwell_diffusion.py index 907627cfd5..e007a5e6f2 100644 --- a/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/full_stefan_maxwell_diffusion.py +++ b/pybamm/models/submodels/electrolyte/stefan_maxwell/diffusion/full_stefan_maxwell_diffusion.py @@ -31,7 +31,7 @@ def get_fundamental_variables(self): def get_coupled_variables(self, variables): - eps = variables["Porosity"] + tor = variables["Electrolyte tortuosity"] c_e = variables["Electrolyte concentration"] # i_e = variables["Electrolyte current density"] v_box = variables["Volume-averaged velocity"] @@ -39,7 +39,7 @@ def get_coupled_variables(self, variables): param = self.param - N_e_diffusion = -(eps ** param.b) * param.D_e(c_e, T) * pybamm.grad(c_e) + N_e_diffusion = -tor * param.D_e(c_e, T) * pybamm.grad(c_e) # N_e_migration = (param.C_e * param.t_plus) / param.gamma_e * i_e # N_e_convection = c_e * v_box diff --git a/pybamm/models/submodels/porosity/base_porosity.py b/pybamm/models/submodels/porosity/base_porosity.py index ec7d873970..72012656ab 100644 --- a/pybamm/models/submodels/porosity/base_porosity.py +++ b/pybamm/models/submodels/porosity/base_porosity.py @@ -34,9 +34,9 @@ def _get_standard_porosity_variables(self, eps, set_leading_order=False): } # activate material volume fractions - eps_solid_n = 1 - eps_n - self.param.epsilon_binder_n - eps_solid_s = 1 - eps_s - self.param.epsilon_binder_s - eps_solid_p = 1 - eps_p - self.param.epsilon_binder_p + eps_solid_n = 1 - eps_n - self.param.epsilon_inactive_n + eps_solid_s = 1 - eps_s - self.param.epsilon_inactive_s + eps_solid_p = 1 - eps_p - self.param.epsilon_inactive_p eps_solid = pybamm.Concatenation(eps_solid_n, eps_solid_s, eps_solid_p) am = "active material volume fraction" diff --git a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py index b4387e3862..0ccc5a8a4b 100644 --- a/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py +++ b/pybamm/models/submodels/tortuosity/bruggeman_tortuosity.py @@ -20,14 +20,16 @@ def get_coupled_variables(self, variables): param = self.param if self.phase == "Electrolyte": - eps = variables["Porosity"] + eps_n, eps_s, eps_p = variables["Porosity"].orphans + tor = pybamm.Concatenation( + eps_n ** param.b_e_n, eps_s ** param.b_e_s, eps_p ** param.b_e_p + ) elif self.phase == "Electrode": - eps = variables["Active material volume fraction"] + eps_n, eps_s, eps_p = variables["Active material volume fraction"].orphans + tor = pybamm.Concatenation( + eps_n ** param.b_s_n, eps_s ** param.b_s_s, eps_p ** param.b_s_p + ) - eps_n, eps_s, eps_p = eps.orphans - tor = pybamm.Concatenation( - eps_n ** param.b_n, eps_s ** param.b_s, eps_p ** param.b_p - ) variables.update( self._get_standard_tortuosity_variables(tor, self.set_leading_order) ) diff --git a/pybamm/parameters/geometric_parameters.py b/pybamm/parameters/geometric_parameters.py index 3b70db4865..d10d4a0264 100644 --- a/pybamm/parameters/geometric_parameters.py +++ b/pybamm/parameters/geometric_parameters.py @@ -36,14 +36,12 @@ a_p_dim = pybamm.Parameter("Positive electrode surface area density [m-1]") R_n = pybamm.Parameter("Negative particle radius [m]") R_p = pybamm.Parameter("Positive particle radius [m]") -b_n = pybamm.Parameter("Negative electrode Bruggeman coefficient") -b_s = pybamm.Parameter("Separator Bruggeman coefficient") -b_p = pybamm.Parameter("Positive electrode Bruggeman coefficient") -b = pybamm.Concatenation( - pybamm.FullBroadcast(b_n, ["negative electrode"], "current collector"), - pybamm.FullBroadcast(b_s, ["separator"], "current collector"), - pybamm.FullBroadcast(b_p, ["positive electrode"], "current collector"), -) +b_e_n = pybamm.Parameter("Negative electrode Bruggeman coefficient (electrolyte)") +b_e_s = pybamm.Parameter("Separator Bruggeman coefficient (electrolyte)") +b_e_p = pybamm.Parameter("Positive electrode Bruggeman coefficient (electrolyte)") +b_s_n = pybamm.Parameter("Negative electrode Bruggeman coefficient (electrode)") +b_s_s = pybamm.Parameter("Separator Bruggeman coefficient (electrode)") +b_s_p = pybamm.Parameter("Positive electrode Bruggeman coefficient (electrode)") # -------------------------------------------------------------------------------------- "Dimensionless Parameters" diff --git a/pybamm/parameters/standard_parameters_lead_acid.py b/pybamm/parameters/standard_parameters_lead_acid.py index 0025378e25..ef92f84dc5 100644 --- a/pybamm/parameters/standard_parameters_lead_acid.py +++ b/pybamm/parameters/standard_parameters_lead_acid.py @@ -72,16 +72,18 @@ # Microstructure a_n_dim = pybamm.geometric_parameters.a_n_dim a_p_dim = pybamm.geometric_parameters.a_p_dim -b_n = pybamm.geometric_parameters.b_n -b_s = pybamm.geometric_parameters.b_s -b_p = pybamm.geometric_parameters.b_p -b = pybamm.geometric_parameters.b +b_e_n = pybamm.geometric_parameters.b_e_n +b_e_s = pybamm.geometric_parameters.b_e_s +b_e_p = pybamm.geometric_parameters.b_e_p +b_s_n = pybamm.geometric_parameters.b_s_n +b_s_s = pybamm.geometric_parameters.b_s_s +b_s_p = pybamm.geometric_parameters.b_s_p xi_n = pybamm.Parameter("Negative electrode morphological parameter") xi_p = pybamm.Parameter("Positive electrode morphological parameter") # no binder -epsilon_binder_n = pybamm.Scalar(0) -epsilon_binder_s = pybamm.Scalar(0) -epsilon_binder_p = pybamm.Scalar(0) +epsilon_inactive_n = pybamm.Scalar(0) +epsilon_inactive_s = pybamm.Scalar(0) +epsilon_inactive_p = pybamm.Scalar(0) # Electrochemical reactions # Main diff --git a/pybamm/parameters/standard_parameters_lithium_ion.py b/pybamm/parameters/standard_parameters_lithium_ion.py index 5e52bdacda..62fbcf646e 100644 --- a/pybamm/parameters/standard_parameters_lithium_ion.py +++ b/pybamm/parameters/standard_parameters_lithium_ion.py @@ -82,10 +82,12 @@ ) R_n = pybamm.geometric_parameters.R_n R_p = pybamm.geometric_parameters.R_p -b_n = pybamm.geometric_parameters.b_n -b_s = pybamm.geometric_parameters.b_s -b_p = pybamm.geometric_parameters.b_p -b = pybamm.geometric_parameters.b +b_e_n = pybamm.geometric_parameters.b_e_n +b_e_s = pybamm.geometric_parameters.b_e_s +b_e_p = pybamm.geometric_parameters.b_e_p +b_s_n = pybamm.geometric_parameters.b_s_n +b_s_s = pybamm.geometric_parameters.b_s_s +b_s_p = pybamm.geometric_parameters.b_s_p # Electrochemical reactions ne_n = pybamm.Parameter("Negative electrode electrons in reaction") @@ -279,9 +281,9 @@ def U_p_dimensional(sto, T): ) epsilon_s_n = pybamm.Parameter("Negative electrode active material volume fraction") epsilon_s_p = pybamm.Parameter("Positive electrode active material volume fraction") -epsilon_binder_n = 1 - epsilon_n - epsilon_s_n -epsilon_binder_s = 1 - epsilon_s -epsilon_binder_p = 1 - epsilon_p - epsilon_s_p +epsilon_inactive_n = 1 - epsilon_n - epsilon_s_n +epsilon_inactive_s = 1 - epsilon_s +epsilon_inactive_p = 1 - epsilon_p - epsilon_s_p a_n = a_n_dim * R_n a_p = a_p_dim * R_p diff --git a/tests/unit/test_expression_tree/test_symbol.py b/tests/unit/test_expression_tree/test_symbol.py index 840185b107..55956c5514 100644 --- a/tests/unit/test_expression_tree/test_symbol.py +++ b/tests/unit/test_expression_tree/test_symbol.py @@ -272,6 +272,7 @@ def test_symbol_visualise(self): variables = { "Porosity": param.epsilon, + "Electrolyte tortuosity": param.epsilon ** 1.5, "Porosity change": deps_dt, "Volume-averaged velocity": v_box, "Negative electrode interfacial current density": one_n, diff --git a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_full_stefan_maxwell_conductivity.py b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_full_stefan_maxwell_conductivity.py index 2aecbf88a1..80870cbc68 100644 --- a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_full_stefan_maxwell_conductivity.py +++ b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_conductivity/test_full_stefan_maxwell_conductivity.py @@ -12,7 +12,7 @@ def test_public_functions(self): param = pybamm.standard_parameters_lithium_ion a = pybamm.Scalar(0) variables = { - "Porosity": a, + "Electrolyte tortuosity": a, "Electrolyte concentration": a, "Negative electrode interfacial current density": pybamm.FullBroadcast( a, "negative electrode", "current collector" diff --git a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_diffusion/test_full_stefan_maxwell_diffusion.py b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_diffusion/test_full_stefan_maxwell_diffusion.py index a45ec88bb2..87b8de8d9f 100644 --- a/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_diffusion/test_full_stefan_maxwell_diffusion.py +++ b/tests/unit/test_models/test_submodels/test_electrolyte/test_stefan_maxwell/test_diffusion/test_full_stefan_maxwell_diffusion.py @@ -13,6 +13,7 @@ def test_public_functions(self): a = pybamm.Scalar(0) variables = { "Porosity": a, + "Electrolyte tortuosity": a, "Porosity change": a, "Volume-averaged velocity": a, "Electrolyte concentration": a,