Skip to content
Merged
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
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
Loading