Skip to content

Commit

Permalink
#191 fix some bugs relating to assuming dicts are ordered
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjrobins committed May 8, 2019
1 parent 0a14aaf commit e8e060c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 32 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ matrix:
# env:
# - PYBAMM_UNIT=true
# if: type != cron
# - python: "3.5"
# env:
# - PYBAMM_UNIT=true
# if: type != cron
- python: "3.5"
env:
- PYBAMM_UNIT=true
if: type != cron
- python: "3.6"
env:
- PYBAMM_UNIT=true
Expand Down
9 changes: 7 additions & 2 deletions pybamm/meshes/submeshes.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,13 @@ def __init__(self, lims, npts):
# currently accept lims and npts as dicts. This may get changed at a future
# date depending on the form of mesh we desire for 2D/3D

spatial_lims = list(lims.values())[0]
npts = list(npts.values())[0]
# check that only one variable passed in
if len(lims) != 1:
raise ValueError("lims should only contain a single variable")

var = list(lims.keys())[0]
spatial_lims = lims[var]
npts = npts[var.id]

edges = np.linspace(spatial_lims["min"], spatial_lims["max"], npts + 1)

Expand Down
28 changes: 14 additions & 14 deletions tests/unit/test_discretisations/test_discretisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,22 +396,22 @@ def test_process_model_ode(self):

disc.process_model(model)
y0 = model.concatenated_initial_conditions
np.testing.assert_array_equal(
y0,
np.concatenate(
[
2 * np.ones_like(combined_submesh[0].nodes),
5 * np.ones_like(mesh["negative electrode"][0].nodes),
8 * np.ones_like(mesh["negative electrode"][0].nodes),
]
),
)
y0_expect = np.array([])
for var, init in model.initial_conditions.items():
if var.id == c.id:
vect = init.evaluate() * np.ones_like(combined_submesh[0].nodes)
else:
vect = init.evaluate() * np.ones_like(mesh[var.domain[0]][0].nodes)

y0_expect = np.concatenate([y0_expect,vect])

np.testing.assert_array_equal(y0,y0_expect)

# grad and div are identity operators here
np.testing.assert_array_equal(y0, model.concatenated_rhs.evaluate(None, y0))
c0, T0, S0 = np.split(
y0,
np.cumsum([combined_submesh[0].npts, mesh["negative electrode"][0].npts]),
)

S0 = model.initial_conditions[S].evaluate() * np.ones_like(mesh[S.domain[0]][0].nodes)
T0 = model.initial_conditions[T].evaluate() * np.ones_like(mesh[T.domain[0]][0].nodes)
np.testing.assert_array_equal(S0 * T0, model.variables["ST"].evaluate(None, y0))

# mass matrix is identity
Expand Down
24 changes: 12 additions & 12 deletions tests/unit/test_geometry/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ def test_combine_geometries(self):
geometry1Dmicro = pybamm.Geometry1DMicro()
geometry = pybamm.Geometry(geometry1Dmacro, geometry1Dmicro)
self.assertEqual(
list(geometry.keys()),
[
set(geometry.keys()),
set([
"negative electrode",
"separator",
"positive electrode",
"negative particle",
"positive particle",
],
]),
)

# update with custom geometry
Expand All @@ -117,14 +117,14 @@ def test_combine_geometries_3D(self):
geometry1Dmicro = pybamm.Geometry1DMicro()
geometry = pybamm.Geometry(geometry3Dmacro, geometry1Dmicro)
self.assertEqual(
list(geometry.keys()),
[
set(geometry.keys()),
set([
"negative electrode",
"separator",
"positive electrode",
"negative particle",
"positive particle",
],
]),
)

with self.assertRaises(ValueError):
Expand All @@ -134,25 +134,25 @@ def test_combine_geometries_3D(self):
def test_combine_geometries_strings(self):
geometry = pybamm.Geometry("1D macro", "1D micro")
self.assertEqual(
list(geometry.keys()),
[
set(geometry.keys()),
set([
"negative electrode",
"separator",
"positive electrode",
"negative particle",
"positive particle",
],
]),
)
geometry = pybamm.Geometry("3D macro", "1D micro")
self.assertEqual(
list(geometry.keys()),
[
set(geometry.keys()),
set([
"negative electrode",
"separator",
"positive electrode",
"negative particle",
"positive particle",
],
]),
)


Expand Down

0 comments on commit e8e060c

Please sign in to comment.