Skip to content

Commit

Permalink
added gradient squared method
Browse files Browse the repository at this point in the history
  • Loading branch information
medha-14 committed Oct 23, 2024
1 parent 164f71e commit 2db150e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/pybamm/spatial_methods/finite_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@ def gradient_matrix(self, domain, domains):

return pybamm.Matrix(matrix)

def gradient_squared(self, symbol, discretised_symbol, boundary_conditions):
"""
Computes the square of the gradient of a symbol.
Parameters
----------
symbol : :class:`pybamm.Symbol`
The symbol for which to compute the gradient squared.
discretised_symbol : :class:`pybamm.Vector`
The discretised variable for which to compute the gradient squared.
boundary_conditions : dict
Boundary conditions for the symbol.
Returns
-------
:class:`pybamm.Vector`
The gradient squared of the symbol.
"""
domain = symbol.domain
gradient_matrix = self.gradient_matrix(domain, symbol.domains)

Check warning on line 150 in src/pybamm/spatial_methods/finite_volume.py

View check run for this annotation

Codecov / codecov/patch

src/pybamm/spatial_methods/finite_volume.py#L149-L150

Added lines #L149 - L150 were not covered by tests

# Compute gradient squared: (∇u)^2 = u^T L^T L u
gradient_squared_matrix = gradient_matrix.T @ gradient_matrix
gradient_squared_result = gradient_squared_matrix @ discretised_symbol

Check warning on line 154 in src/pybamm/spatial_methods/finite_volume.py

View check run for this annotation

Codecov / codecov/patch

src/pybamm/spatial_methods/finite_volume.py#L153-L154

Added lines #L153 - L154 were not covered by tests

return gradient_squared_result

Check warning on line 156 in src/pybamm/spatial_methods/finite_volume.py

View check run for this annotation

Codecov / codecov/patch

src/pybamm/spatial_methods/finite_volume.py#L156

Added line #L156 was not covered by tests

def divergence(self, symbol, discretised_symbol, boundary_conditions):
"""Matrix-vector multiplication to implement the divergence operator.
See :meth:`pybamm.SpatialMethod.divergence`
Expand Down

0 comments on commit 2db150e

Please sign in to comment.