Skip to content

Commit 0b92287

Browse files
authored
Fix non-deterministic ShapeError in 3D FEM gradient method (#5143)
* adding patch to fix 3D FEM CI errors * updating changelog
1 parent d421e3a commit 0b92287

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
## Bug fixes
1919

20+
- Fix non-deterministic ShapeError in 3D FEM gradient method ([#5143](https://github.com/pybamm-team/PyBaMM/pull/5143))
2021
- Fixes negative electrode boundary values for half-cell voltage contributions. ([#5139](https://github.com/pybamm-team/PyBaMM/pull/5139))
2122
- Makes `A_cc` L_z * L_y * number of layers ([#5138](https://github.com/pybamm-team/PyBaMM/pull/5138))
2223
- Fixes `TimeIntegral` expression node summation when dependent on an input parameter. ([#5119](https://github.com/pybamm-team/PyBaMM/pull/5119))

src/pybamm/spatial_methods/scikit_finite_element_3d.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ def gradient(self, symbol, discretised_symbol, boundary_conditions):
8282
:class:`pybamm.Concatenation`
8383
The 3D gradient as concatenation of x, y, z or z, r, theta components
8484
"""
85+
8586
skfem = import_optional_dependency("skfem")
8687
domain = symbol.domain[0]
8788
mesh = self.mesh[domain]
@@ -98,6 +99,12 @@ def mass_form(u, v, w):
9899
mass = skfem.asm(mass_form, mesh.basis)
99100
mass_inv = pybamm.Matrix(inv(csc_matrix(mass)))
100101

102+
if isinstance(discretised_symbol, pybamm.Scalar): # pragma: no cover
103+
zeros = pybamm.Vector(np.zeros((mesh.npts, 1)))
104+
grad = pybamm.Concatenation(zeros, zeros, zeros, check_domain=False)
105+
grad.copy_domains(symbol)
106+
return grad
107+
101108
grad_x = mass_inv @ (grad_x_matrix @ discretised_symbol)
102109
grad_y = mass_inv @ (grad_y_matrix @ discretised_symbol)
103110
grad_z = mass_inv @ (grad_z_matrix @ discretised_symbol)

0 commit comments

Comments
 (0)