-
-
Notifications
You must be signed in to change notification settings - Fork 606
/
Copy pathfast_many_particles.py
84 lines (65 loc) · 2.72 KB
/
fast_many_particles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#
# Class for many particles, each with uniform concentration (i.e. infinitely
# fast diffusion in r)
#
import pybamm
from .base_fast_particle import BaseModel
class ManyParticles(BaseModel):
"""Base class for molar conservation in many particles with
uniform concentration in r (i.e. infinitely fast diffusion within particles).
Parameters
----------
param : parameter class
The parameters to use for this submodel
domain : str
The domain of the model either 'Negative' or 'Positive'
**Extends:** :class:`pybamm.particle.fast.BaseModel`
"""
def __init__(self, param, domain):
super().__init__(param, domain)
def get_fundamental_variables(self):
# The particle concentration is uniform throughout the particle, so we
# can just use the surface value.
if self.domain == "Negative":
c_s_surf = pybamm.standard_variables.c_s_n_surf
c_s = pybamm.PrimaryBroadcast(c_s_surf, ["negative particle"])
c_s_xav = pybamm.x_average(c_s)
N_s = pybamm.FullBroadcast(
0,
["negative particle"],
auxiliary_domains={
"secondary": "negative electrode",
"tertiary": "current collector",
},
)
N_s_xav = pybamm.x_average(N_s)
elif self.domain == "Positive":
c_s_surf = pybamm.standard_variables.c_s_p_surf
c_s = pybamm.PrimaryBroadcast(c_s_surf, ["positive particle"])
c_s_xav = pybamm.x_average(c_s)
N_s = pybamm.FullBroadcast(
0,
["positive particle"],
auxiliary_domains={
"secondary": "positive electrode",
"tertiary": "current collector",
},
)
N_s_xav = pybamm.x_average(N_s)
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):
c_s_surf = variables[self.domain + " particle surface concentration"]
N_s = variables[self.domain + " particle flux"]
j = variables[self.domain + " electrode interfacial current density"]
return c_s_surf, N_s, j
def set_initial_conditions(self, variables):
c, _, _ = self._unpack(variables)
if self.domain == "Negative":
x_n = pybamm.standard_spatial_vars.x_n
c_init = self.param.c_n_init(x_n)
elif self.domain == "Positive":
x_p = pybamm.standard_spatial_vars.x_p
c_init = self.param.c_p_init(x_p)
self.initial_conditions = {c: c_init}