Skip to content

Commit

Permalink
Merge pull request #1503 from pybamm-team/issue-1501-different-submodels
Browse files Browse the repository at this point in the history
Issue 1501 different submodels
  • Loading branch information
valentinsulzer committed Jun 8, 2021
2 parents 08de417 + 22256e8 commit f6cb07a
Show file tree
Hide file tree
Showing 18 changed files with 170 additions and 169 deletions.
99 changes: 44 additions & 55 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@ class BatteryModelOptions(pybamm.FuzzyDict):
variable for instead of solving in PyBaMM. The entries of the lists
are strings that correspond to the submodel names in the keys
of `self.submodels`.
* "interfacial surface area" : str
Sets the model for the interfacial surface area. Can be "constant"
(default) or "varying". Not currently implemented in any of the models.
* "hydrolysis" : str
Whether to include hydrolysis in the model. Only implemented for
lead-acid models. Can be "false" (default) or "true". If "true", then
"surface form" cannot be 'false'.
* "lithium plating" : str, optional
Sets the model for lithium plating. Can be "none" (default),
"reversible" or "irreversible".
Expand Down Expand Up @@ -120,10 +121,6 @@ class BatteryModelOptions(pybamm.FuzzyDict):
* "SEI porosity change" : str
Whether to include porosity change due to SEI formation, can be "false"
(default) or "true".
* "side reactions" : list
Contains a list of any side reactions to include. Default is []. If this
list is not empty (i.e. side reactions are included in the model), then
"surface form" cannot be 'false'.
* "surface form" : str
Whether to use the surface formulation of the problem. Can be "false"
(default), "differential" or "algebraic".
Expand All @@ -141,77 +138,72 @@ class BatteryModelOptions(pybamm.FuzzyDict):

def __init__(self, extra_options):
self.possible_options = {
"surface form": ["false", "differential", "algebraic"],
"cell geometry": ["arbitrary", "pouch"],
"convection": ["none", "uniform transverse", "full transverse"],
"current collector": [
"uniform",
"potential pair",
"potential pair quite conductive",
],
"dimensionality": [0, 1, 2],
"interfacial surface area": ["constant", "varying"],
"thermal": ["isothermal", "lumped", "x-lumped", "x-full"],
"cell geometry": ["arbitrary", "pouch"],
"SEI": [
"none",
"constant",
"reaction limited",
"solvent-diffusion limited",
"electron-migration limited",
"interstitial-diffusion limited",
"ec reaction limited",
"electrolyte conductivity": [
"default",
"full",
"leading order",
"composite",
"integrated",
],
"SEI film resistance": ["none", "distributed", "average"],
"SEI porosity change": ["true", "false"],
"hydrolysis": ["true", "false"],
"lithium plating": ["none", "reversible", "irreversible"],
"lithium plating porosity change": ["true", "false"],
"loss of active material": ["none", "stress-driven", "reaction-driven"],
"operating mode": ["current", "voltage", "power"],
"particle mechanics": [
"none",
"swelling only",
"swelling and cracking",
],
"lithium plating porosity change": ["true", "false"],
"particle": [
"Fickian diffusion",
"fast diffusion",
"uniform profile",
"quadratic profile",
"quartic profile",
],
"particle mechanics": ["none", "swelling only", "swelling and cracking"],
"particle shape": ["spherical", "user", "no particles"],
"electrolyte conductivity": [
"default",
"full",
"leading order",
"composite",
"integrated",
"SEI": [
"none",
"constant",
"reaction limited",
"solvent-diffusion limited",
"electron-migration limited",
"interstitial-diffusion limited",
"ec reaction limited",
],
"SEI film resistance": ["none", "distributed", "average"],
"SEI porosity change": ["true", "false"],
"surface form": ["false", "differential", "algebraic"],
"thermal": ["isothermal", "lumped", "x-lumped", "x-full"],
"total interfacial current density as a state": ["true", "false"],
}

default_options = {
"operating mode": "current",
"dimensionality": 0,
"surface form": "false",
"cell geometry": "none",
"convection": "none",
"side reactions": [],
"interfacial surface area": "constant",
"current collector": "uniform",
"particle": "Fickian diffusion",
"particle shape": "spherical",
"dimensionality": 0,
"electrolyte conductivity": "default",
"thermal": "isothermal",
"cell geometry": "none",
"external submodels": [],
"SEI": "none",
"hydrolysis": "false",
"lithium plating": "none",
"SEI porosity change": "false",
"lithium plating porosity change": "false",
"loss of active material": "none",
"working electrode": "none",
"operating mode": "current",
"particle": "Fickian diffusion",
"particle mechanics": "none",
"particle shape": "spherical",
"SEI": "none",
"SEI porosity change": "false",
"surface form": "false",
"thermal": "isothermal",
"total interfacial current density as a state": "false",
"working electrode": "none",
}

# Change the default for cell geometry based on which thermal option is provided
Expand Down Expand Up @@ -309,11 +301,7 @@ def __init__(self, extra_options):
)

for option, value in options.items():
if (
option == "side reactions"
or option == "external submodels"
or option == "working electrode"
):
if option == "external submodels" or option == "working electrode":
pass
else:
if isinstance(value, str) or option in [
Expand All @@ -328,6 +316,7 @@ def __init__(self, extra_options):
in [
"loss of active material",
"particle mechanics",
"particle",
]
and isinstance(value, tuple)
and len(value) == 2
Expand Down Expand Up @@ -483,14 +472,14 @@ def options(self, extra_options):
if (
isinstance(self, (pybamm.lead_acid.LOQS, pybamm.lead_acid.Composite))
and options["surface form"] == "false"
and options["hydrolysis"] == "true"
):
if len(options["side reactions"]) > 0:
raise pybamm.OptionError(
"""must use surface formulation to solve {!s} with side reactions
raise pybamm.OptionError(
"""must use surface formulation to solve {!s} with hydrolysis
""".format(
self
)
self
)
)

self._options = options

Expand Down
2 changes: 1 addition & 1 deletion pybamm/models/full_battery_models/lead_acid/full.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def set_electrolyte_submodel(self):
] = surf_form.FullAlgebraic(self.param, domain)

def set_side_reaction_submodels(self):
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels["oxygen diffusion"] = pybamm.oxygen_diffusion.Full(
self.param
)
Expand Down
10 changes: 5 additions & 5 deletions pybamm/models/full_battery_models/lead_acid/higher_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def set_full_interface_submodel(self):
)

# Oxygen
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels[
"positive oxygen interface"
] = pybamm.interface.FirstOrderKinetics(
Expand Down Expand Up @@ -231,7 +231,7 @@ def set_electrolyte_diffusion_submodel(self):
] = pybamm.electrolyte_diffusion.FirstOrder(self.param)

def set_other_species_diffusion_submodels(self):
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels["oxygen diffusion"] = pybamm.oxygen_diffusion.FirstOrder(
self.param
)
Expand Down Expand Up @@ -261,7 +261,7 @@ def set_electrolyte_diffusion_submodel(self):
] = pybamm.electrolyte_diffusion.Composite(self.param)

def set_other_species_diffusion_submodels(self):
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels["oxygen diffusion"] = pybamm.oxygen_diffusion.Composite(
self.param
)
Expand Down Expand Up @@ -307,7 +307,7 @@ def set_electrolyte_diffusion_submodel(self):
] = pybamm.electrolyte_diffusion.Composite(self.param, extended="distributed")

def set_other_species_diffusion_submodels(self):
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels["oxygen diffusion"] = pybamm.oxygen_diffusion.Composite(
self.param, extended="distributed"
)
Expand All @@ -329,7 +329,7 @@ def set_electrolyte_diffusion_submodel(self):
] = pybamm.electrolyte_diffusion.Composite(self.param, extended="average")

def set_other_species_diffusion_submodels(self):
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels["oxygen diffusion"] = pybamm.oxygen_diffusion.Composite(
self.param, extended="average"
)
2 changes: 1 addition & 1 deletion pybamm/models/full_battery_models/lead_acid/loqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def set_electrolyte_submodel(self):
] = pybamm.electrolyte_diffusion.LeadingOrder(self.param)

def set_side_reaction_submodels(self):
if "oxygen" in self.options["side reactions"]:
if self.options["hydrolysis"] == "true":
self.submodels[
"leading-order oxygen diffusion"
] = pybamm.oxygen_diffusion.LeadingOrder(self.param)
Expand Down
43 changes: 22 additions & 21 deletions pybamm/models/full_battery_models/lithium_ion/dfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,29 @@ def set_interfacial_submodel(self):

def set_particle_submodel(self):

if self.options["particle"] == "Fickian diffusion":
self.submodels["negative particle"] = pybamm.particle.FickianManyParticles(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.FickianManyParticles(
self.param, "Positive"
)
elif self.options["particle"] in [
"uniform profile",
"quadratic profile",
"quartic profile",
if isinstance(self.options["particle"], str):
particle_left = self.options["particle"]
particle_right = self.options["particle"]
else:
particle_left, particle_right = self.options["particle"]
for particle_side, domain in [
[particle_left, "Negative"],
[particle_right, "Positive"],
]:
self.submodels[
"negative particle"
] = pybamm.particle.PolynomialManyParticles(
self.param, "Negative", self.options["particle"]
)
self.submodels[
"positive particle"
] = pybamm.particle.PolynomialManyParticles(
self.param, "Positive", self.options["particle"]
)
if particle_side == "Fickian diffusion":
self.submodels[
domain.lower() + " particle"
] = pybamm.particle.FickianManyParticles(self.param, domain)
elif particle_side in [
"uniform profile",
"quadratic profile",
"quartic profile",
]:
self.submodels[
domain.lower() + " particle"
] = pybamm.particle.PolynomialManyParticles(
self.param, domain, particle_side
)

def set_solid_submodel(self):

Expand Down
44 changes: 22 additions & 22 deletions pybamm/models/full_battery_models/lithium_ion/spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,29 @@ def set_interfacial_submodel(self):
)

def set_particle_submodel(self):

if self.options["particle"] == "Fickian diffusion":
self.submodels["negative particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Positive"
)
elif self.options["particle"] in [
"uniform profile",
"quadratic profile",
"quartic profile",
if isinstance(self.options["particle"], str):
particle_left = self.options["particle"]
particle_right = self.options["particle"]
else:
particle_left, particle_right = self.options["particle"]
for particle_side, domain in [
[particle_left, "Negative"],
[particle_right, "Positive"],
]:
self.submodels[
"negative particle"
] = pybamm.particle.PolynomialSingleParticle(
self.param, "Negative", self.options["particle"]
)
self.submodels[
"positive particle"
] = pybamm.particle.PolynomialSingleParticle(
self.param, "Positive", self.options["particle"]
)
if particle_side == "Fickian diffusion":
self.submodels[
domain.lower() + " particle"
] = pybamm.particle.FickianSingleParticle(self.param, domain)
elif particle_side in [
"uniform profile",
"quadratic profile",
"quartic profile",
]:
self.submodels[
domain.lower() + " particle"
] = pybamm.particle.PolynomialSingleParticle(
self.param, domain, particle_side
)

def set_negative_electrode_submodel(self):

Expand Down
43 changes: 22 additions & 21 deletions pybamm/models/full_battery_models/lithium_ion/spme.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,29 @@ def set_interfacial_submodel(self):

def set_particle_submodel(self):

if self.options["particle"] == "Fickian diffusion":
self.submodels["negative particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Positive"
)
elif self.options["particle"] in [
"uniform profile",
"quadratic profile",
"quartic profile",
if isinstance(self.options["particle"], str):
particle_left = self.options["particle"]
particle_right = self.options["particle"]
else:
particle_left, particle_right = self.options["particle"]
for particle_side, domain in [
[particle_left, "Negative"],
[particle_right, "Positive"],
]:
self.submodels[
"negative particle"
] = pybamm.particle.PolynomialSingleParticle(
self.param, "Negative", self.options["particle"]
)
self.submodels[
"positive particle"
] = pybamm.particle.PolynomialSingleParticle(
self.param, "Positive", self.options["particle"]
)
if particle_side == "Fickian diffusion":
self.submodels[
domain.lower() + " particle"
] = pybamm.particle.FickianSingleParticle(self.param, domain)
elif particle_side in [
"uniform profile",
"quadratic profile",
"quartic profile",
]:
self.submodels[
domain.lower() + " particle"
] = pybamm.particle.PolynomialSingleParticle(
self.param, domain, particle_side
)

def set_negative_electrode_submodel(self):

Expand Down
Loading

0 comments on commit f6cb07a

Please sign in to comment.