Skip to content

Commit

Permalink
#1748 coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Nov 12, 2021
1 parent 2aa223d commit 58922b5
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 22 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Features

- Stress induced diffusion is now a separate model option instead of being automatically included when using the particle mechanics submodels ([#1797](https://github.com/pybamm-team/PyBaMM/pull/1797))
- Stress-induced diffusion is now a separate model option instead of being automatically included when using the particle mechanics submodels ([#1797](https://github.com/pybamm-team/PyBaMM/pull/1797))
- `Experiment`s with drive cycles can be solved ([#1793](https://github.com/pybamm-team/PyBaMM/pull/1793))
- Added surface area to volume ratio as a factor to the SEI equations ([#1790](https://github.com/pybamm-team/PyBaMM/pull/1790))
- Half-cell SPM and SPMe have been implemented ([#1731](https://github.com/pybamm-team/PyBaMM/pull/1731))
Expand Down
26 changes: 13 additions & 13 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class BatteryModelOptions(pybamm.FuzzyDict):
* "SEI porosity change" : str
Whether to include porosity change due to SEI formation, can be "false"
(default) or "true".
* "stress induced diffusion" : str
Whether to includes stress induced diffusion, can be "false" or "true".
* "stress-induced diffusion" : str
Whether to include stress-induced diffusion, can be "false" or "true".
The default is "false" if "particle mechanics" is "none" and "true"
otherwise. A 2-tuple can be provided for different behaviour in negative
and positive electrodes.
Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(self, extra_options):
],
"SEI film resistance": ["none", "distributed", "average"],
"SEI porosity change": ["true", "false"],
"stress induced diffusion": ["true", "false"],
"stress-induced diffusion": ["true", "false"],
"surface form": ["false", "differential", "algebraic"],
"thermal": ["isothermal", "lumped", "x-lumped", "x-full"],
"total interfacial current density as a state": ["true", "false"],
Expand Down Expand Up @@ -255,14 +255,14 @@ def __init__(self, extra_options):
# The "particle mechanics" option will still be overridden by extra_options if
# provided

# Change the default for stress induced diffusion based on which particle
# Change the default for stress-induced diffusion based on which particle
# mechanics option is provided
mechanics_option = extra_options.get("particle mechanics", "none")
if mechanics_option == "none":
default_options["stress induced diffusion"] = "false"
default_options["stress-induced diffusion"] = "false"
else:
default_options["stress induced diffusion"] = "true"
# The "stress induced diffusion" option will still be overridden by
default_options["stress-induced diffusion"] = "true"
# The "stress-induced diffusion" option will still be overridden by
# extra_options if provided

options = pybamm.FuzzyDict(default_options)
Expand Down Expand Up @@ -323,9 +323,9 @@ def __init__(self, extra_options):
raise NotImplementedError(
"SEI submodels do not yet support particle-size distributions."
)
if options["stress induced diffusion"] == "true":
if options["stress-induced diffusion"] == "true":
raise NotImplementedError(
"Stress induced diffusion cannot yet be included in "
"stress-induced diffusion cannot yet be included in "
"particle-size distributions."
)
if options["thermal"] == "x-full":
Expand Down Expand Up @@ -356,13 +356,13 @@ def __init__(self, extra_options):
raise pybamm.OptionError(
"cannot have transverse convection in 0D model"
)
if isinstance(options["stress induced diffusion"], str):
if isinstance(options["stress-induced diffusion"], str):
if (
options["stress induced diffusion"] == "true"
options["stress-induced diffusion"] == "true"
and options["particle mechanics"] == "none"
):
raise pybamm.OptionError(
"cannot have stress induced diffusion without a particle "
"cannot have stress-induced diffusion without a particle "
"mechanics model"
)

Expand All @@ -383,7 +383,7 @@ def __init__(self, extra_options):
"loss of active material",
"particle mechanics",
"particle",
"stress induced diffusion",
"stress-induced diffusion",
]
and isinstance(value, tuple)
and len(value) == 2
Expand Down
10 changes: 5 additions & 5 deletions pybamm/models/submodels/particle/no_distribution/base_fickian.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def _get_effective_diffusivity(self, c, T):
elif self.domain == "Positive":
D = param.D_p(c, T)

# Account for stress induced diffusion by defining a multiplicative
# Account for stress-induced diffusion by defining a multiplicative
# "stress factor"
# This option can either be a string (both sides the same) or a 2-tuple
# to indicate different options in negative and positive electrodes
if isinstance(self.options["stress induced diffusion"], str):
stress_left = self.options["stress induced diffusion"]
stress_right = self.options["stress induced diffusion"]
if isinstance(self.options["stress-induced diffusion"], str):
stress_left = self.options["stress-induced diffusion"]
stress_right = self.options["stress-induced diffusion"]
else:
stress_left, stress_right = self.options["stress induced diffusion"]
stress_left, stress_right = self.options["stress-induced diffusion"]

if self.domain == "Negative" and stress_left == "true":
stress_factor = 1 + param.theta_n * (c - param.c_n_0) / (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
'total interfacial current density as a state': 'false' (possible: ['true', 'false'])
'working electrode': 'both' (possible: ['both', 'negative', 'positive'])
'SEI film resistance': 'none' (possible: ['none', 'distributed', 'average'])
'stress induced diffusion': 'false' (possible: ['true', 'false'])
'stress-induced diffusion': 'false' (possible: ['true', 'false'])
""" # noqa: E501


Expand Down Expand Up @@ -260,6 +260,11 @@ def test_options(self):
"plating porosity change"
}
)
# stress-induced diffusion
with self.assertRaisesRegex(pybamm.OptionError, "cannot have stress"):
pybamm.BaseBatteryModel({"stress-induced diffusion": "true"})

# hydrolysis
with self.assertRaisesRegex(pybamm.OptionError, "surface formulation"):
pybamm.lead_acid.LOQS({"hydrolysis": "true", "surface form": "false"})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ def test_particle_uniform(self):
model = pybamm.lithium_ion.MPM(options)
model.check_well_posedness()

def test_particle_quadratic(self):
options = {"particle": "quadratic profile"}
with self.assertRaises(NotImplementedError):
pybamm.lithium_ion.MPM(options)

def test_necessary_options(self):
options = {"particle size": "single"}
with self.assertRaises(pybamm.OptionError):
Expand Down Expand Up @@ -78,14 +83,19 @@ def test_loss_active_material_stress_both_not_implemented(self):
with self.assertRaises(NotImplementedError):
pybamm.lithium_ion.MPM(options)

def test_well_posed_reversible_plating_with_porosity_not_implemented(self):
def test_reversible_plating_with_porosity_not_implemented(self):
options = {
"lithium plating": "reversible",
"lithium plating porosity change": "true",
}
with self.assertRaises(NotImplementedError):
pybamm.lithium_ion.MPM(options)

def test_stress_induced_diffusion_not_implemented(self):
options = {"stress-induced diffusion": "true"}
with self.assertRaises(NotImplementedError):
pybamm.lithium_ion.MPM(options)


class TestMPMExternalCircuits(unittest.TestCase):
def test_well_posed_voltage(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_new_model(self):
self.assertEqual(new_model.timescale.id, model.timescale.id)

# with custom submodels
options = {"stress induced diffusion": "false", "thermal": "x-full"}
options = {"stress-induced diffusion": "false", "thermal": "x-full"}
model = pybamm.lithium_ion.SPM(options, build=False)
particle_n = pybamm.particle.no_distribution.XAveragedPolynomialProfile(
model.param, "Negative", "quadratic profile", options
Expand Down Expand Up @@ -257,6 +257,14 @@ def test_well_posed_both_swelling_only(self):
model = pybamm.lithium_ion.SPM(options)
model.check_well_posedness()

def test_stress_induced_diffusion_mixed(self):
options = {
"particle mechanics": "swelling only",
"stress-induced diffusion": ("true", "false"),
}
model = pybamm.lithium_ion.SPM(options)
model.check_well_posedness()


class TestSPMWithPlating(unittest.TestCase):
def test_well_posed_none_plating(self):
Expand Down

0 comments on commit 58922b5

Please sign in to comment.