Skip to content

Commit

Permalink
#2418 fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 20, 2022
1 parent 8d8d658 commit ca8f3ad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 71 deletions.
4 changes: 4 additions & 0 deletions pybamm/expression_tree/variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def __init__(
scale=1,
reference=0,
):
if isinstance(scale, numbers.Number):
scale = pybamm.Scalar(scale)
if isinstance(reference, numbers.Number):
reference = pybamm.Scalar(reference)
self._scale = scale
self._reference = reference
super().__init__(
Expand Down
32 changes: 17 additions & 15 deletions pybamm/models/full_battery_models/lead_acid/basic_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,16 @@ def __init__(self, name="Basic full model"):
j0_p = param.p.prim.j0(c_e_p, T)
j_p = 2 * j0_p * pybamm.sinh(param.p.prim.ne / 2 * (Feta_RT_p))

a_j_n = param.n.a * j_n
a_j_p = param.p.a * j_p
a_n = pybamm.Parameter("Negative electrode surface area to volume ratio [m-1]")
a_p = pybamm.Parameter("Positive electrode surface area to volume ratio [m-1]")
a_j_n = a_n * j_n
a_j_p = a_p * j_p
a_j = pybamm.concatenation(a_j_n, j_s, a_j_p)

######################
# State of Charge
######################
I = param.dimensional_current_with_time
I = param.current_with_time
# The `rhs` dictionary contains differential equations, with the key being the
# variable in the d/dt
self.rhs[Q] = I / 3600
Expand All @@ -137,19 +139,19 @@ def __init__(self, name="Basic full model"):
######################
v_n = -pybamm.grad(pressure_n)
v_p = -pybamm.grad(pressure_p)
l_s = param.s.l
l_n = param.n.l
L_s = param.s.L
L_n = param.n.L
x_s = pybamm.SpatialVariable("x_s", domain="separator")

# Difference in negative and positive electrode velocities determines the
# velocity in the separator
v_n_right = param.n.beta * i_cell
v_p_left = param.p.beta * i_cell
d_v_s__dx = (v_p_left - v_n_right) / l_s
v_n_right = param.n.DeltaV * i_cell
v_p_left = param.p.DeltaV * i_cell
d_v_s__dx = (v_p_left - v_n_right) / L_s

# Simple formula for velocity in the separator
div_V_s = -d_v_s__dx
v_s = d_v_s__dx * (x_s - l_n) + v_n_right
v_s = d_v_s__dx * (x_s - L_n) + v_n_right

# v is the velocity in the x-direction
# div_V is the divergence of the velocity in the yz-directions
Expand All @@ -160,8 +162,8 @@ def __init__(self, name="Basic full model"):
pybamm.PrimaryBroadcast(0, "positive electrode"),
)
# Simple formula for velocity in the separator
self.algebraic[pressure_n] = pybamm.div(v_n) - param.n.beta * a_j_n
self.algebraic[pressure_p] = pybamm.div(v_p) - param.p.beta * a_j_p
self.algebraic[pressure_n] = pybamm.div(v_n) - param.n.DeltaV * a_j_n
self.algebraic[pressure_p] = pybamm.div(v_p) - param.p.DeltaV * a_j_p
self.boundary_conditions[pressure_n] = {
"left": (pybamm.Scalar(0), "Neumann"),
"right": (pybamm.Scalar(0), "Dirichlet"),
Expand Down Expand Up @@ -213,12 +215,12 @@ def __init__(self, name="Basic full model"):
######################
# Porosity
######################
Delta_V = pybamm.concatenation(
pybamm.PrimaryBroadcast(param.n.Delta_V, "negative electrode"),
DeltaVsurf = pybamm.concatenation(
pybamm.PrimaryBroadcast(param.n.DeltaVsurf, "negative electrode"),
pybamm.PrimaryBroadcast(0, "separator"),
pybamm.PrimaryBroadcast(param.p.Delta_V, "positive electrode"),
pybamm.PrimaryBroadcast(param.p.DeltaVsurf, "positive electrode"),
)
deps_dt = -Delta_V * a_j / param.F
deps_dt = -DeltaVsurf * a_j / param.F
self.rhs[eps] = deps_dt
self.initial_conditions[eps] = param.epsilon_init
self.events.extend(
Expand Down
89 changes: 36 additions & 53 deletions pybamm/models/submodels/particle/base_particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,24 @@ def _get_distribution_variables(self, R):
domain, Domain = self.domain_Domain
phase_name = self.phase_name

R_typ = self.phase_param.R_typ
R_typ = self.phase_param.R_typ # [m]
# Particle-size distribution (area-weighted)
f_a_dist = self.phase_param.f_a_dist(R)
f_a_dist = self.phase_param.f_a_dist(R) # [m-1]

# Ensure the distribution is normalised, irrespective of discretisation
# or user input
f_a_dist = f_a_dist / pybamm.Integral(f_a_dist, R)
f_a_dist = f_a_dist / pybamm.Integral(f_a_dist, R) # [m-1]

# Volume-weighted particle-size distribution
f_v_dist = R * f_a_dist / pybamm.Integral(R * f_a_dist, R)
f_v_dist = R * f_a_dist / pybamm.Integral(R * f_a_dist, R) # [m-1]

# Number-based particle-size distribution
f_num_dist = (f_a_dist / R**2) / pybamm.Integral(f_a_dist / R**2, R)
f_num_dist = (f_a_dist / R**2) / pybamm.Integral(
f_a_dist / R**2, R
) # [m-1]

# True mean radii and standard deviations, calculated from the f_a_dist that
# was given
# was given, all have units [m]
R_num_mean = pybamm.Integral(R * f_num_dist, R)
R_a_mean = pybamm.Integral(R * f_a_dist, R)
R_v_mean = pybamm.Integral(R * f_v_dist, R)
Expand Down Expand Up @@ -233,50 +235,30 @@ def _get_distribution_variables(self, R):
)

variables = {
f"{Domain} {phase_name}particle sizes": R,
f"{Domain} {phase_name}particle sizes [m]": R * R_typ,
f"{Domain} area-weighted {phase_name}particle-size distribution": f_a_dist,
f"{Domain} {phase_name}particle sizes": R / R_typ,
f"{Domain} {phase_name}particle sizes [m]": R,
f"{Domain} area-weighted {phase_name}particle-size"
" distribution [m-1]": f_a_dist / R_typ,
" distribution [m-1]": f_a_dist,
f"{Domain} volume-weighted {phase_name}particle-size"
" distribution": f_v_dist,
f"{Domain} volume-weighted {phase_name}particle-size"
" distribution [m-1]": f_v_dist / R_typ,
f"{Domain} number-based {phase_name}particle-size"
" distribution": f_num_dist,
" distribution [m-1]": f_v_dist,
f"{Domain} number-based {phase_name}particle-size"
" distribution [m-1]": f_num_dist / R_typ,
f"{Domain} area-weighted mean particle radius": R_a_mean,
f"{Domain} area-weighted mean particle radius [m]": R_a_mean * R_typ,
f"{Domain} volume-weighted mean particle radius": R_v_mean,
f"{Domain} volume-weighted mean particle radius [m]": R_v_mean * R_typ,
f"{Domain} number-based mean particle radius": R_num_mean,
f"{Domain} number-based mean particle radius [m]": R_num_mean * R_typ,
" distribution [m-1]": f_num_dist,
f"{Domain} area-weighted mean particle radius [m]": R_a_mean,
f"{Domain} volume-weighted mean particle radius [m]": R_v_mean,
f"{Domain} number-based mean particle radius [m]": R_num_mean,
f"{Domain} area-weighted {phase_name}particle-size"
" standard deviation": sd_a,
f"{Domain} area-weighted {phase_name}particle-size"
" standard deviation [m]": sd_a * R_typ,
f"{Domain} volume-weighted {phase_name}particle-size"
" standard deviation": sd_v,
" standard deviation [m]": sd_a,
f"{Domain} volume-weighted {phase_name}particle-size"
" standard deviation [m]": sd_v * R_typ,
" standard deviation [m]": sd_v,
f"{Domain} number-based {phase_name}particle-size"
" standard deviation": sd_num,
f"{Domain} number-based {phase_name}particle-size"
" standard deviation [m]": sd_num * R_typ,
" standard deviation [m]": sd_num,
# X-averaged distributions
f"X-averaged {domain} area-weighted {phase_name}particle-size "
"distribution": f_a_dist_xav,
f"X-averaged {domain} area-weighted {phase_name}particle-size "
"distribution [m-1]": f_a_dist_xav / R_typ,
"distribution [m-1]": f_a_dist_xav,
f"X-averaged {domain} volume-weighted {phase_name}particle-size "
"distribution": f_v_dist_xav,
f"X-averaged {domain} volume-weighted {phase_name}particle-size "
"distribution [m-1]": f_v_dist_xav / R_typ,
f"X-averaged {domain} number-based {phase_name}particle-size "
"distribution": f_num_dist_xav,
"distribution [m-1]": f_v_dist_xav,
f"X-averaged {domain} number-based {phase_name}particle-size "
"distribution [m-1]": f_num_dist_xav / R_typ,
"distribution [m-1]": f_num_dist_xav,
}

return variables
Expand Down Expand Up @@ -364,27 +346,27 @@ def _get_standard_concentration_distribution_variables(self, c_s):

variables = {
f"Average {domain} {phase_name}particle concentration "
"distribution": c_s_av_distribution,
"distribution": c_s_av_distribution / c_scale,
f"{Domain} {phase_name}particle concentration "
"distribution": c_s_distribution,
"distribution": c_s_distribution / c_scale,
f"{Domain} {phase_name}particle concentration distribution "
"[mol.m-3]": c_scale * c_s_distribution,
"[mol.m-3]": c_s_distribution,
f"R-averaged {domain} {phase_name}particle concentration "
"distribution": c_s_rav_distribution,
"distribution": c_s_rav_distribution / c_scale,
f"R-averaged {domain} {phase_name}particle concentration distribution "
"[mol.m-3]": c_scale * c_s_rav_distribution,
"[mol.m-3]": c_s_rav_distribution,
f"X-averaged {domain} {phase_name}particle concentration "
"distribution": c_s_xav_distribution,
"distribution": c_s_xav_distribution / c_scale,
f"X-averaged {domain} {phase_name}particle concentration distribution "
"[mol.m-3]": c_scale * c_s_xav_distribution,
"[mol.m-3]": c_s_xav_distribution,
f"X-averaged {domain} {phase_name}particle surface concentration"
" distribution": c_s_surf_xav_distribution,
" distribution": c_s_surf_xav_distribution / c_scale,
f"X-averaged {domain} {phase_name}particle surface concentration "
"distribution [mol.m-3]": c_scale * c_s_surf_xav_distribution,
"distribution [mol.m-3]": c_s_surf_xav_distribution,
f"{Domain} {phase_name}particle surface concentration"
" distribution": c_s_surf_distribution,
" distribution": c_s_surf_distribution / c_scale,
f"{Domain} {phase_name}particle surface concentration"
" distribution [mol.m-3]": c_scale * c_s_surf_distribution,
" distribution [mol.m-3]": c_s_surf_distribution,
}
return variables

Expand Down Expand Up @@ -416,8 +398,9 @@ def _get_standard_flux_distribution_variables(self, N_s):

variables = {
f"X-averaged {domain} {phase_name}particle flux "
"distribution": N_s_xav_distribution,
f"{Domain} {phase_name}particle flux distribution": N_s_distribution,
"distribution [mol.m-2.s-1]": N_s_xav_distribution,
f"{Domain} {phase_name}particle flux "
"distribution [mol.m-2.s-1]": N_s_distribution,
}

return variables
Expand Down
7 changes: 4 additions & 3 deletions pybamm/models/submodels/particle/fickian_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ def get_fundamental_variables(self):
)
variables = self._get_distribution_variables(R)
f_v_dist = variables[
f"{Domain} volume-weighted particle-size distribution [m]"
f"{Domain} volume-weighted {phase_name}"
"particle-size distribution [m-1]"
]
else:
c_s_distribution = pybamm.Variable(
Expand All @@ -105,8 +106,8 @@ def get_fundamental_variables(self):
)
variables = self._get_distribution_variables(R)
f_v_dist = variables[
f"X-averaged {domain} volume-weighted "
"particle-size distribution [m]"
f"X-averaged {domain} volume-weighted {phase_name}"
"particle-size distribution [m-1]"
]

# Standard concentration distribution variables (size-dependent)
Expand Down

0 comments on commit ca8f3ad

Please sign in to comment.