diff --git a/pybamm/expression_tree/symbol.py b/pybamm/expression_tree/symbol.py index 1bea14eeb1..0bb30419e6 100644 --- a/pybamm/expression_tree/symbol.py +++ b/pybamm/expression_tree/symbol.py @@ -112,9 +112,16 @@ def is_matrix_x(expr, x): if is_constant(expr): result = expr.evaluate_ignoring_errors(t=None) - return (issparse(result) and np.all(result.__dict__["data"] == x)) or ( - isinstance(result, np.ndarray) and np.all(result == x) - ) + return ( + issparse(result) + and ( + (x == 0 and np.prod(len(result.__dict__["data"])) == 0) + or ( + len(result.__dict__["data"]) == np.prod(result.shape) + and np.all(result.__dict__["data"] == x) + ) + ) + ) or (isinstance(result, np.ndarray) and np.all(result == x)) else: return False diff --git a/pybamm/spatial_methods/finite_volume.py b/pybamm/spatial_methods/finite_volume.py index d9851d1d17..65e6fad18d 100644 --- a/pybamm/spatial_methods/finite_volume.py +++ b/pybamm/spatial_methods/finite_volume.py @@ -230,7 +230,7 @@ def laplacian(self, symbol, discretised_symbol, boundary_conditions): return self.divergence(grad, grad, boundary_conditions) def integral(self, child, discretised_child, integration_dimension): - """Vector-vector dot product to implement the integral operator. """ + """Vector-vector dot product to implement the integral operator.""" integration_vector = self.definite_integral_matrix( child, integration_dimension=integration_dimension ) @@ -315,9 +315,9 @@ def definite_integral_matrix( # repeat matrix for each node in higher dimensions third_dim_repeats = self._get_auxiliary_domain_repeats( { - k: v for k, v in domains.items() if ( - k == "tertiary" or k == "quaternary" - ) + k: v + for k, v in domains.items() + if (k == "tertiary" or k == "quaternary") } ) # generate full matrix from the submatrix @@ -330,7 +330,7 @@ def definite_integral_matrix( return pybamm.Matrix(csr_matrix(matrix)) def indefinite_integral(self, child, discretised_child, direction): - """Implementation of the indefinite integral operator. """ + """Implementation of the indefinite integral operator.""" # Different integral matrix depending on whether the integrand evaluates on # edges or nodes