Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 3114 check coord #3394

Closed
wants to merge 12 commits into from
6 changes: 5 additions & 1 deletion pybamm/expression_tree/independent_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import pybamm

KNOWN_COORD_SYS = ["cartesian", "cylindrical polar", "spherical polar"]
KNOWN_COORD_SYS = ["cartesian", "cylindrical polar", "spherical polar","none"]
kratman marked this conversation as resolved.
Show resolved Hide resolved


class IndependentVariable(pybamm.Symbol):
Expand Down Expand Up @@ -131,6 +131,10 @@ def __init__(
raise pybamm.DomainError(
"domain cannot be particle if name is '{}'".format(name)
)
# check coord_sys against KNOWN_COORD_SYS
if coord_sys not in KNOWN_COORD_SYS:
raise ValueError(
f"Coordinate system is {coord_sys}, not in cartesian, cylindrical polar, spherical polar, none")
RuiheLi marked this conversation as resolved.
Show resolved Hide resolved

def create_copy(self):
"""See :meth:`pybamm.Symbol.new_copy()`."""
Expand Down
22 changes: 20 additions & 2 deletions pybamm/spatial_methods/finite_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,29 @@ def divergence(self, symbol, discretised_symbol, boundary_conditions):
out = divergence_matrix @ ((r_edges**2) * discretised_symbol)
elif submesh.coord_sys == "cylindrical polar":
out = divergence_matrix @ (r_edges * discretised_symbol)
else:
elif submesh.coord_sys == "cartesian":
out = divergence_matrix @ discretised_symbol

elif submesh.coord_sys == "none":
# what should we do now
print("It is none!")
out = divergence_matrix @ discretised_symbol
kratman marked this conversation as resolved.
Show resolved Hide resolved
else:
RuiheLi marked this conversation as resolved.
Show resolved Hide resolved
raise ValueError(
f"Coordinate system is {submesh.coord_sys}, not in cartesian, cylindrical polar, spherical polar, none")
return out

def check_coordinate_system(self, symbol):
"""
Double check coordinate system
"""
submesh = self.mesh[symbol.domain]
if submesh.coord_sys not in ["cylindrical polar", "spherical polar","cartesian","none"]:
raise ValueError(
f"Coordinate system is {submesh.coord_sys}, not in cartesian, cylindrical polar, spherical polar")
kratman marked this conversation as resolved.
Show resolved Hide resolved
return



def divergence_matrix(self, domains):
"""
Divergence matrix for finite volumes in the appropriate domain.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ def test_concatenation(self):
with self.assertRaisesRegex(pybamm.ShapeError, "child must have size n_nodes"):
fin_vol.concatenation(edges)

def test_invalid_coordinate_system(self):
with self.assertRaises(ValueError):
pybamm.SpatialVariableEdge(
"x_s",
domain=["separator"],
auxiliary_domains={"secondary": "current collector"},
coord_sys="cartesian_2",
)

def test_discretise_diffusivity_times_spatial_operator(self):
# Setup mesh and discretisation
mesh = get_mesh_for_testing()
Expand Down
Loading