Skip to content

Commit

Permalink
#2418 DFN builds but can't solve
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Nov 1, 2022
1 parent 3b18847 commit 3c261c9
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 736 deletions.
4 changes: 2 additions & 2 deletions examples/scripts/compare_lithium_ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

# load models
models = [
pybamm.lithium_ion.SPM(),
# pybamm.lithium_ion.SPM(),
# pybamm.lithium_ion.SPMe(),
# pybamm.lithium_ion.DFN(),
pybamm.lithium_ion.DFN(),
# pybamm.lithium_ion.NewmanTobias(),
]

Expand Down
19 changes: 11 additions & 8 deletions pybamm/models/standard_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ def __init__(self):

# Electrode potential
self.phi_s_n = pybamm.Variable(
"Negative electrode potential",
"Negative electrode potential [V]",
domain="negative electrode",
auxiliary_domains={"secondary": "current collector"},
)
self.phi_s_p = pybamm.Variable(
"Positive electrode potential",
"Positive electrode potential [V]",
domain="positive electrode",
auxiliary_domains={"secondary": "current collector"},
)
Expand Down Expand Up @@ -49,22 +49,25 @@ def __init__(self):

# current collector variables
self.phi_s_cn = pybamm.Variable(
"Negative current collector potential", domain="current collector"
"Negative current collector potential [V]", domain="current collector"
)
self.phi_s_cp = pybamm.Variable(
"Positive current collector potential", domain="current collector"
"Positive current collector potential [V]", domain="current collector"
)
self.i_boundary_cc = pybamm.Variable(
"Current collector current density", domain="current collector"
"Current collector current density [A.m-2]", domain="current collector"
)
self.phi_s_cn_composite = pybamm.Variable(
"Composite negative current collector potential", domain="current collector"
"Composite negative current collector potential [V]",
domain="current collector",
)
self.phi_s_cp_composite = pybamm.Variable(
"Composite positive current collector potential", domain="current collector"
"Composite positive current collector potential [V]",
domain="current collector",
)
self.i_boundary_cc_composite = pybamm.Variable(
"Composite current collector current density", domain="current collector"
"Composite current collector current density [A.m-2]",
domain="current collector",
)

def __setattr__(self, name, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ def _get_standard_active_material_variables(self, eps_solid):
# some models (e.g. lead-acid) do not have particles
if self.options["particle shape"] == "no particles":
a = self.phase_param.a
a_typ = self.phase_param.a_typ
variables.update(
{
f"{Domain} electrode surface area to volume ratio [m-1]": a,
f"{Domain} electrode surface area to volume ratio [m-1]": a * a_typ,
f"X-averaged {domain} electrode surface area "
"to volume ratio": pybamm.x_average(a),
f"X-averaged {domain} electrode surface area "
"to volume ratio [m-1]": pybamm.x_average(a) * a_typ,
"to volume ratio [m-1]": pybamm.x_average(a),
}
)
return variables
Expand Down Expand Up @@ -101,6 +97,7 @@ def _get_standard_active_material_variables(self, eps_solid):

variables.update(
{
f"{Domain} {phase_name}particle radius": R / self.phase_param.R_typ,
f"{Domain} {phase_name}particle radius [m]": R,
f"{Domain} electrode {phase_name}"
"surface area to volume ratio [m-1]": a,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,8 @@ def _get_standard_current_variables(self, i_cc, i_boundary_cc):
The variables which can be derived from the current in the current
collector.
"""
i_typ = self.param.i_typ

# TO DO: implement grad in 2D to get i_cc
# just need this to get 1D models working for now
variables = {
"Current collector current density": i_boundary_cc,
"Current collector current density [A.m-2]": i_typ * i_boundary_cc,
}
variables = {"Current collector current density [A.m-2]": i_boundary_cc}

return variables
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def get_coupled_variables(self, variables):
# using current structure of lithium-ion models
variables[
"Leading-order current collector current density [A.m-2]"
] = variables["Current collector current density"]
] = variables["Current collector current density [A.m-2]"]

return variables
3 changes: 2 additions & 1 deletion pybamm/models/submodels/electrode/ohm/full_ohm.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def set_algebraic(self, variables):

# Variable summing all of the interfacial current densities
sum_a_j = variables[
f"Sum of {domain} electrode volumetric interfacial current densities"
f"Sum of {domain} electrode volumetric "
"interfacial current densities [A.m-3]"
]

self.algebraic[phi_s] = pybamm.div(i_s) + sum_a_j
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def get_fundamental_variables(self):
phi_e_dict = {}
for domain in self.options.whole_cell_domains:
phi_e_k = pybamm.Variable(
f"{domain.capitalize().split()[0]} electrolyte potential",
f"{domain.capitalize().split()[0]} electrolyte potential [V]",
domain=domain,
auxiliary_domains={"secondary": "current collector"},
)
Expand Down Expand Up @@ -62,7 +62,7 @@ def set_algebraic(self, variables):
i_e = variables["Electrolyte current density [A.m-2]"]

# Variable summing all of the interfacial current densities
sum_a_j = variables["Sum of volumetric interfacial current densities"]
sum_a_j = variables["Sum of volumetric interfacial current densities [A.m-3]"]

# Override print_name
sum_a_j.print_name = "aj"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def _get_standard_concentration_variables(self, c_e_dict):

def _get_standard_porosity_times_concentration_variables(self, eps_c_e_dict):
eps_c_e = pybamm.concatenation(*eps_c_e_dict.values())
variables = {"Porosity times concentration": eps_c_e}
variables = {"Porosity times concentration [mol.m-3]": eps_c_e}

for domain, eps_c_e_k in eps_c_e_dict.items():
Domain = domain.capitalize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def get_fundamental_variables(self):
for domain in self.options.whole_cell_domains:
Domain = domain.capitalize().split()[0]
c_e_k = pybamm.Variable(
f"{Domain} electrolyte concentration",
f"{Domain} electrolyte concentration [mol.m-3]",
domain=domain,
auxiliary_domains={"secondary": "current collector"},
bounds=(0, np.inf),
Expand All @@ -58,8 +58,8 @@ def get_coupled_variables(self, variables):
param = self.param

N_e_diffusion = -tor_0 * param.D_e(c_e_0_av, T_0) * pybamm.grad(c_e)
N_e_migration = param.C_e * param.t_plus(c_e, T_0) * i_e / param.gamma_e
N_e_convection = param.C_e * c_e_0_av * v_box_0
N_e_migration = param.t_plus(c_e, T_0) * i_e / param.F
N_e_convection = c_e_0_av * v_box_0

N_e = N_e_diffusion + N_e_migration + N_e_convection

Expand All @@ -78,28 +78,27 @@ def set_rhs(self, variables):
c_e = variables["Electrolyte concentration [mol.m-3]"]
N_e = variables["Electrolyte flux"]
if self.extended is False:
sum_s_j = variables[
"Leading-order sum of electrolyte reaction source terms"
sum_s_a_j = variables[
"Leading-order sum of electrolyte reaction source terms [A.m-3]"
]
elif self.extended == "distributed":
sum_s_j = variables["Sum of electrolyte reaction source terms"]
sum_s_a_j = variables["Sum of electrolyte reaction source terms [A.m-3]"]
elif self.extended == "average":
sum_s_j_n_av = variables[
"Sum of x-averaged negative electrode electrolyte reaction source terms"
sum_s_a_j_n_av = variables[
"Sum of x-averaged negative electrode electrolyte reaction source terms [A.m-3]"
]
sum_s_j_p_av = variables[
"Sum of x-averaged positive electrode electrolyte reaction source terms"
sum_s_a_j_p_av = variables[
"Sum of x-averaged positive electrode electrolyte reaction source terms [A.m-3]"
]
sum_s_j = pybamm.concatenation(
pybamm.PrimaryBroadcast(sum_s_j_n_av, "negative electrode"),
sum_s_a_j = pybamm.concatenation(
pybamm.PrimaryBroadcast(sum_s_a_j_n_av, "negative electrode"),
pybamm.FullBroadcast(0, "separator", "current collector"),
pybamm.PrimaryBroadcast(sum_s_j_p_av, "positive electrode"),
pybamm.PrimaryBroadcast(sum_s_a_j_p_av, "positive electrode"),
)
source_terms = sum_s_j / self.param.gamma_e
source_terms = sum_s_a_j / param.F

self.rhs = {
c_e: (1 / eps_0)
* (-pybamm.div(N_e) / param.C_e + source_terms - c_e * deps_0_dt)
c_e: (1 / eps_0) * (-pybamm.div(N_e) + source_terms - c_e * deps_0_dt)
}

def set_initial_conditions(self, variables):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ def get_coupled_variables(self, variables):
]
sum_s_j_n_0 = variables[
"Leading-order sum of x-averaged "
"negative electrode electrolyte reaction source terms"
"negative electrode electrolyte reaction source terms [A.m-3]"
]
sum_s_j_p_0 = variables[
"Leading-order sum of x-averaged "
"positive electrode electrolyte reaction source terms"
"positive electrode electrolyte reaction source terms [A.m-3]"
]
rhs_n = (
d_epsc_n_0_dt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_fundamental_variables(self):
for domain in self.options.whole_cell_domains:
Domain = domain.capitalize()
eps_c_e_k = pybamm.Variable(
f"{Domain} porosity times concentration",
f"{Domain} porosity times concentration [mol.m-3]",
domain=domain,
auxiliary_domains={"secondary": "current collector"},
bounds=(0, np.inf),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ def set_rhs(self, variables):
"interfacial current densities"
]
sum_s_j_n_0 = variables[
"Sum of x-averaged negative electrode electrolyte reaction source terms"
"Sum of x-averaged negative electrode electrolyte reaction source terms [A.m-3]"
]
sum_s_j_p_0 = variables[
"Sum of x-averaged positive electrode electrolyte reaction source terms"
"Sum of x-averaged positive electrode electrolyte reaction source terms [A.m-3]"
]
source_terms = (
param.n.l * (sum_s_j_n_0 - param.t_plus(c_e_av, T_av) * sum_a_j_n_0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@ def __init__(self, param, options):
def get_fundamental_variables(self):
# Current is given as a function of time
i_cell = self.param.current_density_with_time
# i_cell_dim = self.param.dimensional_current_density_with_time
I = self.param.current_with_time

variables = {
"Current density variable": pybamm.Scalar(1, name="i_cell"),
"Total current density [A.m-2]": i_cell,
# "Total current density [A.m-2]": i_cell_dim,
"Current [A]": I,
"C-rate": I / self.param.Q,
}
Expand All @@ -42,18 +40,14 @@ def get_coupled_variables(self, variables):

# Current is given as applied power divided by voltage
V = variables["Terminal voltage [V]"]
P = pybamm.FunctionParameter(
"Power function [W]", {"Time [s]": pybamm.t * self.param.timescale}
)
P = pybamm.FunctionParameter("Power function [W]", {"Time [s]": pybamm.t})
I = P / V

# Update derived variables
i_cell = I / abs(param.I_typ)
i_cell_dim = I / (param.n_electrodes_parallel * param.A_cc)
i_cell = I / (param.n_electrodes_parallel * param.A_cc)

variables = {
"Total current density": i_cell,
"Total current density [A.m-2]": i_cell_dim,
"Total current density [A.m-2]": i_cell,
"Current [A]": I,
"C-rate": I / param.Q,
}
Expand All @@ -73,17 +67,15 @@ def get_coupled_variables(self, variables):
# Current is given as applied voltage divided by resistance
V = variables["Terminal voltage [V]"]
R = pybamm.FunctionParameter(
"Resistance function [Ohm]", {"Time [s]": pybamm.t * self.param.timescale}
"Resistance function [Ohm]", {"Time [s]": pybamm.t}
)
I = V / R

# Update derived variables
i_cell = I / abs(param.I_typ)
i_cell_dim = I / (param.n_electrodes_parallel * param.A_cc)
i_cell = I / (param.n_electrodes_parallel * param.A_cc)

variables = {
"Total current density": i_cell,
"Total current density [A.m-2]": i_cell_dim,
"Total current density [A.m-2]": i_cell,
"Current [A]": I,
"C-rate": I / param.Q,
}
Expand Down
10 changes: 4 additions & 6 deletions pybamm/models/submodels/interface/lithium_plating/plating.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,19 @@ def get_coupled_variables(self, variables):

eta_stripping = delta_phi + phi_ref + eta_sei
eta_plating = -eta_stripping
prefactor = 1 / (1 + self.param.Theta * T)
F_RT = param.F / (param.R * T)
# NEW: transfer coefficients can be set by the user
alpha_stripping = self.param.alpha_stripping
alpha_plating = self.param.alpha_plating

if self.options["lithium plating"] in ["reversible", "partially reversible"]:
j_stripping = j0_stripping * pybamm.exp(
prefactor * alpha_stripping * eta_stripping
) - j0_plating * pybamm.exp(prefactor * alpha_plating * eta_plating)
F_RT * alpha_stripping * eta_stripping
) - j0_plating * pybamm.exp(F_RT * alpha_plating * eta_plating)
elif self.options["lithium plating"] == "irreversible":
# j_stripping is always negative, because there is no stripping, only
# plating
j_stripping = -j0_plating * pybamm.exp(
prefactor * alpha_plating * eta_plating
)
j_stripping = -j0_plating * pybamm.exp(F_RT * alpha_plating * eta_plating)

variables.update(self._get_standard_overpotential_variables(eta_stripping))
variables.update(self._get_standard_reaction_variables(j_stripping))
Expand Down
6 changes: 3 additions & 3 deletions pybamm/models/submodels/interface/sei/sei_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ def get_coupled_variables(self, variables):
R_sei = phase_param.R_sei
eta_SEI = delta_phi - j * L_sei * R_sei
# Thermal prefactor for reaction, interstitial and EC models
prefactor = 1 / (1 + self.param.Theta * T)
F_RT = param.F / (param.R * T)

if self.options["SEI"] == "reaction limited":
C_sei = phase_param.C_sei_reaction
j_sei = -(1 / C_sei) * pybamm.exp(-0.5 * prefactor * eta_SEI)
j_sei = -(1 / C_sei) * pybamm.exp(-0.5 * F_RT * eta_SEI)

elif self.options["SEI"] == "electron-migration limited":
U_inner = phase_param.U_inner_electron
Expand All @@ -113,7 +113,7 @@ def get_coupled_variables(self, variables):

elif self.options["SEI"] == "interstitial-diffusion limited":
C_sei = phase_param.C_sei_inter
j_sei = -pybamm.exp(-prefactor * delta_phi) / (C_sei * L_sei_inner)
j_sei = -pybamm.exp(-F_RT * delta_phi) / (C_sei * L_sei_inner)

elif self.options["SEI"] == "solvent-diffusion limited":
C_sei = phase_param.C_sei_solvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,6 @@ def _get_whole_cell_coupled_variables(self, variables):
else:
var_dict[domain] = variables[variable_template.format(domain + " ")]
var = pybamm.concatenation(*var_dict.values())
variables.update({variable_template.format("").capitalize(): var})
variables.update({variable_template.format(""): var})

return variables
12 changes: 0 additions & 12 deletions pybamm/parameters/electrical_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ def __init__(self):
def _set_dimensional_parameters(self):
"""Defines the dimensional parameters."""

self.I_typ = pybamm.Parameter("Typical current [A]")
self.Q = pybamm.Parameter("Nominal cell capacity [A.h]")
self.C_rate = pybamm.AbsoluteValue(self.I_typ / self.Q)
self.n_electrodes_parallel = pybamm.Parameter(
"Number of electrodes connected in parallel to make a cell"
)
self.n_cells = pybamm.Parameter(
"Number of cells connected in series to make a battery"
)
self.i_typ = pybamm.Function(
np.abs, self.I_typ / (self.n_electrodes_parallel * self.geo.A_cc)
)
self.voltage_low_cut = pybamm.Parameter("Lower voltage cut-off [V]")
self.voltage_high_cut = pybamm.Parameter("Upper voltage cut-off [V]")

Expand All @@ -54,12 +49,5 @@ def _set_dimensional_parameters(self):
self.n_electrodes_parallel * self.geo.A_cc
)

# def _set_dimensionless_parameters(self):
# """Defines the dimensionless parameters."""

# self.current_with_time = (
# self.dimensional_current_with_time / self.I_typ * pybamm.sign(self.I_typ)
# )


electrical_parameters = ElectricalParameters()
Loading

0 comments on commit 3c261c9

Please sign in to comment.