From 4775e42395b9f351889295ee4a2e621cd7647cb9 Mon Sep 17 00:00:00 2001 From: Robert Timms Date: Tue, 1 Oct 2019 09:47:49 +0100 Subject: [PATCH] #617 improve coverage --- .../test_one_dimensional_submesh.py | 25 ++++++++++++------- .../test_meshes/test_scikit_fem_submesh.py | 6 +++++ .../test_zero_dimensional_submesh.py | 24 ++++++++++++++++++ 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 tests/unit/test_meshes/test_zero_dimensional_submesh.py diff --git a/tests/unit/test_meshes/test_one_dimensional_submesh.py b/tests/unit/test_meshes/test_one_dimensional_submesh.py index f59e186aa5..d45aff4b16 100644 --- a/tests/unit/test_meshes/test_one_dimensional_submesh.py +++ b/tests/unit/test_meshes/test_one_dimensional_submesh.py @@ -44,7 +44,9 @@ def test_symmetric_mesh_creation_no_parameters(self): } submesh_types = { - "negative particle": pybamm.GetExponential1DSubMesh(side="symmetric") + "negative particle": pybamm.GetExponential1DSubMesh( + side="symmetric", stretch=1.5 + ) } var_pts = {r: 20} mesh = pybamm.Mesh(geometry, submesh_types, var_pts) @@ -77,7 +79,7 @@ def test_left_mesh_creation_no_parameters(self): submesh_types = { "negative particle": pybamm.GetExponential1DSubMesh(side="left") } - var_pts = {r: 20} + var_pts = {r: 21} mesh = pybamm.Mesh(geometry, submesh_types, var_pts) # create mesh @@ -170,21 +172,26 @@ def test_exceptions(self): # test too many lims with self.assertRaises(pybamm.GeometryError): mesh(lims, None) - lims = [0, 1] - # error if len(edges) != npts+1 + x_n = pybamm.standard_spatial_vars.x_n + + # error if npts+1 != len(edges) + lims = {x_n: {"min": 0, "max": 1}} + npts = {x_n.id: 10} with self.assertRaises(pybamm.GeometryError): - mesh(lims, 5) + mesh(lims, npts) # error if lims[0] not equal to edges[0] - lims = [0.1, 1] + lims = {x_n: {"min": 0.1, "max": 1}} + npts = {x_n.id: len(edges) - 1} with self.assertRaises(pybamm.GeometryError): - mesh(lims, len(edges) - 1) + mesh(lims, npts) # error if lims[-1] not equal to edges[-1] - lims = [0, 0.9] + lims = {x_n: {"min": 0, "max": 10}} + npts = {x_n.id: len(edges) - 1} with self.assertRaises(pybamm.GeometryError): - mesh(lims, len(edges) - 1) + mesh(lims, npts) def test_mesh_creation_no_parameters(self): r = pybamm.SpatialVariable( diff --git a/tests/unit/test_meshes/test_scikit_fem_submesh.py b/tests/unit/test_meshes/test_scikit_fem_submesh.py index c74d5a1083..6cc0f7f300 100644 --- a/tests/unit/test_meshes/test_scikit_fem_submesh.py +++ b/tests/unit/test_meshes/test_scikit_fem_submesh.py @@ -427,6 +427,12 @@ def test_exceptions(self): with self.assertRaises(pybamm.GeometryError): mesh(lims, npts) + # error if different coordinate system + lims = {var.y: {"min": 0, "max": 1}, var.r_n: {"min": 0, "max": 1}} + npts = {var.y.id: 3, var.r_n.id: 3} + with self.assertRaises(pybamm.DomainError): + mesh(lims, npts) + if __name__ == "__main__": print("Add -v for more debug output") diff --git a/tests/unit/test_meshes/test_zero_dimensional_submesh.py b/tests/unit/test_meshes/test_zero_dimensional_submesh.py new file mode 100644 index 0000000000..12643d69c8 --- /dev/null +++ b/tests/unit/test_meshes/test_zero_dimensional_submesh.py @@ -0,0 +1,24 @@ +import pybamm +import unittest + + +class TestSubMesh0D(unittest.TestCase): + def test_exceptions(self): + position = {"x": 0, "y": 0} + with self.assertRaises(pybamm.GeometryError): + pybamm.SubMesh0D(position) + + def test_init(self): + position = {"x": 1} + mesh = pybamm.SubMesh0D(position) + mesh.add_ghost_meshes() + + +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()