diff --git a/src/pybamm/meshes/one_dimensional_submeshes.py b/src/pybamm/meshes/one_dimensional_submeshes.py index 612bc98cea..706031a5bf 100644 --- a/src/pybamm/meshes/one_dimensional_submeshes.py +++ b/src/pybamm/meshes/one_dimensional_submeshes.py @@ -88,15 +88,19 @@ def to_json(self): class SymbolicUniform1DSubMesh(SubMesh1D): def __init__(self, lims, npts, tabs=None): spatial_var, spatial_lims, tabs = self.read_lims(lims) + coord_sys = spatial_var.coord_sys + x0 = spatial_lims["min"] if tabs is not None: - raise ValueError("Tabs not supported for symbolic uniform submesh") + raise NotImplementedError("Tabs not supported for symbolic uniform submesh") + if coord_sys != "cartesian" and spatial_lims["min"] != 0: + raise NotImplementedError( + "Symbolic uniform submesh with non-cartesian coordinates and non-zero minimum not supported" + ) npts = npts[spatial_var.name] - length = spatial_lims["max"] - spatial_lims["min"] - x0 = spatial_lims["min"] + length = spatial_lims["max"] - x0 self.edges = np.linspace(0, 1, npts + 1) self.length = length self.min = x0 - coord_sys = spatial_var.coord_sys self.nodes = (self.edges[1:] + self.edges[:-1]) / 2 self.d_edges = np.diff(self.edges) self.d_nodes = np.diff(self.nodes) diff --git a/src/pybamm/spatial_methods/finite_volume.py b/src/pybamm/spatial_methods/finite_volume.py index 904b934114..9891a191dd 100644 --- a/src/pybamm/spatial_methods/finite_volume.py +++ b/src/pybamm/spatial_methods/finite_volume.py @@ -210,19 +210,9 @@ def divergence_matrix(self, domains): matrix = csr_matrix(kron(eye(second_dim_repeats), sub_matrix)) if getattr(submesh, "length", None) is not None: if submesh.coord_sys == "spherical polar": - if submesh.min != 0: - raise AssertionError( - "Spherical polar symbolic meshes must have min r = 0" - ) - else: - return pybamm.Matrix(matrix) * (1 / submesh.length**3) + return pybamm.Matrix(matrix) * (1 / submesh.length**3) elif submesh.coord_sys == "cylindrical polar": - if submesh.min != 0: - raise AssertionError( - "Cylindrical polar symbolic meshes must have min r = 0" - ) - else: - return pybamm.Matrix(matrix) * (1 / (submesh.length**2)) + return pybamm.Matrix(matrix) * (1 / (submesh.length**2)) else: return pybamm.Matrix(matrix) * (1 / submesh.length) else: @@ -336,7 +326,15 @@ def definite_integral_matrix( # not supported by the default kron format # Note that this makes column-slicing inefficient, but this should not be an # issue - return pybamm.Matrix(csr_matrix(matrix)) + matrix = pybamm.Matrix(csr_matrix(matrix)) + if hasattr(submesh, "length"): + if submesh.coord_sys == "spherical polar": + matrix = matrix * submesh.length**3 + elif submesh.coord_sys == "cylindrical polar": + matrix = matrix * submesh.length**2 + else: + matrix = matrix * submesh.length + return matrix def indefinite_integral(self, child, discretised_child, direction): """Implementation of the indefinite integral operator.""" @@ -463,6 +461,8 @@ def indefinite_integral_matrix_edges(self, domains, direction): # add a column of zeros at each end zero_col = csr_matrix((n, 1)) sub_matrix = hstack([zero_col, sub_matrix, zero_col]) + if hasattr(submesh, "length"): + sub_matrix = sub_matrix * submesh.length # Convert to csr_matrix so that we can take the index (row-slicing), which is # not supported by the default kron format # Note that this makes column-slicing inefficient, but this should not be an @@ -508,6 +508,8 @@ def indefinite_integral_matrix_nodes(self, domains, direction): # Note that this makes column-slicing inefficient, but this should not be an # issue matrix = csr_matrix(kron(eye(second_dim_repeats), sub_matrix)) + if hasattr(submesh, "length"): + matrix = matrix * submesh.length return pybamm.Matrix(matrix)