Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Features

- 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))
- EvaluateAt symbol: add support for children evaluated at edges ([#5190](https://github.com/pybamm-team/PyBaMM/pull/5190))
- Added helper functions to import external 3D meshes in PyBaMM ([#5162](https://github.com/pybamm-team/PyBaMM/pull/5162))
- Added support for algebraic and differential surface form in composite models. ([#5165](https://github.com/pybamm-team/PyBaMM/pull/5165))
- Adds a composite electrode electrode soh model ([#5160](https://github.com/pybamm-team/PyBaMM/pull/5129))
Expand Down
3 changes: 3 additions & 0 deletions src/pybamm/expression_tree/unary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,9 @@ def _evaluate_for_shape(self):
"""See :meth:`pybamm.Symbol.evaluate_for_shape_using_domain()`"""
return pybamm.evaluate_for_shape_using_domain(self.domains)

def _evaluates_on_edges(self, dimension: str) -> bool:
return False


class UpwindDownwind(SpatialOperator):
"""
Expand Down
7 changes: 5 additions & 2 deletions src/pybamm/spatial_methods/finite_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -1357,7 +1357,10 @@ def evaluate_at(self, symbol, discretised_child, position):
# Get mesh nodes
domain = discretised_child.domain
mesh = self.mesh[domain]
nodes = mesh.nodes
if symbol.children[0].evaluates_on_edges("primary"):
nodes = mesh.edges
else:
nodes = mesh.nodes
if hasattr(mesh, "length"):
domain = discretised_child.domain
raise NotImplementedError(
Expand All @@ -1369,7 +1372,7 @@ def evaluate_at(self, symbol, discretised_child, position):
index = np.argmin(np.abs(nodes - position.value))

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,22 @@ def test_evaluate_at(self):
y = np.arange(n)[:, np.newaxis]
assert evaluate_at_disc.evaluate(y=y) == y[idx]

disc.bcs = {
var: {
"left": (pybamm.Scalar(0), "Dirichlet"),
"right": (pybamm.Scalar(n - 1), "Dirichlet"),
}
}
position = pybamm.Scalar(mesh["negative electrode"].edges[-1])
downwind_var = pybamm.downwind(var)
evaluate_at = pybamm.EvaluateAt(downwind_var, position)

assert evaluate_at.evaluates_on_edges("primary") is False

evaluate_at_disc = disc.process_symbol(evaluate_at)

assert evaluate_at_disc.evaluate(y=y) == n - 1

mesh = get_mesh_for_testing_symbolic()
spatial_methods = {"domain": pybamm.FiniteVolume()}
var = pybamm.Variable("var", domain="domain")
Expand Down