diff --git a/tests/unit/test_meshes/test_chebyshev_submesh.py b/tests/unit/test_meshes/test_chebyshev_submesh.py deleted file mode 100644 index dd416bcd89..0000000000 --- a/tests/unit/test_meshes/test_chebyshev_submesh.py +++ /dev/null @@ -1,50 +0,0 @@ -import pybamm -import unittest - - -class TestChebyshev1DSubMesh(unittest.TestCase): - def test_exceptions(self): - lims = [[0, 1], [0, 1]] - with self.assertRaises(pybamm.GeometryError): - pybamm.Chebyshev1DSubMesh(lims, None) - - def test_mesh_creation_no_parameters(self): - r = pybamm.SpatialVariable( - "r", domain=["negative particle"], coord_sys="spherical polar" - ) - - geometry = { - "negative particle": { - "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} - } - } - - submesh_types = { - "negative particle": pybamm.Chebyshev1DSubMesh - } - var_pts = {r: 20} - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # create mesh - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # check boundary locations - self.assertEqual(mesh["negative particle"][0].edges[0], 0) - self.assertEqual(mesh["negative particle"][0].edges[-1], 1) - - # check number of edges and nodes - self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) - self.assertEqual( - len(mesh["negative particle"][0].edges), - len(mesh["negative particle"][0].nodes) + 1, - ) - - -if __name__ == "__main__": - print("Add -v for more debug output") - import sys - - if "-v" in sys.argv: - debug = True - pybamm.settings.debug_mode = True - unittest.main() diff --git a/tests/unit/test_meshes/test_exponential_submesh.py b/tests/unit/test_meshes/test_exponential_submesh.py deleted file mode 100644 index ce718d742f..0000000000 --- a/tests/unit/test_meshes/test_exponential_submesh.py +++ /dev/null @@ -1,119 +0,0 @@ -import pybamm -import unittest - - -class TestExponential1DSubMesh(unittest.TestCase): - def test_exceptions(self): - lims = [[0, 1], [0, 1]] - mesh = pybamm.GetExponential1DSubMesh() - with self.assertRaises(pybamm.GeometryError): - mesh(lims, None) - - def test_symmetric_mesh_creation_no_parameters(self): - r = pybamm.SpatialVariable( - "r", domain=["negative particle"], coord_sys="spherical polar" - ) - - geometry = { - "negative particle": { - "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} - } - } - - submesh_types = { - "negative particle": pybamm.GetExponential1DSubMesh( - side="symmetric" - ) - } - var_pts = {r: 20} - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # create mesh - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # check boundary locations - self.assertEqual(mesh["negative particle"][0].edges[0], 0) - self.assertEqual(mesh["negative particle"][0].edges[-1], 1) - - # check number of edges and nodes - self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) - self.assertEqual( - len(mesh["negative particle"][0].edges), - len(mesh["negative particle"][0].nodes) + 1, - ) - - def test_left_mesh_creation_no_parameters(self): - r = pybamm.SpatialVariable( - "r", domain=["negative particle"], coord_sys="spherical polar" - ) - - geometry = { - "negative particle": { - "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} - } - } - - submesh_types = { - "negative particle": pybamm.GetExponential1DSubMesh( - side="left" - ) - } - var_pts = {r: 20} - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # create mesh - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # check boundary locations - self.assertEqual(mesh["negative particle"][0].edges[0], 0) - self.assertEqual(mesh["negative particle"][0].edges[-1], 1) - - # check number of edges and nodes - self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) - self.assertEqual( - len(mesh["negative particle"][0].edges), - len(mesh["negative particle"][0].nodes) + 1, - ) - - def test_right_mesh_creation_no_parameters(self): - r = pybamm.SpatialVariable( - "r", domain=["negative particle"], coord_sys="spherical polar" - ) - - geometry = { - "negative particle": { - "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} - } - } - - submesh_types = { - "negative particle": pybamm.GetExponential1DSubMesh( - side="right" - ) - } - var_pts = {r: 20} - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # create mesh - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # check boundary locations - self.assertEqual(mesh["negative particle"][0].edges[0], 0) - self.assertEqual(mesh["negative particle"][0].edges[-1], 1) - - # check number of edges and nodes - self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) - self.assertEqual( - len(mesh["negative particle"][0].edges), - len(mesh["negative particle"][0].nodes) + 1, - ) - - -if __name__ == "__main__": - print("Add -v for more debug output") - import sys - - if "-v" in sys.argv: - debug = True - pybamm.settings.debug_mode = True - unittest.main() diff --git a/tests/unit/test_meshes/test_one_dimensional_submesh.py b/tests/unit/test_meshes/test_one_dimensional_submesh.py index fd3c38d1c4..f59e186aa5 100644 --- a/tests/unit/test_meshes/test_one_dimensional_submesh.py +++ b/tests/unit/test_meshes/test_one_dimensional_submesh.py @@ -18,6 +18,205 @@ def test_exceptions(self): pybamm.SubMesh1D(edges, None, tabs=tabs) +class TestUniform1DSubMesh(unittest.TestCase): + def test_exceptions(self): + lims = [[0, 1], [0, 1]] + with self.assertRaises(pybamm.GeometryError): + pybamm.Uniform1DSubMesh(lims, None) + + +class TestExponential1DSubMesh(unittest.TestCase): + def test_exceptions(self): + lims = [[0, 1], [0, 1]] + mesh = pybamm.GetExponential1DSubMesh() + with self.assertRaises(pybamm.GeometryError): + mesh(lims, None) + + def test_symmetric_mesh_creation_no_parameters(self): + r = pybamm.SpatialVariable( + "r", domain=["negative particle"], coord_sys="spherical polar" + ) + + geometry = { + "negative particle": { + "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} + } + } + + submesh_types = { + "negative particle": pybamm.GetExponential1DSubMesh(side="symmetric") + } + var_pts = {r: 20} + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # create mesh + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # check boundary locations + self.assertEqual(mesh["negative particle"][0].edges[0], 0) + self.assertEqual(mesh["negative particle"][0].edges[-1], 1) + + # check number of edges and nodes + self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) + self.assertEqual( + len(mesh["negative particle"][0].edges), + len(mesh["negative particle"][0].nodes) + 1, + ) + + def test_left_mesh_creation_no_parameters(self): + r = pybamm.SpatialVariable( + "r", domain=["negative particle"], coord_sys="spherical polar" + ) + + geometry = { + "negative particle": { + "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} + } + } + + submesh_types = { + "negative particle": pybamm.GetExponential1DSubMesh(side="left") + } + var_pts = {r: 20} + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # create mesh + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # check boundary locations + self.assertEqual(mesh["negative particle"][0].edges[0], 0) + self.assertEqual(mesh["negative particle"][0].edges[-1], 1) + + # check number of edges and nodes + self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) + self.assertEqual( + len(mesh["negative particle"][0].edges), + len(mesh["negative particle"][0].nodes) + 1, + ) + + def test_right_mesh_creation_no_parameters(self): + r = pybamm.SpatialVariable( + "r", domain=["negative particle"], coord_sys="spherical polar" + ) + + geometry = { + "negative particle": { + "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} + } + } + + submesh_types = { + "negative particle": pybamm.GetExponential1DSubMesh(side="right") + } + var_pts = {r: 20} + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # create mesh + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # check boundary locations + self.assertEqual(mesh["negative particle"][0].edges[0], 0) + self.assertEqual(mesh["negative particle"][0].edges[-1], 1) + + # check number of edges and nodes + self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) + self.assertEqual( + len(mesh["negative particle"][0].edges), + len(mesh["negative particle"][0].nodes) + 1, + ) + + +class TestChebyshev1DSubMesh(unittest.TestCase): + def test_exceptions(self): + lims = [[0, 1], [0, 1]] + with self.assertRaises(pybamm.GeometryError): + pybamm.Chebyshev1DSubMesh(lims, None) + + def test_mesh_creation_no_parameters(self): + r = pybamm.SpatialVariable( + "r", domain=["negative particle"], coord_sys="spherical polar" + ) + + geometry = { + "negative particle": { + "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} + } + } + + submesh_types = {"negative particle": pybamm.Chebyshev1DSubMesh} + var_pts = {r: 20} + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # create mesh + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # check boundary locations + self.assertEqual(mesh["negative particle"][0].edges[0], 0) + self.assertEqual(mesh["negative particle"][0].edges[-1], 1) + + # check number of edges and nodes + self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) + self.assertEqual( + len(mesh["negative particle"][0].edges), + len(mesh["negative particle"][0].nodes) + 1, + ) + + +class TestUser1DSubMesh(unittest.TestCase): + def test_exceptions(self): + lims = [[0, 1], [0, 1]] + edges = np.array([0, 0.3, 1]) + mesh = pybamm.GetUserSupplied1DSubMesh(edges) + # test too many lims + with self.assertRaises(pybamm.GeometryError): + mesh(lims, None) + lims = [0, 1] + + # error if len(edges) != npts+1 + with self.assertRaises(pybamm.GeometryError): + mesh(lims, 5) + + # error if lims[0] not equal to edges[0] + lims = [0.1, 1] + with self.assertRaises(pybamm.GeometryError): + mesh(lims, len(edges) - 1) + + # error if lims[-1] not equal to edges[-1] + lims = [0, 0.9] + with self.assertRaises(pybamm.GeometryError): + mesh(lims, len(edges) - 1) + + def test_mesh_creation_no_parameters(self): + r = pybamm.SpatialVariable( + "r", domain=["negative particle"], coord_sys="spherical polar" + ) + + geometry = { + "negative particle": { + "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} + } + } + + edges = np.array([0, 0.3, 1]) + submesh_types = {"negative particle": pybamm.GetUserSupplied1DSubMesh(edges)} + var_pts = {r: len(edges) - 1} + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # create mesh + mesh = pybamm.Mesh(geometry, submesh_types, var_pts) + + # check boundary locations + self.assertEqual(mesh["negative particle"][0].edges[0], 0) + self.assertEqual(mesh["negative particle"][0].edges[-1], 1) + + # check number of edges and nodes + self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) + self.assertEqual( + len(mesh["negative particle"][0].edges), + len(mesh["negative particle"][0].nodes) + 1, + ) + + if __name__ == "__main__": print("Add -v for more debug output") import sys diff --git a/tests/unit/test_meshes/test_uniform_submesh.py b/tests/unit/test_meshes/test_uniform_submesh.py deleted file mode 100644 index 17b5339f6a..0000000000 --- a/tests/unit/test_meshes/test_uniform_submesh.py +++ /dev/null @@ -1,19 +0,0 @@ -import pybamm -import unittest - - -class TestUniform1DSubMesh(unittest.TestCase): - def test_exceptions(self): - lims = [[0, 1], [0, 1]] - with self.assertRaises(pybamm.GeometryError): - pybamm.Uniform1DSubMesh(lims, None) - - -if __name__ == "__main__": - print("Add -v for more debug output") - import sys - - if "-v" in sys.argv: - debug = True - pybamm.settings.debug_mode = True - unittest.main() diff --git a/tests/unit/test_meshes/test_user_1D_submesh.py b/tests/unit/test_meshes/test_user_1D_submesh.py deleted file mode 100644 index 5916401cf3..0000000000 --- a/tests/unit/test_meshes/test_user_1D_submesh.py +++ /dev/null @@ -1,72 +0,0 @@ -import pybamm -import unittest -import numpy as np - - -class TestUser1DSubMesh(unittest.TestCase): - def test_exceptions(self): - lims = [[0, 1], [0, 1]] - edges = np.array([0, 0.3, 1]) - mesh = pybamm.GetUserSupplied1DSubMesh(edges) - # test too many lims - with self.assertRaises(pybamm.GeometryError): - mesh(lims, None) - lims = [0, 1] - - # error if len(edges) != npts+1 - with self.assertRaises(pybamm.GeometryError): - mesh(lims, 5) - - # error if lims[0] not equal to edges[0] - lims = [0.1, 1] - with self.assertRaises(pybamm.GeometryError): - mesh(lims, len(edges) - 1) - - # error if lims[-1] not equal to edges[-1] - lims = [0, 0.9] - with self.assertRaises(pybamm.GeometryError): - mesh(lims, len(edges) - 1) - - def test_mesh_creation_no_parameters(self): - r = pybamm.SpatialVariable( - "r", domain=["negative particle"], coord_sys="spherical polar" - ) - - geometry = { - "negative particle": { - "primary": {r: {"min": pybamm.Scalar(0), "max": pybamm.Scalar(1)}} - } - } - - edges = np.array([0, 0.3, 1]) - submesh_types = { - "negative particle": pybamm.GetUserSupplied1DSubMesh( - edges - ) - } - var_pts = {r: len(edges) - 1} - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # create mesh - mesh = pybamm.Mesh(geometry, submesh_types, var_pts) - - # check boundary locations - self.assertEqual(mesh["negative particle"][0].edges[0], 0) - self.assertEqual(mesh["negative particle"][0].edges[-1], 1) - - # check number of edges and nodes - self.assertEqual(len(mesh["negative particle"][0].nodes), var_pts[r]) - self.assertEqual( - len(mesh["negative particle"][0].edges), - len(mesh["negative particle"][0].nodes) + 1, - ) - - -if __name__ == "__main__": - print("Add -v for more debug output") - import sys - - if "-v" in sys.argv: - debug = True - pybamm.settings.debug_mode = True - unittest.main()