Skip to content

Commit

Permalink
#933 merge #546
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Apr 9, 2020
2 parents d6a7f39 + 1fcbd4e commit 23c6e2a
Show file tree
Hide file tree
Showing 40 changed files with 248 additions and 182 deletions.
1 change: 0 additions & 1 deletion .requirements-docs.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@ scikit-fem>=0.2.0
casadi>=3.5.0
guzzle-sphinx-theme
sphinx>=1.5
python-Levenshtein>=0.12.0
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
## Bug fixes

- Reformatted electrolyte submodels ([#927](https://github.com/pybamm-team/PyBaMM/pull/927))
- Reformatted convection submodels ([#635](https://github.com/pybamm-team/PyBaMM/pull/635))

## Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion docs/source/spatial_methods/zero_dimensional_method.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Zero Dimensional Spatial Method
===============================

.. autoclass:: pybamm.ZeroDimensionalMethod
.. autoclass:: pybamm.ZeroDimensionalSpatialMethod
:members:
2 changes: 1 addition & 1 deletion examples/notebooks/change-settings.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
"macroscale FiniteVolume\n",
"negative particle FiniteVolume\n",
"positive particle FiniteVolume\n",
"current collector ZeroDimensionalMethod\n"
"current collector ZeroDimensionalSpatialMethod\n"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/models/SPM.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@
"macroscale is discretised using FiniteVolume method\n",
"negative particle is discretised using FiniteVolume method\n",
"positive particle is discretised using FiniteVolume method\n",
"current collector is discretised using ZeroDimensionalMethod method\n"
"current collector is discretised using ZeroDimensionalSpatialMethod method\n"
]
}
],
Expand Down
3 changes: 1 addition & 2 deletions examples/scripts/DFN.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@


# load model
model = pybamm.lithium_ion.DFN({"operating mode": "voltage"})
model = pybamm.lithium_ion.DFN()

# create geometry
geometry = model.default_geometry

# load parameter values and process model and geometry
param = model.default_parameter_values
param.update({"Voltage function [V]": 4.1}, check_already_exists=False)
param.process_model(model)
param.process_geometry(geometry)

Expand Down
2 changes: 1 addition & 1 deletion examples/scripts/compare_extrapolations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"negative particle": pybamm.FiniteVolume(method_options),
"positive particle": pybamm.FiniteVolume(method_options),
"macroscale": pybamm.FiniteVolume(method_options),
"current collector": pybamm.ZeroDimensionalMethod(),
"current collector": pybamm.ZeroDimensionalSpatialMethod(),
}
sim_quad = pybamm.Simulation(
model_quad, spatial_methods=spatial_methods, var_pts=var_pts
Expand Down
2 changes: 1 addition & 1 deletion pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def version(formatted=False):
# Spatial Methods
#
from .spatial_methods.spatial_method import SpatialMethod
from .spatial_methods.zero_dimensional_method import ZeroDimensionalMethod
from .spatial_methods.zero_dimensional_method import ZeroDimensionalSpatialMethod
from .spatial_methods.finite_volume import FiniteVolume
from .spatial_methods.scikit_finite_element import ScikitFiniteElement

Expand Down
2 changes: 1 addition & 1 deletion pybamm/discretisations/discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,7 @@ def create_mass_matrix(self, model):
mass_list.append(mass)
if isinstance(
self.spatial_methods[var.domain[0]],
(pybamm.ZeroDimensionalMethod, pybamm.FiniteVolume),
(pybamm.ZeroDimensionalSpatialMethod, pybamm.FiniteVolume),
):
# for 0D methods the mass matrix is just a scalar 1 and for
# finite volumes the mass matrix is identity, so no need to
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Electrolyte conductivity [S.m-1],[function]conductivity_Gu1997,,
Darken thermodynamic factor,[function]darken_thermodynamic_factor_Chapman1968,,
Electrolyte diffusivity [m2.s-1],[function]diffusivity_Gu1997,,
Electrolyte viscosity [kg.m-1.s-1],[function]viscosity_Chapman1968,,
MacInnes t_plus function,[function]macinnes_tplus_function,,
,,,
# Other species properties,,,
Oxygen diffusivity [m2.s-1],2.1e-9,cussler2009diffusion
Expand Down
23 changes: 12 additions & 11 deletions pybamm/models/full_battery_models/base_battery_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ def default_spatial_methods(self):
}
if self.options["dimensionality"] == 0:
# 0D submesh - use base spatial method
base_spatial_methods["current collector"] = pybamm.ZeroDimensionalMethod()
base_spatial_methods[
"current collector"
] = pybamm.ZeroDimensionalSpatialMethod()
elif self.options["dimensionality"] == 1:
base_spatial_methods["current collector"] = pybamm.FiniteVolume()
elif self.options["dimensionality"] == 2:
Expand Down Expand Up @@ -165,7 +167,7 @@ def options(self, extra_options):

# Options that are incompatible with models
if isinstance(self, pybamm.lithium_ion.BaseModel):
if options["convection"] is True:
if options["convection"] is not False:
raise pybamm.OptionError(
"convection not implemented for lithium-ion models"
)
Expand Down Expand Up @@ -205,6 +207,14 @@ def options(self, extra_options):
raise pybamm.OptionError(
"surface form '{}' not recognised".format(options["surface form"])
)
if options["convection"] not in [
False,
"uniform transverse",
"full transverse",
]:
raise pybamm.OptionError(
"convection option '{}' not recognised".format(options["convection"])
)
if options["current collector"] not in [
"uniform",
"potential pair",
Expand Down Expand Up @@ -234,7 +244,6 @@ def options(self, extra_options):
if options["dimensionality"] == 0:
if options["current collector"] not in [
"uniform",
"potential pair quite conductive averaged",
]:
raise pybamm.OptionError(
"current collector model must be uniform in 0D model"
Expand All @@ -243,13 +252,6 @@ def options(self, extra_options):
raise pybamm.OptionError(
"cannot have transverse convection in 0D model"
)
if (
options["current collector"] == "potential pair quite conductive averaged"
and options["dimensionality"] == 2
):
raise pybamm.OptionError(
"potential pair quite conductive average model not valid in 2D"
)
if options["particle"] not in ["Fickian diffusion", "fast diffusion"]:
raise pybamm.OptionError(
"particle model '{}' not recognised".format(options["particle"])
Expand Down Expand Up @@ -555,7 +557,6 @@ def set_current_collector_submodel(self):

if self.options["current collector"] in [
"uniform",
"potential pair quite conductive averaged",
]:
submodel = pybamm.current_collector.Uniform(self.param)
elif self.options["current collector"] == "potential pair":
Expand Down
50 changes: 31 additions & 19 deletions pybamm/models/full_battery_models/lead_acid/basic_full.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ def __init__(self, name="Full model"):
pressure_n = pybamm.Variable(
"Negative electrolyte pressure", domain="negative electrode",
)
pressure_s = pybamm.Variable(
"Separator electrolyte pressure", domain="separator",
)
pressure_p = pybamm.Variable(
"Positive electrolyte pressure", domain="positive electrode",
)
pressure = pybamm.Concatenation(pressure_n, pressure_s, pressure_p)

# Constant temperature
T = param.T_init
Expand Down Expand Up @@ -140,32 +136,43 @@ def __init__(self, name="Full model"):
######################
# Convection
######################
v = -pybamm.grad(pressure)
v_n = -pybamm.grad(pressure_n)
v_p = -pybamm.grad(pressure_p)
l_s = pybamm.geometric_parameters.l_s
l_n = pybamm.geometric_parameters.l_n
x_s = pybamm.SpatialVariable("x_s", domain="separator")

# Difference in negative and positive electrode velocities determines the
# velocity in the separator
v_box_n_right = param.beta_n * i_cell
v_box_p_left = param.beta_p * i_cell
d_vbox_s__dx = (v_box_p_left - v_box_n_right) / l_s
v_n_right = param.beta_n * i_cell
v_p_left = param.beta_p * i_cell
d_v_s__dx = (v_p_left - v_n_right) / l_s

# Simple formula for velocity in the separator
dVbox_dz = pybamm.Concatenation(
div_V_s = -d_v_s__dx
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
v = pybamm.Concatenation(v_n, v_s, v_p)
div_V = pybamm.Concatenation(
pybamm.PrimaryBroadcast(0, "negative electrode"),
pybamm.PrimaryBroadcast(-d_vbox_s__dx, "separator"),
pybamm.PrimaryBroadcast(div_V_s, "separator"),
pybamm.PrimaryBroadcast(0, "positive electrode"),
)
beta = pybamm.Concatenation(
pybamm.PrimaryBroadcast(param.beta_n, "negative electrode"),
pybamm.PrimaryBroadcast(0, "separator"),
pybamm.PrimaryBroadcast(param.beta_p, "positive electrode"),
)
self.algebraic[pressure] = pybamm.div(v) + dVbox_dz - beta * j
self.boundary_conditions[pressure] = {
# Simple formula for velocity in the separator
self.algebraic[pressure_n] = pybamm.div(v_n) - param.beta_n * j_n
self.algebraic[pressure_p] = pybamm.div(v_p) - param.beta_p * j_p
self.boundary_conditions[pressure_n] = {
"left": (pybamm.Scalar(0), "Neumann"),
"right": (pybamm.Scalar(0), "Dirichlet"),
}
self.boundary_conditions[pressure_p] = {
"left": (pybamm.Scalar(0), "Dirichlet"),
"right": (pybamm.Scalar(0), "Neumann"),
}
self.initial_conditions[pressure] = pybamm.Scalar(0)
self.initial_conditions[pressure_n] = pybamm.Scalar(0)
self.initial_conditions[pressure_p] = pybamm.Scalar(0)

######################
# Current in the electrolyte
Expand Down Expand Up @@ -237,7 +244,7 @@ def __init__(self, name="Full model"):
######################
# Electrolyte concentration
######################
N_e = -tor * param.D_e(c_e, T) * pybamm.grad(c_e) + c_e * v
N_e = -tor * param.D_e(c_e, T) * pybamm.grad(c_e) + param.C_e * c_e * v
s = pybamm.Concatenation(
-pybamm.PrimaryBroadcast(param.s_plus_n_S, "negative electrode"),
pybamm.PrimaryBroadcast(0, "separator"),
Expand All @@ -247,6 +254,7 @@ def __init__(self, name="Full model"):
-pybamm.div(N_e) / param.C_e
+ (s - param.t_plus(c_e)) * j / param.gamma_e
- c_e * deps_dt
- c_e * div_V
)
self.boundary_conditions[c_e] = {
"left": (pybamm.Scalar(0), "Neumann"),
Expand Down Expand Up @@ -276,6 +284,10 @@ def __init__(self, name="Full model"):
- param.U_n_ref
+ pot * phi_s_p,
"Terminal voltage [V]": param.U_p_ref - param.U_n_ref + pot * voltage,
"x [m]": pybamm.standard_spatial_vars.x * param.L_x,
"x": pybamm.standard_spatial_vars.x,
"Volume-averaged velocity": v,
"X-averaged separator transverse volume-averaged velocity": div_V_s,
}
self.events.extend(
[
Expand Down
5 changes: 1 addition & 4 deletions pybamm/models/full_battery_models/lead_acid/higher_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ def set_current_collector_submodel(self):

if self.options["current collector"] in [
"uniform",
"potential pair quite conductive averaged",
]:
submodel = cc.Uniform(self.param)
elif self.options["current collector"] == "potential pair quite conductive":
Expand Down Expand Up @@ -300,9 +299,7 @@ def __init__(self, options=None, name="Extended composite model (average)"):
def set_electrolyte_diffusion_submodel(self):
self.submodels[
"electrolyte diffusion"
] = pybamm.electrolyte.stefan_maxwell.diffusion.Composite(
self.param, extended="average"
)
] = pybamm.electrolyte_diffusion.Composite(self.param, extended="average")

def set_other_species_diffusion_submodels(self):
if "oxygen" in self.options["side reactions"]:
Expand Down
1 change: 0 additions & 1 deletion pybamm/models/full_battery_models/lead_acid/loqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def set_current_collector_submodel(self):
if self.options["current collector"] in [
"uniform",
"potential pair quite conductive",
"potential pair quite conductive averaged",
]:
submodel = pybamm.current_collector.Uniform(self.param)
elif self.options["current collector"] == "potential pair":
Expand Down
13 changes: 7 additions & 6 deletions pybamm/models/submodels/convection/base_convection.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def _get_standard_whole_cell_velocity_variables(self, variables):
Parameters
----------
v_box : :class:`pybamm.Symbol`
The volume-averaged fluid velocity
variables : dict
The existing variables in the model
Returns
-------
Expand Down Expand Up @@ -58,8 +58,8 @@ def _get_standard_whole_cell_acceleration_variables(self, variables):
Parameters
----------
v_box : :class:`pybamm.Symbol`
The volume-averaged fluid velocity
variables : dict
The existing variables in the model
Returns
-------
Expand Down Expand Up @@ -93,8 +93,8 @@ def _get_standard_whole_cell_pressure_variables(self, variables):
Parameters
----------
p : :class:`pybamm.Symbol`
The fluid pressure
variables : dict
The existing variables in the model
Returns
-------
Expand All @@ -118,6 +118,7 @@ def _separator_velocity(self, variables):
----------
variables : dict
Dictionary of variables in the whole model.
Returns
-------
v_box_s : :class:`pybamm.Symbol`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,6 @@ class BaseThroughCellModel(BaseModel):
def __init__(self, param):
super().__init__(param)

def _get_separator_velocity(self, variables):
# Set up
param = self.param
l_n = pybamm.geometric_parameters.l_n
x_s = pybamm.standard_spatial_vars.x_s

# Transverse velocity in the separator determines through-cell velocity
div_Vbox_s = variables[
"X-averaged separator transverse volume-averaged acceleration"
]
i_boundary_cc = variables["Current collector current density"]
v_box_n_right = param.beta_n * pybamm.PrimaryBroadcast(
i_boundary_cc, "separator"
)
div_v_box_s_av = -div_Vbox_s
div_v_box_s = pybamm.PrimaryBroadcast(div_v_box_s_av, "separator")

# Simple formula for velocity in the separator
v_box_s = div_v_box_s_av * (x_s - l_n) + v_box_n_right

variables = self._get_standard_sep_velocity_variables(v_box_s, div_v_box_s)

return variables

def get_coupled_variables(self, variables):

variables.update(self._get_separator_velocity(variables))
variables.update(self._get_standard_whole_cell_velocity_variables(variables))
variables.update(
self._get_standard_whole_cell_acceleration_variables(variables)
)
variables.update(self._get_standard_whole_cell_pressure_variables(variables))

return variables

def _get_standard_sep_velocity_variables(self, v_box_s, div_v_box_s):
"""Volume-averaged velocity in the separator"""

Expand Down
Loading

0 comments on commit 23c6e2a

Please sign in to comment.