Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions src/pybamm/geometry/battery_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def battery_geometry(
Dictionary of model options. Necessary for "particle-size geometry",
relevant for lithium-ion chemistries.
form_factor : str, optional
The form factor of the cell. Can be "pouch" (default) or "cylindrical".
The form factor of the cell. Can be "pouch" (default).

Returns
-------
Expand Down Expand Up @@ -150,21 +150,9 @@ def battery_geometry(
},
},
}
elif form_factor == "cylindrical":
if current_collector_dimension == 0:
geometry["current collector"] = {"r_macro": {"position": 1}}
elif current_collector_dimension == 1:
geometry["current collector"] = {
"r_macro": {"min": geo.r_inner, "max": 1},
}
else:
raise pybamm.GeometryError(
f"Invalid current collector dimension '{current_collector_dimension}' (should be 0 or 1 for "
"a 'cylindrical' battery geometry)"
)
else:
raise pybamm.GeometryError(
f"Invalid form factor '{form_factor}' (should be 'pouch' or 'cylindrical'"
f"Invalid form factor '{form_factor}' (should be 'pouch')"
)

return pybamm.Geometry(geometry)
35 changes: 0 additions & 35 deletions tests/integration/test_spatial_methods/test_finite_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from tests import (
get_mesh_for_testing,
get_p2d_mesh_for_testing,
get_cylindrical_mesh_for_testing,
)

import numpy as np
Expand Down Expand Up @@ -115,40 +114,6 @@ def get_error(n):
rates = np.log2(err_norm[:-1] / err_norm[1:])
np.testing.assert_array_less(1.99 * np.ones_like(rates), rates)

def test_cylindrical_div_convergence_quadratic(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is not related to the main change in this PR, it should not be removed

# N = sin(r) --> div(N) = sin(r)/r + cos(r)
spatial_methods = {"current collector": pybamm.FiniteVolume()}

# Function for convergence testing
def get_error(n):
# create mesh and discretisation (single particle)
mesh = get_cylindrical_mesh_for_testing(rcellpts=n)
disc = pybamm.Discretisation(mesh, spatial_methods)
submesh = mesh["current collector"]
r = submesh.nodes
r_edge = pybamm.SpatialVariableEdge("r", domain=["current collector"])

# Define flux and eqn
N = pybamm.sin(r_edge)
div_eqn = pybamm.div(N)
# Define exact solutions
div_exact = np.sin(r) / r + np.cos(r)

# Discretise and evaluate
div_eqn_disc = disc.process_symbol(div_eqn)
div_approx = div_eqn_disc.evaluate()

# Return difference between approx and exact
return div_approx[:, 0] - div_exact

# Get errors
ns = 10 * 2 ** np.arange(1, 7)
errs = {n: get_error(int(n)) for n in ns}
# expect quadratic convergence everywhere
err_norm = np.array([np.linalg.norm(errs[n], np.inf) for n in ns])
rates = np.log2(err_norm[:-1] / err_norm[1:])
np.testing.assert_array_less(1.99 * np.ones_like(rates), rates)

def test_spherical_div_convergence_quadratic(self):
# N = sin(r) --> div(N) = 2*sin(r)/r + cos(r)
spatial_methods = {"negative particle": pybamm.FiniteVolume()}
Expand Down
13 changes: 2 additions & 11 deletions tests/unit/test_geometry/test_battery_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ def test_geometry(self):
geometry = pybamm.battery_geometry()
assert "negative particle size" not in geometry

geometry = pybamm.battery_geometry(form_factor="cylindrical")
assert geometry["current collector"]["r_macro"]["position"] == 1

geometry = pybamm.battery_geometry(
form_factor="cylindrical", options={"dimensionality": 1}
)
assert geometry["current collector"]["r_macro"]["min"] == geo.r_inner
assert geometry["current collector"]["r_macro"]["max"] == 1

options = {"particle phases": "2"}
geometry = pybamm.battery_geometry(options=options)
geo = pybamm.GeometricParameters(options=options)
Expand Down Expand Up @@ -88,11 +79,11 @@ def test_geometry(self):
assert "positive secondary particle size" in geometry

def test_geometry_error(self):
with pytest.raises(pybamm.GeometryError, match="Invalid current"):
with pytest.raises(pybamm.GeometryError, match="Invalid form factor"):
pybamm.battery_geometry(
form_factor="cylindrical", options={"dimensionality": 2}
)
with pytest.raises(pybamm.GeometryError, match="Invalid form"):
with pytest.raises(pybamm.GeometryError, match="Invalid form factor"):
pybamm.battery_geometry(form_factor="triangle")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
get_mesh_for_testing,
get_p2d_mesh_for_testing,
get_1p1d_mesh_for_testing,
get_cylindrical_mesh_for_testing,
get_mesh_for_testing_symbolic,
get_spherical_mesh_for_testing_symbolic,
get_cylindrical_mesh_for_testing_symbolic,
Expand Down Expand Up @@ -74,67 +73,6 @@ def test_grad_div_shapes_Dirichlet_bcs(self):
atol=1e-6,
)

def test_cylindrical_grad_div_shapes_Dirichlet_bcs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is not related to the main change in this PR, it should not be removed

"""
Test grad and div with Dirichlet boundary conditions in cylindrical polar
coordinates
"""
# Create discretisation
mesh = get_cylindrical_mesh_for_testing()
spatial_methods = {"current collector": pybamm.FiniteVolume()}
disc = pybamm.Discretisation(mesh, spatial_methods)
submesh = mesh["current collector"]
npts = submesh.npts
npts_edges = submesh.npts + 1

# Test gradient of a constant is zero
# grad(1) = 0
constant_y = np.ones((npts, 1))
var = pybamm.Variable(
"var",
domain=["current collector"],
)
grad_eqn = pybamm.grad(var)
boundary_conditions = {
var: {
"left": (pybamm.Scalar(1), "Dirichlet"),
"right": (pybamm.Scalar(1), "Dirichlet"),
}
}
disc.bcs = boundary_conditions
disc.set_variable_slices([var])
grad_eqn_disc = disc.process_symbol(grad_eqn)
np.testing.assert_array_equal(
grad_eqn_disc.evaluate(None, constant_y), np.zeros((npts_edges, 1))
)

# Test operations on linear and quadratic in r
N = pybamm.grad(var)
div_eqn = pybamm.div(N)
boundary_conditions = {
var: {
"left": (pybamm.Scalar(submesh.edges[0]), "Dirichlet"),
"right": (pybamm.Scalar(1), "Dirichlet"),
}
}
disc.bcs = boundary_conditions
# grad(r) == 1
y_linear = submesh.nodes
grad_eqn_disc = disc.process_symbol(grad_eqn)
np.testing.assert_allclose(
grad_eqn_disc.evaluate(None, y_linear),
np.ones((npts_edges, 1)),
rtol=1e-7,
atol=1e-6,
)
# div(grad r^2) = 4
y_squared = submesh.nodes**2
div_eqn_disc = disc.process_symbol(div_eqn)
div_eval = div_eqn_disc.evaluate(None, y_squared)
np.testing.assert_allclose(
div_eval[1:-1], 4 * np.ones((npts - 2, 1)), rtol=1e-7, atol=1e-6
)

def test_spherical_grad_div_shapes_Dirichlet_bcs(self):
"""
Test grad and div with Dirichlet boundary conditions in spherical polar
Expand Down Expand Up @@ -388,74 +326,6 @@ def test_grad_div_shapes_Dirichlet_and_Neumann_bcs(self):
atol=1e-6,
)

def test_cylindrical_grad_div_shapes_Neumann_bcs(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this test is not related to the main change in this PR, it should not be removed

"""
Test grad and div with Neumann boundary conditions in cylindrical polar
coordinates
"""
# Create discretisation
mesh = get_cylindrical_mesh_for_testing()
spatial_methods = {"current collector": pybamm.FiniteVolume()}
disc = pybamm.Discretisation(mesh, spatial_methods)
submesh = mesh["current collector"]
npts = submesh.npts
npts_edges = submesh.npts + 1

# Test gradient
var = pybamm.Variable("var", domain="current collector")
grad_eqn = pybamm.grad(var)
# grad(1) = 0
constant_y = np.ones((npts, 1))
boundary_conditions = {
var: {
"left": (pybamm.Scalar(0), "Neumann"),
"right": (pybamm.Scalar(0), "Neumann"),
}
}
disc.bcs = boundary_conditions
disc.set_variable_slices([var])
grad_eqn_disc = disc.process_symbol(grad_eqn)
np.testing.assert_array_equal(
grad_eqn_disc.evaluate(None, constant_y), np.zeros((npts_edges, 1))
)
# grad(r) = 1
y_linear = submesh.nodes
boundary_conditions = {
var: {
"left": (pybamm.Scalar(1), "Neumann"),
"right": (pybamm.Scalar(1), "Neumann"),
}
}
disc.bcs = boundary_conditions
disc.set_variable_slices([var])
grad_eqn_disc = disc.process_symbol(grad_eqn)
np.testing.assert_allclose(
grad_eqn_disc.evaluate(None, y_linear),
np.ones((npts_edges, 1)),
rtol=1e-7,
atol=1e-6,
)

# Test divergence
# div(grad(r^2)) = 4 , N_left = 2*r_inner, N_right = 2
y_squared = submesh.nodes**2
N = pybamm.grad(var)
div_eqn = pybamm.div(N)
boundary_conditions = {
var: {
"left": (pybamm.Scalar(2 * submesh.edges[0]), "Neumann"),
"right": (pybamm.Scalar(2), "Neumann"),
}
}
disc.bcs = boundary_conditions
div_eqn_disc = disc.process_symbol(div_eqn)
np.testing.assert_allclose(
div_eqn_disc.evaluate(None, y_squared),
4 * np.ones((npts, 1)),
rtol=1e-7,
atol=1e-6,
)

def test_cylindrical_grad_div_shapes_Neumann_bcs_symbolic(self):
mesh = get_cylindrical_mesh_for_testing_symbolic()
spatial_methods = {"cylindrical domain": pybamm.FiniteVolume()}
Expand Down
Loading