Skip to content

Commit

Permalink
#617 fix quickplot with multiple meshes
Browse files Browse the repository at this point in the history
  • Loading branch information
rtimms committed Oct 16, 2019
1 parent 3ce0360 commit 6618259
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pybamm/meshes/zero_dimensional_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ class SubMesh0D(SubMesh):
Parameters
----------
position : dict
A dictionary that contains the position of the spatial variable
A dictionary that contains the position of the 0D submesh (a signle point)
in space
npts : dict, optional
Number of points to be used. Included for compatibility with other meshes, but
ignored by this mesh class
Number of points to be used. Included for compatibility with other meshes,
but ignored by this mesh class
tabs : dict
A dictionary that contains information about the size and location of
the tabs. Included for compatibility with other meshes, but
Expand Down
2 changes: 1 addition & 1 deletion pybamm/quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(
# If only one mesh is passed but there are multiple models, try to use
# the same mesh for all of them
meshes = [meshes] * len(models)
elif not isinstance(models, list):
elif not isinstance(meshes, list):
raise TypeError("'meshes' must be 'pybamm.Mesh' or list")
if isinstance(solutions, pybamm.Solution):
solutions = [solutions]
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_meshes/test_scikit_fem_submesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ def test_init_failure(self):
with self.assertRaises(pybamm.DomainError):
pybamm.ScikitExponential2DSubMesh(lims, None, None)

# side not top
with self.assertRaises(pybamm.GeometryError):
pybamm.ScikitExponential2DSubMesh(None, None, None, side="bottom")


class TestScikitUser2DSubMesh(unittest.TestCase):
def test_mesh_creation(self):
Expand Down
27 changes: 22 additions & 5 deletions tests/unit/test_quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ def test_loqs_spm_base(self):
t_eval = np.linspace(0, 0.01, 2)

# SPM
options = {"thermal": "isothermal"}
for model in [pybamm.lithium_ion.SPM(options), pybamm.lead_acid.LOQS()]:
for model in [pybamm.lithium_ion.SPM(), pybamm.lead_acid.LOQS()]:
geometry = model.default_geometry
param = model.default_parameter_values
param.process_model(model)
Expand All @@ -126,15 +125,33 @@ def test_loqs_spm_base(self):
solution = solver.solve(model, t_eval)
pybamm.QuickPlot(model, mesh, solution)

# test quick plot of particle for spm
if model.name == "Single Particle Model":
output_variables = [
"X-averaged negative particle concentration [mol.m-3]",
"X-averaged positive particle concentration [mol.m-3]",
]
pybamm.QuickPlot(model, mesh, solution, output_variables)

def test_failure(self):
with self.assertRaisesRegex(TypeError, "'models' must be"):
pybamm.QuickPlot(1, None, None)
with self.assertRaisesRegex(TypeError, "'meshes' must be"):
model = pybamm.lithium_ion.SPM()
pybamm.QuickPlot(model, 1, None)
with self.assertRaisesRegex(TypeError, "'solutions' must be"):
pybamm.QuickPlot(pybamm.BaseModel(), None, 1)
geometry = model.default_geometry
param = model.default_parameter_values
param.process_model(model)
param.process_geometry(geometry)
mesh = pybamm.Mesh(
geometry, model.default_submesh_types, model.default_var_pts
)
pybamm.QuickPlot(model, mesh, 1)
with self.assertRaisesRegex(ValueError, "must provide the same"):
pybamm.QuickPlot(
pybamm.BaseModel(),
None,
model,
mesh,
[pybamm.Solution(0, 0, 0, 0, ""), pybamm.Solution(0, 0, 0, 0, "")],
)

Expand Down

0 comments on commit 6618259

Please sign in to comment.