Skip to content

Commit 47ab807

Browse files
authored
Merge branch 'develop' into pre-commit-ci-update-config
2 parents 99a37e9 + 5d1ee71 commit 47ab807

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Features
44

55
- Added the `num_steps_no_progress` and `t_no_progress` options in the `IDAKLUSolver` to early terminate the simulation if little progress is detected. ([#5201](https://github.com/pybamm-team/PyBaMM/pull/5201))
6+
- EvaluateAt symbol: add support for children evaluated at edges ([#5190](https://github.com/pybamm-team/PyBaMM/pull/5190))
67
- Added helper functions to import external 3D meshes in PyBaMM ([#5162](https://github.com/pybamm-team/PyBaMM/pull/5162))
78
- Added support for algebraic and differential surface form in composite models. ([#5165](https://github.com/pybamm-team/PyBaMM/pull/5165))
89
- Adds a composite electrode electrode soh model ([#5160](https://github.com/pybamm-team/PyBaMM/pull/5129))

src/pybamm/expression_tree/unary_operators.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,6 +1288,9 @@ def _evaluate_for_shape(self):
12881288
"""See :meth:`pybamm.Symbol.evaluate_for_shape_using_domain()`"""
12891289
return pybamm.evaluate_for_shape_using_domain(self.domains)
12901290

1291+
def _evaluates_on_edges(self, dimension: str) -> bool:
1292+
return False
1293+
12911294

12921295
class UpwindDownwind(SpatialOperator):
12931296
"""

src/pybamm/spatial_methods/finite_volume.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,10 @@ def evaluate_at(self, symbol, discretised_child, position):
13571357
# Get mesh nodes
13581358
domain = discretised_child.domain
13591359
mesh = self.mesh[domain]
1360-
nodes = mesh.nodes
1360+
if symbol.children[0].evaluates_on_edges("primary"):
1361+
nodes = mesh.edges
1362+
else:
1363+
nodes = mesh.nodes
13611364
if hasattr(mesh, "length"):
13621365
domain = discretised_child.domain
13631366
raise NotImplementedError(
@@ -1369,7 +1372,7 @@ def evaluate_at(self, symbol, discretised_child, position):
13691372
index = np.argmin(np.abs(nodes - position.value))
13701373

13711374
# Create a sparse matrix with a 1 at the index
1372-
sub_matrix = csr_matrix(([1], ([0], [index])), shape=(1, mesh.npts))
1375+
sub_matrix = csr_matrix(([1], ([0], [index])), shape=(1, len(nodes)))
13731376
# repeat across auxiliary domains
13741377
matrix = csr_matrix(kron(eye(repeats), sub_matrix))
13751378

tests/unit/test_spatial_methods/test_finite_volume/test_finite_volume.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,22 @@ def test_evaluate_at(self):
673673
y = np.arange(n)[:, np.newaxis]
674674
assert evaluate_at_disc.evaluate(y=y) == y[idx]
675675

676+
disc.bcs = {
677+
var: {
678+
"left": (pybamm.Scalar(0), "Dirichlet"),
679+
"right": (pybamm.Scalar(n - 1), "Dirichlet"),
680+
}
681+
}
682+
position = pybamm.Scalar(mesh["negative electrode"].edges[-1])
683+
downwind_var = pybamm.downwind(var)
684+
evaluate_at = pybamm.EvaluateAt(downwind_var, position)
685+
686+
assert evaluate_at.evaluates_on_edges("primary") is False
687+
688+
evaluate_at_disc = disc.process_symbol(evaluate_at)
689+
690+
assert evaluate_at_disc.evaluate(y=y) == n - 1
691+
676692
mesh = get_mesh_for_testing_symbolic()
677693
spatial_methods = {"domain": pybamm.FiniteVolume()}
678694
var = pybamm.Variable("var", domain="domain")

0 commit comments

Comments
 (0)