diff --git a/CHANGELOG.md b/CHANGELOG.md index e1ffbbf594..42ed912528 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/pybamm/models/full_battery_models/base_battery_model.py b/pybamm/models/full_battery_models/base_battery_model.py index 5a2704039b..55acb07bf8 100644 --- a/pybamm/models/full_battery_models/base_battery_model.py +++ b/pybamm/models/full_battery_models/base_battery_model.py @@ -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. @@ -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"], @@ -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) @@ -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": @@ -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" ) @@ -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 diff --git a/pybamm/models/submodels/particle/no_distribution/base_fickian.py b/pybamm/models/submodels/particle/no_distribution/base_fickian.py index e85fd00e77..b61be85394 100644 --- a/pybamm/models/submodels/particle/no_distribution/base_fickian.py +++ b/pybamm/models/submodels/particle/no_distribution/base_fickian.py @@ -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) / ( diff --git a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py index 83117e1660..f35919d005 100644 --- a/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py +++ b/tests/unit/test_models/test_full_battery_models/test_base_battery_model.py @@ -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 @@ -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"}) diff --git a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py index e95338f10a..0798d095c2 100644 --- a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py +++ b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_mpm.py @@ -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): @@ -78,7 +83,7 @@ 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", @@ -86,6 +91,11 @@ def test_well_posed_reversible_plating_with_porosity_not_implemented(self): 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): diff --git a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_spm.py b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_spm.py index 2b0bfeb23c..8c3d12af94 100644 --- a/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_spm.py +++ b/tests/unit/test_models/test_full_battery_models/test_lithium_ion/test_spm.py @@ -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 @@ -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):