Skip to content

Commit 181514e

Browse files
committed
#741 coverage
1 parent 3413dc4 commit 181514e

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Features
44

5+
- Changed finite volume discretisation to use exact values provided by Neumann boundary conditions when computing the gradient ([#748](https://github.com/pybamm-team/PyBaMM/pull/748))
56
- Generalized importing of external variables ([#728](https://github.com/pybamm-team/PyBaMM/pull/728))
67
- Separated active and inactive material volume fractions ([#726](https://github.com/pybamm-team/PyBaMM/pull/726))
78
- Added submodels for tortuosity ([#726](https://github.com/pybamm-team/PyBaMM/pull/726))

pybamm/spatial_methods/finite_volume.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,11 @@ def gradient(self, symbol, discretised_symbol, boundary_conditions):
7171
# Add Dirichlet boundary conditions, if defined
7272
if symbol.id in boundary_conditions:
7373
bcs = boundary_conditions[symbol.id]
74-
# add ghost nodes and update domain
75-
discretised_symbol, domain = self.add_ghost_nodes(
76-
symbol, discretised_symbol, bcs
77-
)
74+
if any(bc[1] == "Dirichlet" for bc in bcs.values()):
75+
# add ghost nodes and update domain
76+
discretised_symbol, domain = self.add_ghost_nodes(
77+
symbol, discretised_symbol, bcs
78+
)
7879

7980
# note in 1D spherical grad and normal grad are the same
8081
gradient_matrix = self.gradient_matrix(domain)
@@ -85,7 +86,8 @@ def gradient(self, symbol, discretised_symbol, boundary_conditions):
8586
# Add Neumann boundary conditions, if defined
8687
if symbol.id in boundary_conditions:
8788
bcs = boundary_conditions[symbol.id]
88-
out = self.add_neumann_values(symbol, out, bcs, domain)
89+
if any(bc[1] == "Neumann" for bc in bcs.values()):
90+
out = self.add_neumann_values(symbol, out, bcs, domain)
8991

9092
return out
9193

tests/unit/test_spatial_methods/test_finite_volume/test_finite_volume.py

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_discretise_diffusivity_times_spatial_operator(self):
8989
pybamm.div(2 * pybamm.grad(var)),
9090
pybamm.div(2 * pybamm.grad(var)) + 3 * var,
9191
-2 * pybamm.div(var * pybamm.grad(var) + 2 * pybamm.grad(var)),
92+
pybamm.laplacian(var),
9293
]:
9394
# Check that the equation can be evaluated in each case
9495
# Dirichlet

tests/unit/test_spatial_methods/test_finite_volume/test_ghost_nodes.py tests/unit/test_spatial_methods/test_finite_volume/test_ghost_nodes_and_neumann.py

+4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,13 @@ def test_add_ghost_nodes(self):
4949
bcs = {"left": (pybamm.Scalar(0), "x"), "right": (pybamm.Scalar(3), "Neumann")}
5050
with self.assertRaisesRegex(ValueError, "boundary condition must be"):
5151
sp_meth.add_ghost_nodes(var, discretised_symbol, bcs)
52+
with self.assertRaisesRegex(ValueError, "boundary condition must be"):
53+
sp_meth.add_neumann_values(var, discretised_symbol, bcs, var.domain)
5254
bcs = {"left": (pybamm.Scalar(0), "Neumann"), "right": (pybamm.Scalar(3), "x")}
5355
with self.assertRaisesRegex(ValueError, "boundary condition must be"):
5456
sp_meth.add_ghost_nodes(var, discretised_symbol, bcs)
57+
with self.assertRaisesRegex(ValueError, "boundary condition must be"):
58+
sp_meth.add_neumann_values(var, discretised_symbol, bcs, var.domain)
5559

5660
def test_add_ghost_nodes_concatenation(self):
5761
# Set up

0 commit comments

Comments
 (0)