Skip to content

Commit

Permalink
#609 reformat particle models
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Mar 14, 2020
1 parent f8053e5 commit 6604a49
Show file tree
Hide file tree
Showing 29 changed files with 97 additions and 149 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions docs/source/models/submodels/particle/fast/index.rst

This file was deleted.

5 changes: 5 additions & 0 deletions docs/source/models/submodels/particle/fast_many_particles.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fast Many Particles
===================

.. autoclass:: pybamm.particle.FastManyParticles
:members:
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fast Single Particle
====================

.. autoclass:: pybamm.particle.FastSingleParticle
:members:

This file was deleted.

This file was deleted.

8 changes: 0 additions & 8 deletions docs/source/models/submodels/particle/fickian/index.rst

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fickian Many Particles
======================

.. autoclass:: pybamm.particle.FickianManyParticles
:members:


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Fickian Single Particle
=======================

.. autoclass:: pybamm.particle.FickianSingleParticle
:members:

6 changes: 4 additions & 2 deletions docs/source/models/submodels/particle/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ Particle
:maxdepth: 1

base_particle
fickian/index
fast/index
fickian_single_particle
fickian_many_particles
fast_single_particle
fast_many_particles
6 changes: 3 additions & 3 deletions examples/notebooks/using-submodels.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"metadata": {},
"outputs": [],
"source": [
"model.submodels[\"negative particle\"] = pybamm.particle.fast.SingleParticle(model.param, \"Negative\")"
"model.submodels[\"negative particle\"] = pybamm.particle.FastSingleParticle(model.param, \"Negative\")"
]
},
{
Expand Down Expand Up @@ -370,10 +370,10 @@
"metadata": {},
"outputs": [],
"source": [
"model.submodels[\"negative particle\"] = pybamm.particle.fast.SingleParticle(\n",
"model.submodels[\"negative particle\"] = pybamm.particle.FastSingleParticle(\n",
" model.param, \"Negative\"\n",
")\n",
"model.submodels[\"positive particle\"] = pybamm.particle.fast.SingleParticle(\n",
"model.submodels[\"positive particle\"] = pybamm.particle.FastSingleParticle(\n",
" model.param, \"Positive\"\n",
")"
]
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/custom_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
model.submodels["positive electrode"] = pybamm.electrode.ohm.LeadingOrder(
model.param, "Positive"
)
model.submodels["negative particle"] = pybamm.particle.fast.SingleParticle(
model.submodels["negative particle"] = pybamm.particle.FastSingleParticle(
model.param, "Negative"
)
model.submodels["positive particle"] = pybamm.particle.fast.SingleParticle(
model.submodels["positive particle"] = pybamm.particle.FastSingleParticle(
model.param, "Positive"
)
model.submodels["negative interface"] = pybamm.interface.InverseButlerVolmer(
Expand Down
8 changes: 4 additions & 4 deletions pybamm/models/full_battery_models/lithium_ion/dfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ def set_interfacial_submodel(self):
def set_particle_submodel(self):

if self.options["particle"] == "Fickian diffusion":
self.submodels["negative particle"] = pybamm.particle.fickian.ManyParticles(
self.submodels["negative particle"] = pybamm.particle.FickianManyParticles(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.fickian.ManyParticles(
self.submodels["positive particle"] = pybamm.particle.FickianManyParticles(
self.param, "Positive"
)
elif self.options["particle"] == "fast diffusion":
self.submodels["negative particle"] = pybamm.particle.fast.ManyParticles(
self.submodels["negative particle"] = pybamm.particle.FastManyParticles(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.fast.ManyParticles(
self.submodels["positive particle"] = pybamm.particle.FastManyParticles(
self.param, "Positive"
)

Expand Down
16 changes: 8 additions & 8 deletions pybamm/models/full_battery_models/lithium_ion/spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ def set_interfacial_submodel(self):
def set_particle_submodel(self):

if self.options["particle"] == "Fickian diffusion":
self.submodels[
"negative particle"
] = pybamm.particle.fickian.SingleParticle(self.param, "Negative")
self.submodels[
"positive particle"
] = pybamm.particle.fickian.SingleParticle(self.param, "Positive")
self.submodels["negative particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Positive"
)
elif self.options["particle"] == "fast diffusion":
self.submodels["negative particle"] = pybamm.particle.fast.SingleParticle(
self.submodels["negative particle"] = pybamm.particle.FastSingleParticle(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.fast.SingleParticle(
self.submodels["positive particle"] = pybamm.particle.FastSingleParticle(
self.param, "Positive"
)

Expand Down
16 changes: 8 additions & 8 deletions pybamm/models/full_battery_models/lithium_ion/spme.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,17 @@ def set_interfacial_submodel(self):
def set_particle_submodel(self):

if self.options["particle"] == "Fickian diffusion":
self.submodels[
"negative particle"
] = pybamm.particle.fickian.SingleParticle(self.param, "Negative")
self.submodels[
"positive particle"
] = pybamm.particle.fickian.SingleParticle(self.param, "Positive")
self.submodels["negative particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.FickianSingleParticle(
self.param, "Positive"
)
elif self.options["particle"] == "fast diffusion":
self.submodels["negative particle"] = pybamm.particle.fast.SingleParticle(
self.submodels["negative particle"] = pybamm.particle.FastSingleParticle(
self.param, "Negative"
)
self.submodels["positive particle"] = pybamm.particle.fast.SingleParticle(
self.submodels["positive particle"] = pybamm.particle.FastSingleParticle(
self.param, "Positive"
)

Expand Down
6 changes: 4 additions & 2 deletions pybamm/models/submodels/particle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .base_particle import BaseParticle
from . import fickian
from . import fast
from .fickian_many_particles import FickianManyParticles
from .fickian_single_particle import FickianSingleParticle
from .fast_many_particles import FastManyParticles
from .fast_single_particle import FastSingleParticle
3 changes: 0 additions & 3 deletions pybamm/models/submodels/particle/fast/__init__.py

This file was deleted.

37 changes: 0 additions & 37 deletions pybamm/models/submodels/particle/fast/base_fast_particle.py

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
import pybamm

from .base_fast_particle import BaseModel
from .base_particle import BaseParticle


class ManyParticles(BaseModel):
class FastManyParticles(BaseParticle):
"""Base class for molar conservation in many particles with
uniform concentration in r (i.e. infinitely fast diffusion within particles).
Expand All @@ -19,7 +19,7 @@ class ManyParticles(BaseModel):
The domain of the model either 'Negative' or 'Positive'
**Extends:** :class:`pybamm.particle.fast.BaseModel`
**Extends:** :class:`pybamm.particle.BaseParticle`
"""

def __init__(self, param, domain):
Expand Down Expand Up @@ -63,16 +63,17 @@ def get_fundamental_variables(self):

return variables

def _unpack(self, variables):
def set_rhs(self, variables):
c_s_surf = variables[self.domain + " particle surface concentration"]
N_s = variables[self.domain + " particle flux"]
j = variables[self.domain + " electrode interfacial current density"]
if self.domain == "Negative":
self.rhs = {c_s_surf: -3 * j / self.param.a_n}

return c_s_surf, N_s, j
elif self.domain == "Positive":
self.rhs = {c_s_surf: -3 * j / self.param.a_p / self.param.gamma_p}

def set_initial_conditions(self, variables):
c, _, _ = self._unpack(variables)

c_s_surf = variables[self.domain + " particle surface concentration"]
if self.domain == "Negative":
x_n = pybamm.standard_spatial_vars.x_n
c_init = self.param.c_n_init(x_n)
Expand All @@ -81,4 +82,4 @@ def set_initial_conditions(self, variables):
x_p = pybamm.standard_spatial_vars.x_p
c_init = self.param.c_p_init(x_p)

self.initial_conditions = {c: c_init}
self.initial_conditions = {c_s_surf: c_init}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
#
import pybamm

from .base_fast_particle import BaseModel
from .base_particle import BaseParticle


class SingleParticle(BaseModel):
class FastSingleParticle(BaseParticle):
"""Base class for molar conservation in a single x-averaged particle with
uniform concentration in r (i.e. infinitely fast diffusion within particles).
Expand All @@ -19,7 +19,7 @@ class SingleParticle(BaseModel):
The domain of the model either 'Negative' or 'Positive'
**Extends:** :class:`pybamm.particle.fast.BaseModel`
**Extends:** :class:`pybamm.particle.BaseParticle`
"""

def __init__(self, param, domain):
Expand All @@ -35,61 +35,67 @@ def get_fundamental_variables(self):
c_s_xav = pybamm.PrimaryBroadcast(c_s_surf_xav, ["negative particle"])
c_s = pybamm.SecondaryBroadcast(c_s_xav, ["negative electrode"])

N_s = pybamm.FullBroadcast(
N_s = pybamm.FullBroadcastToEdges(
0,
["negative particle"],
auxiliary_domains={
"secondary": "negative electrode",
"tertiary": "current collector",
},
)
N_s_xav = pybamm.x_average(N_s)
N_s_xav = pybamm.FullBroadcast(0, "negative electrode", "current collector")

elif self.domain == "Positive":
c_s_surf_xav = pybamm.standard_variables.c_s_p_surf_xav
c_s_xav = pybamm.PrimaryBroadcast(c_s_surf_xav, ["positive particle"])
c_s = pybamm.SecondaryBroadcast(c_s_xav, ["positive electrode"])

N_s = pybamm.FullBroadcast(
N_s = pybamm.FullBroadcastToEdges(
0,
["positive particle"],
auxiliary_domains={
"secondary": "positive electrode",
"tertiary": "current collector",
},
)
N_s_xav = pybamm.x_average(N_s)
N_s_xav = pybamm.FullBroadcast(0, "positive electrode", "current collector")

variables = self._get_standard_concentration_variables(c_s, c_s_xav)
variables.update(self._get_standard_flux_variables(N_s, N_s_xav))

return variables

def _unpack(self, variables):
def set_rhs(self, variables):

c_s_surf_xav = variables[
"X-averaged " + self.domain.lower() + " particle surface concentration"
]
N_s_xav = variables["X-averaged " + self.domain.lower() + " particle flux"]
j_av = variables[
j_xav = variables[
"X-averaged "
+ self.domain.lower()
+ " electrode interfacial current density"
]

return c_s_surf_xav, N_s_xav, j_av
if self.domain == "Negative":
self.rhs = {c_s_surf_xav: -3 * j_xav / self.param.a_n}

elif self.domain == "Positive":
self.rhs = {c_s_surf_xav: -3 * j_xav / self.param.a_p / self.param.gamma_p}

def set_initial_conditions(self, variables):
"""
For single particle models, initial conditions can't depend on x so we
arbitrarily evaluate them at x=0 in the negative electrode and x=1 in the
positive electrode (they will usually be constant)
"""
c, _, _ = self._unpack(variables)
c_s_surf_xav = variables[
"X-averaged " + self.domain.lower() + " particle surface concentration"
]

if self.domain == "Negative":
c_init = self.param.c_n_init(0)

elif self.domain == "Positive":
c_init = self.param.c_p_init(1)

self.initial_conditions = {c: c_init}
self.initial_conditions = {c_s_surf_xav: c_init}
Loading

0 comments on commit 6604a49

Please sign in to comment.