Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Many-Particle Models #1529

Merged
merged 82 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
0d94d25
added BasicMPM class to lithium_ion
tobykirk Jun 17, 2020
fbfe2d2
Merge branch 'develop' into add-PSD-models
tobykirk Jun 17, 2020
095484c
expanded output variables
tobykirk Jun 18, 2020
ec61fb3
rename model class
tobykirk Jun 24, 2020
86a21b5
renamed PSD model file
tobykirk Jun 24, 2020
bf9949b
Merge branch 'develop' into add-PSD-models
tobykirk Jun 24, 2020
1360cc5
added interp for 1D ProcessedVariables in particle-size domain R
tobykirk Jun 24, 2020
274413c
fixed style to black
tobykirk Jun 25, 2020
6b081c2
Merge branch 'develop' into add-PSD-models
tobykirk Jun 26, 2020
4bbc39b
added PSDModel incorporating submodel structure
tobykirk Jul 13, 2020
ad2b172
tidied up PSDModel
tobykirk Jul 13, 2020
1a97965
Merge branch 'develop' into add-PSD-models
tobykirk Jul 13, 2020
a2b7df8
quick plotting for 2D vars of particle size
tobykirk Jul 13, 2020
534b60b
tidied up PSD output variables
tobykirk Jul 14, 2020
8487ef9
added fast diffusion PSD submodels
tobykirk Jul 14, 2020
9eb72e4
Default geometry and meshes etc for PSDs
tobykirk Jul 16, 2020
0c2850f
added R-average
tobykirk Jul 17, 2020
5f489df
fied typos and style
tobykirk Jul 17, 2020
5d938a8
added ManyPSD submodels, and the option to DFN
tobykirk Jul 17, 2020
6e41c07
added option to use SPM as MPM
tobykirk Jul 17, 2020
61ee854
added PSD with fast diffusion submodel to DFN
tobykirk Jul 17, 2020
af48cf0
add distribution parameters to Marquis2019 set
tobykirk Jul 30, 2020
010ac48
automatic distribution normalising
tobykirk Aug 18, 2020
4525057
changed event tolerance
tobykirk Nov 13, 2020
11f1188
revert submodel selection changes to SPM
tobykirk Jun 1, 2021
af4e016
fix SPM interface submodel selection
tobykirk Jun 1, 2021
686c5e2
fix tests
tobykirk Jun 1, 2021
7c91e3f
Merge branch 'develop' into many-particle-models
tobykirk Jun 1, 2021
683f008
fixed MPM
tobykirk Jun 2, 2021
5784af9
name changes to domains, options, spatial vars
tobykirk Jun 4, 2021
65d568f
refactor of size distribution submodels
tobykirk Jun 4, 2021
0a379ab
fix fast diffusion MP submodels and output vars
tobykirk Jun 4, 2021
ba8988b
fix tests
tobykirk Jun 4, 2021
003bff6
added citations to Kirk et al 2020
tobykirk Jun 4, 2021
9050cf2
add unit tests for MPM and submodels
tobykirk Jun 8, 2021
b1a33f8
added standard integration tests for MPM
tobykirk Jun 8, 2021
df13141
change MPM submodels to surface form
tobykirk Jun 10, 2021
415ee98
delete plots_of_MPM script
tobykirk Jun 10, 2021
a6aa477
remove test for Fickian MPDFN
tobykirk Jun 10, 2021
b7d95d8
Merge branch 'develop' into many-particle-models
tobykirk Jun 10, 2021
ea72822
fixed surface area for MP models and tests
tobykirk Jun 11, 2021
31855e7
incompatible options with size distributions
tobykirk Jun 11, 2021
23b9f4a
rename mean radii variables
tobykirk Jun 11, 2021
582d56b
Merge branch 'develop' into many-particle-models
tobykirk Jun 15, 2021
ea1c372
added voltage control to MPM
tobykirk Jun 15, 2021
57b706a
added more distribution output vars
tobykirk Jun 15, 2021
8f4b30e
added doc index files for MPM and submodels
tobykirk Jun 15, 2021
a11b5ec
fix distribution output variables
tobykirk Jun 15, 2021
a6582b6
add output vars to fix lead acid tests
tobykirk Jun 30, 2021
e2a0840
added Kirk2021 citation
tobykirk Jun 30, 2021
e0de928
added MPM notebook
tobykirk Jun 30, 2021
95aecaf
Merge branch 'develop' into many-particle-models
tobykirk Jun 30, 2021
683674c
removed the 'ManyDistributions' submodels
tobykirk Jun 30, 2021
532d47a
revert DFN to develop
tobykirk Jun 30, 2021
b3c12eb
remove size distributions from Marquis param set
tobykirk Jun 30, 2021
f93fa09
remove test for 'FastManyDistributions' submodel
tobykirk Jun 30, 2021
f00d86d
change name of R_average
tobykirk Jul 5, 2021
e081d08
fix exchange current density tests
tobykirk Jul 5, 2021
c955d72
add function get_size_distribution_parameters
tobykirk Jul 6, 2021
23fa913
refactor interface distribution variables
tobykirk Jul 6, 2021
009752f
reduce code duplication in quick_plot
tobykirk Jul 6, 2021
a8e5c16
Merge branch 'develop' into add-mpm
tobykirk Jul 6, 2021
2ca98d4
remove some mpm tests
tobykirk Jul 6, 2021
b9eb06e
change MPM init and reduce tests
tobykirk Jul 7, 2021
339b9f0
moved particle size params to geometric parameters
tobykirk Jul 7, 2021
c2f284b
Merge branch 'develop' into add-mpm
tobykirk Jul 7, 2021
494bf0c
Merge branch 'develop' into add-mpm
tobykirk Jul 16, 2021
82ea288
move default standard deviations
tobykirk Jul 16, 2021
edf67bb
change definition of particle flux
tobykirk Jul 16, 2021
de5afe3
fix notebooks
tobykirk Jul 16, 2021
3fbe86a
add broadcast tests with particle size
tobykirk Jul 20, 2021
c7472ec
add particle size processed variable tests
tobykirk Jul 20, 2021
3e9261d
add mpm tests for coverage
tobykirk Jul 20, 2021
85989da
remove untested code for size distr in DFN
tobykirk Jul 22, 2021
7b87152
tests to increase coverage
tobykirk Jul 22, 2021
681826a
Merge branch 'develop' into add-mpm
tobykirk Jul 27, 2021
8a964b3
update changelog
tobykirk Jul 27, 2021
49a00d6
Merge branch 'develop' into add-mpm
valentinsulzer Jul 28, 2021
7c50b99
reduced code duplication in processed var tests
tobykirk Jul 29, 2021
57f9e08
Merge remote-tracking branch 'upstream/develop' into add-mpm
tobykirk Jul 29, 2021
515590d
remove unusued variable to fix codacy
tobykirk Jul 29, 2021
34700c0
Merge branch 'develop' into add-mpm
tobykirk Jul 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 11 additions & 16 deletions examples/notebooks/using-submodels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"In the Single Particle Model, the overpotential can be obtianed by inverting the Butler-Volmer relation, so we choose the `InverseButlerVolmer` submodel for the interface, with the \"main\" lithium-ion reaction. Because of how the current is implemented, we also need to separately specify the `CurrentForInverseButlerVolmer` submodel"
"In the Single Particle Model, the overpotential can be obtianed by inverting the Butler-Volmer relation, so we choose the `InverseButlerVolmer` submodel for the interface, with the \"main\" lithium-ion reaction (and default lithium ion options). Because of how the current is implemented, we also need to separately specify the `CurrentForInverseButlerVolmer` submodel"
]
},
{
Expand All @@ -414,10 +414,14 @@
"source": [
"model.submodels[\n",
" \"negative interface\"\n",
"] = pybamm.interface.InverseButlerVolmer(model.param, \"Negative\", \"lithium-ion main\")\n",
"] = pybamm.interface.InverseButlerVolmer(\n",
" model.param, \"Negative\", \"lithium-ion main\", options=model.options\n",
")\n",
"model.submodels[\n",
" \"positive interface\"\n",
"] = pybamm.interface.InverseButlerVolmer(model.param, \"Positive\", \"lithium-ion main\")\n",
"] = pybamm.interface.InverseButlerVolmer(\n",
" model.param, \"Positive\", \"lithium-ion main\", options=model.options\n",
")\n",
"model.submodels[\n",
" \"negative interface current\"\n",
"] = pybamm.interface.CurrentForInverseButlerVolmer(\n",
Expand Down Expand Up @@ -540,23 +544,14 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
"display_name": "Python 2.7.17 64-bit",
"name": "python375jvsc74a57bd0fd69f43f58546b570e94fd7eba7b65e6bcc7a5bbc4eab0408017d18902915d69"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.5"
"version": ""
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
4 changes: 2 additions & 2 deletions examples/scripts/custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@
model.param, "Positive", "uniform profile"
)
model.submodels["negative interface"] = pybamm.interface.InverseButlerVolmer(
model.param, "Negative", "lithium-ion main"
model.param, "Negative", "lithium-ion main", options=model.options
)
model.submodels["positive interface"] = pybamm.interface.InverseButlerVolmer(
model.param, "Positive", "lithium-ion main"
model.param, "Positive", "lithium-ion main", options=model.options
)
model.submodels[
"negative interface current"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,15 @@ def get_coupled_variables(self, variables):
[self.domain.lower() + " particle size"],
)
T_k_xav = pybamm.PrimaryBroadcast(T_k_xav, [self.domain.lower() + " particle"],)
R = pybamm.PrimaryBroadcast(
R_spatial_variable, [self.domain.lower() + " particle"],
)

if self.domain == "Negative":
N_s_xav_distribution = -self.param.D_n(
c_s_xav_distribution, T_k_xav
) * pybamm.grad(c_s_xav_distribution) / R
) * pybamm.grad(c_s_xav_distribution)
elif self.domain == "Positive":
N_s_xav_distribution = -self.param.D_p(
c_s_xav_distribution, T_k_xav
) * pybamm.grad(c_s_xav_distribution) / R
) * pybamm.grad(c_s_xav_distribution)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to make the definition of the nondimensional flux consistent with FickianManyParticles (where you can have a size distribution in x), and also the scaling used for the MP-DFN in our recent JES paper. The rhs is unchanged, as the factor of / R is just moved to lines 166 and 172, turning an / R into / R ** 2. Should make it easier to combine the "distribution" and "no distribution" submodels later on.

Meant to make this change much earlier, but seems I forgot. Sorry for the confusion here!


# Standard R-averaged flux variables. Average using the area-weighted
# distribution
Expand Down Expand Up @@ -166,13 +163,13 @@ def set_rhs(self, variables):
self.rhs = {
c_s_xav_distribution: -(1 / self.param.C_n)
* pybamm.div(N_s_xav_distribution)
/ R
/ R ** 2
}
elif self.domain == "Positive":
self.rhs = {
c_s_xav_distribution: -(1 / self.param.C_p)
* pybamm.div(N_s_xav_distribution)
/ R
/ R ** 2
}

def set_boundary_conditions(self, variables):
Expand Down
8 changes: 2 additions & 6 deletions pybamm/parameters/size_distribution_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def get_size_distribution_parameters(
param,
R_n_av=None,
R_p_av=None,
sd_n=None,
sd_p=None,
sd_n=0.3,
sd_p=0.3,
R_min_n=None,
R_min_p=None,
R_max_n=None,
Expand Down Expand Up @@ -64,10 +64,6 @@ def get_size_distribution_parameters(
R_n_av = R_n_av or R_n_typ
R_p_av = R_p_av or R_p_typ

# Standard deviations (scaled by the mean radius)
sd_n = sd_n or 0.3
sd_p = sd_p or 0.3

# Minimum radii
R_min_n = R_min_n or np.max([0, 1 - sd_n * 5])
R_min_p = R_min_p or np.max([0, 1 - sd_p * 5])
Expand Down
11 changes: 7 additions & 4 deletions tests/integration/test_models/standard_output_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def test_concentration_increase_decrease(self):

t, x_n, x_p, r_n, r_p = self.t, self.x_n, self.x_p, self.r_n, self.r_p

tol = 1e-16

if self.model.options["particle"] in ["quadratic profile", "quartic profile"]:
# For the assumed polynomial concentration profiles the values
# can increase/decrease within the particle as the polynomial shifts,
Expand Down Expand Up @@ -331,20 +333,21 @@ def test_concentration_increase_decrease(self):
self.c_s_p_dist(t[-1], r=r_p, R=R_p) -
self.c_s_p_dist(t[0], r=r_p, R=R_p)
)
tol = 1e-15
else:
neg_diff = self.c_s_n(t[1:], x_n, r_n) - self.c_s_n(t[:-1], x_n, r_n)
pos_diff = self.c_s_p(t[1:], x_p, r_p) - self.c_s_p(t[:-1], x_p, r_p)
neg_end_vs_start = self.c_s_n(t[-1], x_n, r_n) - self.c_s_n(t[0], x_n, r_n)
pos_end_vs_start = self.c_s_p(t[-1], x_p, r_p) - self.c_s_p(t[0], x_p, r_p)

if self.operating_condition == "discharge":
np.testing.assert_array_less(neg_diff, 1e-16)
np.testing.assert_array_less(-1e-16, pos_diff)
np.testing.assert_array_less(neg_diff, tol)
np.testing.assert_array_less(-tol, pos_diff)
np.testing.assert_array_less(neg_end_vs_start, 0)
np.testing.assert_array_less(0, pos_end_vs_start)
elif self.operating_condition == "charge":
np.testing.assert_array_less(-1e-16, neg_diff)
np.testing.assert_array_less(pos_diff, 1e-16)
np.testing.assert_array_less(-tol, neg_diff)
np.testing.assert_array_less(pos_diff, tol)
np.testing.assert_array_less(0, neg_end_vs_start)
np.testing.assert_array_less(pos_end_vs_start, 0)
elif self.operating_condition == "off":
Expand Down