Skip to content

Commit

Permalink
#617 mesh tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Sep 30, 2019
1 parent 47d0e2a commit 8df1cb4
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 260 deletions.
50 changes: 0 additions & 50 deletions tests/unit/test_meshes/test_chebyshev_submesh.py

This file was deleted.

119 changes: 0 additions & 119 deletions tests/unit/test_meshes/test_exponential_submesh.py

This file was deleted.

199 changes: 199 additions & 0 deletions tests/unit/test_meshes/test_one_dimensional_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions tests/unit/test_meshes/test_uniform_submesh.py

This file was deleted.

Loading

0 comments on commit 8df1cb4

Please sign in to comment.