Skip to content

Commit

Permalink
pybamm-team#3321 add h_egde(y,z)
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Aug 4, 2023
1 parent a41cbec commit 751b920
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 24 deletions.
24 changes: 20 additions & 4 deletions examples/scripts/pouch_cell_cooling.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

# load model
model = pybamm.lithium_ion.SPM(
{"current collector": "potential pair", "dimensionality": 2}, name="2+1D SPM"
{"current collector": "potential pair", "dimensionality": 2, "thermal": "x-lumped"}
)

# update parameter values, to use:
# 1) a spatially-varying ambient temperature
# 2) a spatially-varying surface heat transfer coefficient
# 3) a spatially-varying edge heat transfer coefficient
param = model.param
L_y = param.L_y
L_z = param.L_z
Expand All @@ -23,13 +25,27 @@ def T_amb(y, z, t):
return 300 + 20 * pybamm.sin(np.pi * y / L_y) * pybamm.sin(np.pi * z / L_z)


parameter_values.update({"Ambient temperature [K]": T_amb})
def h_edge(y, z):
return pybamm.InputParameter("h_right") * (y >= L_y)


parameter_values.update(
{
"Current function [A]": 2 * 0.680616,
"Ambient temperature [K]": 298,
"Negative current collector surface heat transfer coefficient [W.m-2.K-1]": 0,
"Positive current collector surface heat transfer coefficient [W.m-2.K-1]": 0,
"Negative tab heat transfer coefficient [W.m-2.K-1]": 10000,
"Positive tab heat transfer coefficient [W.m-2.K-1]": 0,
"Edge heat transfer coefficient [W.m-2.K-1]": h_edge,
}
)

# create and solve simulation
var_pts = {"x_n": 4, "x_s": 4, "x_p": 4, "r_n": 4, "r_p": 4, "y": 16, "z": 16}
sim = pybamm.Simulation(model, parameter_values=parameter_values, var_pts=var_pts)
sim.build()
sim.solve([0, 3600])
sim.solve([0, 600], inputs={"h_right": 5})

# plot
output_variables = [
Expand All @@ -38,4 +54,4 @@ def T_amb(y, z, t):
"X-averaged cell temperature [K]",
"Voltage [V]",
]
sim.plot(output_variables)
sim.plot(output_variables, variable_limits="tight", shading="gouraud")
41 changes: 41 additions & 0 deletions examples/scripts/pouch_cell_isothermal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Example showing how to customize thermal boundary conditions in a pouch cell model
#
import numpy as np
import pybamm

pybamm.set_logging_level("INFO")

# load model
model = pybamm.lithium_ion.SPM(
{"current collector": "potential pair", "dimensionality": 2}
)

# update parameter values, to use:
# 1) a spatially-varying ambient temperature
param = model.param
L_y = param.L_y
L_z = param.L_z
parameter_values = model.default_parameter_values


def T_amb(y, z, t):
return 300 + 20 * pybamm.sin(np.pi * y / L_y) * pybamm.sin(np.pi * z / L_z)


parameter_values.update({"Ambient temperature [K]": T_amb})

# create and solve simulation
var_pts = {"x_n": 4, "x_s": 4, "x_p": 4, "r_n": 4, "r_p": 4, "y": 16, "z": 16}
sim = pybamm.Simulation(model, parameter_values=parameter_values, var_pts=var_pts)
sim.build()
sim.solve([0, 3600])

# plot
output_variables = [
"Negative current collector potential [V]",
"Positive current collector potential [V]",
"X-averaged cell temperature [K]",
"Voltage [V]",
]
sim.plot(output_variables, variable_limits="tight", shading="gouraud")
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def set_rhs(self, variables):
y = pybamm.standard_spatial_vars.y
z = pybamm.standard_spatial_vars.z

# Account for surface area to volume ratio of pouch cell in cooling
# coefficient
# Account for surface area to volume ratio of pouch cell in surface cooling
# term
cell_volume = self.param.L * self.param.L_y * self.param.L_z

yz_surface_area = self.param.L_y * self.param.L_z
Expand All @@ -69,48 +69,59 @@ def set_rhs(self, variables):
/ cell_volume
)

edge_cooling_coefficient = -self.param.h_edge
# Edge cooling appears as a boundary term, so no need to account for surface
# area to volume ratio
edge_cooling_coefficient = -self.param.h_edge(y, z)

# Governing equations contain:
# - source term for y-z surface cooling
# - boundary source term of edge cooling
# Boundary conditions contain:
# - Neumann condition for tab cooling
# Note: pybamm.source() is used to ensure the source term is multiplied by the
# correct mass matrix when discretised. The first argument is the source term
# and the second argument is the variable governed by the equation that the
# source term appears in.
self.rhs = {
T_av: (
pybamm.laplacian(T_av)
+ pybamm.source(Q_av, T_av)
+ yz_surface_cooling_coefficient * pybamm.source(T_av - T_amb, T_av)
+ edge_cooling_coefficient
* pybamm.source(T_av - T_amb, T_av, boundary=True)
+ pybamm.source(yz_surface_cooling_coefficient * (T_av - T_amb), T_av)
+ pybamm.source(
edge_cooling_coefficient * (T_av - T_amb), T_av, boundary=True
)
)
/ self.param.rho_c_p_eff(T_av)
}

# TODO: Make h_edge a function of position to have bottom/top/side cooled cells.

def set_boundary_conditions(self, variables):
T_av = variables["X-averaged cell temperature [K]"]
T_amb = variables["Ambient temperature [K]"]
y = pybamm.standard_spatial_vars.y
z = pybamm.standard_spatial_vars.z

# Subtract the edge cooling from the tab portion so as to not double count
# Note: tab cooling is also only applied on the current collector hence
# the (l_cn / l) and (l_cp / l) prefactors.
# We also still have edge cooling on the region: x in (0, 1)
# the (l_cn / l) and (l_cp / l) prefactors. We also still have edge cooling
# in the region: x in (0, 1)
h_tab_n_corrected = (self.param.n.L_cc / self.param.L) * (
self.param.n.h_tab - self.param.h_edge
self.param.n.h_tab - self.param.h_edge(y, z)
)
h_tab_p_corrected = (self.param.p.L_cc / self.param.L) * (
self.param.p.h_tab - self.param.h_edge
self.param.p.h_tab - self.param.h_edge(y, z)
)

T_av_n = pybamm.boundary_value(T_av, "negative tab")
T_av_p = pybamm.boundary_value(T_av, "positive tab")
negative_tab_bc = pybamm.boundary_value(
-h_tab_n_corrected * (T_av - T_amb), "negative tab"
)
positive_tab_bc = pybamm.boundary_value(
-h_tab_p_corrected * (T_av - T_amb), "positive tab"
)

self.boundary_conditions = {
T_av: {
"negative tab": (-h_tab_n_corrected * (T_av_n - T_amb), "Neumann"),
"positive tab": (-h_tab_p_corrected * (T_av_p - T_amb), "Neumann"),
"negative tab": (negative_tab_bc, "Neumann"),
"positive tab": (positive_tab_bc, "Neumann"),
}
}

Expand Down
14 changes: 12 additions & 2 deletions pybamm/parameters/thermal_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,13 @@ def _set_parameters(self):
self.T_ref = pybamm.Parameter("Reference temperature [K]")

# Cooling coefficient
self.h_edge = pybamm.Parameter("Edge heat transfer coefficient [W.m-2.K-1]")
self.h_total = pybamm.Parameter("Total heat transfer coefficient [W.m-2.K-1]")

# Initial temperature
self.T_init = pybamm.Parameter("Initial temperature [K]")

def T_amb(self, y, z, t):
"""Dimensional ambient temperature"""
"""Ambient temperature [K]"""
return pybamm.FunctionParameter(
"Ambient temperature [K]",
{
Expand All @@ -52,6 +51,17 @@ def T_amb(self, y, z, t):
},
)

def h_edge(self, y, z):
"""Cell edge heat transfer coefficient [W.m-2.K-1]"""
inputs = {
"Distance along electrode width [m]": y,
"Distance along electrode height [m]": z,
}
return pybamm.FunctionParameter(
"Edge heat transfer coefficient [W.m-2.K-1]",
inputs,
)

def rho_c_p_eff(self, T):
"""Effective volumetric heat capacity [J.m-3.K-1]"""
return (
Expand Down
8 changes: 6 additions & 2 deletions pybamm/plotting/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class QuickPlot(object):
default color loop defined by matplotlib style sheet or rcParams is used.
linestyles : list of str, optional
The linestyles to loop over when plotting. Defaults to ["-", ":", "--", "-."]
shading : str, optional
The shading to use for 2D plots. Defaults to "auto".
figsize : tuple of floats, optional
The size of the figure to make
n_rows : int, optional
Expand Down Expand Up @@ -97,6 +99,7 @@ def __init__(
labels=None,
colors=None,
linestyles=None,
shading="auto",
figsize=None,
n_rows=None,
time_unit=None,
Expand Down Expand Up @@ -140,6 +143,7 @@ def __init__(
else:
self.colors = LoopList(colors)
self.linestyles = LoopList(linestyles or ["-", ":", "--", "-."])
self.shading = shading

# Default output variables for lead-acid and lithium-ion
if output_variables is None:
Expand Down Expand Up @@ -572,7 +576,7 @@ def plot(self, t, dynamic=False):
var,
vmin=vmin,
vmax=vmax,
shading="auto",
shading=self.shading,
)
else:
self.plots[key][0][0] = ax.contourf(
Expand Down Expand Up @@ -725,7 +729,7 @@ def slider_update(self, t):
var,
vmin=vmin,
vmax=vmax,
shading="auto",
shading=self.shading,
)
else:
self.plots[key][0][0] = ax.contourf(
Expand Down

0 comments on commit 751b920

Please sign in to comment.